[Provider Model] Show all carrier's name on MobileNetworkSummaryController's summary

Screenshot of Provider Model: https://screenshot.googleplex.com/6mKLeMWGWZJh86u.png

Screenshot of current: https://screenshot.googleplex.com/Abncb2QGh5TWxEv.png

Doc: https://docs.google.com/presentation/d/1azrZVS54pxM2lt9LkZHtFh_6W3fyDw_kTTPVQ_mJCi4/edit#slide=id.g9c7123c172_0_448

Bug: 172229551
Test: manual and make RunSettingsRoboTests ROBOTEST_FILTER=MobileNetworkSummaryControllerTest

Change-Id: I0f2a23659ef80b6a76b34af9503ad8d746967859
This commit is contained in:
Zoey Chen
2020-11-02 23:03:57 +08:00
parent 16bbb86fa6
commit 87a5961243
4 changed files with 85 additions and 6 deletions

View File

@@ -0,0 +1,43 @@
<!--
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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.5,2H8L4,6v10.5C4,17.33 4.67,18 5.5,18h9c0.83,0 1.5,-0.67 1.5,-1.5v-13C16,2.67 15.33,2 14.5,2zM14.5,16.5h-9V6.62L8.62,3.5h5.88V16.5z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M6.5,9h1.5v3h-1.5z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M6.5,13.5h1.5v1.5h-1.5z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M12,13.5h1.5v1.5h-1.5z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M9.25,9h1.5v1.5h-1.5z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M12,9h1.5v3h-1.5z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M9.25,12h1.5v3h-1.5z"/>
</vector>

View File

@@ -48,7 +48,7 @@
android:key="mobile_network_list" android:key="mobile_network_list"
android:title="@string/provider_network_settings_title" android:title="@string/provider_network_settings_title"
android:summary="@string/summary_placeholder" android:summary="@string/summary_placeholder"
android:icon="@drawable/ic_network_cell" android:icon="@drawable/ic_sim_card"
android:order="-15" android:order="-15"
settings:keywords="@string/keywords_more_mobile_networks" settings:keywords="@string/keywords_more_mobile_networks"
settings:userRestriction="no_config_mobile_networks" settings:userRestriction="no_config_mobile_networks"

View File

@@ -45,6 +45,7 @@ import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class MobileNetworkSummaryController extends AbstractPreferenceController implements public class MobileNetworkSummaryController extends AbstractPreferenceController implements
SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver, SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver,
@@ -124,12 +125,20 @@ public class MobileNetworkSummaryController extends AbstractPreferenceController
return subs.get(0).getDisplayName(); return subs.get(0).getDisplayName();
} }
} else { } else {
if (com.android.settings.Utils.isProviderModelEnabled(mContext)) {
return getSummaryForProviderModel(subs);
}
final int count = subs.size(); final int count = subs.size();
return mContext.getResources().getQuantityString(R.plurals.mobile_network_summary_count, return mContext.getResources().getQuantityString(R.plurals.mobile_network_summary_count,
count, count); count, count);
} }
} }
private CharSequence getSummaryForProviderModel(List<SubscriptionInfo> subs) {
return String.join(", ", subs.stream().map(SubscriptionInfo::getDisplayName)
.collect(Collectors.toList()));
}
private void startAddSimFlow() { private void startAddSimFlow() {
final Intent intent = new Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION); final Intent intent = new Intent(EuiccManager.ACTION_PROVISION_EMBEDDED_SUBSCRIPTION);
intent.putExtra(EuiccManager.EXTRA_FORCE_PROVISION, true); intent.putExtra(EuiccManager.EXTRA_FORCE_PROVISION, true);

View File

@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.notNull; import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -39,10 +40,12 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager; import android.telephony.euicc.EuiccManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.core.FeatureFlags;
import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.network.telephony.MobileNetworkActivity;
import com.android.settings.widget.AddPreference; import com.android.settings.widget.AddPreference;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
@@ -61,7 +64,6 @@ import org.robolectric.RuntimeEnvironment;
import java.util.Arrays; import java.util.Arrays;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class MobileNetworkSummaryControllerTest { public class MobileNetworkSummaryControllerTest {
@Mock @Mock
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@@ -84,10 +86,11 @@ public class MobileNetworkSummaryControllerTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager); doReturn(mEuiccManager).when(mContext).getSystemService(EuiccManager.class);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
when(mTelephonyManager.getNetworkCountryIso()).thenReturn(""); when(mTelephonyManager.getNetworkCountryIso()).thenReturn("");
when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true); when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
when(mEuiccManager.isEnabled()).thenReturn(true); when(mEuiccManager.isEnabled()).thenReturn(true);
@@ -211,6 +214,7 @@ public class MobileNetworkSummaryControllerTest {
@Test @Test
public void getSummary_twoSubscriptions_correctSummaryAndFragment() { public void getSummary_twoSubscriptions_correctSummaryAndFragment() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class); final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub1.getSubscriptionId()).thenReturn(1); when(sub1.getSubscriptionId()).thenReturn(1);
@@ -225,6 +229,7 @@ public class MobileNetworkSummaryControllerTest {
@Test @Test
public void getSummaryAfterUpdate_twoSubscriptionsBecomesOne_correctSummaryAndFragment() { public void getSummaryAfterUpdate_twoSubscriptionsBecomesOne_correctSummaryAndFragment() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class); final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub1.getSubscriptionId()).thenReturn(1); when(sub1.getSubscriptionId()).thenReturn(1);
@@ -253,6 +258,7 @@ public class MobileNetworkSummaryControllerTest {
@Test @Test
public void getSummaryAfterUpdate_oneSubscriptionBecomesTwo_correctSummaryAndFragment() { public void getSummaryAfterUpdate_oneSubscriptionBecomesTwo_correctSummaryAndFragment() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class); final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub1.getSubscriptionId()).thenReturn(1); when(sub1.getSubscriptionId()).thenReturn(1);
@@ -279,6 +285,27 @@ public class MobileNetworkSummaryControllerTest {
assertThat(mPreference.getFragment()).isEqualTo(MobileNetworkListFragment.class.getName()); assertThat(mPreference.getFragment()).isEqualTo(MobileNetworkListFragment.class.getName());
} }
@Test
public void getSummary_providerModel_Enabled() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
when(sub1.getSubscriptionId()).thenReturn(1);
when(sub2.getSubscriptionId()).thenReturn(2);
when(sub1.getDisplayName()).thenReturn("sub1");
when(sub2.getDisplayName()).thenReturn("sub2");
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
mController.displayPreference(mPreferenceScreen);
mController.onResume();
assertThat(mController.getSummary()).isEqualTo("sub1, sub2");
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
mController.displayPreference(mPreferenceScreen);
mController.onResume();
assertThat(mController.getSummary()).isEqualTo("2 SIMs");
}
@Test @Test
public void addButton_noSubscriptionsNoEuiccMgr_noAddClickListener() { public void addButton_noSubscriptionsNoEuiccMgr_noAddClickListener() {
when(mEuiccManager.isEnabled()).thenReturn(false); when(mEuiccManager.isEnabled()).thenReturn(false);