From a1dbd23b6334f23e7853d6cd3d90a90cd1ea8a9b Mon Sep 17 00:00:00 2001 From: Chao Zhang Date: Wed, 20 Jan 2016 20:39:12 +0800 Subject: Gallery2: fix video play abnormal when screen is locked. play video --> lock screen --> call in --> refuse the call. after this step, screen is locked, but video is resume playing because CodeauroraVideoView's doPrepared() is called. add a check of KeyguardManager.inKeyguardRestrictedInputMode() in CodeauroraVideoView.doPreparedIfReady() like MovieActivity. Change-Id: I19d9da0d23ca490e5038316d6b982099b8280aba CRs-Fixed: 945013 --- .../gallery3d/video/CodeauroraVideoView.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java index f8c70505f..3b4312d67 100644 --- a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java +++ b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java @@ -1,6 +1,7 @@ package org.codeaurora.gallery3d.video; import android.app.AlertDialog; +import android.app.KeyguardManager; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -96,6 +97,7 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr private boolean mOnResumed; private boolean mIsShowDialog = false; private boolean mErrorDialogShowing = false; + private KeyguardManager mKeyguardManager; private final Handler mHandler = new Handler() { public void handleMessage(final Message msg) { @@ -946,6 +948,21 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr setVideoURI(uri, headers); } + private boolean isKeyguardLocked() { + if (mKeyguardManager == null) { + mKeyguardManager = + (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); + } + // isKeyguardSecure excludes the slide lock case. + boolean locked = (mKeyguardManager != null) + && mKeyguardManager.inKeyguardRestrictedInputMode(); + if (LOG) { + Log.v(TAG, "isKeyguardLocked() locked=" + locked + ", mKeyguardManager=" + + mKeyguardManager); + } + return locked; + } + private void doPreparedIfReady(final MediaPlayer mp) { if (LOG) { Log.v(TAG, "doPreparedIfReady() mHasGotPreparedCallBack=" + mHasGotPreparedCallBack @@ -953,7 +970,7 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr + mNeedWaitLayout + ", mCurrentState=" + mCurrentState); } - if (mHasGotPreparedCallBack && mHasGotMetaData && !mNeedWaitLayout) { + if (mHasGotPreparedCallBack && mHasGotMetaData && !mNeedWaitLayout && !isKeyguardLocked()) { doPrepared(mp); } } -- cgit v1.2.3