Search in sources :

Example 56 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by omnirom.

the class DataUsageUtils method getDefaultSubscriptionId.

/**
 * Returns the default subscription if available else returns
 * SubscriptionManager#INVALID_SUBSCRIPTION_ID
 */
public static int getDefaultSubscriptionId(Context context) {
    SubscriptionManager subManager = SubscriptionManager.from(context);
    if (subManager == null) {
        return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    }
    SubscriptionInfo subscriptionInfo = subManager.getDefaultDataSubscriptionInfo();
    if (subscriptionInfo == null) {
        List<SubscriptionInfo> list = subManager.getAllSubscriptionInfoList();
        if (list.size() == 0) {
            return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
        }
        subscriptionInfo = list.get(0);
    }
    return subscriptionInfo.getSubscriptionId();
}
Also used : SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager)

Example 57 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by omnirom.

the class SimDialogActivity method displayPreferredDialog.

private void displayPreferredDialog(final int slotId) {
    final Resources res = getResources();
    final Context context = getApplicationContext();
    final SubscriptionInfo sir = SubscriptionManager.from(context).getActiveSubscriptionInfoForSimSlotIndex(slotId);
    if (sir != null) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle(R.string.sim_preferred_title);
        alertDialogBuilder.setMessage(res.getString(R.string.sim_preferred_message, sir.getDisplayName()));
        alertDialogBuilder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                final int subId = sir.getSubscriptionId();
                PhoneAccountHandle phoneAccountHandle = subscriptionIdToPhoneAccountHandle(subId);
                setDefaultDataSubId(context, subId);
                setDefaultSmsSubId(context, subId);
                setUserSelectedOutgoingPhoneAccount(phoneAccountHandle);
                finish();
            }
        });
        alertDialogBuilder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                finish();
            }
        });
        alertDialogBuilder.create().show();
    } else {
        finish();
    }
}
Also used : Context(android.content.Context) AlertDialog(android.app.AlertDialog) PhoneAccountHandle(android.telecom.PhoneAccountHandle) DialogInterface(android.content.DialogInterface) SubscriptionInfo(android.telephony.SubscriptionInfo) Resources(android.content.res.Resources)

Example 58 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by omnirom.

the class SimDialogActivity method createDialog.

public Dialog createDialog(final Context context, final int id) {
    final ArrayList<String> list = new ArrayList<String>();
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final List<SubscriptionInfo> subInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    final int selectableSubInfoLength = subInfoList == null ? 0 : subInfoList.size();
    final ArrayList<SubscriptionInfo> callsSubInfoList = new ArrayList<SubscriptionInfo>();
    final DialogInterface.OnClickListener selectionListener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int value) {
            final SubscriptionInfo sir;
            switch(id) {
                case DATA_PICK:
                    sir = subInfoList.get(value);
                    setDefaultDataSubId(context, sir.getSubscriptionId());
                    break;
                case CALLS_PICK:
                    final TelecomManager telecomManager = TelecomManager.from(context);
                    final List<PhoneAccountHandle> phoneAccountsList = telecomManager.getCallCapablePhoneAccounts();
                    setUserSelectedOutgoingPhoneAccount(value == (callsSubInfoList.size() - 1) ? null : phoneAccountsList.get(value));
                    break;
                case SMS_PICK:
                    sir = subInfoList.get(value);
                    setDefaultSmsSubId(context, sir.getSubscriptionId());
                    break;
                default:
                    throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
            }
            finish();
        }
    };
    Dialog.OnKeyListener keyListener = new Dialog.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                finish();
            }
            return true;
        }
    };
    if (id == CALLS_PICK) {
        final TelecomManager telecomManager = TelecomManager.from(context);
        final TelephonyManager telephonyManager = TelephonyManager.from(context);
        final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
        while (phoneAccounts.hasNext()) {
            final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccounts.next());
            list.add((String) phoneAccount.getLabel());
            int subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount);
            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                final SubscriptionInfo sir = SubscriptionManager.from(context).getActiveSubscriptionInfo(subId);
                callsSubInfoList.add(sir);
            } else {
                callsSubInfoList.add(null);
            }
        }
        list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
        callsSubInfoList.add(null);
    } else {
        for (int i = 0; i < selectableSubInfoLength; ++i) {
            final SubscriptionInfo sir = subInfoList.get(i);
            CharSequence displayName = sir.getDisplayName();
            if (displayName == null) {
                displayName = "";
            }
            list.add(displayName.toString());
        }
    }
    String[] arr = list.toArray(new String[0]);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    ListAdapter adapter = new SelectAccountListAdapter(id == CALLS_PICK ? callsSubInfoList : subInfoList, builder.getContext(), R.layout.select_account_list_item, arr, id);
    switch(id) {
        case DATA_PICK:
            builder.setTitle(R.string.select_sim_for_data);
            break;
        case CALLS_PICK:
            builder.setTitle(R.string.select_sim_for_calls);
            break;
        case SMS_PICK:
            builder.setTitle(R.string.select_sim_for_sms);
            break;
        default:
            throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
    }
    Dialog dialog = builder.setAdapter(adapter, selectionListener).create();
    dialog.setOnKeyListener(keyListener);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            finish();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) KeyEvent(android.view.KeyEvent) TelephonyManager(android.telephony.TelephonyManager) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) ListAdapter(android.widget.ListAdapter) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager) PhoneAccount(android.telecom.PhoneAccount)

