Merge "[Settings] Remaining part of Cross SIM calling (backup calling)"
This commit is contained in:
@@ -12309,14 +12309,14 @@
|
|||||||
<!-- Summary for Wi-Fi calling to explain this feature [CHAR LIMIT=NONE] -->
|
<!-- Summary for Wi-Fi calling to explain this feature [CHAR LIMIT=NONE] -->
|
||||||
<string name="wifi_calling_summary">Use Wi\u2011Fi for calls to improve quality</string>
|
<string name="wifi_calling_summary">Use Wi\u2011Fi for calls to improve quality</string>
|
||||||
|
|
||||||
<!-- Mobile network settings screen, title of Cross SIM calling setting. [CHAR LIMIT=NONE] -->
|
<!-- Mobile network settings screen, title of Backup calling setting. [CHAR LIMIT=NONE] -->
|
||||||
<string name="cross_sim_calling_settings_title">Cross SIM calling</string>
|
<string name="backup_calling_settings_title">Backup calling</string>
|
||||||
|
|
||||||
<!-- Cross SIM calling summary. [CHAR LIMIT=100] -->
|
<!-- Backup calling summary. [CHAR LIMIT=100] -->
|
||||||
<string name="cross_sim_calling_setting_summary">Allow <xliff:g id="cross_sim_calling_operator_text" example="Google Fi">%1$s</xliff:g> call over the default data SIM when <xliff:g id="cross_sim_calling_carrier_text" example="Google Fi">%1$s</xliff:g> is unavailable.</string>
|
<string name="backup_calling_setting_summary">If <xliff:g id="backup_calling_operator_text" example="Google Fi">%1$s</xliff:g> is unavailable, use your mobile data SIM to make and receive <xliff:g id="backup_calling_carrier_text" example="Google Fi">%1$s</xliff:g> calls.</string>
|
||||||
|
|
||||||
<!-- List of synonyms for the cross SIM calling titles, used to match in settings search [CHAR LIMIT=NONE] -->
|
<!-- List of synonyms for the cross SIM calling titles, used to match in settings search [CHAR LIMIT=NONE] -->
|
||||||
<string name="keywords_cross_sim_calling">cross sim calling</string>
|
<string name="keywords_backup_calling">backup calling</string>
|
||||||
|
|
||||||
<!-- Title for enable MMS notification when trying to receive MMS. [CHAR LIMIT=40] -->
|
<!-- Title for enable MMS notification when trying to receive MMS. [CHAR LIMIT=40] -->
|
||||||
<string name="enable_receiving_mms_notification_title">Incoming MMS message</string>
|
<string name="enable_receiving_mms_notification_title">Incoming MMS message</string>
|
||||||
|
@@ -172,12 +172,12 @@
|
|||||||
settings:controller="com.android.settings.network.telephony.VideoCallingPreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.VideoCallingPreferenceController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="cross_sim_calling_key"
|
android:key="backup_calling_key"
|
||||||
android:title="@string/cross_sim_calling_settings_title"
|
android:title="@string/backup_calling_settings_title"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:summary="@string/cross_sim_calling_setting_summary"
|
android:summary="@string/backup_calling_setting_summary"
|
||||||
settings:keywords="@string/keywords_cross_sim_calling"
|
settings:keywords="@string/keywords_backup_calling"
|
||||||
settings:controller="com.android.settings.network.telephony.CrossSimCallingPreferenceController"/>
|
settings:controller="com.android.settings.network.telephony.BackupCallingPreferenceController"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
@@ -44,6 +44,14 @@
|
|||||||
settings:allowDividerAbove="true"
|
settings:allowDividerAbove="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="provider_model_backup_calling_category"
|
||||||
|
android:title="@string/backup_calling_settings_title"
|
||||||
|
android:order="25"
|
||||||
|
settings:controller="com.android.settings.network.telephony.NetworkProviderBackupCallingPreferenceController"
|
||||||
|
settings:allowDividerAbove="true"
|
||||||
|
/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.FooterPreference
|
<com.android.settingslib.widget.FooterPreference
|
||||||
android:key="provider_model_calls_sms_footer"
|
android:key="provider_model_calls_sms_footer"
|
||||||
android:title="@string/calls_sms_footnote"
|
android:title="@string/calls_sms_footnote"
|
||||||
|
@@ -26,6 +26,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.network.telephony.CallsDefaultSubscriptionController;
|
import com.android.settings.network.telephony.CallsDefaultSubscriptionController;
|
||||||
|
import com.android.settings.network.telephony.NetworkProviderBackupCallingPreferenceController;
|
||||||
import com.android.settings.network.telephony.NetworkProviderWifiCallingPreferenceController;
|
import com.android.settings.network.telephony.NetworkProviderWifiCallingPreferenceController;
|
||||||
import com.android.settings.network.telephony.SmsDefaultSubscriptionController;
|
import com.android.settings.network.telephony.SmsDefaultSubscriptionController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
@@ -42,6 +43,9 @@ public class NetworkProviderCallsSmsFragment extends DashboardFragment {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_PREFERENCE_CATEGORY_CALLING = "provider_model_calling_category";
|
static final String KEY_PREFERENCE_CATEGORY_CALLING = "provider_model_calling_category";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
static final String KEY_PREFERENCE_CATEGORY_BACKUP_CALLING =
|
||||||
|
"provider_model_backup_calling_category";
|
||||||
|
@VisibleForTesting
|
||||||
static final String KEY_PREFERENCE_CALLS= "provider_model_calls_preference";
|
static final String KEY_PREFERENCE_CALLS= "provider_model_calls_preference";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_PREFERENCE_SMS = "provider_model_sms_preference";
|
static final String KEY_PREFERENCE_SMS = "provider_model_sms_preference";
|
||||||
@@ -60,6 +64,12 @@ public class NetworkProviderCallsSmsFragment extends DashboardFragment {
|
|||||||
mNetworkProviderWifiCallingPreferenceController.init(getSettingsLifecycle());
|
mNetworkProviderWifiCallingPreferenceController.init(getSettingsLifecycle());
|
||||||
controllers.add(mNetworkProviderWifiCallingPreferenceController);
|
controllers.add(mNetworkProviderWifiCallingPreferenceController);
|
||||||
|
|
||||||
|
NetworkProviderBackupCallingPreferenceController backupCallingPrefCtrl =
|
||||||
|
new NetworkProviderBackupCallingPreferenceController(context,
|
||||||
|
KEY_PREFERENCE_CATEGORY_BACKUP_CALLING);
|
||||||
|
backupCallingPrefCtrl.init(getSettingsLifecycle());
|
||||||
|
controllers.add(backupCallingPrefCtrl);
|
||||||
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,22 +34,22 @@ import com.android.settings.R;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference controller for "Cross SIM Calling"
|
* Preference controller for "Backup Calling"
|
||||||
**/
|
**/
|
||||||
public class CrossSimCallingPreferenceController extends TelephonyTogglePreferenceController {
|
public class BackupCallingPreferenceController extends TelephonyTogglePreferenceController {
|
||||||
|
|
||||||
private static final String LOG_TAG = "CrossSimCallingPrefCtrl";
|
private static final String LOG_TAG = "BackupCallingPrefCtrl";
|
||||||
|
|
||||||
private int mSubId;
|
private int mSubId;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor of cross sim calling.
|
* Class constructor of backup calling.
|
||||||
*
|
*
|
||||||
* @param context of settings
|
* @param context of settings
|
||||||
* @param key assigned within UI entry of XML file
|
* @param key assigned within UI entry of XML file
|
||||||
**/
|
**/
|
||||||
public CrossSimCallingPreferenceController(Context context, String key) {
|
public BackupCallingPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +59,14 @@ public class CrossSimCallingPreferenceController extends TelephonyTogglePreferen
|
|||||||
* @param subId is the subscription id
|
* @param subId is the subscription id
|
||||||
* @return this instance after initialization
|
* @return this instance after initialization
|
||||||
**/
|
**/
|
||||||
public CrossSimCallingPreferenceController init(int subId) {
|
public BackupCallingPreferenceController init(int subId) {
|
||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
return hasCrossSimCallingFeature(subId) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
return hasBackupCallingFeature(subId) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,13 +129,13 @@ public class CrossSimCallingPreferenceController extends TelephonyTogglePreferen
|
|||||||
}
|
}
|
||||||
String summary = displayName;
|
String summary = displayName;
|
||||||
String finalText = String.format(
|
String finalText = String.format(
|
||||||
getResourcesForSubId().getString(R.string.cross_sim_calling_setting_summary),
|
getResourcesForSubId().getString(R.string.backup_calling_setting_summary),
|
||||||
summary)
|
summary)
|
||||||
.toString();
|
.toString();
|
||||||
preference.setSummary(finalText);
|
preference.setSummary(finalText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasCrossSimCallingFeature(int subscriptionId) {
|
private boolean hasBackupCallingFeature(int subscriptionId) {
|
||||||
PersistableBundle carrierConfig = getCarrierConfigForSubId(subscriptionId);
|
PersistableBundle carrierConfig = getCarrierConfigForSubId(subscriptionId);
|
||||||
return (carrierConfig != null)
|
return (carrierConfig != null)
|
||||||
&& carrierConfig.getBoolean(
|
&& carrierConfig.getBoolean(
|
@@ -177,8 +177,8 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
|
|||||||
|
|
||||||
final VideoCallingPreferenceController videoCallingPreferenceController =
|
final VideoCallingPreferenceController videoCallingPreferenceController =
|
||||||
use(VideoCallingPreferenceController.class).init(mSubId);
|
use(VideoCallingPreferenceController.class).init(mSubId);
|
||||||
final CrossSimCallingPreferenceController crossSimCallingPreferenceController =
|
final BackupCallingPreferenceController crossSimCallingPreferenceController =
|
||||||
use(CrossSimCallingPreferenceController.class).init(mSubId);
|
use(BackupCallingPreferenceController.class).init(mSubId);
|
||||||
use(CallingPreferenceCategoryController.class).setChildren(
|
use(CallingPreferenceCategoryController.class).setChildren(
|
||||||
Arrays.asList(wifiCallingPreferenceController, videoCallingPreferenceController,
|
Arrays.asList(wifiCallingPreferenceController, videoCallingPreferenceController,
|
||||||
crossSimCallingPreferenceController));
|
crossSimCallingPreferenceController));
|
||||||
|
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* 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.telephony;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.telephony.SubscriptionInfo;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference controller for "Backup Calling" summary list
|
||||||
|
*/
|
||||||
|
public class NetworkProviderBackupCallingPreferenceController extends
|
||||||
|
BasePreferenceController implements LifecycleObserver {
|
||||||
|
|
||||||
|
private static final String TAG = "NetProvBackupCallingCtrl";
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private PreferenceCategory mPreferenceCategory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference controller for "Backup Calling" summary list
|
||||||
|
*/
|
||||||
|
public NetworkProviderBackupCallingPreferenceController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the binding with Lifecycle
|
||||||
|
*
|
||||||
|
* @param lifecycle Lifecycle of UI which owns this Preference
|
||||||
|
*/
|
||||||
|
public void init(Lifecycle lifecycle) {
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
List<SubscriptionInfo> subList = getActiveSubscriptions();
|
||||||
|
if (subList.size() < 2) {
|
||||||
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
return (getPreferences(subList).size() >= 1) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
|
||||||
|
PreferenceCategory prefCategory = screen.findPreference(getPreferenceKey());
|
||||||
|
updatePreferenceList(prefCategory);
|
||||||
|
prefCategory.setVisible(isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
// Do nothing in this case since preference is invisible
|
||||||
|
if (preference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updatePreferenceList((PreferenceCategory) preference);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPreferenceKey(int subscriptionId) {
|
||||||
|
return getPreferenceKey() + "_subId_" + subscriptionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SwitchPreference getPreference(SubscriptionInfo subInfo) {
|
||||||
|
int subId = subInfo.getSubscriptionId();
|
||||||
|
BackupCallingPreferenceController prefCtrl =
|
||||||
|
new BackupCallingPreferenceController(mContext, getPreferenceKey(subId));
|
||||||
|
prefCtrl.init(subId);
|
||||||
|
if (prefCtrl.getAvailabilityStatus(subId) != BasePreferenceController.AVAILABLE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
SwitchPreference pref = new SwitchPreference(mContext);
|
||||||
|
prefCtrl.updateState(pref);
|
||||||
|
pref.setTitle(subInfo.getDisplayName());
|
||||||
|
return pref;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SwitchPreference> getPreferences(List<SubscriptionInfo> subList) {
|
||||||
|
return subList.stream()
|
||||||
|
.map(subInfo -> getPreference(subInfo))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SubscriptionInfo> getActiveSubscriptions() {
|
||||||
|
return SubscriptionUtil.getActiveSubscriptions(
|
||||||
|
mContext.getSystemService(SubscriptionManager.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePreferenceList(PreferenceCategory prefCategory) {
|
||||||
|
List<SwitchPreference> prefList = getPreferences(getActiveSubscriptions());
|
||||||
|
|
||||||
|
prefCategory.removeAll();
|
||||||
|
for (SwitchPreference pref : prefList) {
|
||||||
|
prefCategory.addPreference(pref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -32,17 +32,17 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class CrossSimCallingPreferenceControllerTest {
|
public class BackupCallingPreferenceControllerTest {
|
||||||
private static final int SUB_ID = 2;
|
private static final int SUB_ID = 2;
|
||||||
|
|
||||||
private CrossSimCallingPreferenceController mController;
|
private BackupCallingPreferenceController mController;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
|
||||||
mController = new CrossSimCallingPreferenceController(mContext, "cross_sim_calling_key");
|
mController = new BackupCallingPreferenceController(mContext, "backup_calling_key");
|
||||||
mController.init(SUB_ID);
|
mController.init(SUB_ID);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user