Check for home activity when switching focus.
When finishing or stopping an activity the code was automatically
refocusing to the next activity on the same stack independent of the
task's onTopOfHome flag. When the activity eventually finished or
stopped it would then honor the onTopOfHome flag.
This fix examines the onTopOfHome flag and arranges the focus
correctly if home is the next activity to run.
Fixes bug 11318263.
Change-Id: I73a8f5e82de04b01acaffe366b085f9e475e1451
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 0397fd5..22daaf3 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -2174,6 +2174,19 @@
r.addResultLocked(null, resultWho, requestCode, resultCode, data);
}
+ private void adjustFocusedActivityLocked(ActivityRecord r) {
+ if (mStackSupervisor.isFrontStack(this) && mService.mFocusedActivity == r) {
+ ActivityRecord next = topRunningActivityLocked(null);
+ if (next != r) {
+ final TaskRecord task = r.task;
+ if (r.frontOfTask && task == topTask() && task.mOnTopOfHome) {
+ mStackSupervisor.moveHomeToTop();
+ }
+ }
+ mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked());
+ }
+ }
+
final void stopActivityLocked(ActivityRecord r) {
if (DEBUG_SWITCH) Slog.d(TAG, "Stopping: " + r);
if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0
@@ -2193,11 +2206,7 @@
}
if (r.app != null && r.app.thread != null) {
- if (mStackSupervisor.isFrontStack(this)) {
- if (mService.mFocusedActivity == r) {
- mService.setFocusedActivityLocked(topRunningActivityLocked(null));
- }
- }
+ adjustFocusedActivityLocked(r);
r.resumeKeyDispatchingLocked();
try {
r.stopped = false;
@@ -2376,11 +2385,8 @@
}
r.pauseKeyDispatchingLocked();
- if (mStackSupervisor.isFrontStack(this)) {
- if (mService.mFocusedActivity == r) {
- mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked());
- }
- }
+
+ adjustFocusedActivityLocked(r);
finishActivityResultsLocked(r, resultCode, resultData);