android.telephony.SubscriptionInfo Java Examples

The following examples show how to use android.telephony.SubscriptionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimChangedReceiver.java    From Silence with GNU General Public License v3.0 7 votes vote down vote up
private static String getDeviceSubscriptions(Context context) {
  if (Build.VERSION.SDK_INT < 22) return "1";

  SubscriptionManager    subscriptionManager = SubscriptionManager.from(context);
  List<SubscriptionInfo> activeSubscriptions = subscriptionManager.getActiveSubscriptionInfoList();

  if (activeSubscriptions == null) return "1";

  String[] subscriptions = new String[activeSubscriptions.size()];
  for(int i=0; i<activeSubscriptions.size(); i++){
    subscriptions[i] = Integer.toString(activeSubscriptions.get(i).getSubscriptionId());
  }

  Arrays.sort(subscriptions);

  return joinString(subscriptions);
}
 
Example #2
Source File: SettingsFragment.java    From sms-ticket with Apache License 2.0 7 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void fillDualSimList(PreferenceScreen preferenceScreen) {
    PreferenceCategory category = (PreferenceCategory) preferenceScreen.findPreference("sms_category");
    ListPreference preference = (ListPreference) category.findPreference(Preferences.DUALSIM_SIM);
    List<String> simIds = new ArrayList<>();
    List<String> simNames = new ArrayList<>();
    simIds.add(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    simNames.add(getString(R.string.sim_default));
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    for (SubscriptionInfo subscriptionInfo : subscriptionManager.getActiveSubscriptionInfoList()) {
        simIds.add(String.valueOf(subscriptionInfo.getSubscriptionId()));
        simNames.add(getString(R.string.sim_name, subscriptionInfo.getSimSlotIndex() + 1, subscriptionInfo
            .getDisplayName()));
    }
    preference.setEntries(simNames.toArray(new String[simNames.size()]));
    preference.setEntryValues(simIds.toArray(new String[simIds.size()]));
    preference.setDefaultValue(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
    preference.setSummary(preference.getEntry());
}
 
Example #3
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 7 votes vote down vote up
private PhoneAccountHandle subscriptionToPhoneAccountHandle(final SubscriptionInfo subInfo) {
    if (subInfo == null)
        return null;

    final TelecomManager telecomManager =
            (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
    final TelephonyManager telephonyManager =
            (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    final Iterator<PhoneAccountHandle> phoneAccounts =
            telecomManager.getCallCapablePhoneAccounts().listIterator();
    while (phoneAccounts.hasNext()) {
        final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next();
        final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
        if (subInfo.getSubscriptionId() == getSubIdForPhoneAccount(telephonyManager, phoneAccount)) {
            return phoneAccountHandle;
        }
    }

    return null;
}
 
Example #4
Source File: DialerActivity.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void call(final CharSequence number, final Context context, SubscriptionInfo subscriptionInfo) {
    try {
        if (subscriptionInfo == null) {
            context.startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse(("tel:" + number).replace("#", Uri.encode("#")))));
        } else {
            final TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
            final List<PhoneAccountHandle> list = telecomManager.getCallCapablePhoneAccounts();
            for (final PhoneAccountHandle phoneAccountHandle : list) {
                if (phoneAccountHandle.getId().contains(subscriptionInfo.getIccId())) {
                    context.startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse(("tel:" + number).replace("#", Uri.encode("#"))))
                            .putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", (Parcelable) phoneAccountHandle));
                    return;
                }
            }
            BaldToast.error(context);

        }
    } catch (SecurityException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        throw new RuntimeException(e);
    }

}
 
Example #5
Source File: EasySimMod.java    From easydeviceinfo with Apache License 2.0 6 votes vote down vote up
/**
 * Gets active multi sim info.
 *
 * You need to declare the below permission in the manifest file to use this properly
 *
 * <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 *
 * @return the active multi sim info
 */
@RequiresPermission(Manifest.permission.READ_PHONE_STATE)
public final List<SubscriptionInfo> getActiveMultiSimInfo() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && PermissionUtil.hasPermission(
      context, Manifest.permission.READ_PHONE_STATE)) {
    List<SubscriptionInfo> tempActiveSub =
        SubscriptionManager.from(context).getActiveSubscriptionInfoList();
    if (tempActiveSub == null || tempActiveSub.isEmpty()) {
      return new ArrayList<>(0);
    } else {
      return tempActiveSub;
    }
  } else {
    if (EasyDeviceInfo.debuggable) {
      Log.w(EasyDeviceInfo.nameOfLib,
          "Device is running on android version that does not support multi sim functionality!");
    }
  }
  return new ArrayList<>(0);
}
 
