[Provider Model] Fix preference summary not update.

- When activity enter onPause, the status will not update, then
 sub id of TelephonyManager keep same value after activity go back.

 - Solution: Everytime update the UI, and always get new
 TelephonyManager with the latest sub id.

Bug: 181196545
Test: atest passed.
Test: Manual test passed.
Change-Id: I1d65bbc06af66b97b6c85f40bed394da03213d06
This commit is contained in:
tom hsu
2021-03-04 20:45:55 +08:00
parent 54e4a3097a
commit edaeb41ff7
2 changed files with 4 additions and 4 deletions

View File

@@ -257,9 +257,10 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
} }
private CharSequence getMobilePreferenceSummary(int subId) { private CharSequence getMobilePreferenceSummary(int subId) {
TelephonyManager tm = mTelephonyManager.createForSubscriptionId(subId);
String result = mSubsPrefCtrlInjector.getNetworkType( String result = mSubsPrefCtrlInjector.getNetworkType(
mContext, mConfig, mTelephonyDisplayInfo, subId); mContext, mConfig, mTelephonyDisplayInfo, subId);
if (!mTelephonyManager.isDataEnabled()) { if (!tm.isDataEnabled()) {
return mContext.getString(R.string.mobile_data_off_summary); return mContext.getString(R.string.mobile_data_off_summary);
} }
if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) { if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) {

View File

@@ -97,6 +97,7 @@ public class SubscriptionsPreferenceControllerTest {
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
@Mock @Mock
private WifiPickerTrackerHelper mWifiPickerTrackerHelper; private WifiPickerTrackerHelper mWifiPickerTrackerHelper;
private LifecycleRegistry mLifecycleRegistry; private LifecycleRegistry mLifecycleRegistry;
private int mOnChildUpdatedCount; private int mOnChildUpdatedCount;
private Context mContext; private Context mContext;
@@ -428,7 +429,6 @@ public class SubscriptionsPreferenceControllerTest {
doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
doReturn(networkType) doReturn(networkType)
.when(sInjector).getNetworkType(any(), any(), any(), anyInt()); .when(sInjector).getNetworkType(any(), any(), any(), anyInt());
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
mController.onResume(); mController.onResume();
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);
@@ -447,7 +447,7 @@ public class SubscriptionsPreferenceControllerTest {
final List<SubscriptionInfo> sub = setupMockSubscriptions(2); final List<SubscriptionInfo> sub = setupMockSubscriptions(2);
doReturn(true).when(sInjector).isProviderModelEnabled(mContext); doReturn(true).when(sInjector).isProviderModelEnabled(mContext);
doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true, setupGetIconConditions(sub.get(0).getSubscriptionId(), false, false,
TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE); TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE);
doReturn(networkType) doReturn(networkType)
.when(sInjector).getNetworkType(any(), any(), any(), anyInt()); .when(sInjector).getNetworkType(any(), any(), any(), anyInt());
@@ -534,7 +534,6 @@ public class SubscriptionsPreferenceControllerTest {
doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext);
doReturn(networkType) doReturn(networkType)
.when(sInjector).getNetworkType(any(), any(), any(), anyInt()); .when(sInjector).getNetworkType(any(), any(), any(), anyInt());
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
mController.onResume(); mController.onResume();
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);