use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by SudaMod.
the class DataUsageList method hasReadyMobileRadio.
/**
* Test if device has a mobile data radio with SIM in ready state.
*/
public static boolean hasReadyMobileRadio(Context context) {
if (DataUsageUtils.TEST_RADIOS) {
return SystemProperties.get(DataUsageUtils.TEST_RADIOS_PROP).contains("mobile");
}
final ConnectivityManager conn = ConnectivityManager.from(context);
final TelephonyManager tele = TelephonyManager.from(context);
final List<SubscriptionInfo> subInfoList = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
// No activated Subscriptions
if (subInfoList == null) {
if (LOGD)
Log.d(TAG, "hasReadyMobileRadio: subInfoList=null");
return false;
}
// require both supported network and ready SIM
boolean isReady = true;
for (SubscriptionInfo subInfo : subInfoList) {
isReady = isReady & tele.getSimState(subInfo.getSimSlotIndex()) == SIM_STATE_READY;
if (LOGD)
Log.d(TAG, "hasReadyMobileRadio: subInfo=" + subInfo);
}
boolean retVal = conn.isNetworkSupported(TYPE_MOBILE) && isReady;
if (LOGD) {
Log.d(TAG, "hasReadyMobileRadio:" + " conn.isNetworkSupported(TYPE_MOBILE)=" + conn.isNetworkSupported(TYPE_MOBILE) + " isReady=" + isReady);
}
return retVal;
}
use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by SudaMod.
the class DataUsageSummary method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Context context = getContext();
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
mDataUsageController = new DataUsageController(context);
mDataInfoController = new DataUsageInfoController();
addPreferencesFromResource(R.xml.data_usage);
int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(context);
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
hasMobileData = false;
}
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, defaultSubId);
mSummaryPreference = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
if (!hasMobileData || !isAdmin()) {
removePreference(KEY_RESTRICT_BACKGROUND);
}
if (hasMobileData) {
mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
List<SubscriptionInfo> subscriptions = services.mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptions == null || subscriptions.size() == 0) {
addMobileSection(defaultSubId);
}
for (int i = 0; subscriptions != null && i < subscriptions.size(); i++) {
SubscriptionInfo subInfo = subscriptions.get(i);
if (subscriptions.size() > 1) {
addMobileSection(subInfo.getSubscriptionId(), subInfo);
} else {
addMobileSection(subInfo.getSubscriptionId());
}
}
mSummaryPreference.setSelectable(true);
} else {
removePreference(KEY_LIMIT_SUMMARY);
mSummaryPreference.setSelectable(false);
}
boolean hasWifiRadio = DataUsageUtils.hasWifiRadio(context);
if (hasWifiRadio) {
addWifiSection();
}
if (hasEthernet(context)) {
addEthernetSection();
}
mDataUsageTemplate = hasMobileData ? R.string.cell_data_template : hasWifiRadio ? R.string.wifi_data_template : R.string.ethernet_data_template;
setHasOptionsMenu(true);
}
use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by SudaMod.
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 SudaMod.
the class SecuritySettings method isSimIccReady.
/* Return true if a there is a Slot that has Icc.
*/
private boolean isSimIccReady() {
TelephonyManager tm = TelephonyManager.getDefault();
final List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
if (tm.hasIccCard(subInfo.getSimSlotIndex())) {
return true;
}
}
}
return false;
}
use of android.telephony.SubscriptionInfo in project android_packages_apps_Settings by SudaMod.
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;
}
Aggregations