Example #6
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private int getDefaultVoiceSubscriptionSimSlot() {
    try {
        final TelecomManager telecomManager =
                (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        final TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        PhoneAccountHandle pah = (PhoneAccountHandle) XposedHelpers.callMethod(telecomManager,
                "getUserSelectedOutgoingPhoneAccount");
        if (pah != null) {
            PhoneAccount pa = telecomManager.getPhoneAccount(pah);
            int subId = getSubIdForPhoneAccount(telephonyManager, pa);
            SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfo(subId);
            if (si != null) {
                return si.getSimSlotIndex();
            }
        }
        return -1;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return -1;
    }
}
 
Example #7
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private boolean setDefaultSubscription(final SubType subType, final SubscriptionInfo subInfo) {
    if (subInfo == null)
        return false;

    try {
        if (subType == SubType.SMS) {
            XposedHelpers.callMethod(mSubMgr, "setDefaultSmsSubId",
                    subInfo.getSubscriptionId());
        } else if (subType == SubType.DATA) {
            XposedHelpers.callMethod(mSubMgr, "setDefaultDataSubId",
                    subInfo.getSubscriptionId());
        }
        return true;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return false;
    }
}
 
Example #8
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private List<IIconListAdapterItem> getSubItemList(final SubType subType) {
    List<IIconListAdapterItem> list = new ArrayList<>();
    if (subType == SubType.VOICE) {
        list.add(new SubListItem(null));
        final TelecomManager telecomManager = 
                (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        final TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        final Iterator<PhoneAccountHandle> phoneAccounts =
                telecomManager.getCallCapablePhoneAccounts().listIterator();
        while (phoneAccounts.hasNext()) {
            final PhoneAccount phoneAccount =
                    telecomManager.getPhoneAccount(phoneAccounts.next());
            int subId = getSubIdForPhoneAccount(telephonyManager, phoneAccount);
            if (subId != -1) {
                list.add(new SubListItem(mSubMgr.getActiveSubscriptionInfo(subId)));
            }
        }
    } else {
        for (SubscriptionInfo si : mSubMgr.getActiveSubscriptionInfoList())
            if (si != null)
                list.add(new SubListItem(si));
    }
    return list;
}
 
Example #9
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
public void changeDefaultSub(final SubType subType, final int simSlot, final boolean showToast) {
    boolean result;
    SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfoForSimSlotIndex(simSlot);
    if (subType == SubType.VOICE) {
        if (si == null && (simSlot == 0 || simSlot == 1)) {
            result = false;
        } else {
            result = setDefaultVoiceSubscription(si);
        }
    } else {
        result = setDefaultSubscription(subType, si);
    }
    if (showToast || !result) {
        final String msg = result ? getChangeOkMsg(subType, getSubDisplayName(si)) :
            getChangeFailedMsg(subType);
        Toast.makeText(mContext, msg, Toast.LENGTH_LONG).show();
    }
}
 
Example #10
Source File: SimCardUtils.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
@SuppressLint({"NewApi"})
private void getDefaultSub(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager subscriptionManager = SubscriptionManager.from(context.getApplicationContext());
        if (subscriptionManager != null) {
            try {
                SubscriptionInfo subscriptionInfo = this.getSubInfo(subscriptionManager, "getDefaultDataSubscriptionInfo", (Object[]) null);
                if (subscriptionInfo != null) {
                    this.mSimCardInfo.simSub = subscriptionInfo.getSimSlotIndex();
                }
            } catch (Exception e) {
                Log.i(TAG, e.toString());
            }
        }
    } else {
        this.mSimCardInfo.simSub = -1;
    }

}
 
Example #11
Source File: SubscriptionHelper.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Nullable
public static List<SubscriptionInfo> getSubscriptions(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(context);
        return sm.getActiveSubscriptionInfoList();
    }

    return null;
}
 
