diff --git a/src/com/android/settings/network/MobileNetworkSummaryStatus.java b/src/com/android/settings/network/MobileNetworkSummaryStatus.java deleted file mode 100644 index b22e48ed021..00000000000 --- a/src/com/android/settings/network/MobileNetworkSummaryStatus.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.network; - -import android.content.Context; -import android.telephony.SubscriptionManager; -import android.util.Log; - -import com.android.settings.network.SubscriptionUtil; -import com.android.settings.network.helper.SelectableSubscriptions; -import com.android.settings.network.helper.SubscriptionAnnotation; -import com.android.settings.network.helper.SubscriptionGrouping; -import com.android.settings.network.telephony.MobileNetworkUtils; -import com.android.settingslib.utils.ThreadUtils; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.Future; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -/** - * This one keeps the information required by MobileNetworkSummaryController. - */ -public class MobileNetworkSummaryStatus { - private static final String LOG_TAG = "MobileNetworkSummaryStatus"; - - private Future> mUniqueNameMapping; - private Map mUniqueNameMappingCache; - - private Future mIsEuiccConfiguable; - private Boolean mIsEuiccConfiguableCache; - - private Future mIsPsimDisableSupported; - private Boolean mIsPsimDisableSupportedCache; - - private List mSubscriptionList; - - private boolean mDisableReEntranceUpdate; - - // Constructor - public MobileNetworkSummaryStatus() {} - - /** - * Update the status - * @param context - * @param andThen Consumer which always performed by the end of #update() - * and avoid from repeated queries. - */ - public void update(Context context, Consumer andThen) { - if (mDisableReEntranceUpdate) { - Log.d(LOG_TAG, "network summary query ignored"); - if (andThen != null) { - andThen.accept(this); - } - return; - } - mDisableReEntranceUpdate = true; - Log.d(LOG_TAG, "network summary query"); - - // Query Euicc in background - mIsEuiccConfiguable = (Future) - ThreadUtils.postOnBackgroundThread(() -> isEuiccConfiguable(context)); - - // Query display name in background - mUniqueNameMapping = (Future>) - ThreadUtils.postOnBackgroundThread(() -> getUniqueNameForDisplay(context)); - - // Query support status of pSIM disable feature - mIsPsimDisableSupported = (Future) ThreadUtils.postOnBackgroundThread(() - -> isPhysicalSimDisableSupported(context)); - - // Query subscription - mSubscriptionList = getSubscriptions(context); - - if (andThen != null) { - andThen.accept(this); - } - mDisableReEntranceUpdate = false; - } - - /** - * Get the subscription information - * @return a list of SubscriptionAnnotation - */ - public List getSubscriptionList() { - return mSubscriptionList; - } - - /** - * Get unique display name for a specific subscription - * @param subscriptionId subscription ID - * @return display name for that subscription - */ - public CharSequence getDisplayName(int subscriptionId) { - if (mUniqueNameMapping != null) { - try { - mUniqueNameMappingCache = mUniqueNameMapping.get(); - } catch (Exception exception) { - Log.w(LOG_TAG, "Fail to get display names", exception); - } - mUniqueNameMapping = null; - } - if (mUniqueNameMappingCache == null) { - return null; - } - return mUniqueNameMappingCache.get(subscriptionId); - } - - // Check if Euicc is currently available - public boolean isEuiccConfigSupport() { - if (mIsEuiccConfiguable != null) { - try { - mIsEuiccConfiguableCache = mIsEuiccConfiguable.get(); - } catch (Exception exception) { - Log.w(LOG_TAG, "Fail to get euicc config status", exception); - } - mIsEuiccConfiguable = null; - } - return (mIsEuiccConfiguableCache == null) ? - false : mIsEuiccConfiguableCache.booleanValue(); - } - - // Check if disable physical SIM is supported - public boolean isPhysicalSimDisableSupport() { - if (mIsPsimDisableSupported != null) { - try { - mIsPsimDisableSupportedCache = mIsPsimDisableSupported.get(); - } catch (Exception exception) { - Log.w(LOG_TAG, "Fail to get pSIM disable support", exception); - } - mIsPsimDisableSupported = null; - } - return (mIsPsimDisableSupportedCache == null) ? - false : mIsPsimDisableSupportedCache.booleanValue(); - } - - private List getSubscriptions(Context context) { - return (new SelectableSubscriptions(context, true)) - - // To maintain the consistency with SubscriptionUtil#getAvailableSubscriptions(). - .addFinisher(new SubscriptionGrouping()) - - .call() - .stream() - .filter(SubscriptionAnnotation::isDisplayAllowed) - .collect(Collectors.toList()); - } - - private Map getUniqueNameForDisplay(Context context) { - return SubscriptionUtil.getUniqueSubscriptionDisplayNames(context); - } - - private boolean isPhysicalSimDisableSupported(Context context) { - SubscriptionManager subMgr = context.getSystemService(SubscriptionManager.class); - return SubscriptionUtil.showToggleForPhysicalSim(subMgr); - } - - private boolean isEuiccConfiguable(Context context) { - return MobileNetworkUtils.showEuiccSettingsDetecting(context); - } -} diff --git a/src/com/android/settings/network/helper/SubscriptionGrouping.java b/src/com/android/settings/network/helper/SubscriptionGrouping.java deleted file mode 100644 index c4e0fd71bb8..00000000000 --- a/src/com/android/settings/network/helper/SubscriptionGrouping.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.settings.network.helper; - -import android.os.ParcelUuid; -import android.util.Log; - -import androidx.annotation.Keep; -import androidx.annotation.VisibleForTesting; - -import com.android.settings.network.helper.SubscriptionAnnotation; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; - -/** - * A UnaryOperator for converting a list of SubscriptionAnnotation into - * another list of SubscriptionAnnotation based on group UUID. - * Only one SubscriptionAnnotation with entries with same (valid) group UUID would be kept. - * - * Here's an example when applying this operation as a finisher of SelectableSubscriptions: - * - * Callable callable = (new SelectableSubscriptions(context, true)) - * .addFinisher(new SubscriptionGrouping()); - * - * List result = ExecutorService.submit(callable).get() - */ -public class SubscriptionGrouping - implements UnaryOperator> { - private static final String LOG_TAG = "SubscriptionGrouping"; - - // implementation of UnaryOperator - public List apply(List listOfSubscriptions) { - Log.d(LOG_TAG, "Grouping " + listOfSubscriptions); - - // group by GUID - Map> groupedSubInfoList = - listOfSubscriptions.stream() - .filter(Objects::nonNull) - .collect(Collectors.groupingBy(subAnno -> getGroupUuid(subAnno))); - - // select best one from subscription(s) within the same group - groupedSubInfoList.replaceAll((uuid, annoList) -> { - if ((uuid == SubscriptionAnnotation.EMPTY_UUID) || (annoList.size() <= 1)) { - return annoList; - } - return Collections.singletonList(selectBestFromList(annoList)); - }); - - // build a stream of subscriptions - return groupedSubInfoList.values() - .stream().flatMap(List::stream).collect(Collectors.toList()); - } - - @Keep - @VisibleForTesting - protected ParcelUuid getGroupUuid(SubscriptionAnnotation subAnno) { - ParcelUuid groupUuid = subAnno.getGroupUuid(); - return (groupUuid == null) ? SubscriptionAnnotation.EMPTY_UUID : groupUuid; - } - - protected SubscriptionAnnotation selectBestFromList(List annoList) { - Comparator annoSelector = (anno1, anno2) -> { - if (anno1.isDisplayAllowed() != anno2.isDisplayAllowed()) { - return anno1.isDisplayAllowed() ? -1 : 1; - } - if (anno1.isActive() != anno2.isActive()) { - return anno1.isActive() ? -1 : 1; - } - if (anno1.isExisted() != anno2.isExisted()) { - return anno1.isExisted() ? -1 : 1; - } - return 0; - }; - annoSelector = annoSelector - // eSIM in front of pSIM - .thenComparingInt(anno -> -anno.getType()) - // maintain the ordering given within constructor - .thenComparingInt(anno -> annoList.indexOf(anno)); - return annoList.stream().sorted(annoSelector).findFirst().orElse(null); - } -} diff --git a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java index bf866b2f0e0..8d6d2d9bc4e 100644 --- a/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/MobileNetworkSummaryControllerTest.java @@ -44,8 +44,6 @@ import androidx.lifecycle.LifecycleOwner; import androidx.preference.PreferenceScreen; import com.android.settings.Settings.MobileNetworkActivity; -import com.android.settings.network.helper.SubscriptionAnnotation; -import com.android.settings.network.helper.SubscriptionGrouping; import com.android.settings.widget.AddPreference; import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.core.lifecycle.Lifecycle; diff --git a/tests/unit/src/com/android/settings/network/helper/SubscriptionGroupingTest.java b/tests/unit/src/com/android/settings/network/helper/SubscriptionGroupingTest.java deleted file mode 100644 index bea720939a3..00000000000 --- a/tests/unit/src/com/android/settings/network/helper/SubscriptionGroupingTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.settings.network.helper; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.os.ParcelUuid; - -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import com.android.settings.network.helper.SubscriptionAnnotation; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; - -import java.util.Arrays; -import java.util.List; - -@RunWith(AndroidJUnit4.class) -public class SubscriptionGroupingTest { - - private ParcelUuid mMockUuid; - - private Context mContext; - private SubscriptionGrouping mTarget; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - - mContext = spy(ApplicationProvider.getApplicationContext()); - mMockUuid = ParcelUuid.fromString("1-1-1-1-1"); - mTarget = spy(new SubscriptionGrouping()); - } - - @Test - public void apply_multipleEntriesWithSameGroupUuid_onlyOneLeft() { - SubscriptionAnnotation subAnno1 = new TestSubAnnotation(1, - SubscriptionAnnotation.TYPE_ESIM, true, true, mMockUuid); - SubscriptionAnnotation subAnno2 = new TestSubAnnotation(2, - SubscriptionAnnotation.TYPE_PSIM, true, true, mMockUuid); - SubscriptionAnnotation subAnno3 = new TestSubAnnotation(3, - SubscriptionAnnotation.TYPE_ESIM, true, true, mMockUuid); - doReturn(mMockUuid).when(mTarget).getGroupUuid(any()); - - List result = mTarget - .apply(Arrays.asList(subAnno2, subAnno1, subAnno3)); - assertThat(result.size()).isEqualTo(1); - assertThat(result.get(0)).isEqualTo(subAnno1); - } - - @Test - public void apply_multipleEntriesWithSameGroupUuid_disabledOneIsAvoided() { - SubscriptionAnnotation subAnno1 = new TestSubAnnotation(1, - SubscriptionAnnotation.TYPE_ESIM, true, true, mMockUuid); - SubscriptionAnnotation subAnno2 = new TestSubAnnotation(2, - SubscriptionAnnotation.TYPE_PSIM, true, true, mMockUuid); - SubscriptionAnnotation subAnno3 = new TestSubAnnotation(3, - SubscriptionAnnotation.TYPE_ESIM, false, false, mMockUuid); - doReturn(mMockUuid).when(mTarget).getGroupUuid(any()); - - List result = mTarget - .apply(Arrays.asList(subAnno2, subAnno1, subAnno3)); - assertThat(result.size()).isEqualTo(1); - assertThat(result.get(0)).isEqualTo(subAnno1); - } - - private class TestSubAnnotation extends SubscriptionAnnotation { - private int mSubId; - private int mSimType; - private boolean mIsActive; - private boolean mIsDisplayAllowed; - private ParcelUuid mUuid; - - private TestSubAnnotation(int subId, int simType, - boolean isActive, boolean isDisplayAllowed, ParcelUuid guuid) { - super(null, -1, null, null, null, null); - mSubId = subId; - mSimType = simType; - mIsActive = isActive; - mIsDisplayAllowed = isDisplayAllowed; - mUuid = guuid; - } - - @Override - public int getSubscriptionId() { - return mSubId; - } - - @Override - public int getType() { - return mSimType; - } - - @Override - public boolean isExisted() { - return true; - } - - @Override - public boolean isActive() { - return mIsActive; - } - - @Override - public boolean isDisplayAllowed() { - return mIsDisplayAllowed; - } - - @Override - public ParcelUuid getGroupUuid() { - return mUuid; - } - } -}