From 0e351e46e0e5b158a7a5ee9ed0cbc14e12551342 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Fri, 3 Nov 2023 00:02:19 -0700 Subject: Alway create window context of TYPE_NAVIGATION_BAR_PANEL for FloatingRotationButton FloatingRotationButton is added with TYPE_NAVIGATION_BAR_PANEL. Currently in task bar, we pass the window context with TYPE_NAVIGATION_BAR directly which caused this crash. To ensure safety of this call, we will always create a window context of TYPE_NAVIGATION_BAR_PANEL for handling everything in this class. Bug: 309053627 Test: with task bar / nav bar unification, tilt the phone to show rotation button. Make sure it doesn't crash Change-Id: Iefa2460ab8a3dd952101efdff36e181403051f01 --- .../systemui/shared/rotation/FloatingRotationButton.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java index b44bf395930e..fec96c675b22 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButton.java @@ -16,6 +16,8 @@ package com.android.systemui.shared.rotation; +import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; + import android.annotation.DimenRes; import android.annotation.IdRes; import android.annotation.LayoutRes; @@ -87,15 +89,15 @@ public class FloatingRotationButton implements RotationButton { @DimenRes int roundedContentPadding, @DimenRes int taskbarLeftMargin, @DimenRes int taskbarBottomMargin, @DimenRes int buttonDiameter, @DimenRes int rippleMaxWidth, @BoolRes int floatingRotationBtnPositionLeftResource) { - mWindowManager = context.getSystemService(WindowManager.class); - mKeyButtonContainer = (ViewGroup) LayoutInflater.from(context).inflate(layout, null); + mContext = context.createWindowContext(context.getDisplay(), TYPE_NAVIGATION_BAR_PANEL, + null); + mWindowManager = mContext.getSystemService(WindowManager.class); + mKeyButtonContainer = (ViewGroup) LayoutInflater.from(mContext).inflate(layout, null); mKeyButtonView = mKeyButtonContainer.findViewById(keyButtonId); mKeyButtonView.setVisibility(View.VISIBLE); - mKeyButtonView.setContentDescription(context.getString(contentDescriptionResource)); + mKeyButtonView.setContentDescription(mContext.getString(contentDescriptionResource)); mKeyButtonView.setRipple(rippleMaxWidth); - mContext = context; - mContentDescriptionResource = contentDescriptionResource; mMinMarginResource = minMargin; mRoundedContentPaddingResource = roundedContentPadding; -- cgit v1.2.3-59-g8ed1b