From d13a5583971a5905ac2ec240282383bde96fc25e Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Mon, 5 May 2014 12:07:40 -0700 Subject: Pause and resume ActivityView when visibility changes Once a Surface has been established the activity in an ActivityView must be paused and resumed as the view goes in and out of visibility = View.GONE. Fixes bug 14034658. Change-Id: Icab43678053c225db70f051dceacd4d024df2153 --- core/java/android/app/ActivityView.java | 24 ++++++++++++++++++++++ .../android/server/am/ActivityStackSupervisor.java | 11 +++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index a810134..097c64e 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -33,6 +33,7 @@ import android.view.MotionEvent; import android.view.Surface; import android.view.TextureView; import android.view.TextureView.SurfaceTextureListener; +import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import dalvik.system.CloseGuard; @@ -51,6 +52,7 @@ public class ActivityView extends ViewGroup { private int mWidth; private int mHeight; private Surface mSurface; + private int mLastVisibility; // Only one IIntentSender or Intent may be queued at a time. Most recent one wins. IIntentSender mQueuedPendingIntent; @@ -95,6 +97,8 @@ public class ActivityView extends ViewGroup { mMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(mMetrics); + mLastVisibility = getVisibility(); + if (DEBUG) Log.v(TAG, "ctor()"); } @@ -103,6 +107,26 @@ public class ActivityView extends ViewGroup { mTextureView.layout(0, 0, r - l, b - t); } + @Override + protected void onVisibilityChanged(View changedView, int visibility) { + super.onVisibilityChanged(changedView, visibility); + + if (mSurface != null) { + try { + if (visibility == View.GONE) { + mActivityContainer.setSurface(null, mWidth, mHeight, mMetrics.densityDpi); + } else if (mLastVisibility == View.GONE) { + // Don't change surface when going between View.VISIBLE and View.INVISIBLE. + mActivityContainer.setSurface(mSurface, mWidth, mHeight, mMetrics.densityDpi); + } + } catch (RemoteException e) { + throw new RuntimeException( + "ActivityView: Unable to set surface of ActivityContainer. " + e); + } + } + mLastVisibility = visibility; + } + private boolean injectInputEvent(InputEvent event) { return mActivityContainer != null && mActivityContainer.injectEvent(event); } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 28b1df5..bc88a7d 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -3187,9 +3187,9 @@ public final class ActivityStackSupervisor implements DisplayListener { } else { mContainerState = CONTAINER_STATE_NO_SURFACE; ((VirtualActivityDisplay) mActivityDisplay).setSurface(null); -// if (mStack.mPausingActivity == null && mStack.mResumedActivity != null) { -// mStack.startPausingLocked(false, true); -// } + if (mStack.mPausingActivity == null && mStack.mResumedActivity != null) { + mStack.startPausingLocked(false, true); + } } setSurfaceIfReady(); @@ -3199,6 +3199,11 @@ public final class ActivityStackSupervisor implements DisplayListener { } @Override + boolean isAttached() { + return mSurface != null && super.isAttached(); + } + + @Override void setDrawn() { synchronized (mService) { mDrawn = true; -- cgit v1.1