DeadObjectException in ActivityManager prevents activity from being launched

2,601 views
Skip to first unread message

Josh

unread,
Jan 22, 2010, 5:08:38 PM1/22/10
to android-platform
I occasionally see the following exception:
01-20 09:07:48.758 W/ActivityManager( 1743): Exception when starting
activity com.android.camera/.Camera

01-20 09:07:48.758 W/ActivityManager( 1743):
android.os.DeadObjectException

01-20 09:07:48.758 W/ActivityManager( 1743): at
android.os.BinderProxy.transact(Native Method)

01-20 09:07:48.758 W/ActivityManager( 1743): at
android.app.ApplicationThreadProxy.scheduleLaunchActivity
(ApplicationThreadNative.java:462)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.realStartActivityLocked
(ActivityManagerService.java:1797)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.startSpecificActivityLocked
(ActivityManagerService.java:1872)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.resumeTopActivityLocked
(ActivityManagerService.java:2795)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.completePauseLocked
(ActivityManagerService.java:2194)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.activityPaused
(ActivityManagerService.java:5598)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.activityPaused
(ActivityManagerService.java:5576)

01-20 09:07:48.758 W/ActivityManager( 1743): at
android.app.ActivityManagerNative.onTransact
(ActivityManagerNative.java:306)

01-20 09:07:48.758 W/ActivityManager( 1743): at
com.android.server.am.ActivityManagerService.onTransact
(ActivityManagerService.java:1535)

01-20 09:07:48.758 W/ActivityManager( 1743): at
android.os.Binder.execTransact(Binder.java:287)

01-20 09:07:48.758 W/ActivityManager( 1743): at
dalvik.system.NativeStart.run(Native Method)

01-20 09:07:48.778 I/ActivityManager( 1743): Start proc
com.android.camera for activity com.android.camera/.Camera: pid=26208
uid=10035 gids={1006, 1015}

01-20 09:07:48.778 I/ActivityManager( 1743): Process
com.android.camera (pid 2256) has died.
01-20 09:07:49.288 W/ActivityManager( 1743): No pending application
record for pid 26208 (IApplicationThread
android.app.ApplicationThreadProxy@2ea43f98); dropping process

01-20 09:07:49.288 I/Process ( 1743): Sending signal. PID: 26208 SIG:
9

Tracing through ActivityManangerService it seems that this could
happen when an application that is being resumed gets killed due to
memory pressure. There is some code in ActivityManagerService to
recover from this by restarting the process, which does successfully
restart it, but it does not find a pending application record for it
so it gets killed.

private final void startSpecificActivityLocked(HistoryRecord r,
boolean andResume, boolean checkConfig) {
// Is this activity's application already running?
ProcessRecord app = getProcessRecordLocked(r.processName,
r.info.applicationInfo.uid);

if (r.startTime == 0) {
r.startTime = SystemClock.uptimeMillis();
if (mInitialStartTime == 0) {
mInitialStartTime = r.startTime;
}
} else if (mInitialStartTime == 0) {
mInitialStartTime = SystemClock.uptimeMillis();
}

if (app != null && app.thread != null) {
try {
realStartActivityLocked(r, app, andResume,
checkConfig);
return;
} catch (RemoteException e) {
Log.w(TAG, "Exception when starting activity "
+ r.intent.getComponent().flattenToShortString
(), e);
}

// If a dead object exception was thrown -- fall through
to
// restart the application.
}

startProcessLocked(r.processName, r.info.applicationInfo,
true, 0,
"activity", r.intent.getComponent());
}

I am able to reproduce this scenario by doing the following:
1. Debug system_server in jdb
2. Open the camera application (which application does not really
matter)
3. Close the camera application
4. Put a breakpoint at ActivityManagerService:1872 (on the call to
realStartActivityLocked in startSpecificActivityLocked)
5. Open the camera application -- you will hit the breakpoint in
ActivityManagerService at this point
6. Kill the camera application (adb shell kill -9 <pid of camera>)
7. Continue from the breakpoint in system_server
8. In the logcat output you will see the camera process being started
but it won't get focus

I was able to workaround this by calling appDiedLocked and
startActivityLocked instead of calling startProcessLocked, but I was
not sure if this was the best solution. Below are the changes:

private final void startSpecificActivityLocked(HistoryRecord r,
boolean andResume, boolean checkConfig) {
// Is this activity's application already running?
ProcessRecord app = getProcessRecordLocked(r.processName,
r.info.applicationInfo.uid);

if (r.startTime == 0) {
r.startTime = SystemClock.uptimeMillis();
if (mInitialStartTime == 0) {
mInitialStartTime = r.startTime;
}
} else if (mInitialStartTime == 0) {
mInitialStartTime = SystemClock.uptimeMillis();
}

if (app != null && app.thread != null) {
try {
realStartActivityLocked(r, app, andResume,
checkConfig);
return;
} catch (RemoteException e) {
Log.w(TAG, "Exception when starting activity "
+ r.intent.getComponent().flattenToShortString
(), e);
appDiedLocked(app, app.pid, app.thread);
startActivityLocked(r, true, true);
return;
}
}

startProcessLocked(r.processName, r.info.applicationInfo,
true, 0,
"activity", r.intent.getComponent());
}

Does anyone more familiar with ActivityManager have any feedback on
whether this is the right solution to the problem or not?

thanks,

Josh

Dianne Hackborn

unread,
Jan 22, 2010, 9:15:01 PM1/22/10
to android-...@googlegroups.com
Are you seeing this in practice?  Generally at the point where we are trying to start an activity, we will have raised the oom_adj up so the process doesn't get killed.  At the same time, we don't want to get stuck continually trying to start an activity if its process is crashing, so we tend to allow the top activity to be remove if the process goes away unexpectedly.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Joshua Bartel

unread,
Jan 25, 2010, 7:11:52 AM1/25/10
to android-...@googlegroups.com
Yes I see it when running automated tests but it takes several (~18) hours before it happens.  It seems to be a race with the process going away when ActivityManagerService is trying to resume it.  There is a recovery path in there for it so it seems that a recovery mechanism for it was added at some point -- it is just not working as I would expect.

If an end user saw this I suppose they would just think they had not clicked the icon properly and would just click again.

thanks,

Josh
Reply all
Reply to author
Forward
0 new messages