Example 59 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by omnirom.

the class SimSettings method updateSubscriptions.

private void updateSubscriptions() {
    mSubInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
    for (int i = 0; i < mNumSlots; ++i) {
        Preference pref = mSimCards.findPreference("sim" + i);
        if (pref instanceof SimPreference) {
            mSimCards.removePreference(pref);
        }
    }
    mAvailableSubInfos.clear();
    mSelectableSubInfos.clear();
    for (int i = 0; i < mNumSlots; ++i) {
        final SubscriptionInfo sir = mSubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(i);
        SimPreference simPreference = new SimEnablerPreference(getPrefContext(), sir, i);
        simPreference.setOrder(i - mNumSlots);
        mSimCards.addPreference(simPreference);
        mAvailableSubInfos.add(sir);
        if (sir != null && mUiccProvisionStatus[i] == PROVISIONED) {
            mSelectableSubInfos.add(sir);
        }
    }
    updateAllOptions();
}
Also used : Preference(android.support.v7.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo)

Example 60 with SubscriptionInfo

use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by omnirom.

the class SimSettings method updateSmsValues.

private void updateSmsValues() {
    final Preference simPref = findPreference(KEY_SMS);
    final SubscriptionInfo sir = mSubscriptionManager.getDefaultSmsSubscriptionInfo();
    simPref.setTitle(R.string.sms_messages_title);
    if (DBG)
        log("[updateSmsValues] mSubInfoList=" + mSubInfoList);
    if (sir != null) {
        simPref.setSummary(getSubscriptionDisplayName(sir));
        simPref.setEnabled(mSelectableSubInfos.size() > 1);
    } else if (sir == null) {
        simPref.setSummary(R.string.sim_selection_required_pref);
        simPref.setEnabled(mSelectableSubInfos.size() >= 1);
    }
}
Also used : Preference(android.support.v7.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo)

Aggregations

SubscriptionInfo (android.telephony.SubscriptionInfo)335 TelephonyManager (android.telephony.TelephonyManager)64 SubscriptionManager (android.telephony.SubscriptionManager)63 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)49 Context (android.content.Context)38 Intent (android.content.Intent)38 Preference (android.support.v7.preference.Preference)27 PhoneAccountHandle (android.telecom.PhoneAccountHandle)18 IntentFilter (android.content.IntentFilter)16 Resources (android.content.res.Resources)16 ConnectivityManager (android.net.ConnectivityManager)15 Preference (androidx.preference.Preference)15 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 DataUsageController (com.android.settingslib.net.DataUsageController)14 View (android.view.View)13 PhoneAccount (android.telecom.PhoneAccount)11 TelecomManager (android.telecom.TelecomManager)11 PendingIntent (android.app.PendingIntent)9