[Settings] Initial config UI support for cross sim calling

This is the initial configuration UI support for cross SIM calling.

Mock UI: https://docs.google.com/presentation/d/1u9eO9Fs2_kr1mqkzyVe-_iNldM6OBv4ucmhUTr3Z-0w/edit?resourcekey=0-siV3RVBkI_fjH8mMWHbtHg#slide=id.gb4a3581a82_0_0
Screenshot: https://screenshot.googleplex.com/3QX3Y6vAhBYv7LC

Bug: 174012397
Test: manual
Change-Id: Id96b72054bee9b3359e5336cc90acbff7e6d78ea
This commit is contained in:
Bonian Chen
2020-12-24 22:54:34 +08:00
parent bfcb1dc2c4
commit 5e12677d00
3 changed files with 108 additions and 3 deletions

View File

@@ -12311,7 +12311,7 @@
<string name="cross_sim_calling_settings_title">Cross SIM calling</string>
<!-- Cross SIM calling summary. [CHAR LIMIT=100] -->
<string name="cross_sim_calling_setting_summary">Allow another SIM calls and SMSs over this SIM.</string>
<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>
<!-- 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>

View File

@@ -17,12 +17,32 @@
package com.android.settings.network.telephony;
import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.ims.ImsException;
import android.telephony.ims.ImsManager;
import android.telephony.ims.ImsMmTelManager;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import java.util.Objects;
/**
* Preference controller for "Cross SIM Calling"
**/
public class CrossSimCallingPreferenceController extends TelephonyTogglePreferenceController {
private static final String LOG_TAG = "CrossSimCallingPrefCtrl";
private int mSubId;
private Preference mPreference;
/**
* Class constructor of cross sim calling.
*
@@ -40,26 +60,101 @@ public class CrossSimCallingPreferenceController extends TelephonyTogglePreferen
* @return this instance after initialization
**/
public CrossSimCallingPreferenceController init(int subId) {
mSubId = subId;
return this;
}
@Override
public int getAvailabilityStatus(int subId) {
return CONDITIONALLY_UNAVAILABLE;
return hasCrossSimCallingFeature(subId) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
/**
* Implementation of abstract methods
**/
public boolean setChecked(boolean isChecked) {
ImsMmTelManager imsMmTelMgr = getImsMmTelManager();
if (imsMmTelMgr == null) {
return false;
}
try {
imsMmTelMgr.setCrossSimCallingEnabled(isChecked);
} catch (ImsException exception) {
Log.w(LOG_TAG, "fail to change cross SIM calling configuration: " + isChecked,
exception);
return false;
}
return true;
}
/**
* Implementation of abstract methods
**/
public boolean isChecked() {
ImsMmTelManager imsMmTelMgr = getImsMmTelManager();
if (imsMmTelMgr == null) {
return false;
}
try {
return imsMmTelMgr.isCrossSimCallingEnabledByUser();
} catch (ImsException exception) {
Log.w(LOG_TAG, "fail to get cross SIM calling configuration", exception);
}
return false;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if ((preference == null) || (!(preference instanceof SwitchPreference))) {
return;
}
mPreference = preference;
final SwitchPreference switchPreference = (SwitchPreference) preference;
switchPreference.setChecked(isChecked());
updateSummary(getLatestSummary());
}
private String getLatestSummary() {
SubscriptionInfo subInfo = getSubscriptionInfo();
return Objects.toString((subInfo == null) ? null : subInfo.getDisplayName(), "");
}
private void updateSummary(String displayName) {
Preference preference = mPreference;
if (preference == null) {
return;
}
String summary = displayName;
String finalText = String.format(
getResourcesForSubId().getString(R.string.cross_sim_calling_setting_summary),
summary)
.toString();
preference.setSummary(finalText);
}
private boolean hasCrossSimCallingFeature(int subscriptionId) {
PersistableBundle carrierConfig = getCarrierConfigForSubId(subscriptionId);
return (carrierConfig != null)
&& carrierConfig.getBoolean(
CarrierConfigManager.KEY_CARRIER_CROSS_SIM_IMS_AVAILABLE_BOOL, false);
}
private ImsMmTelManager getImsMmTelManager() {
if (!SubscriptionManager.isUsableSubscriptionId(mSubId)) {
return null;
}
ImsManager imsMgr = mContext.getSystemService(ImsManager.class);
return (imsMgr == null) ? null : imsMgr.getImsMmTelManager(mSubId);
}
private SubscriptionInfo getSubscriptionInfo() {
SubscriptionManager subInfoMgr = mContext.getSystemService(SubscriptionManager.class);
if (subInfoMgr == null) {
return null;
}
return subInfoMgr.getActiveSubscriptionInfo(mSubId);
}
}

View File

@@ -17,6 +17,7 @@
package com.android.settings.network.telephony;
import android.content.Context;
import android.content.res.Resources;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
@@ -79,4 +80,13 @@ public abstract class TelephonyTogglePreferenceController extends TogglePreferen
mContext.getSystemService(CarrierConfigManager.class);
return carrierConfigMgr.getConfigForSubId(subId);
}
/**
* Returns the resources associated with Subscription.
*
* @return Resources associated with Subscription.
*/
public Resources getResourcesForSubId() {
return SubscriptionManager.getResourcesForSubId(mContext, mSubId);
}
}