Merge "Call TelephonyProvider apis for backup/restore per-sim settings." am: 1f9d1566c2
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1684527 Change-Id: I6d7ee0a1e1eb34e031bb19199787f429a6c521f0
This commit is contained in:
@@ -10069,6 +10069,7 @@ package android.telephony {
|
||||
method public boolean canManageSubscription(@NonNull android.telephony.SubscriptionInfo, @NonNull String);
|
||||
method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int[] getActiveSubscriptionIdList();
|
||||
method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public android.telephony.SubscriptionInfo getActiveSubscriptionInfoForIcc(@NonNull String);
|
||||
method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public byte[] getAllSimSpecificSettingsForBackup();
|
||||
method public java.util.List<android.telephony.SubscriptionInfo> getAvailableSubscriptionInfoList();
|
||||
method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int[] getCompleteActiveSubscriptionIdList();
|
||||
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getEnabledSubscriptionId(int);
|
||||
@@ -10076,6 +10077,7 @@ package android.telephony {
|
||||
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isSubscriptionEnabled(int);
|
||||
method public void requestEmbeddedSubscriptionInfoListRefresh();
|
||||
method public void requestEmbeddedSubscriptionInfoListRefresh(int);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void restoreAllSimSpecificSettingsFromBackup(@NonNull byte[]);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultDataSubId(int);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultSmsSubId(int);
|
||||
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDefaultVoiceSubscriptionId(int);
|
||||
|
||||
@@ -42,6 +42,7 @@ import android.provider.settings.validators.GlobalSettingsValidators;
|
||||
import android.provider.settings.validators.SecureSettingsValidators;
|
||||
import android.provider.settings.validators.SystemSettingsValidators;
|
||||
import android.provider.settings.validators.Validator;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.BackupUtils;
|
||||
@@ -95,10 +96,11 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
private static final String KEY_NETWORK_POLICIES = "network_policies";
|
||||
private static final String KEY_WIFI_NEW_CONFIG = "wifi_new_config";
|
||||
private static final String KEY_DEVICE_SPECIFIC_CONFIG = "device_specific_config";
|
||||
private static final String KEY_SIM_SPECIFIC_SETTINGS = "sim_specific_settings";
|
||||
|
||||
// Versioning of the state file. Increment this version
|
||||
// number any time the set of state items is altered.
|
||||
private static final int STATE_VERSION = 8;
|
||||
private static final int STATE_VERSION = 9;
|
||||
|
||||
// Versioning of the Network Policies backup payload.
|
||||
private static final int NETWORK_POLICIES_BACKUP_VERSION = 1;
|
||||
@@ -106,19 +108,20 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
|
||||
// Slots in the checksum array. Never insert new items in the middle
|
||||
// of this array; new slots must be appended.
|
||||
private static final int STATE_SYSTEM = 0;
|
||||
private static final int STATE_SECURE = 1;
|
||||
private static final int STATE_LOCALE = 2;
|
||||
private static final int STATE_WIFI_SUPPLICANT = 3;
|
||||
private static final int STATE_WIFI_CONFIG = 4;
|
||||
private static final int STATE_GLOBAL = 5;
|
||||
private static final int STATE_LOCK_SETTINGS = 6;
|
||||
private static final int STATE_SOFTAP_CONFIG = 7;
|
||||
private static final int STATE_NETWORK_POLICIES = 8;
|
||||
private static final int STATE_WIFI_NEW_CONFIG = 9;
|
||||
private static final int STATE_DEVICE_CONFIG = 10;
|
||||
private static final int STATE_SYSTEM = 0;
|
||||
private static final int STATE_SECURE = 1;
|
||||
private static final int STATE_LOCALE = 2;
|
||||
private static final int STATE_WIFI_SUPPLICANT = 3;
|
||||
private static final int STATE_WIFI_CONFIG = 4;
|
||||
private static final int STATE_GLOBAL = 5;
|
||||
private static final int STATE_LOCK_SETTINGS = 6;
|
||||
private static final int STATE_SOFTAP_CONFIG = 7;
|
||||
private static final int STATE_NETWORK_POLICIES = 8;
|
||||
private static final int STATE_WIFI_NEW_CONFIG = 9;
|
||||
private static final int STATE_DEVICE_CONFIG = 10;
|
||||
private static final int STATE_SIM_SPECIFIC_SETTINGS = 11;
|
||||
|
||||
private static final int STATE_SIZE = 11; // The current number of state items
|
||||
private static final int STATE_SIZE = 12; // The current number of state items
|
||||
|
||||
// Number of entries in the checksum array at various version numbers
|
||||
private static final int STATE_SIZES[] = {
|
||||
@@ -130,7 +133,8 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
8, // version 5 added STATE_SOFTAP_CONFIG
|
||||
9, // version 6 added STATE_NETWORK_POLICIES
|
||||
10, // version 7 added STATE_WIFI_NEW_CONFIG
|
||||
STATE_SIZE // version 8 added STATE_DEVICE_CONFIG
|
||||
11, // version 8 added STATE_DEVICE_CONFIG
|
||||
STATE_SIZE // version 9 added STATE_SIM_SPECIFIC_SETTINGS
|
||||
};
|
||||
|
||||
private static final int FULL_BACKUP_ADDED_GLOBAL = 2; // added the "global" entry
|
||||
@@ -218,6 +222,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
byte[] netPoliciesData = getNetworkPolicies();
|
||||
byte[] wifiFullConfigData = getNewWifiConfigData();
|
||||
byte[] deviceSpecificInformation = getDeviceSpecificConfiguration();
|
||||
byte[] simSpecificSettingsData = getSimSpecificSettingsData();
|
||||
|
||||
long[] stateChecksums = readOldChecksums(oldState);
|
||||
|
||||
@@ -246,6 +251,9 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
stateChecksums[STATE_DEVICE_CONFIG] =
|
||||
writeIfChanged(stateChecksums[STATE_DEVICE_CONFIG], KEY_DEVICE_SPECIFIC_CONFIG,
|
||||
deviceSpecificInformation, data);
|
||||
stateChecksums[STATE_SIM_SPECIFIC_SETTINGS] =
|
||||
writeIfChanged(stateChecksums[STATE_SIM_SPECIFIC_SETTINGS],
|
||||
KEY_SIM_SPECIFIC_SETTINGS, simSpecificSettingsData, data);
|
||||
|
||||
writeNewChecksums(stateChecksums, newState);
|
||||
}
|
||||
@@ -386,6 +394,12 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
preservedSettings);
|
||||
break;
|
||||
|
||||
case KEY_SIM_SPECIFIC_SETTINGS:
|
||||
byte[] restoredSimSpecificSettings = new byte[size];
|
||||
data.readEntityData(restoredSimSpecificSettings, 0, size);
|
||||
restoreSimSpecificSettings(restoredSimSpecificSettings);
|
||||
break;
|
||||
|
||||
default :
|
||||
data.skipEntityData();
|
||||
|
||||
@@ -1189,6 +1203,20 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
private byte[] getSimSpecificSettingsData() {
|
||||
SubscriptionManager subManager = SubscriptionManager.from(getBaseContext());
|
||||
byte[] simSpecificData = subManager.getAllSimSpecificSettingsForBackup();
|
||||
Log.i(TAG, "sim specific data of length + " + simSpecificData.length
|
||||
+ " successfully retrieved");
|
||||
|
||||
return simSpecificData;
|
||||
}
|
||||
|
||||
private void restoreSimSpecificSettings(byte[] data) {
|
||||
SubscriptionManager subManager = SubscriptionManager.from(getBaseContext());
|
||||
subManager.restoreAllSimSpecificSettingsFromBackup(data);
|
||||
}
|
||||
|
||||
private void updateWindowManagerIfNeeded(Integer previousDensity) {
|
||||
int newDensity;
|
||||
try {
|
||||
|
||||
@@ -47,6 +47,7 @@ import android.net.NetworkPolicyManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelUuid;
|
||||
@@ -150,6 +151,22 @@ public class SubscriptionManager {
|
||||
public static final String CACHE_KEY_SLOT_INDEX_PROPERTY =
|
||||
"cache_key.telephony.get_slot_index";
|
||||
|
||||
/** @hide */
|
||||
public static final String GET_SIM_SPECIFIC_SETTINGS_METHOD_NAME = "getSimSpecificSettings";
|
||||
|
||||
/** @hide */
|
||||
public static final String RESTORE_SIM_SPECIFIC_SETTINGS_METHOD_NAME =
|
||||
"restoreSimSpecificSettings";
|
||||
|
||||
/**
|
||||
* Key to the backup & restore data byte array in the Bundle that is returned by {@link
|
||||
* #getAllSimSpecificSettingsForBackup()} or to be pass in to {@link
|
||||
* #restoreAllSimSpecificSettings()}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final String KEY_SIM_SPECIFIC_SETTINGS_DATA = "KEY_SIM_SPECIFIC_SETTINGS_DATA";
|
||||
|
||||
private static final int MAX_CACHE_SIZE = 4;
|
||||
|
||||
private static class VoidPropertyInvalidatedCache<T>
|
||||
@@ -372,6 +389,28 @@ public class SubscriptionManager {
|
||||
public static final Uri WFC_ROAMING_ENABLED_CONTENT_URI = Uri.withAppendedPath(
|
||||
CONTENT_URI, "wfc_roaming_enabled");
|
||||
|
||||
|
||||
/**
|
||||
* A content {@link uri} used to call the appropriate backup or restore method for sim-specific
|
||||
* settings
|
||||
* <p>
|
||||
* See {@link #GET_SIM_SPECIFIC_SETTINGS_METHOD_NAME} and {@link
|
||||
* #RESTORE_SIM_SPECIFIC_SETTINGS_METHOD_NAME} for information on what method to call.
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static final Uri SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI = Uri.withAppendedPath(
|
||||
CONTENT_URI, "backup_and_restore");
|
||||
|
||||
/**
|
||||
* A content {@link uri} used to notify contentobservers listening to siminfo restore during
|
||||
* SuW.
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public static final Uri SIM_INFO_SUW_RESTORE_CONTENT_URI = Uri.withAppendedPath(
|
||||
SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI, "suw_restore");
|
||||
|
||||
/**
|
||||
* TelephonyProvider unique key column name is the subscription id.
|
||||
* <P>Type: TEXT (String)</P>
|
||||
@@ -3446,4 +3485,71 @@ public class SubscriptionManager {
|
||||
sSlotIndexCache.clear();
|
||||
sPhoneIdCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to retrieve SIM-specific settings data to be backed up.
|
||||
*
|
||||
* @return data in byte[] to be backed up.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
@SystemApi
|
||||
@RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
|
||||
public byte[] getAllSimSpecificSettingsForBackup() {
|
||||
Bundle bundle = mContext.getContentResolver().call(
|
||||
SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI,
|
||||
GET_SIM_SPECIFIC_SETTINGS_METHOD_NAME, null, null);
|
||||
return bundle.getByteArray(SubscriptionManager.KEY_SIM_SPECIFIC_SETTINGS_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to attempt to restore the backed up sim-specific configs to device for specific sim.
|
||||
* This will try to restore the data that was stored internally when {@link
|
||||
* #restoreAllSimSpecificSettingsFromBackup(byte[] data)} was called during setup wizard.
|
||||
* End result is SimInfoDB is modified to match any backed up configs for the requested
|
||||
* inserted sim.
|
||||
*
|
||||
* <p>
|
||||
* The {@link Uri} {@link #SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI} is notified if any SimInfoDB
|
||||
* entry is updated as the result of this method call.
|
||||
*
|
||||
* @param iccId of the sim that a restore is requested for.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
|
||||
public void restoreSimSpecificSettingsForIccIdFromBackup(@NonNull String iccId) {
|
||||
mContext.getContentResolver().call(
|
||||
SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI,
|
||||
RESTORE_SIM_SPECIFIC_SETTINGS_METHOD_NAME,
|
||||
iccId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called during setup wizard restore flow to attempt to restore the backed up sim-specific
|
||||
* configs to device for all existing SIMs in SimInfoDB. Internally, it will store the backup
|
||||
* data in an internal file. This file will persist on device for device's lifetime and will be
|
||||
* used later on when a SIM is inserted to restore that specific SIM's settings by calling
|
||||
* {@link #restoreSimSpecificSettingsForIccIdFromBackup(String iccId)}. End result is
|
||||
* SimInfoDB is modified to match any backed up configs for the appropriate inserted SIMs.
|
||||
*
|
||||
* <p>
|
||||
* The {@link Uri} {@link #SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI} is notified if any SimInfoDB
|
||||
* entry is updated as the result of this method call.
|
||||
*
|
||||
* @param data with the sim specific configs to be backed up.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
|
||||
public void restoreAllSimSpecificSettingsFromBackup(@NonNull byte[] data) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putByteArray(KEY_SIM_SPECIFIC_SETTINGS_DATA, data);
|
||||
mContext.getContentResolver().call(
|
||||
SIM_INFO_BACKUP_AND_RESTORE_CONTENT_URI,
|
||||
RESTORE_SIM_SPECIFIC_SETTINGS_METHOD_NAME,
|
||||
null, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user