Merge change 6689 into donut

* changes:
  Don't crash the app when restore agent bringup throws
This commit is contained in:
Android (Google) Code Review
2009-07-09 15:58:39 -07:00

View File

@@ -2544,16 +2544,13 @@ public final class ActivityThread {
} }
classname = "android.app.FullBackupAgent"; classname = "android.app.FullBackupAgent";
} }
try {
IBinder binder = null;
try { try {
java.lang.ClassLoader cl = packageInfo.getClassLoader(); java.lang.ClassLoader cl = packageInfo.getClassLoader();
agent = (BackupAgent) cl.loadClass(data.appInfo.backupAgentName).newInstance(); agent = (BackupAgent) cl.loadClass(data.appInfo.backupAgentName).newInstance();
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate backup agent "
+ data.appInfo.backupAgentName + ": " + e.toString(), e);
}
// set up the agent's context // set up the agent's context
try {
if (DEBUG_BACKUP) Log.v(TAG, "Initializing BackupAgent " if (DEBUG_BACKUP) Log.v(TAG, "Initializing BackupAgent "
+ data.appInfo.backupAgentName); + data.appInfo.backupAgentName);
@@ -2561,16 +2558,26 @@ public final class ActivityThread {
context.init(packageInfo, null, this); context.init(packageInfo, null, this);
context.setOuterContext(agent); context.setOuterContext(agent);
agent.attach(context); agent.attach(context);
agent.onCreate(); agent.onCreate();
binder = agent.onBind();
mBackupAgents.put(packageName, agent);
} catch (Exception e) {
// If this is during restore, fail silently; otherwise go
// ahead and let the user see the crash.
Log.e(TAG, "Agent threw during creation: " + e);
if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE) {
throw e;
}
// falling through with 'binder' still null
}
// tell the OS that we're live now // tell the OS that we're live now
IBinder binder = agent.onBind();
try { try {
ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder); ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder);
} catch (RemoteException e) { } catch (RemoteException e) {
// nothing to do. // nothing to do.
} }
mBackupAgents.put(packageName, agent);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Unable to create BackupAgent " throw new RuntimeException("Unable to create BackupAgent "
+ data.appInfo.backupAgentName + ": " + e.toString(), e); + data.appInfo.backupAgentName + ": " + e.toString(), e);