[Settings] Remaining part of Cross SIM calling (backup calling)

1. Change the wording
2. Add a list of summary within Calls and SMSs UI

Bug: 174012397
Test: manual
Change-Id: I6dde0cea9c1386029377b3ea2682ed8b977f9427
This commit is contained in:
Bonian Chen
2021-01-18 18:01:37 +08:00
parent 7c22644825
commit 26552500f6
8 changed files with 173 additions and 24 deletions

View File

@@ -26,6 +26,7 @@ import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
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.SmsDefaultSubscriptionController;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -42,6 +43,9 @@ public class NetworkProviderCallsSmsFragment extends DashboardFragment {
@VisibleForTesting
static final String KEY_PREFERENCE_CATEGORY_CALLING = "provider_model_calling_category";
@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";
@VisibleForTesting
static final String KEY_PREFERENCE_SMS = "provider_model_sms_preference";
@@ -60,6 +64,12 @@ public class NetworkProviderCallsSmsFragment extends DashboardFragment {
mNetworkProviderWifiCallingPreferenceController.init(getSettingsLifecycle());
controllers.add(mNetworkProviderWifiCallingPreferenceController);
NetworkProviderBackupCallingPreferenceController backupCallingPrefCtrl =
new NetworkProviderBackupCallingPreferenceController(context,
KEY_PREFERENCE_CATEGORY_BACKUP_CALLING);
backupCallingPrefCtrl.init(getSettingsLifecycle());
controllers.add(backupCallingPrefCtrl);
return controllers;
}

View File

@@ -34,22 +34,22 @@ import com.android.settings.R;
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 Preference mPreference;
/**
* Class constructor of cross sim calling.
* Class constructor of backup calling.
*
* @param context of settings
* @param key assigned within UI entry of XML file
**/
public CrossSimCallingPreferenceController(Context context, String key) {
public BackupCallingPreferenceController(Context context, String key) {
super(context, key);
}
@@ -59,14 +59,14 @@ public class CrossSimCallingPreferenceController extends TelephonyTogglePreferen
* @param subId is the subscription id
* @return this instance after initialization
**/
public CrossSimCallingPreferenceController init(int subId) {
public BackupCallingPreferenceController init(int subId) {
mSubId = subId;
return this;
}
@Override
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 finalText = String.format(
getResourcesForSubId().getString(R.string.cross_sim_calling_setting_summary),
getResourcesForSubId().getString(R.string.backup_calling_setting_summary),
summary)
.toString();
preference.setSummary(finalText);
}
private boolean hasCrossSimCallingFeature(int subscriptionId) {
private boolean hasBackupCallingFeature(int subscriptionId) {
PersistableBundle carrierConfig = getCarrierConfigForSubId(subscriptionId);
return (carrierConfig != null)
&& carrierConfig.getBoolean(

View File

@@ -177,8 +177,8 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings {
final VideoCallingPreferenceController videoCallingPreferenceController =
use(VideoCallingPreferenceController.class).init(mSubId);
final CrossSimCallingPreferenceController crossSimCallingPreferenceController =
use(CrossSimCallingPreferenceController.class).init(mSubId);
final BackupCallingPreferenceController crossSimCallingPreferenceController =
use(BackupCallingPreferenceController.class).init(mSubId);
use(CallingPreferenceCategoryController.class).setChildren(
Arrays.asList(wifiCallingPreferenceController, videoCallingPreferenceController,
crossSimCallingPreferenceController));

View File

@@ -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);
}
}
}