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
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.res.Resources;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.telephony.Annotation;
|
||||||
import android.telephony.CarrierConfigManager;
|
import android.telephony.CarrierConfigManager;
|
||||||
import android.telephony.CellSignalStrength;
|
import android.telephony.CellSignalStrength;
|
||||||
import android.telephony.PhoneStateListener;
|
import android.telephony.PhoneStateListener;
|
||||||
@@ -105,15 +106,18 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
public void onSubscriptionsChanged() {
|
public void onSubscriptionsChanged() {
|
||||||
mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfo(
|
mSubscriptionInfo = mSubscriptionManager.getActiveSubscriptionInfo(
|
||||||
mSubscriptionInfo.getSubscriptionId());
|
mSubscriptionInfo.getSubscriptionId());
|
||||||
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(
|
||||||
|
mSubscriptionInfo.getSubscriptionId());
|
||||||
updateNetworkProvider();
|
updateNetworkProvider();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private SubscriptionInfo mSubscriptionInfo;
|
private SubscriptionInfo mSubscriptionInfo;
|
||||||
|
|
||||||
private final int mSlotIndex;
|
private final int mSlotIndex;
|
||||||
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
private final SimStatusDialogFragment mDialog;
|
private final SimStatusDialogFragment mDialog;
|
||||||
private final TelephonyManager mTelephonyManager;
|
|
||||||
private final SubscriptionManager mSubscriptionManager;
|
private final SubscriptionManager mSubscriptionManager;
|
||||||
private final CarrierConfigManager mCarrierConfigManager;
|
private final CarrierConfigManager mCarrierConfigManager;
|
||||||
private final EuiccManager mEuiccManager;
|
private final EuiccManager mEuiccManager;
|
||||||
@@ -171,11 +175,13 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
mPhoneStateListener = getPhoneStateListener();
|
mPhoneStateListener = getPhoneStateListener();
|
||||||
updateNetworkProvider();
|
updateNetworkProvider();
|
||||||
|
|
||||||
final ServiceState serviceState = getCurrentServiceState();
|
final ServiceState serviceState = mTelephonyManager.getServiceState();
|
||||||
|
final SignalStrength signalStrength = mTelephonyManager.getSignalStrength();
|
||||||
|
|
||||||
updatePhoneNumber();
|
updatePhoneNumber();
|
||||||
updateLatestAreaInfo();
|
updateLatestAreaInfo();
|
||||||
updateServiceState(serviceState);
|
updateServiceState(serviceState);
|
||||||
updateSignalStrength(getSignalStrength());
|
updateSignalStrength(signalStrength);
|
||||||
updateNetworkType();
|
updateNetworkType();
|
||||||
updateRoamingStatus(serviceState);
|
updateRoamingStatus(serviceState);
|
||||||
updateIccidNumber();
|
updateIccidNumber();
|
||||||
@@ -187,12 +193,12 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
if (mSubscriptionInfo == null) {
|
if (mSubscriptionInfo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(
|
||||||
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
|
mSubscriptionInfo.getSubscriptionId());
|
||||||
.listen(mPhoneStateListener,
|
mTelephonyManager.listen(mPhoneStateListener,
|
||||||
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
|
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
|
||||||
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
|
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
|
||||||
| PhoneStateListener.LISTEN_SERVICE_STATE);
|
| PhoneStateListener.LISTEN_SERVICE_STATE);
|
||||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
||||||
|
|
||||||
if (mShowLatestAreaInfo) {
|
if (mShowLatestAreaInfo) {
|
||||||
@@ -214,8 +220,7 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
mSubscriptionManager.removeOnSubscriptionsChangedListener(mOnSubscriptionsChangedListener);
|
||||||
mTelephonyManager.createForSubscriptionId(mSubscriptionInfo.getSubscriptionId())
|
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
||||||
.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
|
|
||||||
|
|
||||||
if (mShowLatestAreaInfo) {
|
if (mShowLatestAreaInfo) {
|
||||||
mContext.unregisterReceiver(mAreaInfoReceiver);
|
mContext.unregisterReceiver(mAreaInfoReceiver);
|
||||||
@@ -318,7 +323,7 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceState serviceState = getCurrentServiceState();
|
ServiceState serviceState = mTelephonyManager.getServiceState();
|
||||||
if (serviceState == null || !Utils.isInService(serviceState)) {
|
if (serviceState == null || !Utils.isInService(serviceState)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -347,13 +352,13 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
String dataNetworkTypeName = null;
|
String dataNetworkTypeName = null;
|
||||||
String voiceNetworkTypeName = null;
|
String voiceNetworkTypeName = null;
|
||||||
final int subId = mSubscriptionInfo.getSubscriptionId();
|
final int subId = mSubscriptionInfo.getSubscriptionId();
|
||||||
final int actualDataNetworkType = mTelephonyManager.getDataNetworkType(subId);
|
final int actualDataNetworkType = mTelephonyManager.getDataNetworkType();
|
||||||
final int actualVoiceNetworkType = mTelephonyManager.getVoiceNetworkType(subId);
|
final int actualVoiceNetworkType = mTelephonyManager.getVoiceNetworkType();
|
||||||
if (TelephonyManager.NETWORK_TYPE_UNKNOWN != actualDataNetworkType) {
|
if (TelephonyManager.NETWORK_TYPE_UNKNOWN != actualDataNetworkType) {
|
||||||
dataNetworkTypeName = mTelephonyManager.getNetworkTypeName(actualDataNetworkType);
|
dataNetworkTypeName = getNetworkTypeName(actualDataNetworkType);
|
||||||
}
|
}
|
||||||
if (TelephonyManager.NETWORK_TYPE_UNKNOWN != actualVoiceNetworkType) {
|
if (TelephonyManager.NETWORK_TYPE_UNKNOWN != actualVoiceNetworkType) {
|
||||||
voiceNetworkTypeName = mTelephonyManager.getNetworkTypeName(actualVoiceNetworkType);
|
voiceNetworkTypeName = getNetworkTypeName(actualVoiceNetworkType);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean show4GForLTE = false;
|
boolean show4GForLTE = false;
|
||||||
@@ -398,7 +403,7 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
mDialog.removeSettingFromScreen(ICCID_INFO_LABEL_ID);
|
mDialog.removeSettingFromScreen(ICCID_INFO_LABEL_ID);
|
||||||
mDialog.removeSettingFromScreen(ICCID_INFO_VALUE_ID);
|
mDialog.removeSettingFromScreen(ICCID_INFO_VALUE_ID);
|
||||||
} else {
|
} else {
|
||||||
mDialog.setText(ICCID_INFO_VALUE_ID, getSimSerialNumber(subscriptionId));
|
mDialog.setText(ICCID_INFO_VALUE_ID, mTelephonyManager.getSimSerialNumber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,12 +469,6 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
return SubscriptionManager.from(mContext).getActiveSubscriptionInfoForSimSlotIndex(slotId);
|
return SubscriptionManager.from(mContext).getActiveSubscriptionInfoForSimSlotIndex(slotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
ServiceState getCurrentServiceState() {
|
|
||||||
return mTelephonyManager.getServiceStateForSubscriber(
|
|
||||||
mSubscriptionInfo.getSubscriptionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getDbm(SignalStrength signalStrength) {
|
private int getDbm(SignalStrength signalStrength) {
|
||||||
List<CellSignalStrength> cellSignalStrengthList = signalStrength.getCellSignalStrengths();
|
List<CellSignalStrength> cellSignalStrengthList = signalStrength.getCellSignalStrengths();
|
||||||
int dbm = -1;
|
int dbm = -1;
|
||||||
@@ -528,12 +527,50 @@ public class SimStatusDialogController implements LifecycleObserver, OnResume, O
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
SignalStrength getSignalStrength() {
|
static String getNetworkTypeName(@Annotation.NetworkType int type) {
|
||||||
return mTelephonyManager.getSignalStrength();
|
switch (type) {
|
||||||
}
|
case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||||
|
return "GPRS";
|
||||||
@VisibleForTesting
|
case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||||
String getSimSerialNumber(int subscriptionId) {
|
return "EDGE";
|
||||||
return mTelephonyManager.getSimSerialNumber(subscriptionId);
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -134,7 +134,6 @@ public class SimStatusDialogControllerTest {
|
|||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */));
|
mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */));
|
||||||
ShadowDeviceInfoUtils.setPhoneNumber("");
|
ShadowDeviceInfoUtils.setPhoneNumber("");
|
||||||
doReturn(mServiceState).when(mController).getCurrentServiceState();
|
|
||||||
//CellSignalStrength setup
|
//CellSignalStrength setup
|
||||||
doReturn(0).when(mCellSignalStrengthCdma).getDbm();
|
doReturn(0).when(mCellSignalStrengthCdma).getDbm();
|
||||||
doReturn(0).when(mCellSignalStrengthCdma).getAsuLevel();
|
doReturn(0).when(mCellSignalStrengthCdma).getAsuLevel();
|
||||||
@@ -145,7 +144,6 @@ public class SimStatusDialogControllerTest {
|
|||||||
|
|
||||||
doReturn(null).when(mSignalStrength).getCellSignalStrengths();
|
doReturn(null).when(mSignalStrength).getCellSignalStrengths();
|
||||||
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
|
doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
|
||||||
doReturn(mSignalStrength).when(mController).getSignalStrength();
|
|
||||||
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
|
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
|
||||||
|
|
||||||
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
|
ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
|
||||||
@@ -168,6 +166,9 @@ public class SimStatusDialogControllerTest {
|
|||||||
when(mPersistableBundle.getBoolean(
|
when(mPersistableBundle.getBoolean(
|
||||||
CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL))
|
CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
|
||||||
|
doReturn(mServiceState).when(mTelephonyManager).getServiceState();
|
||||||
|
doReturn(mSignalStrength).when(mTelephonyManager).getSignalStrength();
|
||||||
|
|
||||||
final ShadowPackageManager shadowPackageManager =
|
final ShadowPackageManager shadowPackageManager =
|
||||||
Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
|
Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
|
||||||
@@ -330,25 +331,25 @@ public class SimStatusDialogControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void initialize_updateVoiceNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
|
public void initialize_updateVoiceNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
|
||||||
when(mTelephonyManager.getVoiceNetworkType(anyInt())).thenReturn(
|
when(mTelephonyManager.getVoiceNetworkType()).thenReturn(
|
||||||
TelephonyManager.NETWORK_TYPE_EDGE);
|
TelephonyManager.NETWORK_TYPE_EDGE);
|
||||||
|
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
verify(mDialog).setText(CELL_VOICE_NETWORK_TYPE_VALUE_ID,
|
verify(mDialog).setText(CELL_VOICE_NETWORK_TYPE_VALUE_ID,
|
||||||
TelephonyManager.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
|
SimStatusDialogController.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void initialize_updateDataNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
|
public void initialize_updateDataNetworkTypeWithEdge_shouldUpdateSettingToEdge() {
|
||||||
when(mTelephonyManager.getDataNetworkType(anyInt())).thenReturn(
|
when(mTelephonyManager.getDataNetworkType()).thenReturn(
|
||||||
TelephonyManager.NETWORK_TYPE_EDGE);
|
TelephonyManager.NETWORK_TYPE_EDGE);
|
||||||
|
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
verify(mDialog).setText(CELL_DATA_NETWORK_TYPE_VALUE_ID,
|
verify(mDialog).setText(CELL_DATA_NETWORK_TYPE_VALUE_ID,
|
||||||
TelephonyManager.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
|
SimStatusDialogController.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -417,7 +418,7 @@ public class SimStatusDialogControllerTest {
|
|||||||
final String iccid = "12351351231241";
|
final String iccid = "12351351231241";
|
||||||
when(mPersistableBundle.getBoolean(
|
when(mPersistableBundle.getBoolean(
|
||||||
CarrierConfigManager.KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL)).thenReturn(true);
|
CarrierConfigManager.KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL)).thenReturn(true);
|
||||||
doReturn(iccid).when(mController).getSimSerialNumber(anyInt());
|
doReturn(iccid).when(mTelephonyManager).getSimSerialNumber();
|
||||||
|
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
|
|
||||||
@@ -757,7 +758,7 @@ public class SimStatusDialogControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void initialize_nullSignalStrength_noCrash() {
|
public void initialize_nullSignalStrength_noCrash() {
|
||||||
doReturn(null).when(mController).getSignalStrength();
|
doReturn(null).when(mTelephonyManager).getSignalStrength();
|
||||||
// we should not crash when running the following line
|
// we should not crash when running the following line
|
||||||
mController.initialize();
|
mController.initialize();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user