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

Commit 9fe9e19d authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Automerger Merge Worker
Browse files

Merge "Only register listeners if setView was success." into sc-qpr1-dev am: f16f8630

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16091135

Change-Id: I74a7c0dc68c26310bb8dcbda1418fa5a1af5c7b5
parents ff384b67 f16f8630
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -800,11 +800,7 @@ public final class ViewRootImpl implements ViewParent,
                context);
        mCompatibleVisibilityInfo = new SystemUiVisibilityInfo();
        mAccessibilityManager = AccessibilityManager.getInstance(context);
        mAccessibilityManager.addAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager, mHandler);
        mHighContrastTextManager = new HighContrastTextManager();
        mAccessibilityManager.addHighTextContrastStateChangeListener(
                mHighContrastTextManager, mHandler);
        mViewConfiguration = ViewConfiguration.get(context);
        mDensity = context.getResources().getDisplayMetrics().densityDpi;
        mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi;
@@ -1004,8 +1000,6 @@ public final class ViewRootImpl implements ViewParent,
                mView = view;

                mAttachInfo.mDisplayState = mDisplay.getState();
                mDisplayManager.registerDisplayListener(mDisplayListener, mHandler);

                mViewLayoutDirectionInitial = mView.getRawLayoutDirection();
                mFallbackEventHandler.setView(view);
                mWindowAttributes.copyFrom(attrs);
@@ -1198,6 +1192,7 @@ public final class ViewRootImpl implements ViewParent,
                            "Unable to add window -- unknown error code " + res);
                }

                registerListeners();
                if ((res & WindowManagerGlobal.ADD_FLAG_USE_BLAST) != 0) {
                    mUseBLASTAdapter = true;
                }
@@ -1254,6 +1249,28 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    /**
     * Register any kind of listeners if setView was success.
     */
    private void registerListeners() {
        mAccessibilityManager.addAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager, mHandler);
        mAccessibilityManager.addHighTextContrastStateChangeListener(
                mHighContrastTextManager, mHandler);
        mDisplayManager.registerDisplayListener(mDisplayListener, mHandler);
    }

    /**
     * Unregister all listeners while detachedFromWindow.
     */
    private void unregisterListeners() {
        mAccessibilityManager.removeAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager);
        mAccessibilityManager.removeHighTextContrastStateChangeListener(
                mHighContrastTextManager);
        mDisplayManager.unregisterDisplayListener(mDisplayListener);
    }

    private void setTag() {
        final String[] split = mWindowAttributes.getTitle().toString().split("\\.");
        if (split.length > 0) {
@@ -4979,10 +4996,6 @@ public final class ViewRootImpl implements ViewParent,
        }

        mAccessibilityInteractionConnectionManager.ensureNoConnection();
        mAccessibilityManager.removeAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager);
        mAccessibilityManager.removeHighTextContrastStateChangeListener(
                mHighContrastTextManager);
        removeSendWindowContentChangedCallback();

        destroyHardwareRenderer();
@@ -5015,8 +5028,7 @@ public final class ViewRootImpl implements ViewParent,
            mInputEventReceiver = null;
        }

        mDisplayManager.unregisterDisplayListener(mDisplayListener);

        unregisterListeners();
        unscheduleTraversals();
    }