android.telephony.SubscriptionManager Java Examples

The following examples show how to use android.telephony.SubscriptionManager. 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: JNIUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 7 votes vote down vote up
public static String[] getCarrierInfo(){
	TelephonyManager tm=(TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
	if(Build.VERSION.SDK_INT>=24){
		tm=tm.createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId());
	}
	if(!TextUtils.isEmpty(tm.getNetworkOperatorName())){
		String mnc="", mcc="";
		String carrierID=tm.getNetworkOperator();
		if(carrierID!=null && carrierID.length()>3){
			mcc=carrierID.substring(0, 3);
			mnc=carrierID.substring(3);
		}
		return new String[]{tm.getNetworkOperatorName(), tm.getNetworkCountryIso().toUpperCase(), mcc, mnc};
	}
	return null;
}
 
Example #2
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 #3
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 #4
Source File: JNIUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static String[] getCarrierInfo(){
	TelephonyManager tm=(TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
	if(Build.VERSION.SDK_INT>=24){
		tm=tm.createForSubscriptionId(SubscriptionManager.getDefaultDataSubscriptionId());
	}
	if(!TextUtils.isEmpty(tm.getNetworkOperatorName())){
		String mnc="", mcc="";
		String carrierID=tm.getNetworkOperator();
		if(carrierID!=null && carrierID.length()>3){
			mcc=carrierID.substring(0, 3);
			mnc=carrierID.substring(3);
		}
		return new String[]{tm.getNetworkOperatorName(), tm.getNetworkCountryIso().toUpperCase(), mcc, mnc};
	}
	return null;
}
 
Example #5
Source File: EmergencyAffordanceService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onBootPhase(int phase) {
    if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
        mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
        mVoiceCapable = mTelephonyManager.isVoiceCapable();
        if (!mVoiceCapable) {
            updateEmergencyAffordanceNeeded();
            return;
        }
        mSubscriptionManager = SubscriptionManager.from(mContext);
        HandlerThread thread = new HandlerThread(TAG);
        thread.start();
        mHandler = new MyHandler(thread.getLooper());
        mHandler.obtainMessage(INITIALIZE_STATE).sendToTarget();
        startScanning();
        IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        mContext.registerReceiver(mAirplaneModeReceiver, filter);
        mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionChangedListener);
    }
}
 
Example #6
Source File: ConnectivityManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 * @deprecated Talk to TelephonyManager directly
 */