Example #12
Source File: SubscriptionManagerCompat.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public @NonNull List<SubscriptionInfoCompat> updateActiveSubscriptionInfoList() {
  compatList = new LinkedList<>();

  if (Build.VERSION.SDK_INT < 22) {
    TelephonyManager telephonyManager = ServiceUtil.getTelephonyManager(context);
    compatList.add(new SubscriptionInfoCompat(context,
                                              -1,
                                              telephonyManager.getSimOperatorName(),
                                              telephonyManager.getLine1Number(),
                                              telephonyManager.getSimSerialNumber(),
                                              1,
                                              -1,
                                              -1,
                                              false));
    return compatList;
  }

  List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
  updateDisplayNameList(subscriptionInfos);

  if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
    return compatList;
  }

  for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
    compatList.add(new SubscriptionInfoCompat(context,
                                              subscriptionInfo.getSubscriptionId(),
                                              subscriptionInfo.getDisplayName(),
                                              subscriptionInfo.getNumber(),
                                              subscriptionInfo.getIccId(),
                                              subscriptionInfo.getSimSlotIndex()+1,
                                              subscriptionInfo.getMcc(),
                                              subscriptionInfo.getMnc(),
                                              knowThisDisplayNameTwice(subscriptionInfo.getDisplayName())));
  }

  return compatList;
}
 
Example #13
Source File: SubscriptionManagerCompat.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(22)
private void updateDisplayNameList(List<SubscriptionInfo> activeSubscriptions) {
  displayNameList = new LinkedList<String>();

  if (activeSubscriptions != null) {
    for (SubscriptionInfo subscriptionInfo : activeSubscriptions) {
      displayNameList.add(subscriptionInfo.getDisplayName().toString());
    }
  }
}
 
Example #14
Source File: EmergencyAffordanceService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean handleUpdateSimSubscriptionInfo() {
    boolean neededBefore = simNeededAffordanceBefore();
    boolean neededNow = neededBefore;
    List<SubscriptionInfo> activeSubscriptionInfoList =
            mSubscriptionManager.getActiveSubscriptionInfoList();
    if (activeSubscriptionInfoList == null) {
        setSimNeedsEmergencyAffordance(neededNow);
        return neededNow;
    }
    for (SubscriptionInfo info : activeSubscriptionInfoList) {
        int mcc = info.getMcc();
        if (mccRequiresEmergencyAffordance(mcc)) {
            neededNow = true;
            break;
        } else if (mcc != 0 && mcc != Integer.MAX_VALUE){
            // a Sim with a different mcc code was found
            neededNow = false;
        }
        String simOperator  = mTelephonyManager.getSimOperator(info.getSubscriptionId());
        mcc = 0;
        if (simOperator != null && simOperator.length() >= 3) {
            mcc = Integer.parseInt(simOperator.substring(0, 3));
        }
        if (mcc != 0) {
            if (mccRequiresEmergencyAffordance(mcc)) {
                neededNow = true;
                break;
            } else {
                // a Sim with a different mcc code was found
                neededNow = false;
            }
        }
    }
    setSimNeedsEmergencyAffordance(neededNow);
    return neededNow;
}
 
Example #15
Source File: DialerActivity.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public static void call(final CharSequence number, final Context context, final boolean directly) {
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1 && !directly && BPrefs.get(context).getBoolean(BPrefs.DUAL_SIM_KEY, BPrefs.DUAL_SIM_DEFAULT_VALUE)) {
            final SubscriptionManager subscriptionManager = (SubscriptionManager) context
                    .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
            final List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
            if (activeSubscriptionInfoList != null && (activeSubscriptionInfoList.size() > 1)) {
                final CharSequence[] simNames = new CharSequence[activeSubscriptionInfoList.size()];
                for (int i = 0; i < activeSubscriptionInfoList.size(); i++) {
                    simNames[i] = activeSubscriptionInfoList.get(i).getDisplayName();
                }
                BDB.from(context)
                        .addFlag(BDialog.FLAG_OK | BDialog.FLAG_CANCEL)
                        .setTitle(R.string.choose_sim)
                        .setSubText(R.string.choose_sim_subtext)
                        .setOptions(simNames)
                        .setPositiveButtonListener(params -> {
                            call(number, context, activeSubscriptionInfoList.get((Integer) params[0]));
                            return true;
                        }).show();
            } else
                call(number, context, null);
        } else
            call(number, context, null);
    } else
        BaldToast.error(context);

}
 
Example #16
Source File: SimCard.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
/**
 * Experimental call to retrieve sim operator names by subscription ids.
 *
 * @param context Application context
 * @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;
}
 
Example #17
Source File: Phone.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves network operator names from subscription manager.
 * NOTE: Requires SDK level 22 or above
 *
 * @param context
 * @return
 */
