Skip to content

Commit 64ccb70

Browse files
author
Craig Mautner
committed
Don't clear visible-behind activity if it is top
Previously if an activity requested to keep running behind translucent activities (Activity.requestVisibleBehind()) and then converted itself to opaque (Activity.convertFromTranslucent()), we would clear the visible-behind activity. This change tests to see if the top activity is the visible-behind activity and does not clear it in that case. This change also clears the visible-behind activity whenever it comes back to the front. That forces the activity to call requestVisibleBehind() each time it is resumed. Fixes bug 17648436. Change-Id: Id0fc4d7e2a2b907675305d98bad1b08cb610919e
1 parent bc156ba commit 64ccb70

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

core/java/android/app/Activity.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5466,27 +5466,33 @@ ActivityOptions getActivityOptions() {
54665466

54675467
/**
54685468
* Activities that want to remain visible behind a translucent activity above them must call
5469-
* this method anytime before a return from {@link #onPause()}. If this call is successful
5470-
* then the activity will remain visible when {@link #onPause()} is called, and can continue to
5471-
* play media in the background, but it must stop playing and release resources prior to or
5472-
* within the call to {@link #onVisibleBehindCanceled()}. If this call returns false, the
5473-
* activity will not be visible in the background, and must release any media resources
5474-
* immediately.
5469+
* this method anytime between the start of {@link #onResume()} and the return from
5470+
* {@link #onPause()}. If this call is successful then the activity will remain visible after
5471+
* {@link #onPause()} is called, and is allowed to continue playing media in the background.
5472+
*
5473+
* <p>The actions of this call are reset each time that this activity is brought to the
5474+
* front. That is, every time {@link #onResume()} is called the activity will be assumed
5475+
* to not have requested visible behind. Therefore, if you want this activity to continue to
5476+
* be visible in the background you must call this method again.
54755477
*
54765478
* <p>Only fullscreen opaque activities may make this call. I.e. this call is a nop
54775479
* for dialog and translucent activities.
54785480
*
5479-
* <p>False will be returned any time this method is call between the return of onPause and
5481+
* <p>Under all circumstances, the activity must stop playing and release resources prior to or
5482+
* within a call to {@link #onVisibleBehindCanceled()} or if this call returns false.
5483+
*
5484+
* <p>False will be returned any time this method is called between the return of onPause and
54805485
* the next call to onResume.
54815486
*
54825487
* @param visible true to notify the system that the activity wishes to be visible behind other
54835488
* translucent activities, false to indicate otherwise. Resources must be
54845489
* released when passing false to this method.
5485-
* @return the resulting visibiity state. If true the activity may remain visible beyond
5486-
* {@link #onPause()}. If false then the activity may not count on being visible behind
5487-
* other translucent activities, and must stop any media playback and release resources.
5488-
* Returning false may occur in lieu of a call to onVisibleBehindCanceled() so the return
5489-
* value must be checked.
5490+
* @return the resulting visibiity state. If true the activity will remain visible beyond
5491+
* {@link #onPause()} if the next activity is translucent or not fullscreen. If false
5492+
* then the activity may not count on being visible behind other translucent activities,
5493+
* and must stop any media playback and release resources.
5494+
* Returning false may occur in lieu of a call to {@link #onVisibleBehindCanceled()} so
5495+
* the return value must be checked.
54905496
*
54915497
* @see #onVisibleBehindCanceled()
54925498
* @see #onBackgroundVisibleBehindChanged(boolean)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,11 @@ private void completeResumeLocked(ActivityRecord next) {
11051105
invalidateLastScreenshot();
11061106
}
11071107
next.returningOptions = null;
1108+
1109+
if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == next) {
1110+
// When resuming an activity, require it to call requestVisibleBehind() again.
1111+
mActivityContainer.mActivityDisplay.setVisibleBehindActivity(null);
1112+
}
11081113
}
11091114

11101115
private void setVisibile(ActivityRecord r, boolean visible) {
@@ -3291,6 +3296,11 @@ void releaseBackgroundResources() {
32913296
if (hasVisibleBehindActivity() &&
32923297
!mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) {
32933298
final ActivityRecord r = getVisibleBehindActivity();
3299+
if (r == topRunningActivityLocked(null)) {
3300+
// Don't release the top activity if it has requested to run behind the next
3301+
// activity.
3302+
return;
3303+
}
32943304
if (DEBUG_STATES) Slog.d(TAG, "releaseBackgroundResources activtyDisplay=" +
32953305
mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app +
32963306
" thread=" + r.app.thread);

0 commit comments

Comments
 (0)