diff options
| author | 2024-01-12 23:23:20 +0800 | |
|---|---|---|
| committer | 2024-01-25 04:10:00 +0800 | |
| commit | bd8baaa2a8a5854d38e8e04f0c834a551d73e3a2 (patch) | |
| tree | a2fdf7af1aeb6b7caf1ce4733b0d7245693ee14c | |
| parent | 6c202d41c8eb9b795db0c6224b32f1b1e3c4e172 (diff) | |
Reduce the number of getActiveSubscriptionIdList calls
- Refresh getActiveSubscriptionIdList data when onSubscriptionsChanged
Fix: 316004516
Flag: None
Test: unit test
atest -c SystemUITests:InternetDialogControllerTest
Change-Id: I35080b578e82a7fdd133e880edf9c9d8c4736911
2 files changed, 31 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java index 592cb3b18e80..211b459471de 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java @@ -192,6 +192,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi private DialogLaunchAnimator mDialogLaunchAnimator; private boolean mHasWifiEntries; private WifiStateWorker mWifiStateWorker; + private boolean mHasActiveSubId; @VisibleForTesting static final float TOAST_PARAMS_HORIZONTAL_WEIGHT = 1.0f; @@ -299,6 +300,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi mExecutor); // Listen the subscription changes mOnSubscriptionsChangedListener = new InternetOnSubscriptionChangedListener(); + refreshHasActiveSubId(); mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor, mOnSubscriptionsChangedListener); mDefaultDataSubId = getDefaultDataSubscriptionId(); @@ -901,18 +903,22 @@ public class InternetDialogController implements AccessPointController.AccessPoi * @return whether there is the carrier item in the slice. */ boolean hasActiveSubId() { - if (mSubscriptionManager == null) { - if (DEBUG) { - Log.d(TAG, "SubscriptionManager is null, can not check carrier."); - } + if (isAirplaneModeEnabled() || mTelephonyManager == null) { return false; } - if (isAirplaneModeEnabled() || mTelephonyManager == null - || mSubscriptionManager.getActiveSubscriptionIdList().length <= 0) { - return false; + return mHasActiveSubId; + } + + private void refreshHasActiveSubId() { + if (mSubscriptionManager == null) { + mHasActiveSubId = false; + Log.e(TAG, "SubscriptionManager is null, set mHasActiveSubId = false"); + return; } - return true; + + mHasActiveSubId = mSubscriptionManager.getActiveSubscriptionIdList().length > 0; + Log.i(TAG, "mHasActiveSubId:" + mHasActiveSubId); } /** @@ -1204,6 +1210,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi @Override public void onSubscriptionsChanged() { + refreshHasActiveSubId(); updateListener(); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java index b24b8773d600..c0ef50fa9072 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java @@ -1069,6 +1069,22 @@ public class InternetDialogControllerTest extends SysuiTestCase { assertThat(mInternetDialogController.mCallback).isNull(); } + @Test + public void hasActiveSubId_activeSubIdListIsEmpty_returnFalse() { + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{}); + mInternetDialogController.mOnSubscriptionsChangedListener.onSubscriptionsChanged(); + + assertThat(mInternetDialogController.hasActiveSubId()).isFalse(); + } + + @Test + public void hasActiveSubId_activeSubIdListNotEmpty_returnTrue() { + when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[]{SUB_ID}); + mInternetDialogController.mOnSubscriptionsChangedListener.onSubscriptionsChanged(); + + assertThat(mInternetDialogController.hasActiveSubId()).isTrue(); + } + private String getResourcesString(String name) { return mContext.getResources().getString(getResourcesId(name)); } |