private static String getNetworkOperators(Context context) {
    String operator = "";

    if (!PermissionsUtils.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
        return operator;
    }

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
        if (subscriptionManager != null) {
            List<SubscriptionInfo> subscriptions =
                    subscriptionManager.getActiveSubscriptionInfoList();
            if (subscriptions != null) {
                for (SubscriptionInfo info : subscriptions) {
                    CharSequence carrierName = info.getCarrierName();
                    if (carrierName != null && carrierName.length() > 0) {
                        operator += carrierName + ";";
                    }
                }
                // Remove last delimiter
                if (operator.length() >= 1) {
                    operator = operator.substring(0, operator.length() - 1);
                }
            }
        }
    }
    return operator;
}
 
Example #18
Source File: DualNetworkIconData.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public void register() {
    if (telephonyManager != null) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && subscriptionManager != null) {

                if (networkListener == null) {
                    int index = 0;
                    for (SubscriptionInfo info : subscriptionManager.getActiveSubscriptionInfoList()) {
                        if (info.getSimSlotIndex() > index) {
                            networkListener = new NetworkListener(info.getSubscriptionId());
                            index = info.getSimSlotIndex();
                        }
                    }
                }
            }

            if (networkListener != null)
                telephonyManager.listen(networkListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }

    isRegistered = true;
}
 
Example #19
Source File: BuilderSimCard.java    From SmsScheduler with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RadioGroup build() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
        return getView();
    }
    SubscriptionManager subscriptionManager = (SubscriptionManager) activity.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    if (null == subscriptionManager) {
        return getView();
    }
    if (subscriptionManager.getActiveSubscriptionInfoCount() < 2) {
        sms.setSubscriptionId(subscriptionManager.getActiveSubscriptionInfoList().get(0).getSubscriptionId());
        return getView();
    }
    getView().setVisibility(View.VISIBLE);
    List<Pair<Integer, String>> simCards = new ArrayList<>();
    for (SubscriptionInfo info: subscriptionManager.getActiveSubscriptionInfoList()) {
        simCards.add(new Pair<>(info.getSubscriptionId(), info.getCarrierName().toString()));
    }
    RadioButton radio1 = getView().findViewById(R.id.radio_sim1);
    RadioButton radio2 = getView().findViewById(R.id.radio_sim2);
    prepareRadioButton(radio1, simCards.get(0));
    prepareRadioButton(radio2, simCards.get(1));
    if (!radio1.isChecked() && !radio2.isChecked()) {
        radio1.setChecked(true);
    }
    return getView();
}
 
Example #20
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private String getSubDisplayName(final SubscriptionInfo si) {
    if (si == null) {
        Context gbContext = getGbContext();
        return gbContext == null ? "Ask every time" :
            gbContext.getString(R.string.sm_voice_ask);
    } else {
        return si.getDisplayName() == null ?
            String.format(Locale.getDefault(), "SIM %d", (si.getSimSlotIndex()+1)) :
                si.getDisplayName().toString();
    }
}
 
Example #21
Source File: SimCardUtils.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
@SuppressLint({"NewApi"})
private SubscriptionInfo getSubsInfo(List<SubscriptionInfo> list, int i) {
    SubscriptionInfo subscriptionInfo = (SubscriptionInfo) list.get(0);
    Iterator iterator = list.iterator();

    while (iterator.hasNext()) {
        SubscriptionInfo info = (SubscriptionInfo) iterator.next();
        if (info.getSimSlotIndex() == i) {
            subscriptionInfo = info;
        }
    }

    return subscriptionInfo;
}
 
Example #22
Source File: SimCardUtils.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
@SuppressLint({"NewApi"})
private List<SubscriptionInfo> getSubInfoList(Context context) {
    SubscriptionManager subscriptionManager = SubscriptionManager.from(context.getApplicationContext());
    List list = null;
    if (subscriptionManager != null) {
        list = subscriptionManager.getActiveSubscriptionInfoList();
    }

    return list;
}
 
