List of usage examples for android.telephony SubscriptionInfo getSubscriptionId
public int getSubscriptionId()
From source file:hmatalonga.greenhub.models.SimCard.java
/** * Experimental call to retrieve sim operator names by subscription ids. * * @param context Application context/*from w w w.j ava 2s .c o m*/ * @return SIM operator name/names with ";" as a delimiter for many. */ private static String getSIMOperators(final Context context) { String operators = ""; if (!PermissionsUtils.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) { return operators; } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) { List<SubscriptionInfo> subscriptions = SubscriptionManager.from(context) .getActiveSubscriptionInfoList(); if (subscriptions != null && subscriptions.size() > 0) { for (SubscriptionInfo info : subscriptions) { int subId = info.getSubscriptionId(); String operator = getSimOperatorNameForSubscription(context, subId); if (operator != null && operator.length() > 0) { operators += operator + ";"; } } // Remove last delimiter if (operators.length() > 1) { operators = operators.substring(0, operators.length() - 1); } } } return operators; }
From source file:com.android.messaging.datamodel.ParticipantRefresh.java
/** * Ensure that there is a self participant corresponding to every active SIM. Also, ensure * that any other older SIM self participants are marked as inactive. *///from w ww. j a va 2s.c o m private static void refreshSelfParticipantList() { if (!OsUtil.isAtLeastL_MR1()) { return; } final DatabaseWrapper db = DataModel.get().getDatabase(); final List<SubscriptionInfo> subInfoRecords = PhoneUtils.getDefault().toLMr1() .getActiveSubscriptionInfoList(); final ArrayMap<Integer, SubscriptionInfo> activeSubscriptionIdToRecordMap = new ArrayMap<Integer, SubscriptionInfo>(); db.beginTransaction(); final Set<Integer> existingSubIds = getExistingSubIds(); try { if (subInfoRecords != null) { for (final SubscriptionInfo subInfoRecord : subInfoRecords) { final int subId = subInfoRecord.getSubscriptionId(); // If its a new subscription, add it to the database. if (!existingSubIds.contains(subId)) { db.execSQL(DatabaseHelper.getCreateSelfParticipantSql(subId)); // Add it to the local set to guard against duplicated entries returned // by subscription manager. existingSubIds.add(subId); } activeSubscriptionIdToRecordMap.put(subId, subInfoRecord); if (subId == PhoneUtils.getDefault().getDefaultSmsSubscriptionId()) { // This is the system default subscription, so update the default self. activeSubscriptionIdToRecordMap.put(ParticipantData.DEFAULT_SELF_SUB_ID, subInfoRecord); } } } // For subscriptions already in the database, refresh ParticipantColumns.SIM_SLOT_ID. for (final Integer subId : activeSubscriptionIdToRecordMap.keySet()) { final SubscriptionInfo record = activeSubscriptionIdToRecordMap.get(subId); final String displayName = DatabaseUtils.sqlEscapeString(record.getDisplayName().toString()); db.execSQL(getUpdateSelfParticipantSubscriptionInfoSql(record.getSimSlotIndex(), record.getIconTint(), displayName, ParticipantColumns.SUB_ID + " = " + subId)); } db.execSQL(getUpdateSelfParticipantSubscriptionInfoSql(ParticipantData.INVALID_SLOT_ID, Color.TRANSPARENT, "''", ParticipantColumns.SUB_ID + " NOT IN (" + Joiner.on(", ").join(activeSubscriptionIdToRecordMap.keySet()) + ")")); db.setTransactionSuccessful(); } finally { db.endTransaction(); } // Fix up conversation self ids by reverting to default self for conversations whose self // ids are no longer active. refreshConversationSelfIds(); }
From source file:android_network.hetnet.vpn_service.Util.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) public static String getSubscriptionInfo(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) return "Not supported"; if (!hasPhoneStatePermission(context)) return "No permission"; StringBuilder sb = new StringBuilder(); SubscriptionManager sm = SubscriptionManager.from(context); sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/') .append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n"); int dataid = -1; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) dataid = sm.getDefaultDataSubscriptionId(); int voiceid = -1; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) voiceid = sm.getDefaultVoiceSubscriptionId(); List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList(); if (subscriptions != null) for (SubscriptionInfo si : subscriptions) sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId()) .append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc()) .append(' ').append(si.getCarrierName()) .append(si.getSubscriptionId() == dataid ? " D" : "") .append(si.getSubscriptionId() == voiceid ? " V" : "") .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "") .append("\r\n"); if (sb.length() > 2) sb.setLength(sb.length() - 2);/*from w ww . jav a2s.c om*/ return sb.toString(); }
From source file:com.android.messaging.util.PhoneUtils.java
/** * A convenience method for iterating through all active subscriptions * * @param runnable a {@link SubscriptionRunnable} for performing work on each subscription. *//*from ww w. j a v a2 s .co m*/ public static void forEachActiveSubscription(final SubscriptionRunnable runnable) { if (OsUtil.isAtLeastL_MR1()) { final List<SubscriptionInfo> subscriptionList = getDefault().toLMr1().getActiveSubscriptionInfoList(); for (final SubscriptionInfo subscriptionInfo : subscriptionList) { runnable.runForSubscription(subscriptionInfo.getSubscriptionId()); } } else { runnable.runForSubscription(ParticipantData.DEFAULT_SELF_SUB_ID); } }
From source file:com.master.metehan.filtereagle.Util.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) public static String getSubscriptionInfo(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) return "Not supported"; if (!hasPhoneStatePermission(context)) return "No permission"; StringBuilder sb = new StringBuilder(); SubscriptionManager sm = SubscriptionManager.from(context); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/') .append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n"); int dataSubId; try {/*from w w w . j a v a2s . c o m*/ dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1); } catch (Throwable ignored) { dataSubId = -1; } Method getNetworkCountryIso = null; Method getNetworkOperator = null; Method getNetworkOperatorName = null; Method getDataEnabled = null; try { getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription", int.class); getNetworkOperator = tm.getClass().getMethod("getNetworkOperatorForSubscription", int.class); getNetworkOperatorName = tm.getClass().getMethod("getNetworkOperatorName", int.class); getDataEnabled = tm.getClass().getMethod("getDataEnabled", int.class); getNetworkCountryIso.setAccessible(true); getNetworkOperator.setAccessible(true); getNetworkOperatorName.setAccessible(true); getDataEnabled.setAccessible(true); } catch (NoSuchMethodException ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList(); if (subscriptions != null) for (SubscriptionInfo si : subscriptions) { sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId()) .append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc()) .append(' ').append(si.getCarrierName()) .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "") .append(si.getSubscriptionId() == dataSubId ? " *" : "").append("\r\n"); if (getNetworkCountryIso != null && getNetworkOperator != null && getNetworkOperatorName != null && getDataEnabled != null) try { sb.append("Network ").append(si.getSimSlotIndex() + 1).append('/') .append(si.getSubscriptionId()).append(' ') .append(getNetworkCountryIso.invoke(tm, si.getSubscriptionId())).append('/') .append(getNetworkOperator.invoke(tm, si.getSubscriptionId())).append(' ') .append(getNetworkOperatorName.invoke(tm, si.getSubscriptionId())) .append(sm.isNetworkRoaming(si.getSubscriptionId()) ? " R" : "").append(' ') .append(String.format("%B", getDataEnabled.invoke(tm, si.getSubscriptionId()))) .append("\r\n"); } catch (IllegalAccessException | InvocationTargetException ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } } if (sb.length() > 2) sb.setLength(sb.length() - 2); return sb.toString(); }
From source file:com.android.settings.datausage.CellDataPreference.java
private void disableDataForOtherSubscriptions(int subId) { List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList(); if (subInfoList != null) { for (SubscriptionInfo subInfo : subInfoList) { if (subInfo.getSubscriptionId() != subId) { mTelephonyManager.setDataEnabled(subInfo.getSubscriptionId(), false); }//from ww w. j a v a2 s. c o m } } }
From source file:com.android.settings.sim.SimBootReceiver.java
private void detectChangeAndNotify() { final int numSlots = mTelephonyManager.getSimCount(); final boolean isInProvisioning = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) == 0; boolean notificationSent = false; int numSIMsDetected = 0; int lastSIMSlotDetected = -1; // Do not create notifications on single SIM devices or when provisiong. if (numSlots < 2 || isInProvisioning) { return;//from w w w . j av a 2s .co m } // We wait until SubscriptionManager returns a valid list of Subscription informations // by checking if the list is empty. // This is not completely correct, but works for most cases. // See Bug: 18377252 List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(); if (sil == null || sil.size() < 1) { return; } for (int i = 0; i < numSlots; i++) { final SubscriptionInfo sir = Utils.findRecordBySlotId(mContext, i); final String key = SLOT_PREFIX + i; final int lastSubId = getLastSubId(key); if (sir != null) { numSIMsDetected++; final int currentSubId = sir.getSubscriptionId(); if (lastSubId == INVALID_SLOT) { setLastSubId(key, currentSubId); } else if (lastSubId != currentSubId) { createNotification(mContext); setLastSubId(key, currentSubId); notificationSent = true; } lastSIMSlotDetected = i; } else if (lastSubId != SLOT_EMPTY) { createNotification(mContext); setLastSubId(key, SLOT_EMPTY); notificationSent = true; } } if (notificationSent) { Intent intent = new Intent(mContext, SimDialogActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (numSIMsDetected == 1) { intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK); intent.putExtra(SimDialogActivity.PREFERRED_SIM, lastSIMSlotDetected); } else { intent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK); } mContext.startActivity(intent); } }
From source file:com.android.settings.datausage.CellDataPreference.java
@Override protected void performClick(View view) { final Context context = getContext(); FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, MetricsEvent.ACTION_CELL_DATA_TOGGLE, !mChecked); final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(mSubId); final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo(); if (mChecked) { // If the device is single SIM or is enabling data on the active data SIM then forgo // the pop-up. if (!Utils.showSimCardTile(getContext()) || (nextSir != null && currentSir != null && currentSir.getSubscriptionId() == nextSir.getSubscriptionId())) { setMobileDataEnabled(false); if (nextSir != null && currentSir != null && currentSir.getSubscriptionId() == nextSir.getSubscriptionId()) { disableDataForOtherSubscriptions(mSubId); }// w w w. jav a2 s. c o m return; } // disabling data; show confirmation dialog which eventually // calls setMobileDataEnabled() once user confirms. mMultiSimDialog = false; super.performClick(view); } else { // If we are showing the Sim Card tile then we are a Multi-Sim device. if (Utils.showSimCardTile(getContext())) { mMultiSimDialog = true; if (nextSir != null && currentSir != null && currentSir.getSubscriptionId() == nextSir.getSubscriptionId()) { setMobileDataEnabled(true); disableDataForOtherSubscriptions(mSubId); return; } super.performClick(view); } else { setMobileDataEnabled(true); } } }
From source file:com.android.mms.ui.MessageUtils.java
public static boolean isSmsSubIdActive(Context context, int subId) { List<SubscriptionInfo> subinfoList = SubscriptionManager.from(context).getActiveSubscriptionInfoList(); for (SubscriptionInfo subInfo : subinfoList) { if (subInfo.getSubscriptionId() == subId) { return true; }//from w w w. j a v a 2 s .c o m } return false; }
From source file:com.android.mms.ui.MessageUtils.java
public static boolean isSimMessageAccessable(Context context, int... subId) { // First, forbid to access SIM message if this is not default MMS. boolean isSmsEnable = MmsConfig.isSmsEnabled(context); if (!isSmsEnable) { MmsLog.d(TAG, "isSimMessageAccessable Sms not enabled"); return false; }/*from www . j a va2 s. c om*/ // Second, check airplane mode boolean airplaneOn = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; if (airplaneOn) { MmsLog.d(TAG, "isSimMessageAccessable airplane is On"); return false; } // Third, check whether has inserted SIM List<SubscriptionInfo> subInfoList = SubscriptionManager.from(MmsApp.getApplication()) .getActiveSubscriptionInfoList(); if (subInfoList == null || subInfoList.size() == 0) { MmsLog.d(TAG, "isSimMessageAccessable SIM not insert"); return false; } // Forth, check sms ready ISms mSmsManager = ISms.Stub.asInterface(ServiceManager.getService("isms")); if (mSmsManager == null) { MmsLog.d(TAG, "isSimMessageAccessable mSmsManager is null"); return false; } boolean isSimReady = false; try { if (subId.length == 1) { isSimReady = mSmsManager.isSmsReadyForSubscriber(subId[0]); } else { for (SubscriptionInfo subInfoRecord : subInfoList) { isSimReady = mSmsManager.isSmsReadyForSubscriber(subInfoRecord.getSubscriptionId()); if (isSimReady) { break; } } } } catch (RemoteException e) { MmsLog.e(TAG, "isSimMessageAccessable failed to get sms state"); isSimReady = false; } MmsLog.d(TAG, "isSimMessageAccessable" + isSimReady); return isSimReady; }