Move hasReadyMobileRadio() to DataUsageUtils.
- move the method from DataUsageList to DataUsageUtils where other utility methods are. Bug: 111751694 Test: make RunSettingsRoboTests Change-Id: If7176cb4278d568f890a0c94437c4483bbd472f9
This commit is contained in:
@@ -132,7 +132,7 @@ public class AppDataUsagePreferenceController extends AppInfoPreferenceControlle
|
||||
}
|
||||
|
||||
private static NetworkTemplate getTemplate(Context context) {
|
||||
if (DataUsageList.hasReadyMobileRadio(context)) {
|
||||
if (DataUsageUtils.hasReadyMobileRadio(context)) {
|
||||
return NetworkTemplate.buildTemplateMobileWildcard();
|
||||
}
|
||||
if (DataUsageUtils.hasWifiRadio(context)) {
|
||||
|
@@ -479,63 +479,6 @@ public class DataUsageList extends DataUsageBaseFragment {
|
||||
return Math.max(largest, item.total);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: consider adding to TelephonyManager or SubscriptionManager.
|
||||
*/
|
||||
public static boolean hasReadyMobileRadio(Context context, int subId) {
|
||||
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 int slotId = SubscriptionManager.getSlotIndex(subId);
|
||||
final boolean isReady = tele.getSimState(slotId) == SIM_STATE_READY;
|
||||
|
||||
boolean retVal = conn.isNetworkSupported(TYPE_MOBILE) && isReady;
|
||||
if (LOGD) {
|
||||
Log.d(TAG, "hasReadyMobileRadio: subId=" + subId
|
||||
+ " conn.isNetworkSupported(TYPE_MOBILE)="
|
||||
+ conn.isNetworkSupported(TYPE_MOBILE)
|
||||
+ " isReady=" + isReady);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private OnItemSelectedListener mCycleListener = new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
@@ -483,63 +483,6 @@ public class DataUsageListV2 extends DataUsageBaseFragment {
|
||||
return Math.max(largest, item.total);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: consider adding to TelephonyManager or SubscriptionManager.
|
||||
*/
|
||||
public static boolean hasReadyMobileRadio(Context context, int subId) {
|
||||
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 int slotId = SubscriptionManager.getSlotIndex(subId);
|
||||
final boolean isReady = tele.getSimState(slotId) == SIM_STATE_READY;
|
||||
|
||||
boolean retVal = conn.isNetworkSupported(TYPE_MOBILE) && isReady;
|
||||
if (LOGD) {
|
||||
Log.d(TAG, "hasReadyMobileRadio: subId=" + subId
|
||||
+ " conn.isNetworkSupported(TYPE_MOBILE)="
|
||||
+ conn.isNetworkSupported(TYPE_MOBILE)
|
||||
+ " isReady=" + isReady);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private OnItemSelectedListener mCycleListener = new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
@@ -14,7 +14,9 @@
|
||||
|
||||
package com.android.settings.datausage;
|
||||
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.telephony.TelephonyManager.SIM_STATE_READY;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
@@ -31,6 +33,7 @@ import android.telephony.TelephonyManager;
|
||||
import android.text.BidiFormatter;
|
||||
import android.text.format.Formatter;
|
||||
import android.text.format.Formatter.BytesResult;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -40,7 +43,9 @@ import java.util.List;
|
||||
public final class DataUsageUtils {
|
||||
static final boolean TEST_RADIOS = false;
|
||||
static final String TEST_RADIOS_PROP = "test.radios";
|
||||
private static final boolean LOGD = false;
|
||||
private static final String ETHERNET = "ethernet";
|
||||
private static final String TAG = "DataUsageUtils";
|
||||
|
||||
private DataUsageUtils() {
|
||||
}
|
||||
@@ -98,6 +103,42 @@ public final class DataUsageUtils {
|
||||
.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 List<SubscriptionInfo> subInfoList =
|
||||
SubscriptionManager.from(context).getActiveSubscriptionInfoList();
|
||||
// No activated Subscriptions
|
||||
if (subInfoList == null) {
|
||||
if (LOGD) {
|
||||
Log.d(TAG, "hasReadyMobileRadio: subInfoList=null");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
final TelephonyManager tele = TelephonyManager.from(context);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
final ConnectivityManager conn = ConnectivityManager.from(context);
|
||||
final 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether device has a Wi-Fi data radio.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user