Remove NetworkProviderSimsCategoryController

Which no real logic in it, just a proxy of
NetworkProviderSimListController.

Bug: 302628642
Test: manually - on MobileNetworkListFragment
Test: robo test
Change-Id: I4785ac9509f92f5a778e1bda1f8da12e2880589e
This commit is contained in:
Chaohui Wang
2023-10-18 19:35:45 +08:00
parent 9a437cb696
commit d1577c5e68
6 changed files with 35 additions and 316 deletions

View File

@@ -16,19 +16,16 @@
package com.android.settings.network;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static androidx.lifecycle.Lifecycle.Event;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -36,18 +33,15 @@ import android.text.TextUtils;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.preference.PreferenceManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.R;
import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
import org.junit.Before;
@@ -83,8 +77,6 @@ public class NetworkProviderSimListControllerTest {
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private Lifecycle mLifecycle;
@Mock
private LifecycleOwner mLifecycleOwner;
private LifecycleRegistry mLifecycleRegistry;
@@ -100,12 +92,10 @@ public class NetworkProviderSimListControllerTest {
* Mock the NetworkProviderSimListController that allows one to set a default voice,
* SMS and mobile data subscription ID.
*/
@SuppressWarnings("ClassCanBeStatic")
private class MockNetworkProviderSimListController extends
com.android.settings.network.NetworkProviderSimListController {
public MockNetworkProviderSimListController(Context context, Lifecycle lifecycle,
LifecycleOwner lifecycleOwner) {
super(context, lifecycle, lifecycleOwner);
private static class MockNetworkProviderSimListController
extends NetworkProviderSimListController {
MockNetworkProviderSimListController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
private List<SubscriptionInfoEntity> mSubscriptionInfoEntity;
@@ -136,8 +126,7 @@ public class NetworkProviderSimListControllerTest {
mPreference.setKey(KEY_PREFERENCE_SIM_LIST);
mPreferenceCategory = new PreferenceCategory(mContext);
mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_SIM);
mController = new MockNetworkProviderSimListController(mContext, mLifecycle,
mLifecycleOwner);
mController = new MockNetworkProviderSimListController(mContext, "test_key");
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
}

View File

@@ -1,152 +0,0 @@
/*
* Copyright (C) 2020 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 static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import com.android.settings.testutils.ResourcesUtils;
import com.android.settingslib.core.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.Arrays;
//TODO: Remove NetworkProviderSimsCategoryControllerTest once it is removed in the b/244769887.
@RunWith(AndroidJUnit4.class)
public class NetworkProviderSimsCategoryControllerTest {
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
private static final String SUB_1 = "SUB_1";
private static final String SUB_2 = "SUB_2";
private static final int SUB_ID_1 = 1;
private static final int SUB_ID_2 = 2;
@Mock
private Lifecycle mLifecycle;
@Mock
private SubscriptionInfo mSubscriptionInfo1;
@Mock
private SubscriptionInfo mSubscriptionInfo2;
private Context mContext;
private NetworkProviderSimsCategoryController mCategoryController;
private PreferenceManager mPreferenceManager;
private PreferenceScreen mPreferenceScreen;
private PreferenceCategory mPreferenceCategory;
private LifecycleOwner mLifecycleOwner;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
if (Looper.myLooper() == null) {
Looper.prepare();
}
mLifecycleOwner = () -> mLifecycle;
mPreferenceManager = new PreferenceManager(mContext);
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
mPreferenceCategory = new PreferenceCategory(mContext);
mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_SIM);
mPreferenceScreen.addPreference(mPreferenceCategory);
mCategoryController = new NetworkProviderSimsCategoryController(
mContext, KEY_PREFERENCE_CATEGORY_SIM, mLifecycle, mLifecycleOwner);
}
@Ignore
@Test
public void getAvailabilityStatus_returnUnavailable() {
SubscriptionUtil.setAvailableSubscriptionsForTesting(new ArrayList<>());
assertThat(mCategoryController.getAvailabilityStatus()).isEqualTo(
CONDITIONALLY_UNAVAILABLE);
}
@Ignore
@Test
public void displayPreference_isVisible() {
setUpSubscriptionInfoForPhysicalSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscriptionInfo1));
mCategoryController.displayPreference(mPreferenceScreen);
assertEquals(mPreferenceCategory.isVisible(), true);
}
@Ignore
@Test
public void updateState_setTitle_withTwoPhysicalSims_returnSims() {
setUpSubscriptionInfoForPhysicalSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
setUpSubscriptionInfoForPhysicalSim(SUB_ID_2, SUB_2, mSubscriptionInfo2);
SubscriptionUtil.setAvailableSubscriptionsForTesting(
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
mCategoryController.displayPreference(mPreferenceScreen);
mCategoryController.updateState(mPreferenceCategory);
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2);
assertThat(mPreferenceCategory.getTitle()).isEqualTo(
ResourcesUtils.getResourcesString(mContext, "provider_network_settings_title"));
}
@Ignore
@Test
public void updateState_setTitle_withOnePhysicalSim_returnSim() {
setUpSubscriptionInfoForPhysicalSim(SUB_ID_1, SUB_1, mSubscriptionInfo1);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscriptionInfo1));
mCategoryController.displayPreference(mPreferenceScreen);
mCategoryController.updateState(mPreferenceCategory);
assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
assertThat(mPreferenceCategory.getTitle()).isEqualTo(
ResourcesUtils.getResourcesString(mContext, "sim_category_title"));
}
private void setUpSubscriptionInfoForPhysicalSim(int subId, String displayName,
SubscriptionInfo subscriptionInfo) {
when(subscriptionInfo.isEmbedded()).thenReturn(false);
when(subscriptionInfo.getSubscriptionId()).thenReturn(subId);
when(subscriptionInfo.getDisplayName()).thenReturn(displayName);
}
}