@@ -11119,8 +11119,8 @@ public void serviceDoneExecuting(IBinder token, int type, int startId, int res)
1111911119 // instantiated. The backup agent will invoke backupAgentCreated() on the
1112011120 // activity manager to announce its creation.
1112111121 public boolean bindBackupAgent(ApplicationInfo app, int backupMode) {
11122- if (DEBUG_BACKUP) Slog.v(TAG, "startBackupAgent : app=" + app + " mode=" + backupMode);
11123- enforceCallingPermission("android.permission.BACKUP", "startBackupAgent ");
11122+ if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent : app=" + app + " mode=" + backupMode);
11123+ enforceCallingPermission("android.permission.BACKUP", "bindBackupAgent ");
1112411124
1112511125 synchronized(this) {
1112611126 // !!! TODO: currently no check here that we're already bound
@@ -11181,6 +11181,17 @@ public boolean bindBackupAgent(ApplicationInfo app, int backupMode) {
1118111181 return true;
1118211182 }
1118311183
11184+ @Override
11185+ public void clearPendingBackup() {
11186+ if (DEBUG_BACKUP) Slog.v(TAG, "clearPendingBackup");
11187+ enforceCallingPermission("android.permission.BACKUP", "clearPendingBackup");
11188+
11189+ synchronized (this) {
11190+ mBackupTarget = null;
11191+ mBackupAppName = null;
11192+ }
11193+ }
11194+
1118411195 // A backup agent has just come up
1118511196 public void backupAgentCreated(String agentPackageName, IBinder agent) {
1118611197 if (DEBUG_BACKUP) Slog.v(TAG, "backupAgentCreated: " + agentPackageName
@@ -11217,32 +11228,34 @@ public void unbindBackupAgent(ApplicationInfo appInfo) {
1121711228 }
1121811229
1121911230 synchronized(this) {
11220- if (mBackupAppName == null) {
11221- Slog.w(TAG, "Unbinding backup agent with no active backup");
11222- return;
11223- }
11224-
11225- if (!mBackupAppName.equals(appInfo.packageName)) {
11226- Slog.e(TAG, "Unbind of " + appInfo + " but is not the current backup target");
11227- return;
11228- }
11231+ try {
11232+ if (mBackupAppName == null) {
11233+ Slog.w(TAG, "Unbinding backup agent with no active backup");
11234+ return;
11235+ }
1122911236
11230- ProcessRecord proc = mBackupTarget.app;
11231- mBackupTarget = null;
11232- mBackupAppName = null;
11237+ if (!mBackupAppName.equals(appInfo.packageName)) {
11238+ Slog.e(TAG, "Unbind of " + appInfo + " but is not the current backup target");
11239+ return;
11240+ }
1123311241
11234- // Not backing this app up any more; reset its OOM adjustment
11235- updateOomAdjLocked(proc);
11242+ // Not backing this app up any more; reset its OOM adjustment
11243+ final ProcessRecord proc = mBackupTarget.app;
11244+ updateOomAdjLocked(proc);
1123611245
11237- // If the app crashed during backup, 'thread' will be null here
11238- if (proc.thread != null) {
11239- try {
11240- proc.thread.scheduleDestroyBackupAgent(appInfo,
11241- compatibilityInfoForPackageLocked(appInfo));
11242- } catch (Exception e) {
11243- Slog.e(TAG, "Exception when unbinding backup agent:");
11244- e.printStackTrace();
11246+ // If the app crashed during backup, 'thread' will be null here
11247+ if (proc.thread != null) {
11248+ try {
11249+ proc.thread.scheduleDestroyBackupAgent(appInfo,
11250+ compatibilityInfoForPackageLocked(appInfo));
11251+ } catch (Exception e) {
11252+ Slog.e(TAG, "Exception when unbinding backup agent:");
11253+ e.printStackTrace();
11254+ }
1124511255 }
11256+ } finally {
11257+ mBackupTarget = null;
11258+ mBackupAppName = null;
1124611259 }
1124711260 }
1124811261 }
0 commit comments