Prevent potential NPE when updating state to bar manager
If the process of bar window is died, the associated window
will be set to null. Since BarController is associated with
display, the display id can be a final field, so it no longer
depends on the nullable member mWin.
Fixes: 129240719
Test: manual - Play video in landscape mode and make systemui
crash, e.g. adb shell kill -11 ${pid of systemui}. The
result should be only the systemui is restarted.
Change-Id: If5b93e76cb856dd0dd80fb8523788f4587222c9c
This commit is contained in:
@@ -51,6 +51,7 @@ public class BarController {
|
||||
private static final int MSG_NAV_BAR_VISIBILITY_CHANGED = 1;
|
||||
|
||||
protected final String mTag;
|
||||
protected final int mDisplayId;
|
||||
private final int mTransientFlag;
|
||||
private final int mUnhideFlag;
|
||||
private final int mTranslucentFlag;
|
||||
@@ -74,9 +75,10 @@ public class BarController {
|
||||
|
||||
private OnBarVisibilityChangedListener mVisibilityChangeListener;
|
||||
|
||||
BarController(String tag, int transientFlag, int unhideFlag, int translucentFlag,
|
||||
BarController(String tag, int displayId, int transientFlag, int unhideFlag, int translucentFlag,
|
||||
int statusBarManagerId, int translucentWmFlag, int transparentFlag) {
|
||||
mTag = "BarController." + tag;
|
||||
mDisplayId = displayId;
|
||||
mTransientFlag = transientFlag;
|
||||
mUnhideFlag = unhideFlag;
|
||||
mTranslucentFlag = translucentFlag;
|
||||
@@ -230,7 +232,7 @@ public class BarController {
|
||||
public void run() {
|
||||
StatusBarManagerInternal statusbar = getStatusBarInternal();
|
||||
if (statusbar != null) {
|
||||
statusbar.setWindowState(mWin.getDisplayId(), mStatusBarManagerId, state);
|
||||
statusbar.setWindowState(mDisplayId, mStatusBarManagerId, state);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -261,15 +261,9 @@ public class DisplayPolicy {
|
||||
/** Cached value of {@link ScreenShapeHelper#getWindowOutsetBottomPx} */
|
||||
@Px private int mWindowOutsetBottom;
|
||||
|
||||
private final StatusBarController mStatusBarController = new StatusBarController();
|
||||
private final StatusBarController mStatusBarController;
|
||||
|
||||
private final BarController mNavigationBarController = new BarController("NavigationBar",
|
||||
View.NAVIGATION_BAR_TRANSIENT,
|
||||
View.NAVIGATION_BAR_UNHIDE,
|
||||
View.NAVIGATION_BAR_TRANSLUCENT,
|
||||
StatusBarManager.WINDOW_NAVIGATION_BAR,
|
||||
FLAG_TRANSLUCENT_NAVIGATION,
|
||||
View.NAVIGATION_BAR_TRANSPARENT);
|
||||
private final BarController mNavigationBarController;
|
||||
|
||||
private final BarController.OnBarVisibilityChangedListener mNavBarVisibilityListener =
|
||||
new BarController.OnBarVisibilityChangedListener() {
|
||||
@@ -416,6 +410,17 @@ public class DisplayPolicy {
|
||||
mDisplayContent = displayContent;
|
||||
mLock = service.getWindowManagerLock();
|
||||
|
||||
final int displayId = displayContent.getDisplayId();
|
||||
mStatusBarController = new StatusBarController(displayId);
|
||||
mNavigationBarController = new BarController("NavigationBar",
|
||||
displayId,
|
||||
View.NAVIGATION_BAR_TRANSIENT,
|
||||
View.NAVIGATION_BAR_UNHIDE,
|
||||
View.NAVIGATION_BAR_TRANSLUCENT,
|
||||
StatusBarManager.WINDOW_NAVIGATION_BAR,
|
||||
FLAG_TRANSLUCENT_NAVIGATION,
|
||||
View.NAVIGATION_BAR_TRANSPARENT);
|
||||
|
||||
final Resources r = mContext.getResources();
|
||||
mCarDockEnablesAccelerometer = r.getBoolean(R.bool.config_carDockEnablesAccelerometer);
|
||||
mDeskDockEnablesAccelerometer = r.getBoolean(R.bool.config_deskDockEnablesAccelerometer);
|
||||
@@ -527,7 +532,6 @@ public class DisplayPolicy {
|
||||
if (mWindowSleepToken != null) {
|
||||
return;
|
||||
}
|
||||
final int displayId = displayContent.getDisplayId();
|
||||
mWindowSleepToken = service.mAtmInternal.acquireSleepToken(
|
||||
"WindowSleepTokenOnDisplay" + displayId, displayId);
|
||||
};
|
||||
|
||||
@@ -36,22 +36,22 @@ public class StatusBarController extends BarController {
|
||||
|
||||
private Runnable mAppTransitionPending = () -> {
|
||||
StatusBarManagerInternal statusBar = getStatusBarInternal();
|
||||
if (statusBar != null && mWin != null) {
|
||||
statusBar.appTransitionPending(mWin.getDisplayId());
|
||||
if (statusBar != null) {
|
||||
statusBar.appTransitionPending(mDisplayId);
|
||||
}
|
||||
};
|
||||
|
||||
private Runnable mAppTransitionCancelled = () -> {
|
||||
StatusBarManagerInternal statusBar = getStatusBarInternal();
|
||||
if (statusBar != null && mWin != null) {
|
||||
statusBar.appTransitionCancelled(mWin.getDisplayId());
|
||||
if (statusBar != null) {
|
||||
statusBar.appTransitionCancelled(mDisplayId);
|
||||
}
|
||||
};
|
||||
|
||||
private Runnable mAppTransitionFinished = () -> {
|
||||
StatusBarManagerInternal statusBar = getStatusBarInternal();
|
||||
if (statusBar != null && mWin != null) {
|
||||
statusBar.appTransitionFinished(mWin.getDisplayId());
|
||||
if (statusBar != null) {
|
||||
statusBar.appTransitionFinished(mDisplayId);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,8 +65,8 @@ public class StatusBarController extends BarController {
|
||||
long statusBarAnimationStartTime, long statusBarAnimationDuration) {
|
||||
mHandler.post(() -> {
|
||||
StatusBarManagerInternal statusBar = getStatusBarInternal();
|
||||
if (statusBar != null && mWin != null) {
|
||||
statusBar.appTransitionStarting(mWin.getDisplayId(),
|
||||
if (statusBar != null) {
|
||||
statusBar.appTransitionStarting(mDisplayId,
|
||||
statusBarAnimationStartTime, statusBarAnimationDuration);
|
||||
}
|
||||
});
|
||||
@@ -84,8 +84,9 @@ public class StatusBarController extends BarController {
|
||||
}
|
||||
};
|
||||
|
||||
StatusBarController() {
|
||||
StatusBarController(int displayId) {
|
||||
super("StatusBar",
|
||||
displayId,
|
||||
View.STATUS_BAR_TRANSIENT,
|
||||
View.STATUS_BAR_UNHIDE,
|
||||
View.STATUS_BAR_TRANSLUCENT,
|
||||
|
||||
Reference in New Issue
Block a user