Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1203b3b authored by Weng Su's avatar Weng Su Committed by Android (Google) Code Review
Browse files

Merge "Reduce the number of getActiveSubscriptionIdList calls" into main

parents 8790c082 bd8baaa2
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -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;
    }
        return true;

    private void refreshHasActiveSubId() {
        if (mSubscriptionManager == null) {
            mHasActiveSubId = false;
            Log.e(TAG, "SubscriptionManager is null, set mHasActiveSubId = false");
            return;
        }

        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();
        }
    }
+16 −0
Original line number Diff line number Diff line
@@ -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));
    }