use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by crdroidandroid.
the class CellDataPreference method performClick.
@Override
protected void performClick(View view) {
final Context context = getContext();
FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(context, MetricsEvent.ACTION_CELL_DATA_TOGGLE, !mChecked);
final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
if (mChecked) {
// the pop-up.
if (!Utils.showSimCardTile(getContext()) || (nextSir != null && currentSir != null && currentSir.getSubscriptionId() == nextSir.getSubscriptionId())) {
setMobileDataEnabled(false);
if (nextSir != null && currentSir != null && currentSir.getSubscriptionId() == nextSir.getSubscriptionId()) {
disableDataForOtherSubscriptions(mSubId);
}
return;
}
// disabling data; show confirmation dialog which eventually
// calls setMobileDataEnabled() once user confirms.
mMultiSimDialog = false;
super.performClick(view);
} else {
// If we are showing the Sim Card tile then we are a Multi-Sim device.
if (Utils.showSimCardTile(getContext())) {
mMultiSimDialog = true;
if (nextSir != null && currentSir != null && currentSir.getSubscriptionId() == nextSir.getSubscriptionId()) {
setMobileDataEnabled(true);
disableDataForOtherSubscriptions(mSubId);
return;
}
super.performClick(view);
} else {
setMobileDataEnabled(true);
}
}
}
use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by crdroidandroid.
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);
setUserPrefDataSubIdInDb(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 crdroidandroid.
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 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());
setUserPrefDataSubIdInDb(sir.getSubscriptionId());
break;
case CALLS_PICK:
final TelecomManager telecomManager = TelecomManager.from(context);
final List<PhoneAccountHandle> phoneAccountsList = telecomManager.getCallCapablePhoneAccounts();
setUserSelectedOutgoingPhoneAccount(value < 1 ? null : phoneAccountsList.get(value - 1));
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;
}
};
ArrayList<SubscriptionInfo> callsSubInfoList = new ArrayList<SubscriptionInfo>();
if (id == CALLS_PICK) {
final TelecomManager telecomManager = TelecomManager.from(context);
final TelephonyManager telephonyManager = TelephonyManager.from(context);
final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
callsSubInfoList.add(null);
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);
}
}
} 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.sim_card_select_title);
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 crdroidandroid.
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 crdroidandroid.
the class ResetNetwork method establishInitialState.
/**
* In its initial state, the activity presents a button for the user to
* click in order to initiate a confirmation sequence. This method is
* called from various other points in the code to reset the activity to
* this base state.
*
* <p>Reinflating views from resources is expensive and prevents us from
* caching widget pointers, so we use a single-inflate pattern: we lazy-
* inflate each view, caching all of the widget pointers we'll need at the
* time, then simply reuse the inflated views directly whenever we need
* to change contents.
*/
private void establishInitialState() {
mSubscriptionSpinner = (Spinner) mContentView.findViewById(R.id.reset_network_subscription);
mSubscriptions = SubscriptionManager.from(getActivity()).getActiveSubscriptionInfoList();
if (mSubscriptions != null && mSubscriptions.size() > 0) {
// Get the default subscription in the order of data, voice, sms, first up.
int defaultSubscription = SubscriptionManager.getDefaultDataSubscriptionId();
if (!SubscriptionManager.isUsableSubIdValue(defaultSubscription)) {
defaultSubscription = SubscriptionManager.getDefaultVoiceSubscriptionId();
}
if (!SubscriptionManager.isUsableSubIdValue(defaultSubscription)) {
defaultSubscription = SubscriptionManager.getDefaultSmsSubscriptionId();
}
if (!SubscriptionManager.isUsableSubIdValue(defaultSubscription)) {
defaultSubscription = SubscriptionManager.getDefaultSubscriptionId();
}
int selectedIndex = 0;
int size = mSubscriptions.size();
List<String> subscriptionNames = new ArrayList<>();
for (SubscriptionInfo record : mSubscriptions) {
if (record.getSubscriptionId() == defaultSubscription) {
// Set the first selected value to the default
selectedIndex = subscriptionNames.size();
}
String name = record.getDisplayName().toString();
if (TextUtils.isEmpty(name)) {
name = record.getNumber();
}
if (TextUtils.isEmpty(name)) {
name = record.getCarrierName().toString();
}
if (TextUtils.isEmpty(name)) {
name = String.format("MCC:%s MNC:%s Slot:%s Id:%s", record.getMcc(), record.getMnc(), record.getSimSlotIndex(), record.getSubscriptionId());
}
subscriptionNames.add(name);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, subscriptionNames);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSubscriptionSpinner.setAdapter(adapter);
mSubscriptionSpinner.setSelection(selectedIndex);
if (mSubscriptions.size() > 1) {
mSubscriptionSpinner.setVisibility(View.VISIBLE);
} else {
mSubscriptionSpinner.setVisibility(View.INVISIBLE);
}
} else {
mSubscriptionSpinner.setVisibility(View.INVISIBLE);
}
mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_reset_network);
mInitiateButton.setOnClickListener(mInitiateListener);
}
Aggregations