Prevent notifyScreenshotError() from calling twice

Found this while investigating the attached bug.
Fixes potential race condition between onServiceDisconnected and
mScreenshotTimeout both calling notifyScreenshotError.

If onServiceDisconnected is going to show an error to the user, I think
it should also unbind, as we would expect the user to re-take the shot
at that point.  Ideally, this would replace the timeout handler entirely.

Not exactly sure how to test this - I tried crashing the
TakeScreenshotService locally, but onServiceDisconnected didn't trigger.

Bug: 28982719
Change-Id: I5093c61735b0661f9874c686e197cd894c3ef7ae
This commit is contained in:
Geoffrey Pitsch
2016-08-24 10:37:19 -04:00
parent edaaef304a
commit b2d6ed3cd1

View File

@@ -5511,7 +5511,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
@Override
public void onServiceDisconnected(ComponentName name) {
notifyScreenshotError();
synchronized (mScreenshotLock) {
if (mScreenshotConnection != null) {
mContext.unbindService(mScreenshotConnection);
mScreenshotConnection = null;
mHandler.removeCallbacks(mScreenshotTimeout);
notifyScreenshotError();
}
}
}
};
if (mContext.bindServiceAsUser(serviceIntent, conn,
@@ -7748,7 +7755,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
int delta = newRotation - oldRotation;
if (delta < 0) delta += 4;
// Likewise we don't rotate seamlessly for 180 degree rotations
// in this case the surfaces never resize, and our logic to
// in this case the surfaces never resize, and our logic to
// revert the transformations on size change will fail. We could
// fix this in the future with the "tagged" frames idea.
if (delta == Surface.ROTATION_180) {