Java 类android.telephony.SubscriptionManager 实例源码

项目:PeSanKita-android    文件:SubscriptionManagerCompat.java   
public @NonNull List<SubscriptionInfoCompat> getActiveSubscriptionInfoList() {
  if (Build.VERSION.SDK_INT < 22) {
    return new LinkedList<>();
  }

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

  if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
    return new LinkedList<>();
  }

  List<SubscriptionInfoCompat> compatList = new LinkedList<>();

  for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
    compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
                                              subscriptionInfo.getDisplayName()));
  }

  return compatList;
}
项目:NotifyTools    文件:SimService.java   
@Override
protected void onHandleIntent(Intent intent) {
    log.d("onHandleIntent");
    //SubscriptionManager  该类主要包含了所有sim卡的信息
    SubscriptionManager mSubscriptionManager = SubscriptionManager.from(this);
    int simcnt = mSubscriptionManager.getActiveSubscriptionInfoCount();
    List<SubscriptionInfo> lstSim = mSubscriptionManager.getActiveSubscriptionInfoList();
    for (int i = 0; i < lstSim.size(); i++) {
        SubscriptionInfo si = lstSim.get(i);
        if (si != null)
            log.d(si.toString());
    }
    TelecomManager telecomManager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        List<PhoneAccountHandle> lstPA=telecomManager.getCallCapablePhoneAccounts();
        int accoutSum =lstPA.size();
        for(int i=0;i<accoutSum;i++)
            log.d("accountSum: " + accoutSum +lstPA.get(i) );
    }

}
项目:Cable-Android    文件:SubscriptionManagerCompat.java   
public @NonNull List<SubscriptionInfoCompat> getActiveSubscriptionInfoList() {
  if (Build.VERSION.SDK_INT < 22) {
    return new LinkedList<>();
  }

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

  if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
    return new LinkedList<>();
  }

  List<SubscriptionInfoCompat> compatList = new LinkedList<>();

  for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
    compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
                                              subscriptionInfo.getDisplayName(),
                                              subscriptionInfo.getMcc(),
                                              subscriptionInfo.getMnc()));
  }

  return compatList;
}
项目:Silence    文件:SubscriptionManagerCompat.java   
public @NonNull List<SubscriptionInfoCompat> getActiveSubscriptionInfoList() {
  if (Build.VERSION.SDK_INT < 22) {
    return new LinkedList<>();
  }

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

  if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
    return new LinkedList<>();
  }

  List<SubscriptionInfoCompat> compatList = new LinkedList<>();

  for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
    compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
                                              subscriptionInfo.getDisplayName()));
  }

  return compatList;
}
项目:sms-ticket    文件:SettingsFragment.java   
@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());
}
项目:PeSanKita-android    文件:SubscriptionManagerCompat.java   
public Optional<Integer> getPreferredSubscriptionId() {
  if (Build.VERSION.SDK_INT < 24) {
    return Optional.absent();
  }

  return Optional.of(SubscriptionManager.getDefaultSmsSubscriptionId());
}
项目:PeSanKita-android    文件:SubscriptionManagerCompat.java   
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfo(int subscriptionId) {
  if (Build.VERSION.SDK_INT < 22) {
    return Optional.absent();
  }

  SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);

  if (subscriptionInfo != null) {
    return Optional.of(new SubscriptionInfoCompat(subscriptionId, subscriptionInfo.getDisplayName()));
  } else {
    return Optional.absent();
  }
}
项目:Msgs    文件:MainActivity.java   
@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();
        }
    }
}
项目:open-rmbt    文件:DualSimNewApiWrapper.java   
public static boolean isDualSim(final Context context)
{
    try
    {
        final SubscriptionManager sm = SubscriptionManager.from(context);
        final int activeSubscriptionInfoCount = sm.getActiveSubscriptionInfoCount();
        //System.out.println("active subscription count: " + activeSubscriptionInfoCount);
        return activeSubscriptionInfoCount > 1;
    }
    catch (Throwable t)
    {
        //t.printStackTrace();
        return false;
    }
}
项目:BlackList    文件:SubscriptionHelper.java   
@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;
}
项目:Cable-Android    文件:SubscriptionManagerCompat.java   
public Optional<Integer> getPreferredSubscriptionId() {
  if (Build.VERSION.SDK_INT < 24) {
    return Optional.absent();
  }

  return Optional.of(SubscriptionManager.getDefaultSmsSubscriptionId());
}
项目:Cable-Android    文件:SubscriptionManagerCompat.java   
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfo(int subscriptionId) {
  if (Build.VERSION.SDK_INT < 22) {
    return Optional.absent();
  }

  SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);

  if (subscriptionInfo != null) {
    return Optional.of(new SubscriptionInfoCompat(subscriptionId, subscriptionInfo.getDisplayName(),
                                                  subscriptionInfo.getMcc(), subscriptionInfo.getMnc()));
  } else {
    return Optional.absent();
  }
}
项目:advancedSmsManager    文件:SendSmsPresenterImpl.java   
@Override
public void prepareSendSms() {

    if (view != null && needDialog) {

        view.showLoading();
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {

        SubscriptionManager mSubscriptionManager = SubscriptionManager.from(context);
        subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
        if (subInfoList != null && subInfoList.size() > 1) {
            carriersICC.add(0, subInfoList.get(0).getSubscriptionId());
            carriersICC.add(1, subInfoList.get(1).getSubscriptionId());
            carriersNAME.add(0, subInfoList.get(0).getCarrierName().toString());
            carriersNAME.add(1, subInfoList.get(1).getCarrierName().toString());

            view.hideLoading();
            view.renderSimChooserView(context, carriersNAME.get(0), carriersNAME.get(1));

        } else {
            carriersICC.add(0, subInfoList.get(0).getSubscriptionId());
            carriersNAME.add(0, subInfoList.get(0).getCarrierName().toString());
            sendSmsFromSubscriptionIdIndex(0);
        }

    } else {
        sendSmsForOldPhones();
    }
}
项目:SmsScheduler    文件:BuilderSimCard.java   
@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();
}
项目:SmsScheduler    文件:SmsSenderService.java   
private SmsManager getSmsManager(int subscriptionId) {
    SmsManager smsManager = SmsManager.getDefault();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
        return smsManager;
    }
    SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    if (null == subscriptionManager) {
        return smsManager;
    }
    if (null == subscriptionManager.getActiveSubscriptionInfo(subscriptionId)) {
        return smsManager;
    }
    return SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
}
项目:Status    文件:DualNetworkIconData.java   
public DualNetworkIconData(Context context) {
    super(context);

    telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
        subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}
