Merge "Remove NetworkProviderSimsCategoryController" into main
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
android:title="@string/summary_placeholder"
|
android:title="@string/summary_placeholder"
|
||||||
android:layout="@layout/preference_category_no_label"
|
android:layout="@layout/preference_category_no_label"
|
||||||
android:order="20"
|
android:order="20"
|
||||||
settings:controller="com.android.settings.network.NetworkProviderSimsCategoryController"/>
|
settings:controller="com.android.settings.network.NetworkProviderSimListController"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="add_sim"
|
android:key="add_sim"
|
||||||
|
@@ -19,26 +19,19 @@ package com.android.settings.network;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||||
public class MobileNetworkListFragment extends DashboardFragment {
|
public class MobileNetworkListFragment extends DashboardFragment {
|
||||||
private static final String LOG_TAG = "NetworkListFragment";
|
private static final String LOG_TAG = "NetworkListFragment";
|
||||||
|
|
||||||
static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
|
||||||
private static final String KEY_ADD_SIM = "add_sim";
|
private static final String KEY_ADD_SIM = "add_sim";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,34 +61,8 @@ public class MobileNetworkListFragment extends DashboardFragment {
|
|||||||
return SettingsEnums.MOBILE_NETWORK_LIST;
|
return SettingsEnums.MOBILE_NETWORK_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
|
||||||
if (!SubscriptionUtil.isSimHardwareVisible(getContext())) {
|
|
||||||
finish();
|
|
||||||
return controllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkProviderSimsCategoryController simCategoryPrefCtrl =
|
|
||||||
new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM,
|
|
||||||
getSettingsLifecycle(), this);
|
|
||||||
controllers.add(simCategoryPrefCtrl);
|
|
||||||
|
|
||||||
return controllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider(R.xml.network_provider_sims_list) {
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
|
||||||
boolean enabled) {
|
|
||||||
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
|
|
||||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
||||||
sir.xmlResId = R.xml.network_provider_sims_list;
|
|
||||||
result.add(sir);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
|
@@ -16,69 +16,60 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class NetworkProviderSimListController extends AbstractPreferenceController implements
|
public class NetworkProviderSimListController extends BasePreferenceController implements
|
||||||
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback,
|
DefaultLifecycleObserver, MobileNetworkRepository.MobileNetworkCallback,
|
||||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
||||||
private static final String TAG = "NetworkProviderSimListCtrl";
|
|
||||||
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
|
||||||
private static final String KEY_PREFERENCE_SIM = "provider_model_sim_list";
|
|
||||||
|
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private final SubscriptionManager mSubscriptionManager;
|
||||||
|
@Nullable
|
||||||
private PreferenceCategory mPreferenceCategory;
|
private PreferenceCategory mPreferenceCategory;
|
||||||
private Map<Integer, RestrictedPreference> mPreferences;
|
private Map<Integer, RestrictedPreference> mPreferences;
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private final MobileNetworkRepository mMobileNetworkRepository;
|
||||||
private MobileNetworkRepository mMobileNetworkRepository;
|
|
||||||
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
||||||
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
private final DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
||||||
|
|
||||||
public NetworkProviderSimListController(Context context, Lifecycle lifecycle,
|
public NetworkProviderSimListController(Context context, String preferenceKey) {
|
||||||
LifecycleOwner lifecycleOwner) {
|
super(context, preferenceKey);
|
||||||
super(context);
|
|
||||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||||
mPreferences = new ArrayMap<>();
|
mPreferences = new ArrayMap<>();
|
||||||
mLifecycleOwner = lifecycleOwner;
|
|
||||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
||||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
||||||
lifecycle.addObserver(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(ON_RESUME)
|
@Override
|
||||||
public void onResume() {
|
public void onResume(@NonNull LifecycleOwner owner) {
|
||||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
mMobileNetworkRepository.addRegister(owner, this,
|
||||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
mMobileNetworkRepository.updateEntity();
|
mMobileNetworkRepository.updateEntity();
|
||||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(ON_PAUSE)
|
@Override
|
||||||
public void onPause() {
|
public void onPause(@NonNull LifecycleOwner owner) {
|
||||||
mMobileNetworkRepository.removeRegister(this);
|
mMobileNetworkRepository.removeRegister(this);
|
||||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
||||||
}
|
}
|
||||||
@@ -86,7 +77,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
|||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_SIM);
|
mPreferenceCategory = screen.findPreference(getPreferenceKey());
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,31 +145,22 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
if (!getAvailablePhysicalSubscriptions().isEmpty()) {
|
return getAvailablePhysicalSubscriptions().isEmpty()
|
||||||
return true;
|
? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected List<SubscriptionInfoEntity> getAvailablePhysicalSubscriptions() {
|
protected List<SubscriptionInfoEntity> getAvailablePhysicalSubscriptions() {
|
||||||
List<SubscriptionInfoEntity> subList = new ArrayList<>();
|
return new ArrayList<>(mSubInfoEntityList);
|
||||||
for (SubscriptionInfoEntity info : mSubInfoEntityList) {
|
|
||||||
subList.add(info);
|
|
||||||
}
|
|
||||||
return subList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_PREFERENCE_SIM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||||
mSubInfoEntityList = subInfoEntityList;
|
mSubInfoEntityList = subInfoEntityList;
|
||||||
|
if (mPreferenceCategory != null) {
|
||||||
mPreferenceCategory.setVisible(isAvailable());
|
mPreferenceCategory.setVisible(isAvailable());
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,67 +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.util.Log;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceCategory;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.widget.PreferenceCategoryController;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
|
|
||||||
public class NetworkProviderSimsCategoryController extends PreferenceCategoryController implements
|
|
||||||
LifecycleObserver {
|
|
||||||
private static final String LOG_TAG = "NetworkProviderSimsCategoryController";
|
|
||||||
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
|
||||||
private NetworkProviderSimListController mNetworkProviderSimListController;
|
|
||||||
private PreferenceCategory mPreferenceCategory;
|
|
||||||
|
|
||||||
public NetworkProviderSimsCategoryController(Context context, String key, Lifecycle lifecycle,
|
|
||||||
LifecycleOwner lifecycleOwner) {
|
|
||||||
super(context, key);
|
|
||||||
mNetworkProviderSimListController =
|
|
||||||
new NetworkProviderSimListController(mContext, lifecycle, lifecycleOwner);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
if (mNetworkProviderSimListController == null
|
|
||||||
|| !mNetworkProviderSimListController.isAvailable()) {
|
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
|
||||||
} else {
|
|
||||||
return AVAILABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mNetworkProviderSimListController.displayPreference(screen);
|
|
||||||
mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_SIM);
|
|
||||||
if (mPreferenceCategory == null) {
|
|
||||||
Log.d(LOG_TAG, "displayPreference(), Can not find the category.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mPreferenceCategory.setVisible(isAvailable());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -16,19 +16,16 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
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 androidx.lifecycle.Lifecycle.Event;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -36,18 +33,15 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LifecycleRegistry;
|
import androidx.lifecycle.LifecycleRegistry;
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.annotation.UiThreadTest;
|
import androidx.test.annotation.UiThreadTest;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.testutils.ResourcesUtils;
|
import com.android.settings.testutils.ResourcesUtils;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -83,8 +77,6 @@ public class NetworkProviderSimListControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionManager mSubscriptionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private Lifecycle mLifecycle;
|
|
||||||
@Mock
|
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private LifecycleOwner mLifecycleOwner;
|
||||||
private LifecycleRegistry mLifecycleRegistry;
|
private LifecycleRegistry mLifecycleRegistry;
|
||||||
|
|
||||||
@@ -100,12 +92,10 @@ public class NetworkProviderSimListControllerTest {
|
|||||||
* Mock the NetworkProviderSimListController that allows one to set a default voice,
|
* Mock the NetworkProviderSimListController that allows one to set a default voice,
|
||||||
* SMS and mobile data subscription ID.
|
* SMS and mobile data subscription ID.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("ClassCanBeStatic")
|
private static class MockNetworkProviderSimListController
|
||||||
private class MockNetworkProviderSimListController extends
|
extends NetworkProviderSimListController {
|
||||||
com.android.settings.network.NetworkProviderSimListController {
|
MockNetworkProviderSimListController(Context context, String preferenceKey) {
|
||||||
public MockNetworkProviderSimListController(Context context, Lifecycle lifecycle,
|
super(context, preferenceKey);
|
||||||
LifecycleOwner lifecycleOwner) {
|
|
||||||
super(context, lifecycle, lifecycleOwner);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SubscriptionInfoEntity> mSubscriptionInfoEntity;
|
private List<SubscriptionInfoEntity> mSubscriptionInfoEntity;
|
||||||
@@ -136,8 +126,7 @@ public class NetworkProviderSimListControllerTest {
|
|||||||
mPreference.setKey(KEY_PREFERENCE_SIM_LIST);
|
mPreference.setKey(KEY_PREFERENCE_SIM_LIST);
|
||||||
mPreferenceCategory = new PreferenceCategory(mContext);
|
mPreferenceCategory = new PreferenceCategory(mContext);
|
||||||
mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_SIM);
|
mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_SIM);
|
||||||
mController = new MockNetworkProviderSimListController(mContext, mLifecycle,
|
mController = new MockNetworkProviderSimListController(mContext, "test_key");
|
||||||
mLifecycleOwner);
|
|
||||||
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
||||||
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user