From 4ebf6dd961bf4f5ee0577af0cf8221af65f8c017 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 29 Feb 2016 17:34:43 -0800 Subject: [PATCH] Don't use restricted backup launch mode for system-ish processes We now impose restricted launch behavior and lifetime only on "ordinary" apps' backup/restore operations. System-ish targets such as the telephony provider continue to get their full Application instance and providers, and won't get killed following conclusion of the data-moving operations. Such customers of backup/restore are expected to be able to deal gracefully with this sort of thing. Bug 27362301 Bug 27076602 Change-Id: Ib62483b8469cc750a20f80b7c596ad486a397564 --- .../server/backup/BackupManagerService.java | 17 +++++++++-------- .../server/am/ActivityManagerService.java | 7 ++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index f1a9c44ffe6c5..cd4d107d5a980 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -3495,9 +3495,8 @@ public class BackupManagerService { // The agent was running with a stub Application object, so shut it down. // !!! We hardcode the confirmation UI's package name here rather than use a // manifest flag! TODO something less direct. - if (app.uid != Process.SYSTEM_UID - && !app.packageName.equals("com.android.backupconfirm") - && app.uid != Process.PHONE_UID) { + if (app.uid >= Process.FIRST_APPLICATION_UID + && !app.packageName.equals("com.android.backupconfirm")) { if (MORE_DEBUG) Slog.d(TAG, "Killing agent host process"); mActivityManager.killApplicationProcess(app.processName, app.uid); } else { @@ -6881,7 +6880,7 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF // The agent was running with a stub Application object, so shut it down. // !!! We hardcode the confirmation UI's package name here rather than use a // manifest flag! TODO something less direct. - if (app.uid != Process.SYSTEM_UID + if (app.uid >= Process.FIRST_APPLICATION_UID && !app.packageName.equals("com.android.backupconfirm")) { if (DEBUG) Slog.d(TAG, "Killing host process"); mActivityManager.killApplicationProcess(app.processName, app.uid); @@ -8625,13 +8624,15 @@ if (MORE_DEBUG) Slog.v(TAG, " + got " + nRead + "; now wanting " + (size - soF // it is explicitly not killed following that operation. // // We execute this kill when these conditions hold: - // 1. the app did not request its own restore (mTargetPackage == null), and either - // 2a. the app is a full-data target (TYPE_FULL_STREAM) or + // 1. it's not a system-uid process, + // 2. the app did not request its own restore (mTargetPackage == null), and either + // 3a. the app is a full-data target (TYPE_FULL_STREAM) or // b. the app does not state android:killAfterRestore="false" in its manifest final int appFlags = mCurrentPackage.applicationInfo.flags; final boolean killAfterRestore = - (mRestoreDescription.getDataType() == RestoreDescription.TYPE_FULL_STREAM) - || ((appFlags & ApplicationInfo.FLAG_KILL_AFTER_RESTORE) != 0); + (mCurrentPackage.applicationInfo.uid >= Process.FIRST_APPLICATION_UID) + && ((mRestoreDescription.getDataType() == RestoreDescription.TYPE_FULL_STREAM) + || ((appFlags & ApplicationInfo.FLAG_KILL_AFTER_RESTORE) != 0)); if (mTargetPackage == null && killAfterRestore) { if (DEBUG) Slog.d(TAG, "Restore complete, killing host process of " diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 5f40e5c380858..446f55a7ec201 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -6230,9 +6230,10 @@ public final class ActivityManagerService extends ActivityManagerNative // If the app is being launched for restore or full backup, set it up specially boolean isRestrictedBackupMode = false; if (mBackupTarget != null && mBackupAppName.equals(processName)) { - isRestrictedBackupMode = (mBackupTarget.backupMode == BackupRecord.RESTORE) - || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL) - || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL); + isRestrictedBackupMode = mBackupTarget.appInfo.uid >= Process.FIRST_APPLICATION_UID + && ((mBackupTarget.backupMode == BackupRecord.RESTORE) + || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL) + || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL)); } notifyPackageUse(app.instrumentationInfo != null