[Provider Model] Implement Calls & SMS controller
Screenshot of Provider Model: Single SIM: https://screenshot.googleplex.com/4pGBU7XK55CwJ7o.png Dual SIM: https://screenshot.googleplex.com/bXaFjsfGkgyHoYF.png Screenshot of current: https://screenshot.googleplex.com/BtCgYmnpvT97SQs.png Doc: https://docs.google.com/presentation/d/1azrZVS54pxM2lt9LkZHtFh_6W3fyDw_kTTPVQ_mJCi4/edit#slide=id.g9c7123c172_0_448 New controller: NetworkProviderCallsSmsController Bug: 172053880 Test: manual Change-Id: I86e9fc71d2b8562d838c5b5c6bd9c443656e2624
This commit is contained in:
30
res/drawable/ic_calls_sms.xml
Normal file
30
res/drawable/ic_calls_sms.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<!--
|
||||
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="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.2,18.21c1.21,0.41 2.48,0.67 3.8,0.76v-1.5c-0.88,-0.07 -1.75,-0.22 -2.6,-0.45l-1.2,1.19zM6.54,5h-1.5c0.09,1.32 0.35,2.59 0.75,3.79l1.2,-1.21c-0.24,-0.83 -0.39,-1.7 -0.45,-2.58zM14,8h5V5h-5z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillAlpha="0"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,15.5c-1.25,0 -2.45,-0.2 -3.57,-0.57 -0.1,-0.03 -0.21,-0.05 -0.31,-0.05 -0.26,0 -0.51,0.1 -0.71,0.29l-2.2,2.2c-2.83,-1.44 -5.15,-3.75 -6.59,-6.58l2.2,-2.21c0.28,-0.27 0.36,-0.66 0.25,-1.01C8.7,6.45 8.5,5.25 8.5,4c0,-0.55 -0.45,-1 -1,-1L4,3c-0.55,0 -1,0.45 -1,1 0,9.39 7.61,17 17,17 0.55,0 1,-0.45 1,-1v-3.5c0,-0.55 -0.45,-1 -1,-1zM5.03,5h1.5c0.07,0.88 0.22,1.75 0.46,2.59L5.79,8.8c-0.41,-1.21 -0.67,-2.48 -0.76,-3.8zM19,18.97c-1.32,-0.09 -2.6,-0.35 -3.8,-0.76l1.2,-1.2c0.85,0.24 1.72,0.39 2.6,0.45v1.51zM12,3v10l3,-3h6L21,3h-9zM19,8h-5L14,5h5v3z"/>
|
||||
</vector>
|
25
res/drawable/ic_sms.xml
Normal file
25
res/drawable/ic_sms.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
~ 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="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM9,11L7,11L7,9h2v2zM13,11h-2L11,9h2v2zM17,11h-2L15,9h2v2z"/>
|
||||
</vector>
|
@@ -12447,9 +12447,9 @@
|
||||
<!-- Provider Model: Name for call settings category [CHAR LIMIT=NONE] -->
|
||||
<string name="calls_and_sms_category">Wi\u2011Fi Calling</string>
|
||||
<!-- Provider Model: Summary for calling preference -->
|
||||
<string name="calls_sms_wfc_summary">Make and receive calls over non-carrier networks like Wi\u2011Fi</string>
|
||||
<string name="calls_sms_wfc_summary">Make and receive calls over non\u2011carrier networks like Wi\u2011Fi</string>
|
||||
<!-- Provider Model: Label for footnote on calling preference -->
|
||||
<string name="calls_sms_footnote">Wi-Fi calling allows you to make and receive calls over non-carrier networks such as some Wi\u2011Fi networks.\n\nCross-SIM calling allows you to leverage the mobile data of a SIM to make and receive calls from another SIM.</string>
|
||||
<string name="calls_sms_footnote">Wi\u2011Fi calling allows you to make and receive calls over non\u2011carrier networks such as some Wi\u2011Fi networks.</string>
|
||||
<!-- Provider Model: Calls preference title -->
|
||||
<string name="calls_preference_title">Calls</string>
|
||||
<!-- Provider Model: SMS preference title -->
|
||||
|
@@ -25,6 +25,7 @@
|
||||
android:title="@string/calls_preference_title"
|
||||
settings:controller="com.android.settings.network.telephony.CallsDefaultSubscriptionController"
|
||||
android:order="10"
|
||||
android:icon="@drawable/ic_phone"
|
||||
/>
|
||||
|
||||
<ListPreference
|
||||
@@ -32,13 +33,14 @@
|
||||
android:title="@string/sms_preference_title"
|
||||
settings:controller="com.android.settings.network.telephony.SmsDefaultSubscriptionController"
|
||||
android:order="15"
|
||||
android:icon="@drawable/ic_sms"
|
||||
/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="provider_model_calling_category"
|
||||
android:title="@string/calls_and_sms_category"
|
||||
android:order="20"
|
||||
settings:controller="com.android.settings.network.telephony.CallingPreferenceCategoryController"
|
||||
settings:controller="com.android.settings.network.telephony.NetworkProviderWifiCallingPreferenceController"
|
||||
settings:allowDividerAbove="true"
|
||||
/>
|
||||
|
||||
|
@@ -21,13 +21,13 @@ import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.network.MobilePlanPreferenceController.MobilePlanPreferenceHost;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
@@ -58,7 +58,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
if (isProviderModelEnabled(getContext())) {
|
||||
if (Utils.isProviderModelEnabled(getContext())) {
|
||||
return R.xml.network_provider_internet;
|
||||
} else {
|
||||
return R.xml.network_and_internet;
|
||||
@@ -69,7 +69,7 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
if (!isProviderModelEnabled(context)) {
|
||||
if (!Utils.isProviderModelEnabled(context)) {
|
||||
use(MultiNetworkHeaderController.class).init(getSettingsLifecycle());
|
||||
}
|
||||
use(AirplaneModePreferenceController.class).setFragment(this);
|
||||
@@ -104,13 +104,15 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
final MobilePlanPreferenceController mobilePlanPreferenceController =
|
||||
new MobilePlanPreferenceController(context, mobilePlanHost);
|
||||
final WifiPrimarySwitchPreferenceController wifiPreferenceController =
|
||||
isProviderModelEnabled(context)
|
||||
Utils.isProviderModelEnabled(context)
|
||||
? null
|
||||
: new WifiPrimarySwitchPreferenceController(
|
||||
context,
|
||||
metricsFeatureProvider);
|
||||
final InternetPreferenceController internetPreferenceController =
|
||||
isProviderModelEnabled(context) ? new InternetPreferenceController(context) : null;
|
||||
Utils.isProviderModelEnabled(context)
|
||||
? new InternetPreferenceController(context)
|
||||
: null;
|
||||
|
||||
final VpnPreferenceController vpnPreferenceController =
|
||||
new VpnPreferenceController(context);
|
||||
@@ -143,6 +145,9 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
controllers.add(internetPreferenceController);
|
||||
}
|
||||
controllers.add(privateDnsPreferenceController);
|
||||
if (Utils.isProviderModelEnabled(context)) {
|
||||
controllers.add(new NetworkProviderCallsSmsController(context, lifecycle));
|
||||
}
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@@ -187,8 +192,4 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
||||
null /* mobilePlanHost */);
|
||||
}
|
||||
};
|
||||
|
||||
private static boolean isProviderModelEnabled(Context context) {
|
||||
return FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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 androidx.lifecycle.Lifecycle.Event;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkProviderCallsSmsController extends AbstractPreferenceController implements
|
||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver {
|
||||
|
||||
private static final String TAG = "NetworkProviderCallsSmsController";
|
||||
private static final String KEY = "calls_and_sms";
|
||||
private static final String PREFERRED_CALL_SMS = "preferred";
|
||||
private static final String PREFERRED_CALL = "calls preferred";
|
||||
private static final String PREFERRED_SMS = "SMS preferred";
|
||||
private static final String UNAVAILABLE = "unavailable";
|
||||
|
||||
private UserManager mUserManager;
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
private SubscriptionsChangeListener mSubscriptionsChangeListener;
|
||||
|
||||
private RestrictedPreference mPreference;
|
||||
|
||||
/**
|
||||
* The summary text and click behavior of the "Calls & SMS" item on the
|
||||
* Network & internet page.
|
||||
*/
|
||||
public NetworkProviderCallsSmsController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
|
||||
mUserManager = context.getSystemService(UserManager.class);
|
||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||
if (lifecycle != null) {
|
||||
mSubscriptionsChangeListener = new SubscriptionsChangeListener(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Event.ON_RESUME)
|
||||
public void onResume() {
|
||||
mSubscriptionsChangeListener.start();
|
||||
update();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Event.ON_PAUSE)
|
||||
public void onPause() {
|
||||
mSubscriptionsChangeListener.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(
|
||||
mSubscriptionManager);
|
||||
|
||||
if (subs.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
for (SubscriptionInfo subInfo : subs) {
|
||||
int subsSize = subs.size();
|
||||
|
||||
// Set displayName as summary if there is only one valid SIM.
|
||||
if (subsSize == 1
|
||||
&& SubscriptionManager.isValidSubscriptionId(subInfo.getSubscriptionId())) {
|
||||
return subInfo.getDisplayName();
|
||||
}
|
||||
|
||||
CharSequence status = getPreferredStatus(subInfo);
|
||||
if (status.toString().isEmpty()) {
|
||||
// If there are 2 or more SIMs and one of these has no preferred status,
|
||||
// set only its displayName as summary.
|
||||
summary.append(subInfo.getDisplayName());
|
||||
} else {
|
||||
summary.append(subInfo.getDisplayName())
|
||||
.append(" (")
|
||||
.append(status)
|
||||
.append(")");
|
||||
}
|
||||
// Do not add ", " for the last subscription.
|
||||
if (subInfo != subs.get(subs.size() - 1)) {
|
||||
summary.append(", ");
|
||||
}
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected CharSequence getPreferredStatus(SubscriptionInfo subInfo) {
|
||||
final int subId = subInfo.getSubscriptionId();
|
||||
String status = "";
|
||||
boolean isDataPreferred = subId == getDefaultVoiceSubscriptionId();
|
||||
boolean isSmsPreferred = subId == getDefaultSmsSubscriptionId();
|
||||
|
||||
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
status = UNAVAILABLE;
|
||||
} else {
|
||||
if (isDataPreferred && isSmsPreferred) {
|
||||
status = PREFERRED_CALL_SMS;
|
||||
} else if (isDataPreferred) {
|
||||
status = PREFERRED_CALL;
|
||||
} else if (isSmsPreferred) {
|
||||
status = PREFERRED_SMS;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getDefaultVoiceSubscriptionId(){
|
||||
return SubscriptionManager.getDefaultVoiceSubscriptionId();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getDefaultSmsSubscriptionId(){
|
||||
return SubscriptionManager.getDefaultSmsSubscriptionId();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (mPreference == null || mPreference.isDisabledByAdmin()) {
|
||||
return;
|
||||
}
|
||||
refreshSummary(mPreference);
|
||||
mPreference.setOnPreferenceClickListener(null);
|
||||
mPreference.setFragment(null);
|
||||
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(
|
||||
mSubscriptionManager);
|
||||
if (subs.isEmpty()) {
|
||||
mPreference.setEnabled(false);
|
||||
} else {
|
||||
mPreference.setFragment(NetworkProviderCallsSmsFragment.class.getCanonicalName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mUserManager.isAdminUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
refreshSummary(mPreference);
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
refreshSummary(mPreference);
|
||||
update();
|
||||
}
|
||||
}
|
@@ -36,6 +36,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.SubscriptionsChangeListener;
|
||||
|
||||
@@ -90,7 +91,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
@Override
|
||||
public int getAvailabilityStatus(int subId) {
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(mManager);
|
||||
if (subs.size() > 1) {
|
||||
if (subs.size() > 1 || Utils.isProviderModelEnabled(mContext)) {
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
@@ -157,6 +158,12 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
final ArrayList<CharSequence> displayNames = new ArrayList<>();
|
||||
final ArrayList<CharSequence> subscriptionIds = new ArrayList<>();
|
||||
|
||||
if (Utils.isProviderModelEnabled(mContext) && subs.size() == 1) {
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setSummary(subs.get(0).getDisplayName());
|
||||
return;
|
||||
}
|
||||
|
||||
final int serviceDefaultSubId = getDefaultSubscriptionId();
|
||||
boolean subIsAvailable = false;
|
||||
|
||||
|
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* 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 androidx.lifecycle.Lifecycle.Event;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LifecycleRegistry;
|
||||
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 androidx.test.InstrumentationRegistry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class NetworkProviderCallsSmsControllerTest {
|
||||
|
||||
private static final int SUB_ID_1 = 1;
|
||||
private static final int SUB_ID_2 = 2;
|
||||
private static final String KEY_PREFERENCE_CALLS_SMS = "calls_and_sms";
|
||||
private static final String DISPLAY_NAME_1 = "Sub 1";
|
||||
private static final String DISPLAY_NAME_2 = "Sub 2";
|
||||
private static final String PREFERRED_CALL_SMS = "preferred";
|
||||
private static final String PREFERRED_CALL = "calls preferred";
|
||||
private static final String PREFERRED_SMS = "SMS preferred";
|
||||
private static final String UNAVAILABLE = "unavailable";
|
||||
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscriptionInfo1;
|
||||
@Mock
|
||||
private SubscriptionInfo mSubscriptionInfo2;
|
||||
@Mock
|
||||
private Lifecycle mLifecycle;
|
||||
@Mock
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private LifecycleRegistry mLifecycleRegistry;
|
||||
|
||||
private MockNetworkProviderCallsSmsController mController;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private RestrictedPreference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
/**
|
||||
* Mock the NetworkProviderCallsSmsController that allows allows one to set a default voice
|
||||
* and SMS subscription ID.
|
||||
*/
|
||||
private class MockNetworkProviderCallsSmsController extends
|
||||
com.android.settings.network.NetworkProviderCallsSmsController {
|
||||
public MockNetworkProviderCallsSmsController(Context context, Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
private int mDefaultVoiceSubscriptionId;
|
||||
private int mDefaultSmsSubscriptionId;
|
||||
|
||||
@Override
|
||||
protected int getDefaultVoiceSubscriptionId() {
|
||||
return mDefaultVoiceSubscriptionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultSmsSubscriptionId() {
|
||||
return mDefaultSmsSubscriptionId;
|
||||
}
|
||||
|
||||
public void setDefaultVoiceSubscriptionId(int subscriptionId) {
|
||||
mDefaultVoiceSubscriptionId = subscriptionId;
|
||||
}
|
||||
|
||||
public void setDefaultSmsSubscriptionId(int subscriptionId) {
|
||||
mDefaultSmsSubscriptionId = subscriptionId;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mPreference.setKey(KEY_PREFERENCE_CALLS_SMS);
|
||||
mController = new MockNetworkProviderCallsSmsController(mContext, mLifecycle);
|
||||
|
||||
mLifecycleRegistry = new LifecycleRegistry(mLifecycleOwner);
|
||||
when(mLifecycleOwner.getLifecycle()).thenReturn(mLifecycleRegistry);
|
||||
}
|
||||
|
||||
private void displayPreferenceWithLifecycle() {
|
||||
mLifecycleRegistry.addObserver(mController);
|
||||
mPreferenceScreen.addPreference(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mLifecycleRegistry.handleLifecycleEvent(Event.ON_RESUME);
|
||||
}
|
||||
|
||||
private void setupSubscriptionInfoList(int subId, String displayName,
|
||||
SubscriptionInfo subscriptionInfo) {
|
||||
when(subscriptionInfo.getSubscriptionId()).thenReturn(subId);
|
||||
doReturn(subscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(subId);
|
||||
when(subscriptionInfo.getDisplayName()).thenReturn(displayName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_invalidSubId_returnUnavailable() {
|
||||
setupSubscriptionInfoList(SubscriptionManager.INVALID_SUBSCRIPTION_ID, DISPLAY_NAME_1,
|
||||
mSubscriptionInfo1);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
summary.append(DISPLAY_NAME_1)
|
||||
.append(" (")
|
||||
.append(UNAVAILABLE)
|
||||
.append(")");
|
||||
|
||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_oneIsInvalidSubIdTwoIsValidSubId_returnOneIsUnavailable() {
|
||||
setupSubscriptionInfoList(SubscriptionManager.INVALID_SUBSCRIPTION_ID, DISPLAY_NAME_1,
|
||||
mSubscriptionInfo1);
|
||||
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
summary.append(DISPLAY_NAME_1)
|
||||
.append(" (")
|
||||
.append(UNAVAILABLE)
|
||||
.append(")")
|
||||
.append(", ")
|
||||
.append(DISPLAY_NAME_2);
|
||||
|
||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_oneSubscription_returnDisplayName() {
|
||||
setupSubscriptionInfoList(SUB_ID_1, DISPLAY_NAME_1, mSubscriptionInfo1);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(DISPLAY_NAME_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_allSubscriptionsHaveNoPreferredStatus_returnDisplayName() {
|
||||
setupSubscriptionInfoList(SUB_ID_1, DISPLAY_NAME_1, mSubscriptionInfo1);
|
||||
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
summary.append(DISPLAY_NAME_1).append(", ").append(DISPLAY_NAME_2);
|
||||
|
||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_oneSubscriptionsIsCallPreferredTwoIsSmsPreferred_returnStatus() {
|
||||
|
||||
mController.setDefaultVoiceSubscriptionId(SUB_ID_1);
|
||||
mController.setDefaultSmsSubscriptionId(SUB_ID_2);
|
||||
|
||||
setupSubscriptionInfoList(SUB_ID_1, DISPLAY_NAME_1, mSubscriptionInfo1);
|
||||
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
summary.append(DISPLAY_NAME_1)
|
||||
.append(" (")
|
||||
.append(PREFERRED_CALL)
|
||||
.append(")")
|
||||
.append(", ")
|
||||
.append(DISPLAY_NAME_2)
|
||||
.append(" (")
|
||||
.append(PREFERRED_SMS)
|
||||
.append(")");
|
||||
|
||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_oneSubscriptionsIsSmsPreferredTwoIsCallPreferred_returnStatus() {
|
||||
|
||||
mController.setDefaultVoiceSubscriptionId(SUB_ID_2);
|
||||
mController.setDefaultSmsSubscriptionId(SUB_ID_1);
|
||||
|
||||
setupSubscriptionInfoList(SUB_ID_1, DISPLAY_NAME_1, mSubscriptionInfo1);
|
||||
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
summary.append(DISPLAY_NAME_1)
|
||||
.append(" (")
|
||||
.append(PREFERRED_SMS)
|
||||
.append(")")
|
||||
.append(", ")
|
||||
.append(DISPLAY_NAME_2)
|
||||
.append(" (")
|
||||
.append(PREFERRED_CALL)
|
||||
.append(")");
|
||||
|
||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getSummary_oneSubscriptionsIsSmsPreferredAndIsCallPreferred_returnStatus() {
|
||||
|
||||
mController.setDefaultVoiceSubscriptionId(SUB_ID_1);
|
||||
mController.setDefaultSmsSubscriptionId(SUB_ID_1);
|
||||
|
||||
setupSubscriptionInfoList(SUB_ID_1, DISPLAY_NAME_1, mSubscriptionInfo1);
|
||||
setupSubscriptionInfoList(SUB_ID_2, DISPLAY_NAME_2, mSubscriptionInfo2);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2));
|
||||
displayPreferenceWithLifecycle();
|
||||
|
||||
final StringBuilder summary = new StringBuilder();
|
||||
summary.append(DISPLAY_NAME_1)
|
||||
.append(" (")
|
||||
.append(PREFERRED_CALL_SMS)
|
||||
.append(")")
|
||||
.append(", ")
|
||||
.append(DISPLAY_NAME_2);
|
||||
|
||||
assertTrue(TextUtils.equals(mController.getSummary(), summary));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user