Skip to content

Commit ad9b321

Browse files
author
Dianne Hackborn
committed
Try again to fix issue #6912004:tap on gmail notification sends me to home screen
Add a new call to the activity manager to tell it when the activity is resumed, so it can mark its state as dirty then instead of when it first tries to create it. Also tweak things to update the LRU list for the upcoming activity at the point we start pausing the current activity, to avoid an inefficiency where we may decide to kill the process of the upcoming activity if it is at the end of the LRU list. Change-Id: Ia6dc8c34dc6d4b085a1efbe3a5d5f47721d55078
1 parent c71a57d commit ad9b321

5 files changed

Lines changed: 75 additions & 30 deletions

File tree

core/java/android/app/ActivityManagerNative.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
404404
return true;
405405
}
406406

407+
case ACTIVITY_RESUMED_TRANSACTION: {
408+
data.enforceInterface(IActivityManager.descriptor);
409+
IBinder token = data.readStrongBinder();
410+
activityResumed(token);
411+
reply.writeNoException();
412+
return true;
413+
}
414+
407415
case ACTIVITY_PAUSED_TRANSACTION: {
408416
data.enforceInterface(IActivityManager.descriptor);
409417
IBinder token = data.readStrongBinder();
@@ -2152,6 +2160,17 @@ public void activityIdle(IBinder token, Configuration config, boolean stopProfil
21522160
data.recycle();
21532161
reply.recycle();
21542162
}
2163+
public void activityResumed(IBinder token) throws RemoteException
2164+
{
2165+
Parcel data = Parcel.obtain();
2166+
Parcel reply = Parcel.obtain();
2167+
data.writeInterfaceToken(IActivityManager.descriptor);
2168+
data.writeStrongBinder(token);
2169+
mRemote.transact(ACTIVITY_RESUMED_TRANSACTION, data, reply, 0);
2170+
reply.readException();
2171+
data.recycle();
2172+
reply.recycle();
2173+
}
21552174
public void activityPaused(IBinder token) throws RemoteException
21562175
{
21572176
Parcel data = Parcel.obtain();

core/java/android/app/ActivityThread.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ public void handleMessage(Message msg) {
12451245
case RESUME_ACTIVITY:
12461246
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityResume");
12471247
handleResumeActivity((IBinder)msg.obj, true,
1248-
msg.arg1 != 0);
1248+
msg.arg1 != 0, true);
12491249
Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
12501250
break;
12511251
case SEND_RESULT:
@@ -2175,7 +2175,8 @@ private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) {
21752175
if (a != null) {
21762176
r.createdConfig = new Configuration(mConfiguration);
21772177
Bundle oldState = r.state;
2178-
handleResumeActivity(r.token, false, r.isForward);
2178+
handleResumeActivity(r.token, false, r.isForward,
2179+
!r.activity.mFinished && !r.startsNotResumed);
21792180

21802181
if (!r.activity.mFinished && r.startsNotResumed) {
21812182
// The activity manager actually wants this one to start out
@@ -2684,7 +2685,8 @@ static final void cleanUpPendingRemoveWindows(ActivityClientRecord r) {
26842685
r.mPendingRemoveWindowManager = null;
26852686
}
26862687

2687-
final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward) {
2688+
final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward,
2689+
boolean reallyResume) {
26882690
// If we are getting ready to gc after going to the background, well
26892691
// we are back active so skip it.
26902692
unscheduleGcIdler();
@@ -2781,6 +2783,14 @@ final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForw
27812783
}
27822784
r.onlyLocalRequest = false;
27832785

2786+
// Tell the activity manager we have resumed.
2787+
if (reallyResume) {
2788+
try {
2789+
ActivityManagerNative.getDefault().activityResumed(token);
2790+
} catch (RemoteException ex) {
2791+
}
2792+
}
2793+
27842794
} else {
27852795
// If an exception was thrown when trying to resume, then
27862796
// just end this activity.
@@ -2865,7 +2875,7 @@ private void handlePauseActivity(IBinder token, boolean finished,
28652875
if (r.isPreHoneycomb()) {
28662876
QueuedWork.waitToFinish();
28672877
}
2868-
2878+
28692879
// Tell the activity manager we have paused.
28702880
try {
28712881
ActivityManagerNative.getDefault().activityPaused(token);

core/java/android/app/IActivityManager.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,15 @@ public int broadcastIntent(IApplicationThread caller, Intent intent,
8787
String resultData, Bundle map, String requiredPermission,
8888
boolean serialized, boolean sticky, int userId) throws RemoteException;
8989
public void unbroadcastIntent(IApplicationThread caller, Intent intent, int userId) throws RemoteException;
90-
/* oneway */
9190
public void finishReceiver(IBinder who, int resultCode, String resultData, Bundle map, boolean abortBroadcast) throws RemoteException;
9291
public void attachApplication(IApplicationThread app) throws RemoteException;
93-
/* oneway */
92+
public void activityResumed(IBinder token) throws RemoteException;
9493
public void activityIdle(IBinder token, Configuration config,
9594
boolean stopProfiling) throws RemoteException;
9695
public void activityPaused(IBinder token) throws RemoteException;
97-
/* oneway */
9896
public void activityStopped(IBinder token, Bundle state,
9997
Bitmap thumbnail, CharSequence description) throws RemoteException;
100-
/* oneway */
10198
public void activitySlept(IBinder token) throws RemoteException;
102-
/* oneway */
10399
public void activityDestroyed(IBinder token) throws RemoteException;
104100
public String getCallingPackage(IBinder token) throws RemoteException;
105101
public ComponentName getCallingActivity(IBinder token) throws RemoteException;
@@ -496,7 +492,7 @@ private WaitResult(Parcel source) {
496492
int BIND_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+35;
497493
int UNBIND_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+36;
498494
int PUBLISH_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+37;
499-
495+
int ACTIVITY_RESUMED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+38;
500496
int GOING_TO_SLEEP_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+39;
501497
int WAKING_UP_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+40;
502498
int SET_DEBUG_APP_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+41;

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ final void setFocusedActivityLocked(ActivityRecord r) {
17941794
}
17951795

17961796
private final void updateLruProcessInternalLocked(ProcessRecord app,
1797-
boolean oomAdj, boolean updateActivityTime, int bestPos) {
1797+
boolean updateActivityTime, int bestPos) {
17981798
// put it on the LRU to keep track of when it should be exited.
17991799
int lrui = mLruProcesses.indexOf(app);
18001800
if (lrui >= 0) mLruProcesses.remove(lrui);
@@ -1851,29 +1851,29 @@ private final void updateLruProcessInternalLocked(ProcessRecord app,
18511851
if (cr.binding != null && cr.binding.service != null
18521852
&& cr.binding.service.app != null
18531853
&& cr.binding.service.app.lruSeq != mLruSeq) {
1854-
updateLruProcessInternalLocked(cr.binding.service.app, false,
1854+
updateLruProcessInternalLocked(cr.binding.service.app,
18551855
updateActivityTime, i+1);
18561856
}
18571857
}
18581858
}
18591859
for (int j=app.conProviders.size()-1; j>=0; j--) {
18601860
ContentProviderRecord cpr = app.conProviders.get(j).provider;
18611861
if (cpr.proc != null && cpr.proc.lruSeq != mLruSeq) {
1862-
updateLruProcessInternalLocked(cpr.proc, false,
1862+
updateLruProcessInternalLocked(cpr.proc,
18631863
updateActivityTime, i+1);
18641864
}
18651865
}
1866-
1867-
//Slog.i(TAG, "Putting proc to front: " + app.processName);
1868-
if (oomAdj) {
1869-
updateOomAdjLocked();
1870-
}
18711866
}
18721867

18731868
final void updateLruProcessLocked(ProcessRecord app,
18741869
boolean oomAdj, boolean updateActivityTime) {
18751870
mLruSeq++;
1876-
updateLruProcessInternalLocked(app, oomAdj, updateActivityTime, 0);
1871+
updateLruProcessInternalLocked(app, updateActivityTime, 0);
1872+
1873+
//Slog.i(TAG, "Putting proc to front: " + app.processName);
1874+
if (oomAdj) {
1875+
updateOomAdjLocked();
1876+
}
18771877
}
18781878

18791879
final ProcessRecord getProcessRecordLocked(
@@ -4455,7 +4455,13 @@ final void ensureBootCompleted() {
44554455
enableScreenAfterBoot();
44564456
}
44574457
}
4458-
4458+
4459+
public final void activityResumed(IBinder token) {
4460+
final long origId = Binder.clearCallingIdentity();
4461+
mMainStack.activityResumed(token);
4462+
Binder.restoreCallingIdentity(origId);
4463+
}
4464+
44594465
public final void activityPaused(IBinder token) {
44604466
final long origId = Binder.clearCallingIdentity();
44614467
mMainStack.activityPaused(token, false);

services/java/com/android/server/am/ActivityStack.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import android.os.Message;
5353
import android.os.ParcelFileDescriptor;
5454
import android.os.PowerManager;
55-
import android.os.Process;
5655
import android.os.RemoteException;
5756
import android.os.SystemClock;
5857
import android.os.UserHandle;
@@ -755,8 +754,6 @@ final boolean realStartActivityLocked(ActivityRecord r,
755754
completeResumeLocked(r);
756755
checkReadyForSleepLocked();
757756
if (DEBUG_SAVED_STATE) Slog.i(TAG, "Launch completed; removing icicle of " + r.icicle);
758-
r.icicle = null;
759-
r.haveState = false;
760757
} else {
761758
// This activity is not starting in the resumed state... which
762759
// should look like we asked it to pause+stop (but remain visible),
@@ -1010,7 +1007,21 @@ private final void startPausingLocked(boolean userLeaving, boolean uiSleeping) {
10101007
resumeTopActivityLocked(null);
10111008
}
10121009
}
1013-
1010+
1011+
final void activityResumed(IBinder token) {
1012+
ActivityRecord r = null;
1013+
1014+
synchronized (mService) {
1015+
int index = indexOfTokenLocked(token);
1016+
if (index >= 0) {
1017+
r = mHistory.get(index);
1018+
if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
1019+
r.icicle = null;
1020+
r.haveState = false;
1021+
}
1022+
}
1023+
}
1024+
10141025
final void activityPaused(IBinder token, boolean timeout) {
10151026
if (DEBUG_PAUSE) Slog.v(
10161027
TAG, "Activity paused: token=" + token + ", timeout=" + timeout);
@@ -1488,6 +1499,15 @@ final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
14881499
// can be resumed...
14891500
if (mResumedActivity != null) {
14901501
if (DEBUG_SWITCH) Slog.v(TAG, "Skip resume: need to start pausing");
1502+
// At this point we want to put the upcoming activity's process
1503+
// at the top of the LRU list, since we know we will be needing it
1504+
// very soon and it would be a waste to let it get killed if it
1505+
// happens to be sitting towards the end.
1506+
if (next.app != null && next.app.thread != null) {
1507+
// No reason to do full oom adj update here; we'll let that
1508+
// happen whenever it needs to later.
1509+
mService.updateLruProcessLocked(next.app, false, true);
1510+
}
14911511
startPausingLocked(userLeaving, false);
14921512
return true;
14931513
}
@@ -1728,11 +1748,6 @@ final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
17281748
"resume-exception", true);
17291749
return true;
17301750
}
1731-
1732-
// Didn't need to use the icicle, and it is now out of date.
1733-
if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; didn't need icicle of: " + next);
1734-
next.icicle = null;
1735-
next.haveState = false;
17361751
next.stopped = false;
17371752

17381753
} else {
@@ -2578,7 +2593,6 @@ final int startActivityLocked(IApplicationThread caller,
25782593
mDismissKeyguardOnNextActivity = false;
25792594
mService.mWindowManager.dismissKeyguard();
25802595
}
2581-
Slog.i(TAG, "DONE STARTING!");
25822596
return err;
25832597
}
25842598

0 commit comments

Comments
 (0)