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();
}
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();
}
}
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;
}
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();
}
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);
}
}
Aggregations