From edaeb41ff796a0c49f5187c6b2ec530ffb5c8455 Mon Sep 17 00:00:00 2001 From: tom hsu Date: Thu, 4 Mar 2021 20:45:55 +0800 Subject: [PATCH] [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 --- .../settings/network/SubscriptionsPreferenceController.java | 3 ++- .../network/SubscriptionsPreferenceControllerTest.java | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java index 392ccc6aba5..f89ccfdde80 100644 --- a/src/com/android/settings/network/SubscriptionsPreferenceController.java +++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java @@ -257,9 +257,10 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl } private CharSequence getMobilePreferenceSummary(int subId) { + TelephonyManager tm = mTelephonyManager.createForSubscriptionId(subId); String result = mSubsPrefCtrlInjector.getNetworkType( mContext, mConfig, mTelephonyDisplayInfo, subId); - if (!mTelephonyManager.isDataEnabled()) { + if (!tm.isDataEnabled()) { return mContext.getString(R.string.mobile_data_off_summary); } if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) { diff --git a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java index 6b31342d31e..699760741e8 100644 --- a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java @@ -97,6 +97,7 @@ public class SubscriptionsPreferenceControllerTest { private LifecycleOwner mLifecycleOwner; @Mock private WifiPickerTrackerHelper mWifiPickerTrackerHelper; + private LifecycleRegistry mLifecycleRegistry; private int mOnChildUpdatedCount; private Context mContext; @@ -428,7 +429,6 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); - when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen); @@ -447,7 +447,7 @@ public class SubscriptionsPreferenceControllerTest { final List sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); 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); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); @@ -534,7 +534,6 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); - when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen);