summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulia Reynolds <juliacr@google.com>2017-08-15 14:43:00 -0400
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-08-17 06:08:22 +0000
commit72c138be306b17527a169e7ea495b66b2e8a1ca2 (patch)
treea7123c5434bee9a77f0c5047a395de0f7ca4163c
parent92b424749346b860fb043dd831746a0b0d3a3e4b (diff)
downloadbase-72c138be306b17527a169e7ea495b66b2e8a1ca2.tar.gz
Optionally append managed service approvals
If the backup comes from a pre O device, don't wipe preexisting managed service grants (which were introduced in O). Merged-In: I142df7acb11309bc4f5f185e45a1f91f86d0334a Merged-In: Ie569972dc0d076718a3a9c59e1ebd942c5bfa987 Test: manual, restore from N to O DR Bug: 64232609 Change-Id: Ieec2c821d9a088c69a5bc143acf8537ba300202d (cherry picked from commit 00004c44d73f7f46e8f25188403ca17a70edea8f)
-rw-r--r--core/java/android/content/Intent.java15
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java10
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java5
-rw-r--r--services/core/java/com/android/server/notification/ManagedServices.java13
4 files changed, 35 insertions, 8 deletions
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index f70215b46a5e..9008ddc75b09 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -3444,11 +3444,13 @@ public class Intent implements Parcelable, Cloneable {
"android.intent.extra.FORCE_FACTORY_RESET";
/**
- * Broadcast action: report that a settings element is being restored from backup. The intent
- * contains three extras: EXTRA_SETTING_NAME is a string naming the restored setting,
- * EXTRA_SETTING_NEW_VALUE is the value being restored, and EXTRA_SETTING_PREVIOUS_VALUE
- * is the value of that settings entry prior to the restore operation. All of these values are
- * represented as strings.
+ * Broadcast action: report that a settings element is being restored from backup. The intent
+ * contains four extras: EXTRA_SETTING_NAME is a string naming the restored setting,
+ * EXTRA_SETTING_NEW_VALUE is the value being restored, EXTRA_SETTING_PREVIOUS_VALUE
+ * is the value of that settings entry prior to the restore operation, and
+ * EXTRA_SETTING_RESTORED_FROM_SDK_INT is the version of the SDK that the setting has been
+ * restored from (corresponds to {@link android.os.Build.VERSION#SDK_INT}). The first three
+ * values are represented as strings, the fourth one as int.
*
* <p>This broadcast is sent only for settings provider entries known to require special handling
* around restore time. These entries are found in the BROADCAST_ON_RESTORE table within
@@ -3457,6 +3459,7 @@ public class Intent implements Parcelable, Cloneable {
* @see #EXTRA_SETTING_NAME
* @see #EXTRA_SETTING_PREVIOUS_VALUE
* @see #EXTRA_SETTING_NEW_VALUE
+ * @see #EXTRA_SETTING_RESTORED_FROM_SDK_INT
* {@hide}
*/
public static final String ACTION_SETTING_RESTORED = "android.os.action.SETTING_RESTORED";
@@ -3467,6 +3470,8 @@ public class Intent implements Parcelable, Cloneable {
public static final String EXTRA_SETTING_PREVIOUS_VALUE = "previous_value";
/** {@hide} */
public static final String EXTRA_SETTING_NEW_VALUE = "new_value";
+ /** {@hide} */
+ public static final String EXTRA_SETTING_RESTORED_FROM_SDK_INT = "restored_from_sdk_int";
/**
* Activity Action: Process a piece of text.
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
index 533c52b20f4e..f8701c40427a 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
@@ -147,6 +147,10 @@ public class SettingsBackupAgent extends BackupAgentHelper {
private WifiManager mWifiManager;
+ // Version of the SDK that com.android.providers.settings package has been restored from.
+ // Populated in onRestore().
+ private int mRestoredFromSdkInt;
+
@Override
public void onCreate() {
if (DEBUG_BACKUP) Log.d(TAG, "onCreate() invoked");
@@ -201,6 +205,9 @@ public class SettingsBackupAgent extends BackupAgentHelper {
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
+ // versionCode of com.android.providers.settings corresponds to SDK_INT
+ mRestoredFromSdkInt = appVersionCode;
+
HashSet<String> movedToGlobal = new HashSet<String>();
Settings.System.getMovedToGlobalSettings(movedToGlobal);
Settings.Secure.getMovedToGlobalSettings(movedToGlobal);
@@ -640,7 +647,8 @@ public class SettingsBackupAgent extends BackupAgentHelper {
final Uri destination = (movedToGlobal != null && movedToGlobal.contains(key))
? Settings.Global.CONTENT_URI
: contentUri;
- settingsHelper.restoreValue(this, cr, contentValues, destination, key, value);
+ settingsHelper.restoreValue(this, cr, contentValues, destination, key, value,
+ mRestoredFromSdkInt);
if (DEBUG) {
Log.d(TAG, "Restored setting: " + destination + " : " + key + "=" + value);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index 8abdc641d675..344cd8fcc36d 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -112,7 +112,7 @@ public class SettingsHelper {
* and in some cases the property value needs to be modified before setting.
*/
public void restoreValue(Context context, ContentResolver cr, ContentValues contentValues,
- Uri destination, String name, String value) {
+ Uri destination, String name, String value, int restoredFromSdkInt) {
// Will we need a post-restore broadcast for this element?
String oldValue = null;
boolean sendBroadcast = false;
@@ -169,7 +169,8 @@ public class SettingsHelper {
.setPackage("android").addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY)
.putExtra(Intent.EXTRA_SETTING_NAME, name)
.putExtra(Intent.EXTRA_SETTING_NEW_VALUE, value)
- .putExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE, oldValue);
+ .putExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE, oldValue)
+ .putExtra(Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT, restoredFromSdkInt);
context.sendBroadcastAsUser(intent, UserHandle.SYSTEM, null);
}
}
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index 73a365b0da72..5251c78f9541 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -139,6 +139,19 @@ abstract public class ManagedServices {
|| Objects.equals(element, mConfig.secondarySettingName)) {
String prevValue = intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE);
String newValue = intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE);
+ int restoredFromSdkInt = intent.getIntExtra(
+ Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT, 0);
+ if (restoredFromSdkInt < Build.VERSION_CODES.O) {
+ // automatic system grants were added in O, so append the approved apps
+ // rather than wiping out the setting
+ if (!TextUtils.isEmpty(prevValue)) {
+ if (!TextUtils.isEmpty(newValue)) {
+ newValue = newValue + ENABLED_SERVICES_SEPARATOR + prevValue;
+ } else {
+ newValue = prevValue;
+ }
+ }
+ }
settingRestored(element, prevValue, newValue, getSendingUserId());
}
}