From 3de034371b86cfc02121c5ff091d6ccec8596501 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Wed, 23 Sep 2020 13:18:35 -0700 Subject: [PATCH] [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 --- .../src/com/android/systemui/pip/PipTaskOrganizer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java index e6abea72da628..54df53dbe6d7a 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java @@ -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()