Example #23
Source File: SubscriptionManager.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private boolean setDefaultVoiceSubscription(final SubscriptionInfo subInfo) {
    try {
        final TelecomManager telecomManager =
            (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
        XposedHelpers.callMethod(telecomManager,
                "setUserSelectedOutgoingPhoneAccount",
                subscriptionToPhoneAccountHandle(subInfo));
        return true;
    } catch (Throwable t) {
        XposedBridge.log(t);
        return false;
    }
}
 
Example #24
Source File: MainActivity.java    From Msgs with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
private void sendSms(final int which,String phone,String context) {
    SubscriptionInfo sInfo = null;

    final SubscriptionManager sManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

    List<SubscriptionInfo> list = sManager.getActiveSubscriptionInfoList();

    if (list.size() == 2) {
        // 双卡
        sInfo = list.get(which);
    } else {
        // 单卡
        sInfo = list.get(0);
    }

    if (sInfo != null) {
        int subId = sInfo.getSubscriptionId();
        SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(subId);

        if (!TextUtils.isEmpty(phone)) {
            ArrayList<String> messageList =manager.divideMessage(context);
            for(String text:messageList){
                manager.sendTextMessage(phone, null, text, null, null);
            }
            Toast.makeText(this, "信息正在发送,请稍候", Toast.LENGTH_SHORT)
                    .show();
        } else {
            Toast.makeText(this, "无法正确的获取SIM卡信息,请稍候重试",
                    Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example #25
Source File: SubscriptionHelper.java    From BlackList with Apache License 2.0 5 votes vote down vote up
/**
 * @return id of the current subscription (id of SIM)
 */
@Nullable
public static Integer getCurrentSubscriptionId(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionInfo info = getCurrentSubscription(context);
        if (info != null) return info.getSubscriptionId();
    }

    return null;
}
 
Example #26
Source File: SubscriptionHelper.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String getCurrentSubscriptionName(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionInfo info = getCurrentSubscription(context);
        if (info != null) return info.getDisplayName().toString();
    }

    return null;
}
 
Example #27
Source File: SettingsActivity.java    From call_manage with MIT License 5 votes vote down vote up
private void setupSimSelection() {
            if (!Utilities.checkPermissionGranted(getContext(), READ_PHONE_STATE)) {
                Toast.makeText(getContext(), "No permission, please give permission to read phone state", Toast.LENGTH_LONG).show();
                return;
            }

            ListPreference simSelectionPreference = (ListPreference) findPreference(getString(R.string.pref_sim_select_key));

            @SuppressLint("MissingPermission")
            List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(getContext()).getActiveSubscriptionInfoList();
            int simCount = subscriptionInfoList.size();

            if (simCount == 1) {
                simSelectionPreference.setSummary(getString(R.string.pref_sim_select_disabled));
                simSelectionPreference.setEnabled(false);
            } else {
                List<CharSequence> simsEntries = new ArrayList<>();

                for (int i = 0; i < simCount; i++) {
                    SubscriptionInfo si = subscriptionInfoList.get(i);
                    Timber.i("Sim info " + i + " : " + si.getDisplayName());
                    simsEntries.add(si.getDisplayName());
                }

                CharSequence[] simsEntriesList = simsEntries.toArray(new CharSequence[simsEntries.size()]);
                simSelectionPreference.setEntries(simsEntriesList);
//                simsEntries.add(getString(R.string.pref_sim_select_ask_entry));
//                CharSequence[] simsEntryValues = {"0", "1", "2"};
                CharSequence[] simsEntryValues = {"0", "1"};
                simSelectionPreference.setEntryValues(simsEntryValues);
            }
        }
 
Example #28
Source File: ExampleInstrumentedTest.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Test
public void smsSubscriptionManager() throws Exception {
    Context context = InstrumentationRegistry.getTargetContext();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        List<SubscriptionInfo> list = SubscriptionHelper.getSubscriptions(context);
        if (list != null) {
            int subscriptionId = -1;
            for (SubscriptionInfo info : list) {
                Log.d("TEST_SmsManager", info.toString());
                subscriptionId = info.getSubscriptionId();
            }
            assertTrue(subscriptionId >= 0);
        }
    }
}
 
Example #29
Source File: SubscriptionHelper.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Nullable
public static SubscriptionInfo getCurrentSubscription(Context context) {
    Integer subscriptionId = Settings.getIntegerValue(context, Settings.SIM_SUBSCRIPTION_ID);
    if (subscriptionId != null && subscriptionId >= 0) {
        return getSubscriptionById(context, subscriptionId);
    }

    return null;
}
 
Example #30
Source File: SubscriptionHelper.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Integer getId(SubscriptionInfo info) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && info != null) {
        return info.getSubscriptionId();
    }
    return null;
}