项目:ForceDoze    文件:ForceDozeService.java   
public void setMobileNetwork(Context context, int targetState) {

        if (!Utils.isReadPhoneStatePermissionGranted(context)) {
            grantReadPhoneStatePermission();
        }

        String command;
        try {
            String transactionCode = getTransactionCode(context);
            SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
            for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) {
                if (transactionCode != null && transactionCode.length() > 0) {
                    int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId();
                    command = "service call phone " + transactionCode + " i32 " + subscriptionId + " i32 " + targetState;
                    List<String> output = Shell.SU.run(command);
                    if (output != null) {
                        for (String s : output) {
                            Log.i(TAG, s);
                        }
                    } else {
                        Log.i(TAG, "Error occurred while executing command (" + command + ")");
                    }
                }
            }
        } catch (Exception e) {
            Log.i(TAG, "Failed to toggle mobile data: " + e.getMessage());
        }
    }
项目:android-protwall    文件: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");

    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("\r\n");

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}
项目:batteryhub    文件:Phone.java   
/**
 * 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;
}
项目:batteryhub    文件:SimCard.java   
/**
 * 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;
}
项目:RememBirthday    文件:SmsSenderService.java   
private SmsManager getSmsManager(int subscriptionId) {
    SmsManager smsManager = SmsManager.getDefault();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
        return smsManager;
    }
    SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    if (null == subscriptionManager) {
        return smsManager;
    }
    if (null == subscriptionManager.getActiveSubscriptionInfo(subscriptionId)) {
        return smsManager;
    }
    return SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
}
项目:react-native-sim-data    文件:RNSimDataModule.java   
@Override
public Map<String, Object> getConstants() {

  final Map<String, Object> constants = new HashMap<>();

  try {
    TelephonyManager telManager = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);

    SubscriptionManager manager = (SubscriptionManager) this.reactContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList();

    int sub = 0;
    for (SubscriptionInfo subInfo : subscriptionInfos) {
      CharSequence carrierName = subInfo.getCarrierName();
      String countryIso        = subInfo.getCountryIso();
      int dataRoaming          = subInfo.getDataRoaming();  // 1 is enabled ; 0 is disabled
      CharSequence displayName = subInfo.getDisplayName();
      String iccId             = subInfo.getIccId();
      int mcc                  = subInfo.getMcc();
      int mnc                  = subInfo.getMnc();
      String number            = subInfo.getNumber();
      int simSlotIndex         = subInfo.getSimSlotIndex();
      int subscriptionId       = subInfo.getSubscriptionId();
      boolean networkRoaming   = telManager.isNetworkRoaming();
      String deviceId          = telManager.getDeviceId(simSlotIndex);
      //String deviceId          = telManager.getImei(simSlotIndex) || telManager.getMeid(simSlotIndex);

      constants.put("carrierName" + sub, carrierName.toString());
      constants.put("displayName" + sub, displayName.toString());
      constants.put("countryCode" + sub, countryIso);
      constants.put("mcc" + sub, mcc);
      constants.put("mnc" + sub, mnc);
      constants.put("isNetworkRoaming" + sub, networkRoaming);
      constants.put("isDataRoaming"    + sub, (dataRoaming == 1));
      constants.put("simSlotIndex"     + sub, simSlotIndex);
      constants.put("phoneNumber"      + sub, number);
      constants.put("deviceId"         + sub, deviceId);
      constants.put("simSerialNumber"  + sub, iccId);
      constants.put("subscriptionId"   + sub, subscriptionId);
      sub++;
    }
  } catch (Exception e) {
    e.printStackTrace();
  }

  return constants;
}
项目:WiFiAPManager    文件:Commons.java   
public static void setMobileNetworkfromLollipop(Context context)
        throws InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException, IllegalAccessException, NoSuchFieldException {
    String command;
    int state;
    // Get the current state of the mobile network.
    state = isMobileDataEnabled(context) ? 0 : 1;
    // Get the value of the "TRANSACTION_setDataEnabled" field.
    String transactionCode = getTransactionCode(context);
    // Android 5.1+ (API 22) and later.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        SubscriptionManager mSubscriptionManager = (SubscriptionManager)
                context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        // Loop through the subscription list i.e. SIM list.
        for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) {
            if (transactionCode.length() > 0) {
                // Get the active subscription ID for a given SIM card.
                int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList()
                        .get(i).getSubscriptionId();
                // Execute the command via `su` to turn off
                // mobile network for a subscription service.
                command = "service call phone " + transactionCode + " i32 "
                        + subscriptionId + " i32 " + state;
                ShellUtils.execCommand(command, true);
            }
        }
    } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
        // Android 5.0 (API 21) only.
        if (transactionCode.length() > 0) {
            // Execute the command via `su` to turn off mobile network.
            command = "service call phone " + transactionCode + " i32 " + state;
            ShellUtils.execCommand(command, true);
        }
    }
}
项目:Silence    文件:SubscriptionManagerCompat.java   
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfo(int subscriptionId) {
  if (Build.VERSION.SDK_INT < 22) {
    return Optional.absent();
  }

  SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);

  if (subscriptionInfo != null) {
    return Optional.of(new SubscriptionInfoCompat(subscriptionId, subscriptionInfo.getDisplayName()));
  } else {
    return Optional.absent();
  }
}
项目:Xposed-ShowSimOperator    文件:ShowSimOperator.java   
/**
 * Get the original network operator name (as if TelephonyManager#getNetworkOperatorName were unhooked)
 *
 * @param subId subscription id
 * @return the original network operator name
 */