@Deprecated
public boolean getMobileDataEnabled() {
    IBinder b = ServiceManager.getService(Context.TELEPHONY_SERVICE);
    if (b != null) {
        try {
            ITelephony it = ITelephony.Stub.asInterface(b);
            int subId = SubscriptionManager.getDefaultDataSubscriptionId();
            Log.d("ConnectivityManager", "getMobileDataEnabled()+ subId=" + subId);
            boolean retVal = it.isUserDataEnabled(subId);
            Log.d("ConnectivityManager", "getMobileDataEnabled()- subId=" + subId
                    + " retVal=" + retVal);
            return retVal;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    Log.d("ConnectivityManager", "getMobileDataEnabled()- remote exception retVal=false");
    return false;
}
 
Example #7
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 #8
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) {
    if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) {
        return;
    }

    synchronized (mRecords) {
        for (Record r : mRecords) {
            if (VDBG) {
                log("notifyOemHookRawEventForSubscriber:  r=" + r + " subId=" + subId);
            }
            if ((r.matchPhoneStateListenerEvent(
                    PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) &&
                    ((r.subId == subId) ||
                    (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) {
                try {
                    r.callback.onOemHookRawEvent(rawData);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #9
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void notifyDataActivityForSubscriber(int subId, int state) {
    if (!checkNotifyPermission("notifyDataActivity()" )) {
        return;
    }
    int phoneId = SubscriptionManager.getPhoneId(subId);
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            mDataActivity[phoneId] = state;
            for (Record r : mRecords) {
                // Notify by correct subId.
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) &&
                        idMatch(r.subId, subId, phoneId)) {
                    try {
                        r.callback.onDataActivity(state);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #10
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 #11
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 #12
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 #13
Source File: ForceDozeService.java    From ForceDoze with GNU General Public License v3.0 5 votes vote down vote up
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());
        }
    }
 
Example #14
Source File: DualNetworkIconData.java    From Status with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #15
Source File: SmsSenderService.java    From SmsScheduler with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: SmsSenderService.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #17
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 #18
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 #19
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 #20
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 #21
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 #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: SmsHandlerHook.java    From NekoSMS with GNU General Public License v3.0 5 votes vote down vote up
private void putPhoneIdAndSubIdExtra(Object inboundSmsHandler, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        try {
            Object phone = XposedHelpers.getObjectField(inboundSmsHandler, "mPhone");
            int phoneId = (Integer)XposedHelpers.callMethod(phone, "getPhoneId");
            XposedHelpers.callStaticMethod(SubscriptionManager.class, "putPhoneIdAndSubIdExtra", intent, phoneId);
        } catch (Exception e) {
            Xlog.e("Could not update intent with subscription id", e);
        }
    }
}
 
Example #24
Source File: DualSimNewApiWrapper.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
public 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;
    }
}
 
Example #25
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 #26
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void notifyDataConnection(int state, boolean isDataAllowed,
        String reason, String apn, String apnType, LinkProperties linkProperties,
        NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
    notifyDataConnectionForSubscriber(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, state,
        isDataAllowed,reason, apn, apnType, linkProperties,
        networkCapabilities, networkType, roaming);
}
 
Example #27
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void notifyCellInfoForSubscriber(int subId, List<CellInfo> cellInfo) {
    if (!checkNotifyPermission("notifyCellInfo()")) {
        return;
    }
    if (VDBG) {
        log("notifyCellInfoForSubscriber: subId=" + subId
            + " cellInfo=" + cellInfo);
    }
    int phoneId = SubscriptionManager.getPhoneId(subId);
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            mCellInfo.set(phoneId, cellInfo);
            for (Record r : mRecords) {
                if (validateEventsAndUserLocked(r, PhoneStateListener.LISTEN_CELL_INFO) &&
                        idMatch(r.subId, subId, phoneId) &&
                        checkLocationAccess(r)) {
                    try {
                        if (DBG_LOC) {
                            log("notifyCellInfo: mCellInfo=" + cellInfo + " r=" + r);
                        }
                        r.callback.onCellInfoChanged(cellInfo);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #28
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void notifyPhysicalChannelConfigurationForSubscriber(int subId,
        List<PhysicalChannelConfig> configs) {
    if (!checkNotifyPermission("notifyPhysicalChannelConfiguration()")) {
        return;
    }

    if (VDBG) {
        log("notifyPhysicalChannelConfiguration: subId=" + subId + " configs=" + configs);
    }

    synchronized (mRecords) {
        int phoneId = SubscriptionManager.getPhoneId(subId);
        if (validatePhoneId(phoneId)) {
            mPhysicalChannelConfigs.set(phoneId, configs);
            for (Record r : mRecords) {
                if (r.matchPhoneStateListenerEvent(
                        PhoneStateListener.LISTEN_PHYSICAL_CHANNEL_CONFIGURATION)
                        && idMatch(r.subId, subId, phoneId)) {
                    try {
                        if (DBG_LOC) {
                            log("notifyPhysicalChannelConfiguration: mPhysicalChannelConfigs="
                                    + configs + " r=" + r);
                        }
                        r.callback.onPhysicalChannelConfigurationChanged(configs);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
}
 
Example #29
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void notifyCallStateForPhoneId(int phoneId, int subId, int state,
            String incomingNumber) {
    if (!checkNotifyPermission("notifyCallState()")) {
        return;
    }
    if (VDBG) {
        log("notifyCallStateForPhoneId: subId=" + subId
            + " state=" + state + " incomingNumber=" + incomingNumber);
    }
    synchronized (mRecords) {
        if (validatePhoneId(phoneId)) {
            mCallState[phoneId] = state;
            mCallIncomingNumber[phoneId] = incomingNumber;
            for (Record r : mRecords) {
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
                        (r.subId == subId) &&
                        (r.subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
                    try {
                        String incomingNumberOrEmpty = getCallIncomingNumber(r, phoneId);
                        r.callback.onCallStateChanged(state, incomingNumberOrEmpty);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
    broadcastCallStateChanged(state, incomingNumber, phoneId, subId);
}
 
Example #30
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void notifyCallState(int state, String phoneNumber) {
    if (!checkNotifyPermission("notifyCallState()")) {
        return;
    }

    if (VDBG) {
        log("notifyCallState: state=" + state + " phoneNumber=" + phoneNumber);
    }

    synchronized (mRecords) {
        for (Record r : mRecords) {
            if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_CALL_STATE) &&
                    (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID)) {
                try {
                    // Ensure the listener has read call log permission; if they do not return
                    // an empty phone number.
                    String phoneNumberOrEmpty = r.canReadCallLog() ? phoneNumber : "";
                    r.callback.onCallStateChanged(state, phoneNumberOrEmpty);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }

    // Called only by Telecomm to communicate call state across different phone accounts. So
    // there is no need to add a valid subId or slotId.
    broadcastCallStateChanged(state, phoneNumber,
            SubscriptionManager.INVALID_PHONE_INDEX,
            SubscriptionManager.INVALID_SUBSCRIPTION_ID);
}