Internet Picker implementation.
This version is to resolve the Reverted CL, ag/13127781 and make NetworkProviderSettingsTest passed Show mobile network on internet page With mobile network - https://screenshot.googleplex.com/7HzGhnbpitErynY Without mobile network - https://screenshot.googleplex.com/8sNVggTpKEhKeRh Class diff: https://diff.googleplex.com/#key=WosyTF0ANVMf Doc: https://docs.google.com/presentation/d/1azrZVS54pxM2lt9LkZHtFh_6W3fyDw_kTTPVQ_mJCi4/edit#slide=id.g9c7123c172_0_448 Bug: 173105859 Test: atest NetworkMobileProviderControllerTest passed Test: make RunSettingsRoboTests ROBOTEST_FILTER=SubscriptionsPreferenceControllerTest passed Test: make RunSettingsRoboTests ROBOTEST_FILTER=NetworkProviderSettingsTest passed Change-Id: Ib0bdd148424881353f18307cb83798b4217060fc
This commit is contained in:
@@ -27,6 +27,12 @@
|
|||||||
android:key="connected_access_point"
|
android:key="connected_access_point"
|
||||||
android:layout="@layout/preference_category_no_label"/>
|
android:layout="@layout/preference_category_no_label"/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="provider_model_mobile_network"
|
||||||
|
android:title="@string/summary_placeholder"
|
||||||
|
android:layout="@layout/preference_category_no_label"
|
||||||
|
settings:controller="com.android.settings.network.NetworkMobileProviderController"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="access_points"
|
android:key="access_points"
|
||||||
android:layout="@layout/preference_category_no_label"/>
|
android:layout="@layout/preference_category_no_label"/>
|
||||||
|
@@ -27,9 +27,14 @@ import com.android.settings.core.BasePreferenceController;
|
|||||||
import com.android.settings.wifi.WifiConnectionPreferenceController;
|
import com.android.settings.wifi.WifiConnectionPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
// This controls a header at the top of the Network & internet page that only appears when there
|
/**
|
||||||
// are two or more active mobile subscriptions. It shows an overview of available network
|
* This controls a header at the top of the Network & internet page that only appears when there
|
||||||
// connections with an entry for wifi (if connected) and an entry for each subscription.
|
* are two or more active mobile subscriptions. It shows an overview of available network
|
||||||
|
* connections with an entry for wifi (if connected) and an entry for each subscription.
|
||||||
|
*
|
||||||
|
* TODO(tomhsu) when provider model is completed, this class will be replaced
|
||||||
|
* by {@link NetworkMobileProviderController}
|
||||||
|
*/
|
||||||
public class MultiNetworkHeaderController extends BasePreferenceController implements
|
public class MultiNetworkHeaderController extends BasePreferenceController implements
|
||||||
WifiConnectionPreferenceController.UpdateListener,
|
WifiConnectionPreferenceController.UpdateListener,
|
||||||
SubscriptionsPreferenceController.UpdateListener {
|
SubscriptionsPreferenceController.UpdateListener {
|
||||||
|
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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 android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This controls mobile network display of the internet page that only appears when there
|
||||||
|
* are active mobile subscriptions. It shows an overview of available mobile network
|
||||||
|
* connections with an entry for each subscription.
|
||||||
|
*
|
||||||
|
* {@link NetworkMobileProviderController} is used to show subscription status on internet
|
||||||
|
* page for provider model. This original class can refer to {@link MultiNetworkHeaderController},
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NetworkMobileProviderController extends BasePreferenceController implements
|
||||||
|
SubscriptionsPreferenceController.UpdateListener {
|
||||||
|
|
||||||
|
private static final String TAG = NetworkMobileProviderController.class.getSimpleName();
|
||||||
|
|
||||||
|
public static final String PREF_KEY_PROVIDER_MOBILE_NETWORK = "provider_model_mobile_network";
|
||||||
|
private static final int PREFERENCE_START_ORDER = 10;
|
||||||
|
|
||||||
|
private PreferenceCategory mPreferenceCategory;
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
|
private SubscriptionsPreferenceController mSubscriptionsController;
|
||||||
|
|
||||||
|
private int mOriginalExpandedChildrenCount;
|
||||||
|
|
||||||
|
public NetworkMobileProviderController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize NetworkMobileProviderController
|
||||||
|
* @param lifecycle Lifecycle of Settings
|
||||||
|
*/
|
||||||
|
public void init(Lifecycle lifecycle) {
|
||||||
|
mSubscriptionsController = createSubscriptionsController(lifecycle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
SubscriptionsPreferenceController createSubscriptionsController(Lifecycle lifecycle) {
|
||||||
|
if (mSubscriptionsController == null) {
|
||||||
|
return new SubscriptionsPreferenceController(
|
||||||
|
mContext,
|
||||||
|
lifecycle,
|
||||||
|
this,
|
||||||
|
PREF_KEY_PROVIDER_MOBILE_NETWORK,
|
||||||
|
PREFERENCE_START_ORDER);
|
||||||
|
}
|
||||||
|
return mSubscriptionsController;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
if (mSubscriptionsController == null) {
|
||||||
|
Log.e(TAG, "[displayPreference] SubscriptionsController is null.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mPreferenceScreen = screen;
|
||||||
|
mOriginalExpandedChildrenCount = mPreferenceScreen.getInitialExpandedChildrenCount();
|
||||||
|
mPreferenceCategory = screen.findPreference(PREF_KEY_PROVIDER_MOBILE_NETWORK);
|
||||||
|
mPreferenceCategory.setVisible(isAvailable());
|
||||||
|
// TODO(tomhsu) For the provider model, subscriptionsController shall do more
|
||||||
|
// implementation of preference type change and summary control.
|
||||||
|
mSubscriptionsController.displayPreference(screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
if (mSubscriptionsController == null) {
|
||||||
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
return mSubscriptionsController.isAvailable() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChildrenUpdated() {
|
||||||
|
final boolean available = isAvailable();
|
||||||
|
// TODO(b/129893781) we need a better way to express where the advanced collapsing starts
|
||||||
|
// for preference groups that have items dynamically added/removed in the top expanded
|
||||||
|
// section.
|
||||||
|
if (mOriginalExpandedChildrenCount != Integer.MAX_VALUE) {
|
||||||
|
if (available) {
|
||||||
|
mPreferenceScreen.setInitialExpandedChildrenCount(
|
||||||
|
mOriginalExpandedChildrenCount + mPreferenceCategory.getPreferenceCount());
|
||||||
|
} else {
|
||||||
|
mPreferenceScreen.setInitialExpandedChildrenCount(mOriginalExpandedChildrenCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mPreferenceCategory.setVisible(available);
|
||||||
|
}
|
||||||
|
}
|
@@ -207,6 +207,12 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
|||||||
DataUsagePreference mDataUsagePreference;
|
DataUsagePreference mDataUsagePreference;
|
||||||
private LinkablePreference mStatusMessagePreference;
|
private LinkablePreference mStatusMessagePreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mobile networks list for provider model
|
||||||
|
*/
|
||||||
|
private static final String PREF_KEY_PROVIDER_MOBILE_NETWORK = "provider_model_mobile_network";
|
||||||
|
private NetworkMobileProviderController mNetworkMobileProviderController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks whether the user initiated a connection via clicking in order to autoscroll to the
|
* Tracks whether the user initiated a connection via clicking in order to autoscroll to the
|
||||||
* network once connected.
|
* network once connected.
|
||||||
@@ -255,6 +261,16 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
|||||||
mDataUsagePreference.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(),
|
mDataUsagePreference.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(),
|
||||||
0 /*subId*/,
|
0 /*subId*/,
|
||||||
null /*service*/);
|
null /*service*/);
|
||||||
|
addNetworkMobileProviderController();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNetworkMobileProviderController() {
|
||||||
|
if (mNetworkMobileProviderController == null) {
|
||||||
|
mNetworkMobileProviderController = new NetworkMobileProviderController(
|
||||||
|
getContext(), PREF_KEY_PROVIDER_MOBILE_NETWORK);
|
||||||
|
}
|
||||||
|
mNetworkMobileProviderController.init(getSettingsLifecycle());
|
||||||
|
mNetworkMobileProviderController.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -340,6 +356,12 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
mWorkerThread.quit();
|
mWorkerThread.quit();
|
||||||
|
@@ -41,6 +41,7 @@ import androidx.preference.PreferenceGroup;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.network.telephony.DataConnectivityListener;
|
import com.android.settings.network.telephony.DataConnectivityListener;
|
||||||
import com.android.settings.network.telephony.MobileNetworkActivity;
|
import com.android.settings.network.telephony.MobileNetworkActivity;
|
||||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||||
@@ -77,7 +78,6 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
|||||||
// Map of subscription id to Preference
|
// Map of subscription id to Preference
|
||||||
private Map<Integer, Preference> mSubscriptionPreferences;
|
private Map<Integer, Preference> mSubscriptionPreferences;
|
||||||
private int mStartOrder;
|
private int mStartOrder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface lets a parent of this class know that some change happened - this could
|
* This interface lets a parent of this class know that some change happened - this could
|
||||||
* either be because overall availability changed, or because we've added/removed/updated some
|
* either be because overall availability changed, or because we've added/removed/updated some
|
||||||
@@ -291,7 +291,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl
|
|||||||
// subscriptions with same group UUID.
|
// subscriptions with same group UUID.
|
||||||
.filter(subInfo ->
|
.filter(subInfo ->
|
||||||
isSubscriptionCanBeDisplayed(mContext, subInfo.getSubscriptionId()))
|
isSubscriptionCanBeDisplayed(mContext, subInfo.getSubscriptionId()))
|
||||||
.count() >= 2;
|
.count() >= (Utils.isProviderModelEnabled(mContext) ? 1 : 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,180 @@
|
|||||||
|
/*
|
||||||
|
* 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.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||||
|
import static com.android.settings.network.NetworkMobileProviderController.PREF_KEY_PROVIDER_MOBILE_NETWORK;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertFalse;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
|
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 com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for NetworkMobileProviderController.
|
||||||
|
*
|
||||||
|
* {@link NetworkMobileProviderController} is used to show subscription status on internet page for
|
||||||
|
* provider model. This original class can refer to {@link MultiNetworkHeaderController}, and
|
||||||
|
* NetworkMobileProviderControllerTest can also refer to {@link MultiNetworkHeaderControllerTest}.
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class NetworkMobileProviderControllerTest {
|
||||||
|
|
||||||
|
private static final int EXPANDED_CHILDREN_COUNT = 3;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
@Mock
|
||||||
|
private PreferenceCategory mPreferenceCategory;
|
||||||
|
@Mock
|
||||||
|
private SubscriptionsPreferenceController mSubscriptionsController;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private PreferenceManager mPreferenceManager;
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
private NetworkMobileProviderController mNetworkMobileProviderController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
if (Looper.myLooper() == null) {
|
||||||
|
Looper.prepare();
|
||||||
|
}
|
||||||
|
|
||||||
|
when(mPreferenceCategory.getKey()).thenReturn(PREF_KEY_PROVIDER_MOBILE_NETWORK);
|
||||||
|
when(mPreferenceCategory.getPreferenceCount()).thenReturn(3);
|
||||||
|
|
||||||
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
mNetworkMobileProviderController =
|
||||||
|
new NetworkMobileProviderController(mContext, PREF_KEY_PROVIDER_MOBILE_NETWORK) {
|
||||||
|
@Override
|
||||||
|
SubscriptionsPreferenceController createSubscriptionsController(
|
||||||
|
Lifecycle lifecycle) {
|
||||||
|
return mSubscriptionsController;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mPreferenceManager = new PreferenceManager(mContext);
|
||||||
|
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||||
|
mPreferenceScreen.setInitialExpandedChildrenCount(EXPANDED_CHILDREN_COUNT);
|
||||||
|
mPreferenceScreen.addPreference(mPreferenceCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayPreference_subscriptionsControllerAvailable() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(true);
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
assertTrue(mPreferenceCategory.isVisible());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayPreference_subscriptionsControllerUnAvailable() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(false);
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
assertFalse(mPreferenceCategory.isVisible());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAvailabilityStatus_subscriptionsControllerIsNull() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(false);
|
||||||
|
mNetworkMobileProviderController = new NetworkMobileProviderController(mContext,
|
||||||
|
PREF_KEY_PROVIDER_MOBILE_NETWORK) {
|
||||||
|
@Override
|
||||||
|
SubscriptionsPreferenceController createSubscriptionsController(Lifecycle lifecycle) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
final int result = mNetworkMobileProviderController.getAvailabilityStatus();
|
||||||
|
|
||||||
|
assertEquals(result, CONDITIONALLY_UNAVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAvailabilityStatus_subscriptionsControllerAvailable() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(true);
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
final int result = mNetworkMobileProviderController.getAvailabilityStatus();
|
||||||
|
|
||||||
|
assertEquals(result, AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnChildUpdated_subscriptionsControllerAvailable_categoryIsVisible() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(true);
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
mNetworkMobileProviderController.onChildrenUpdated();
|
||||||
|
|
||||||
|
assertTrue(mPreferenceCategory.isVisible());
|
||||||
|
assertThat(mPreferenceScreen.getInitialExpandedChildrenCount()).isEqualTo(
|
||||||
|
EXPANDED_CHILDREN_COUNT + mPreferenceCategory.getPreferenceCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnChildUpdated_subscriptionsControllerUnavailable_categoryIsInvisible() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(false);
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
mNetworkMobileProviderController.onChildrenUpdated();
|
||||||
|
|
||||||
|
assertFalse(mPreferenceCategory.isVisible());
|
||||||
|
assertThat(mPreferenceScreen.getInitialExpandedChildrenCount()).isEqualTo(
|
||||||
|
EXPANDED_CHILDREN_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnChildUpdated_noExpandedChildCountAndAvailable_doesNotSetExpandedCount() {
|
||||||
|
when(mSubscriptionsController.isAvailable()).thenReturn(true);
|
||||||
|
mPreferenceScreen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
|
||||||
|
setupNetworkMobileProviderController();
|
||||||
|
|
||||||
|
mNetworkMobileProviderController.onChildrenUpdated();
|
||||||
|
|
||||||
|
assertEquals(mPreferenceScreen.getInitialExpandedChildrenCount(), Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupNetworkMobileProviderController() {
|
||||||
|
mNetworkMobileProviderController.init(mLifecycle);
|
||||||
|
mNetworkMobileProviderController.displayPreference(mPreferenceScreen);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user