From 2c00fcfb166d9379f89232ab0b875f18b710b9d2 Mon Sep 17 00:00:00 2001 From: JianYang Liu Date: Thu, 10 Oct 2019 15:37:29 -0700 Subject: [PATCH] Changed car status bar to show or hide by setting layout height instead of removing/adding the view. Adding/removing the car status bar via window manager causes issues if trying to do too quickly since the calls are asynchronous. So if the status bar is under the process of being removed when we want to show the status bar, it will throw a BadTokenException because not all of the references have been cleaned up. Bug: 142272085 Test: manual Change-Id: Ia0f46ba4f7582aaadd24dd885788609f027fa156 --- .../systemui/statusbar/car/CarStatusBar.java | 62 +++++++------------ 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index 25191f6a9617d..a6693cb403d61 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -794,15 +794,25 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt } boolean isKeyboardVisible = (vis & InputMethodService.IME_VISIBLE) != 0; - if (!isKeyboardVisible) { - attachBottomNavBarWindow(); - } else { - detachBottomNavBarWindow(); - } + showBottomNavBarWindow(isKeyboardVisible); } private void attachNavBarWindows() { - attachBottomNavBarWindow(); + if (mShowBottom && !mBottomNavBarVisible) { + mBottomNavBarVisible = true; + + WindowManager.LayoutParams lp = new WindowManager.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, + WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL + | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH + | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, + PixelFormat.TRANSLUCENT); + lp.setTitle("CarNavigationBar"); + lp.windowAnimations = 0; + mWindowManager.addView(mNavigationBarWindow, lp); + } if (mShowLeft) { int width = mContext.getResources().getDimensionPixelSize( @@ -840,47 +850,19 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt } } - /** - * Attaches the bottom nav bar window. Can be extended to modify the specific behavior of - * attaching the bottom nav bar. - */ - protected void attachBottomNavBarWindow() { + private void showBottomNavBarWindow(boolean isKeyboardVisible) { if (!mShowBottom) { return; } - if (mBottomNavBarVisible) { - return; - } - mBottomNavBarVisible = true; - - WindowManager.LayoutParams lp = new WindowManager.LayoutParams( - LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, - WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL - | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH - | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH, - PixelFormat.TRANSLUCENT); - lp.setTitle("CarNavigationBar"); - lp.windowAnimations = 0; - mWindowManager.addView(mNavigationBarWindow, lp); - } - - /** - * Detaches the bottom nav bar window. Can be extended to modify the specific behavior of - * detaching the bottom nav bar. - */ - protected void detachBottomNavBarWindow() { - if (!mShowBottom) { + // If keyboard is visible and bottom nav bar not visible, this is the correct state, so do + // nothing. Same with if keyboard is not visible and bottom nav bar is visible. + if (isKeyboardVisible ^ mBottomNavBarVisible) { return; } - if (!mBottomNavBarVisible) { - return; - } - mBottomNavBarVisible = false; - mWindowManager.removeView(mNavigationBarWindow); + mNavigationBarWindow.setVisibility(isKeyboardVisible ? View.GONE : View.VISIBLE); + mBottomNavBarVisible = !isKeyboardVisible; } private void buildBottomBar(int layout) {