Skip to content

Commit

Permalink
Android screencapture: fix possible hang in stopCapture()
Browse files Browse the repository at this point in the history
When user denies screencapture by clicking 'Cancel' in OS permission dialog,
Chrome will stop the capture after receiving the OnError() report. At this
point, the |mMediaProjection| is not created yet and |mCaptureState| has moved
to |ATTACHED|. So the capture state won't be |STOPPED| which will keep
stopCapture() waiting at [1].

The fix is to change the capture state to |STOPPED| for such a scenario.

[1]: https://cs.chromium.org/chromium/src/media/capture/content/android/java/src/org/chromium/media/ScreenCapture.java?l=324

BUG=718082

Review-Url: https://codereview.chromium.org/2857743003
Cr-Commit-Position: refs/heads/master@{#469255}
  • Loading branch information
braveyao authored and Commit bot committed May 4, 2017
1 parent 4e8a529 commit 8c6cff6
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,16 @@ public void stopCapture() {
if (mMediaProjection != null && mCaptureState == CaptureState.STARTED) {
mMediaProjection.stop();
changeCaptureStateAndNotify(CaptureState.STOPPING);
}

while (mCaptureState != CaptureState.STOPPED) {
try {
mCaptureStateLock.wait();
} catch (InterruptedException ex) {
Log.e(TAG, "ScreenCaptureEvent: " + ex);
while (mCaptureState != CaptureState.STOPPED) {
try {
mCaptureStateLock.wait();
} catch (InterruptedException ex) {
Log.e(TAG, "ScreenCaptureEvent: " + ex);
}
}
} else {
changeCaptureStateAndNotify(CaptureState.STOPPED);
}
}
}
Expand Down

0 comments on commit 8c6cff6

Please sign in to comment.