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

Commit 5f6cbca2 authored by Tiger Huang's avatar Tiger Huang
Browse files

Fix a NullPointerException caused by NEW_INSETS_MODE_FULL

InsetsSourceProvider.updateControlForTarget must be called while mWin
has the SurfaceControl. Otherwise, mAdapter will be cleared by
ControlAdapter.onAnimationCancelled. See
SurfaceAnimator.startAnimation.

This CL separates DisplayPolicy.prepareAddWindowLw into two parts:
1. Check if we can add a window to the system.
2. Apply policies on certain types of window.
We move the second part below mToken.addWindow. So the window has the
SurfaceControl while we set insets provider.

Bug: 118118435
Test: atest DisplayPolicyInsetsTests DisplayPolicyLayoutTests
Test: See if the system can be rebooted after entering the commands:
      adb root
      adb setprop persist.wm.new_insets 2
      adb reboot

Change-Id: I15c9a3ab49dee1c0f7009334adbd6fd1af8e0ba7
parent d211a321
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16071,7 +16071,7 @@ PLcom/android/server/wm/DisplayPolicy;->notifyDisplayReady()V
PLcom/android/server/wm/DisplayPolicy;->offsetInputMethodWindowLw(Lcom/android/server/wm/WindowState;Lcom/android/server/wm/DisplayFrames;)V
HSPLcom/android/server/wm/DisplayPolicy;->onConfigurationChanged()V
PLcom/android/server/wm/DisplayPolicy;->onPowerKeyDown(Z)V
HSPLcom/android/server/wm/DisplayPolicy;->prepareAddWindowLw(Lcom/android/server/wm/WindowState;Landroid/view/WindowManager$LayoutParams;)I
HSPLcom/android/server/wm/DisplayPolicy;->validateAddingWindowLw(Landroid/view/WindowManager$LayoutParams;)I
HSPLcom/android/server/wm/DisplayPolicy;->removeWindowLw(Lcom/android/server/wm/WindowState;)V
HSPLcom/android/server/wm/DisplayPolicy;->requestTransientBars(Lcom/android/server/wm/WindowState;)V
HSPLcom/android/server/wm/DisplayPolicy;->resetSystemUiVisibilityLw()V
+41 −25
Original line number Diff line number Diff line
@@ -877,27 +877,24 @@ public class DisplayPolicy {
    }

    /**
     * Preflight adding a window to the system.
     * Check if a window can be added to the system.
     *
     * Currently enforces that three window types are singletons per display:
     * Currently enforces that two window types are singletons per display:
     * <ul>
     * <li>{@link WindowManager.LayoutParams#TYPE_STATUS_BAR}</li>
     * <li>{@link WindowManager.LayoutParams#TYPE_NAVIGATION_BAR}</li>
     * </ul>
     *
     * @param win The window to be added
     * @param attrs Information about the window to be added
     * @param attrs Information about the window to be added.
     *
     * @return If ok, WindowManagerImpl.ADD_OKAY.  If too many singletons,
     * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
     */
    public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {

    int validateAddingWindowLw(WindowManager.LayoutParams attrs) {
        if ((attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.STATUS_BAR_SERVICE,
                    "DisplayPolicy");
            mScreenDecorWindows.add(win);
        }

        switch (attrs.type) {
@@ -910,6 +907,42 @@ public class DisplayPolicy {
                        return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
                    }
                }
                break;
            case TYPE_NAVIGATION_BAR:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                        "DisplayPolicy");
                if (mNavigationBar != null) {
                    if (mNavigationBar.isAlive()) {
                        return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
                    }
                }
                break;
            case TYPE_NAVIGATION_BAR_PANEL:
            case TYPE_STATUS_BAR_PANEL:
            case TYPE_STATUS_BAR_SUB_PANEL:
            case TYPE_VOICE_INTERACTION_STARTING:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                        "DisplayPolicy");
                break;
        }
        return ADD_OKAY;
    }

    /**
     * Called when a window is being added to the system.  Must not throw an exception.
     *
     * @param win The window being added.
     * @param attrs Information about the window to be added.
     */
    void addWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
        if ((attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0) {
            mScreenDecorWindows.add(win);
        }

        switch (attrs.type) {
            case TYPE_STATUS_BAR:
                mStatusBar = win;
                mStatusBarController.setWindow(win);
                if (mDisplayContent.isDefaultDisplay) {
@@ -925,14 +958,6 @@ public class DisplayPolicy {
                mDisplayContent.setInsetProvider(TYPE_TOP_TAPPABLE_ELEMENT, win, frameProvider);
                break;
            case TYPE_NAVIGATION_BAR:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                        "DisplayPolicy");
                if (mNavigationBar != null) {
                    if (mNavigationBar.isAlive()) {
                        return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
                    }
                }
                mNavigationBar = win;
                mNavigationBarController.setWindow(win);
                mNavigationBarController.setOnBarVisibilityChangedListener(
@@ -966,16 +991,7 @@ public class DisplayPolicy {
                        });
                if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
                break;
            case TYPE_NAVIGATION_BAR_PANEL:
            case TYPE_STATUS_BAR_PANEL:
            case TYPE_STATUS_BAR_SUB_PANEL:
            case TYPE_VOICE_INTERACTION_STARTING:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                        "DisplayPolicy");
                break;
        }
        return ADD_OKAY;
    }

    /**
@@ -984,7 +1000,7 @@ public class DisplayPolicy {
     *
     * @param win The window being removed.
     */
    public void removeWindowLw(WindowState win) {
    void removeWindowLw(WindowState win) {
        if (mStatusBar == win) {
            mStatusBar = null;
            mStatusBarController.setWindow(null);
+2 −1
Original line number Diff line number Diff line
@@ -1432,7 +1432,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    Binder.getCallingUid());
            win.setShowToOwnerOnlyLocked(mPolicy.checkShowToOwnerOnly(attrs));

            res = displayPolicy.prepareAddWindowLw(win, attrs);
            res = displayPolicy.validateAddingWindowLw(attrs);
            if (res != WindowManagerGlobal.ADD_OKAY) {
                return res;
            }
@@ -1508,6 +1508,7 @@ public class WindowManagerService extends IWindowManager.Stub
            boolean imMayMove = true;

            win.mToken.addWindow(win);
            displayPolicy.addWindowLw(win, attrs);
            if (type == TYPE_INPUT_METHOD) {
                displayContent.setInputMethodWindowLocked(win);
                imMayMove = false;
+2 −1
Original line number Diff line number Diff line
@@ -102,7 +102,8 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {
        mDisplayPolicy.adjustWindowParamsLw(win, win.mAttrs, Binder.getCallingPid(),
                Binder.getCallingUid());
        assertEquals(WindowManagerGlobal.ADD_OKAY,
                mDisplayPolicy.prepareAddWindowLw(win, win.mAttrs));
                mDisplayPolicy.validateAddingWindowLw(win.mAttrs));
        mDisplayPolicy.addWindowLw(win, win.mAttrs);
        win.mHasSurface = true;
    }