Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 615502e7 authored by Riddle Hsu's avatar Riddle Hsu Committed by android-build-team Robot
Browse files

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. It must be checked before using.

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
(cherry picked from commit 52b5816d2ae7f5fd51d921d7f69a147c97afce4b)
parent f5f1a2e7
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.wm;

import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.wm.BarControllerProto.STATE;
import static com.android.server.wm.BarControllerProto.TRANSIENT_STATE;

@@ -90,6 +92,12 @@ public class BarController {
        mWin = win;
    }

    /** @return The display id of {@link #mWin}. It is used to be called from {@link #mHandler}. */
    int getDisplayId() {
        final WindowState win = mWin;
        return win != null ? win.getDisplayId() : INVALID_DISPLAY;
    }

    /**
     * Sets the frame within which the bar will display its content.
     *
@@ -228,8 +236,9 @@ public class BarController {
                @Override
                public void run() {
                    StatusBarManagerInternal statusbar = getStatusBarInternal();
                    if (statusbar != null) {
                        statusbar.setWindowState(mWin.getDisplayId(), mStatusBarManagerId, state);
                    int displayId = getDisplayId();
                    if (statusbar != null && displayId != INVALID_DISPLAY) {
                        statusbar.setWindowState(displayId, mStatusBarManagerId, state);
                    }
                }
            });
+13 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.wm;

import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
import static android.view.WindowManager.LayoutParams.MATCH_PARENT;

@@ -36,22 +37,25 @@ public class StatusBarController extends BarController {

        private Runnable mAppTransitionPending = () -> {
            StatusBarManagerInternal statusBar = getStatusBarInternal();
            if (statusBar != null && mWin != null) {
                statusBar.appTransitionPending(mWin.getDisplayId());
            int displayId = getDisplayId();
            if (statusBar != null && displayId != INVALID_DISPLAY) {
                statusBar.appTransitionPending(displayId);
            }
        };

        private Runnable mAppTransitionCancelled = () -> {
            StatusBarManagerInternal statusBar = getStatusBarInternal();
            if (statusBar != null && mWin != null) {
                statusBar.appTransitionCancelled(mWin.getDisplayId());
            int displayId = getDisplayId();
            if (statusBar != null && displayId != INVALID_DISPLAY) {
                statusBar.appTransitionCancelled(displayId);
            }
        };

        private Runnable mAppTransitionFinished = () -> {
            StatusBarManagerInternal statusBar = getStatusBarInternal();
            if (statusBar != null && mWin != null) {
                statusBar.appTransitionFinished(mWin.getDisplayId());
            int displayId = getDisplayId();
            if (statusBar != null && displayId != INVALID_DISPLAY) {
                statusBar.appTransitionFinished(displayId);
            }
        };

@@ -65,8 +69,9 @@ public class StatusBarController extends BarController {
                long statusBarAnimationStartTime, long statusBarAnimationDuration) {
            mHandler.post(() -> {
                StatusBarManagerInternal statusBar = getStatusBarInternal();
                if (statusBar != null && mWin != null) {
                    statusBar.appTransitionStarting(mWin.getDisplayId(),
                int displayId = getDisplayId();
                if (statusBar != null && displayId != INVALID_DISPLAY) {
                    statusBar.appTransitionStarting(displayId,
                            statusBarAnimationStartTime, statusBarAnimationDuration);
                }
            });