[DO NOT MERGE] Bail early if mToken.asBinder() not found

Not able to reproduce what's in the original bug report, this null check
is added as a safe guard. A possible scenario is
PipTaskOrganizer#exitPip is called twice and there is a race condition
that the first applySyncTransaction is not ready yet and leave the
internal state as it was, the second call tries to get configuration and
it is null, which leads to a NPE.

Bug: 169173459
Test: N/A
Change-Id: Ie5292e8749bc186fba930dfee59c26d10ea680cd
This commit is contained in:
Hongwei Wang
2020-09-23 13:18:35 -07:00
parent 7d2354bdc5
commit 3de034371b

View File

@@ -303,15 +303,20 @@ public class PipTaskOrganizer extends TaskOrganizer implements
* @param animationDurationMs duration in millisecond for the exiting PiP transition
*/
public void exitPip(int animationDurationMs) {
if (!mState.isInPip() || mState == State.EXITING_PIP || mToken == null) {
if (!mState.isInPip() || mToken == null) {
Log.wtf(TAG, "Not allowed to exitPip in current state"
+ " mState=" + mState + " mToken=" + mToken);
return;
}
final PipWindowConfigurationCompact config = mCompactState.remove(mToken.asBinder());
if (config == null) {
Log.wtf(TAG, "Token not in record, this should not happen mToken=" + mToken);
return;
}
mPipUiEventLoggerLogger.log(
PipUiEventLogger.PipUiEventEnum.PICTURE_IN_PICTURE_EXPAND_TO_FULLSCREEN);
final PipWindowConfigurationCompact config = mCompactState.remove(mToken.asBinder());
config.syncWithScreenOrientation(mRequestedOrientation,
mPipBoundsHandler.getDisplayRotation());
final boolean orientationDiffers = config.getRotation()