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

Commit dc31a023 authored by Charles Chen's avatar Charles Chen
Browse files

Hold lock when checking window type

Test: presubmit
Fixes: 413433638
Flag: EXEMPT bugfix
Change-Id: I7c6b8db703280795d2456ff0b4e12c8e3bbe60ed
parent 0c493654
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -153,23 +153,31 @@ public final class WindowManagerGlobal {
    private final Object mLock = new Object();

    @UnsupportedAppUsage
    @GuardedBy("mLock")
    private final ArrayList<View> mViews = new ArrayList<View>();
    /**
     * The {@link ListenerGroup} that is associated to {@link #mViews}.
     * @hide
     */
    @GuardedBy("mLock")
    private final ListenerGroup<List<View>> mWindowViewsListenerGroup =
            new ListenerGroup<>(new ArrayList<>(), new Handler(Looper.getMainLooper()));
    @UnsupportedAppUsage
    @GuardedBy("mLock")
    private final ArrayList<ViewRootImpl> mRoots = new ArrayList<ViewRootImpl>();
    @UnsupportedAppUsage
    @GuardedBy("mLock")
    private final ArrayList<WindowManager.LayoutParams> mParams =
            new ArrayList<WindowManager.LayoutParams>();

    @GuardedBy("mLock")
    private final ArraySet<View> mDyingViews = new ArraySet<View>();

    @GuardedBy("mLock")
    private final ArrayList<ViewRootImpl> mWindowlessRoots = new ArrayList<ViewRootImpl>();

    /** A context token only has one remote registration to system. */
    @GuardedBy("mLock")
    private WeakHashMap<IBinder, ProposedRotationListenerDelegate> mProposedRotationListenerMap;

    private Runnable mSystemPropertyUpdater;
@@ -1130,17 +1138,19 @@ public final class WindowManagerGlobal {
    public boolean canApplyWindowTypeOverride(
            @WindowManager.LayoutParams.WindowType int windowTypeToOverride,
            @NonNull View view) {
        synchronized (mLock) {
            final int index = findViewLocked(view, false /* required */);
            if (index < 0) {
                // The view has not been added yet. Window type can be overridden.
                return true;
            }
            final WindowManager.LayoutParams params = mParams.get(index);
        // If the view has been attached, we should make sure the override type matches the existing
        // one. The window type can't be changed after the view was added.
            // If the view has been attached, we should make sure the override type matches the
            // existing one. The window type can't be changed after the view was added.
            return windowTypeToOverride == params.type;
        }
    }
}

final class WindowLeaked extends AndroidRuntimeException {
    @UnsupportedAppUsage