private static String getRealNetworkOperatorNameBySubId(int subId) throws Throwable {
  Method getPhoneId = XposedHelpers.findMethodExact(SubscriptionManager.class.getName(), null, "getPhoneId", int.class);
  int phoneId = (Integer) getPhoneId.invoke(getSubscriptionManager(), subId);

  Class<?> TelephonyProperties = XposedHelpers.findClass("com.android.internal.telephony.TelephonyProperties", null);
  String PROPERTY_OPERATOR_ALPHA = (String) XposedHelpers.getStaticObjectField(TelephonyProperties, "PROPERTY_OPERATOR_ALPHA");

  Method getTelephonyProperty = XposedHelpers.findMethodExact(TelephonyManager.class.getName(), null, "getTelephonyProperty", int.class, String.class, String.class);
  return (String) getTelephonyProperty.invoke(getTelephonyManager(), phoneId, PROPERTY_OPERATOR_ALPHA, "");
}
项目:MKAPP    文件:ServiceSinkhole.java   
@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageChanged) {
        unregisterReceiver(packageChangedReceiver);
        registeredPackageChanged = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener((SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}
项目:MKAPP    文件: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 = SubscriptionManager.getDefaultDataSubscriptionId();

    int voiceid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        voiceid = SubscriptionManager.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);

    return sb.toString();
}
项目:open-rmbt    文件:SubscriptionInfoHelper.java   
public SubscriptionInfoHelper(Context context) {
    subscriptionManager = (SubscriptionManager) context
            .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

}
项目:NoRootFirewall-Custom    文件:ServiceSinkhole.java   
@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageAdded) {
        unregisterReceiver(packageAddedReceiver);
        registeredPackageAdded = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener((SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}
项目:NoRootFirewall-Custom    文件: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);

    return sb.toString();
}
项目:kcanotify    文件: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);

    return sb.toString();
}
项目:android-protwall    文件:ServiceSinkhole.java   
@Override
public void onDestroy() {
    Log.i(TAG, "Destroy");

    commandLooper.quit();
    logLooper.quit();
    statsLooper.quit();

    if (registeredInteractiveState) {
        unregisterReceiver(interactiveStateReceiver);
        registeredInteractiveState = false;
    }
    if (registeredPowerSave) {
        unregisterReceiver(powerSaveReceiver);
        registeredPowerSave = false;
    }
    if (registeredUser) {
        unregisterReceiver(userReceiver);
        registeredUser = false;
    }
    if (registeredIdleState) {
        unregisterReceiver(idleStateReceiver);
        registeredIdleState = false;
    }
    if (registeredConnectivityChanged) {
        unregisterReceiver(connectivityChangedReceiver);
        registeredConnectivityChanged = false;
    }
    if (registeredPackageAdded) {
        unregisterReceiver(packageAddedReceiver);
        registeredPackageAdded = false;
    }

    if (phone_state) {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null) {
            tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
            phone_state = false;
        }
    }

    if (subscriptionsChangedListener != null &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sm = SubscriptionManager.from(this);
        sm.removeOnSubscriptionsChangedListener((SubscriptionManager.OnSubscriptionsChangedListener) subscriptionsChangedListener);
        subscriptionsChangedListener = null;
    }

    try {
        if (vpn != null) {
            stopNative(vpn, true);
            stopVPN(vpn);
            vpn = null;
            unprepare();
        }
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    jni_done();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    super.onDestroy();
}
项目:Android-App-Template    文件:ServiceUtil.java   
@TargetApi(22)
public static SubscriptionManager getSubscriptionManager() {
    return (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}
项目:kitkat-sms-patch    文件:Patch.java   
private static void putPhoneIdAndSubIdExtra(Object thisObject, Intent intent) {
    PhoneBase phone = (PhoneBase) XposedHelpers.getObjectField(thisObject, "mPhone");
    XposedHelpers.callStaticMethod(SubscriptionManager.class, "putPhoneIdAndSubIdExtra",
            intent, phone.getPhoneId());
}
项目:sprockets-android    文件:Managers.java   
/**
 * @since 4.0.0
 */
public static SubscriptionManager telephonySubscription(Context context) {
    return (SubscriptionManager) context.getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE);
}
项目:Xposed-ShowSimOperator    文件:ShowSimOperator.java   
private static SubscriptionManager getSubscriptionManager() {
  return (SubscriptionManager) getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}
项目:android_Skeleton    文件:SystemServices.java   
@TargetApi(AndroidHelper.API_22)
public static SubscriptionManager subscriptionManager() {
    return (SubscriptionManager) get(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}
项目:android-wheels    文件:ContextUtils.java   
/**
 * Obtain a {@link SubscriptionManager} instance associated with specified {@link Context}
 *
 * @param context Context
 * @return {@link SubscriptionManager} associated with specified {@link Context}
 * @throws InvalidContextException if {@link SubscriptionManager} can't be obtained
 *                                 from specified {@link Context}
 */
@NonNull
@RequiresApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static SubscriptionManager getSubscriptionManager(@NonNull Context context) {
    return validate(context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
}