Mainline:SimStatusDialogController decouple TelephonyManager hidden APIs
- telephonymanager set subid by createForSubscriptionId
-getDataNetworkType(I)
-getVoiceNetworkType(I)
-getSimSerialNumber(I)
-getServiceStateForSubscriber(I)
- copy getNetworkTypeName() to SimStatusDialogController
Bug: 143998492
Test: Build pass.
make RunSettingsRoboTests ROBOTEST_FILTER\
=SimStatusDialogControllerTest
Change-Id: Ieb8547496a4b0da7332abd227056f9b786c7ef6a
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index b1f089a..26d8e2b 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -25,6 +25,7 @@
import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.UserHandle;
+import android.telephony.Annotation;
import android.telephony.CarrierConfigManager;
import android.telephony.CellSignalStrength;
import android.telephony.PhoneStateListener;
@@ -105,15 +106,18 @@
public void onSubscriptionsChanged() {
mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfo(
mSubscriptionInfo.getSubscriptionId());
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(
+ mSubscriptionInfo.getSubscriptionId());
updateNetworkProvider();
}
};
private SubscriptionInfo mSubscriptionInfo;
+
private final int mSlotIndex;
+ private TelephonyManager mTelephonyManager;
private final SimStatusDialogFragment mDialog;
- private final TelephonyManager mTelephonyManager;
private final SubscriptionManager mSubscriptionManager;
private final CarrierConfigManager mCarrierConfigManager;
private final EuiccManager mEuiccManager;
@@ -171,11 +175,13 @@
mPhoneStateListener = getPhoneStateListener();
updateNetworkProvider();
- final ServiceState serviceState = getCurrentServiceState();
+ final ServiceState serviceState = mTelephonyManager.getServiceState();
+ final SignalStrength signalStrength = mTelephonyManager.getSignalStrength();
+
updatePhoneNumber();
updateLatestAreaInfo();
updateServiceState(serviceState);
- updateSignalStrength(getSignalStrength());
+ updateSignalStrength(signalStrength);
updateNetworkType();
updateRoamingStatus(serviceState);
updateIccidNumber();
@@ -187,12 +193,12 @@
if (mSubscriptionInfo == null) {
return;
}
-
- mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
- .listen(mPhoneStateListener,
- PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
- | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
- | PhoneStateListener.LISTEN_SERVICE_STATE);
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(
+ mSubscriptionInfo.getSubscriptionId());
+ mTelephonyManager.listen(mPhoneStateListener,
+ PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
+ | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
+ | PhoneStateListener.LISTEN_SERVICE_STATE);
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
if (mShowLatestAreaInfo) {
@@ -214,8 +220,7 @@
}
mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
- mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
- .listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+ mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
if (mShowLatestAreaInfo) {
mContext.unregisterReceiver(mAreaInfoReceiver);
@@ -318,7 +323,7 @@
return;
}
- ServiceState serviceState = getCurrentServiceState();
+ ServiceState serviceState = mTelephonyManager.getServiceState();
if (serviceState == null || !Utils.isInService(serviceState)) {
return;
}
@@ -347,13 +352,13 @@
String dataNetworkTypeName = null;
String voiceNetworkTypeName = null;
final int subId = mSubscriptionInfo.getSubscriptionId();
- final int actualDataNetworkType = mTelephonyManager.getDataNetworkType(subId);
- final int actualVoiceNetworkType = mTelephonyManager.getVoiceNetworkType(subId);
+ final int actualDataNetworkType = mTelephonyManager.getDataNetworkType();
+ final int actualVoiceNetworkType = mTelephonyManager.getVoiceNetworkType();
if (TelephonyManager.NETWORK_TYPE_UNKNOWN != actualDataNetworkType) {
- dataNetworkTypeName = mTelephonyManager.getNetworkTypeName(actualDataNetworkType);
+ dataNetworkTypeName = getNetworkTypeName(actualDataNetworkType);
}
if (TelephonyManager.NETWORK_TYPE_UNKNOWN != actualVoiceNetworkType) {
- voiceNetworkTypeName = mTelephonyManager.getNetworkTypeName(actualVoiceNetworkType);
+ voiceNetworkTypeName = getNetworkTypeName(actualVoiceNetworkType);
}
boolean show4GForLTE = false;
@@ -398,7 +403,7 @@
mDialog.removeSettingFromScreen(ICCID_INFO_LABEL_ID);
mDialog.removeSettingFromScreen(ICCID_INFO_VALUE_ID);
} else {
- mDialog.setText(ICCID_INFO_VALUE_ID, getSimSerialNumber(subscriptionId));
+ mDialog.setText(ICCID_INFO_VALUE_ID, mTelephonyManager.getSimSerialNumber());
}
}
@@ -464,12 +469,6 @@
return SubscriptionManager.from(mContext).getActiveSubscriptionInfoForSimSlotIndex(slotId);
}
- @VisibleForTesting
- ServiceState getCurrentServiceState() {
- return mTelephonyManager.getServiceStateForSubscriber(
- mSubscriptionInfo.getSubscriptionId());
- }
-
private int getDbm(SignalStrength signalStrength) {
List<CellSignalStrength> cellSignalStrengthList = signalStrength.getCellSignalStrengths();
int dbm = -1;
@@ -528,12 +527,50 @@
}
@VisibleForTesting
- SignalStrength getSignalStrength() {
- return mTelephonyManager.getSignalStrength();
- }
-
- @VisibleForTesting
- String getSimSerialNumber(int subscriptionId) {
- return mTelephonyManager.getSimSerialNumber(subscriptionId);
+ static String getNetworkTypeName(@Annotation.NetworkType int type) {
+ switch (type) {
+ case TelephonyManager.NETWORK_TYPE_GPRS:
+ return "GPRS";
+ case TelephonyManager.NETWORK_TYPE_EDGE:
+ return "EDGE";
+ case TelephonyManager.NETWORK_TYPE_UMTS:
+ return "UMTS";
+ case TelephonyManager.NETWORK_TYPE_HSDPA:
+ return "HSDPA";
+ case TelephonyManager.NETWORK_TYPE_HSUPA:
+ return "HSUPA";
+ case TelephonyManager.NETWORK_TYPE_HSPA:
+ return "HSPA";
+ case TelephonyManager.NETWORK_TYPE_CDMA:
+ return "CDMA";
+ case TelephonyManager.NETWORK_TYPE_EVDO_0:
+ return "CDMA - EvDo rev. 0";
+ case TelephonyManager.NETWORK_TYPE_EVDO_A:
+ return "CDMA - EvDo rev. A";
+ case TelephonyManager.NETWORK_TYPE_EVDO_B:
+ return "CDMA - EvDo rev. B";
+ case TelephonyManager.NETWORK_TYPE_1xRTT:
+ return "CDMA - 1xRTT";
+ case TelephonyManager.NETWORK_TYPE_LTE:
+ return "LTE";
+ case TelephonyManager.NETWORK_TYPE_EHRPD:
+ return "CDMA - eHRPD";
+ case TelephonyManager.NETWORK_TYPE_IDEN:
+ return "iDEN";
+ case TelephonyManager.NETWORK_TYPE_HSPAP:
+ return "HSPA+";
+ case TelephonyManager.NETWORK_TYPE_GSM:
+ return "GSM";
+ case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
+ return "TD_SCDMA";
+ case TelephonyManager.NETWORK_TYPE_IWLAN:
+ return "IWLAN";
+ case TelephonyManager.NETWORK_TYPE_LTE_CA:
+ return "LTE_CA";
+ case TelephonyManager.NETWORK_TYPE_NR:
+ return "NR";
+ default:
+ return "UNKNOWN";
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
index 41ae49c..782fb25 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
@@ -134,7 +134,6 @@
mLifecycle = new Lifecycle(mLifecycleOwner);
mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */));
ShadowDeviceInfoUtils.setPhoneNumber("");
- doReturn(mServiceState).when(mController).getCurrentServiceState();
//CellSignalStrength setup
doReturn(0).when(mCellSignalStrengthCdma).getDbm();
doReturn(0).when(mCellSignalStrengthCdma).getAsuLevel();
@@ -145,7 +144,6 @@
doReturn(null).when(mSignalStrength).getCellSignalStrengths();
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
- doReturn(mSignalStrength).when(mController).getSignalStrength();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
@@ -168,6 +166,9 @@
when(mPersistableBundle.getBoolean(
CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL))
.thenReturn(true);
+ when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
+ doReturn(mServiceState).when(mTelephonyManager).getServiceState();
+ doReturn(mSignalStrength).when(mTelephonyManager).getSignalStrength();
final ShadowPackageManager shadowPackageManager =
Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
@@ -330,25 +331,25 @@
@Test
@Ignore
public void initialize_updateVoiceNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
- when(mTelephonyManager.getVoiceNetworkType(anyInt())).thenReturn(
+ when(mTelephonyManager.getVoiceNetworkType()).thenReturn(
TelephonyManager.NETWORK_TYPE_EDGE);
mController.initialize();
verify(mDialog).setText(CELL_VOICE_NETWORK_TYPE_VALUE_ID,
- TelephonyManager.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
+ SimStatusDialogController.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
}
@Test
@Ignore
public void initialize_updateDataNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
- when(mTelephonyManager.getDataNetworkType(anyInt())).thenReturn(
+ when(mTelephonyManager.getDataNetworkType()).thenReturn(
TelephonyManager.NETWORK_TYPE_EDGE);
mController.initialize();
verify(mDialog).setText(CELL_DATA_NETWORK_TYPE_VALUE_ID,
- TelephonyManager.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
+ SimStatusDialogController.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
}
@Test
@@ -417,7 +418,7 @@
final String iccid = "12351351231241";
when(mPersistableBundle.getBoolean(
CarrierConfigManager.KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL)).thenReturn(true);
- doReturn(iccid).when(mController).getSimSerialNumber(anyInt());
+ doReturn(iccid).when(mTelephonyManager).getSimSerialNumber();
mController.initialize();
@@ -757,7 +758,7 @@
@Test
@Ignore
public void initialize_nullSignalStrength_noCrash() {
- doReturn(null).when(mController).getSignalStrength();
+ doReturn(null).when(mTelephonyManager).getSignalStrength();
// we should not crash when running the following line
mController.initialize();
}