From 5e1ab335e6e8fbfa19c64d53880a22f472010953 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Tue, 1 Sep 2009 20:32:49 -0700 Subject: [PATCH] Expand apps' control over the settings restore process Applications can now specify two more aspects of the restore process: whether they need to run with their own custom Application subclass rather than being launched in the usual restricted mode during restore, and whether it's okay for the backup manager to kill the app process once restore has completed. The new manifest attributes for these are, respectively, android:restoreNeedsApplication and android:killAfterRestore. If unspecified in the manifest, restoreNeedsApplication is false, and killAfterRestore is true. In order to support kill-after-restore cleanly, this change also adds a new system-process-only interface to the Activity Manager, which will schedule a "commit suicide" event on the target app's main thread looper. The framework backup agents have been given the appropriate new backup attributes as well. --- api/current.xml | 22 +++++++++++ .../android/app/ActivityManagerNative.java | 23 +++++++++++- core/java/android/app/ActivityThread.java | 13 ++++++- .../android/app/ApplicationThreadNative.java | 17 ++++++++- core/java/android/app/IActivityManager.java | 2 + core/java/android/app/IApplicationThread.java | 2 + .../android/content/pm/ApplicationInfo.java | 27 +++++++++++++- .../android/content/pm/PackageParser.java | 14 +++++++ core/res/AndroidManifest.xml | 1 + core/res/res/values/attrs_manifest.xml | 11 ++++++ core/res/res/values/public.xml | 5 ++- packages/SettingsProvider/AndroidManifest.xml | 1 + .../android/server/BackupManagerService.java | 37 +++++++++++++++++-- .../server/am/ActivityManagerService.java | 29 ++++++++++++++- 14 files changed, 192 insertions(+), 12 deletions(-) diff --git a/api/current.xml b/api/current.xml index 8fad21363f8fe..ef7c3d276fcb1 100644 --- a/api/current.xml +++ b/api/current.xml @@ -4695,6 +4695,17 @@ visibility="public" > + + + + services) throws RemoteException; void scheduleExit() throws RemoteException; + void scheduleSuicide() throws RemoteException; void requestThumbnail(IBinder token) throws RemoteException; void scheduleConfigurationChanged(Configuration config) throws RemoteException; void updateTimeZone() throws RemoteException; @@ -133,4 +134,5 @@ public interface IApplicationThread extends IInterface { int SCHEDULE_CREATE_BACKUP_AGENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+29; int SCHEDULE_DESTROY_BACKUP_AGENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+30; int GET_MEMORY_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+31; + int SCHEDULE_SUICIDE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+32; } diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index 0a42a6faf9f4b..8839f95a9b5e8 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -184,7 +184,29 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { * {@hide} */ public static final int FLAG_ALLOW_BACKUP = 1<<14; - + + /** + * Value for {@link #flags}: this is false if the application has set + * its android:killAfterRestore to false, true otherwise. + * + *

If android:allowBackup is set to false or no android:backupAgent + * is specified, this flag will be ignored. + * + * {@hide} + */ + public static final int FLAG_KILL_AFTER_RESTORE = 1<<15; + + /** + * Value for {@link #flags}: this is true if the application has set + * its android:restoreNeedsApplication to true, false otherwise. + * + *

If android:allowBackup is set to false or no android:backupAgent + * is specified, this flag will be ignored. + * + * {@hide} + */ + public static final int FLAG_RESTORE_NEEDS_APPLICATION = 1<<16; + /** * Flags associated with the application. Any combination of * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE}, @@ -193,7 +215,8 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP}, * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS}, * {@link #FLAG_SUPPORTS_NORMAL_SCREENS}, - * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS}. + * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS}, + * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}. */ public int flags = 0; diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 4399df405ab32..b4a6fee2772e0 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -1296,12 +1296,26 @@ public class PackageParser { com.android.internal.R.styleable.AndroidManifestApplication_allowBackup, true); if (allowBackup) { ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP; + + // backupAgent, killAfterRestore, and restoreNeedsApplication are only relevant + // if backup is possible for the given application. String backupAgent = sa.getNonResourceString( com.android.internal.R.styleable.AndroidManifestApplication_backupAgent); if (backupAgent != null) { ai.backupAgentName = buildClassName(pkgName, backupAgent, outError); Log.v(TAG, "android:backupAgent = " + ai.backupAgentName + " from " + pkgName + "+" + backupAgent); + + if (sa.getBoolean( + com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore, + true)) { + ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE; + } + if (sa.getBoolean( + com.android.internal.R.styleable.AndroidManifestApplication_restoreNeedsApplication, + false)) { + ai.flags |= ApplicationInfo.FLAG_RESTORE_NEEDS_APPLICATION; + } } } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 1ea5fa32eb2ba..53e0125835714 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1113,6 +1113,7 @@ android:label="@string/android_system_label" android:allowClearUserData="false" android:backupAgent="com.android.server.SystemBackupAgent" + android:killAfterRestore="false" android:icon="@drawable/ic_launcher_android"> + + + + + +