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

Commit dcee1dea authored by Chong Zhang's avatar Chong Zhang
Browse files

Make window callbacks non static member of ViewRootImpl

Move add/removeWindowCallbacks to onAttachedToWindow/onDetachedFromWindow.

There might be more than one windows in an app process, the window
callbacks need to be per window, not global.

bug: 24679461
Change-Id: I216ff27b2a41ecfe7399a8161df362bebc0ac96a
parent 3e832afe
Loading
Loading
Loading
Loading
+24 −22
Original line number Diff line number Diff line
@@ -141,10 +141,10 @@ public final class ViewRootImpl implements ViewParent,

    static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList();
    static boolean sFirstDrawComplete = false;
    static final ArrayList<WindowCallbacks> sWindowCallbacks = new ArrayList();

    static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList();

    final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList();
    final Context mContext;
    final IWindowSession mWindowSession;
    final Display mDisplay;
@@ -424,18 +424,18 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    public static void addWindowCallbacks(WindowCallbacks callback) {
    public void addWindowCallbacks(WindowCallbacks callback) {
        if (USE_MT_RENDERER) {
            synchronized (sWindowCallbacks) {
                sWindowCallbacks.add(callback);
            synchronized (mWindowCallbacks) {
                mWindowCallbacks.add(callback);
            }
        }
    }

    public static void removeWindowCallbacks(WindowCallbacks callback) {
    public void removeWindowCallbacks(WindowCallbacks callback) {
        if (USE_MT_RENDERER) {
            synchronized (sWindowCallbacks) {
                sWindowCallbacks.remove(callback);
            synchronized (mWindowCallbacks) {
                mWindowCallbacks.remove(callback);
            }
        }
    }
@@ -5653,6 +5653,17 @@ public final class ViewRootImpl implements ViewParent,
                + " contentInsets=" + contentInsets.toShortString()
                + " visibleInsets=" + visibleInsets.toShortString()
                + " reportDraw=" + reportDraw);

        // Tell all listeners that we are resizing the window so that the chrome can get
        // updated as fast as possible on a separate thread,
        if (mDragResizing) {
            synchronized (mWindowCallbacks) {
                for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) {
                    mWindowCallbacks.get(i).onWindowSizeIsChanging(frame);
                }
            }
        }

        Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED);
        if (mTranslator != null) {
            mTranslator.translateRectInScreenToAppWindow(frame);
@@ -6665,15 +6676,6 @@ public final class ViewRootImpl implements ViewParent,
                Configuration newConfig) {
            final ViewRootImpl viewAncestor = mViewAncestor.get();
            if (viewAncestor != null) {
                // Tell all listeners that we are resizing the window so that the chrome can get
                // updated as fast as possible on a separate thread,
                if (mViewAncestor.get().mDragResizing) {
                    synchronized (sWindowCallbacks) {
                        for (int i = sWindowCallbacks.size() - 1; i >= 0; i--) {
                            sWindowCallbacks.get(i).onWindowSizeIsChanging(frame);
                        }
                    }
                }
                viewAncestor.dispatchResized(frame, overscanInsets, contentInsets,
                        visibleInsets, stableInsets, outsets, reportDraw, newConfig);
            }
@@ -6848,9 +6850,9 @@ public final class ViewRootImpl implements ViewParent,
    private void startDragResizing(Rect initialBounds) {
        if (!mDragResizing) {
            mDragResizing = true;
            synchronized (sWindowCallbacks) {
                for (int i = sWindowCallbacks.size() - 1; i >= 0; i--) {
                    sWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds);
            synchronized (mWindowCallbacks) {
                for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) {
                    mWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds);
                }
            }
            mFullRedrawNeeded = true;
@@ -6863,9 +6865,9 @@ public final class ViewRootImpl implements ViewParent,
    private void endDragResizing() {
        if (mDragResizing) {
            mDragResizing = false;
            synchronized (sWindowCallbacks) {
                for (int i = sWindowCallbacks.size() - 1; i >= 0; i--) {
                    sWindowCallbacks.get(i).onWindowDragResizeEnd();
            synchronized (mWindowCallbacks) {
                for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) {
                    mWindowCallbacks.get(i).onWindowDragResizeEnd();
                }
            }
            mFullRedrawNeeded = true;
+24 −15
Original line number Diff line number Diff line
@@ -110,6 +110,30 @@ public class NonClientDecorView extends LinearLayout
        super(context, attrs, defStyle);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (!mAttachedCallbacksToRootViewImpl) {
            // If there is no window callback installed there was no window set before. Set it now.
            // Note that our ViewRootImpl object will not change.
            getViewRootImpl().addWindowCallbacks(this);
            mAttachedCallbacksToRootViewImpl = true;
        } else if (mFrameRendererThread != null) {
            // We are resizing and this call happened due to a configuration change. Tell the
            // renderer about it.
            mFrameRendererThread.onConfigurationChange();
        }
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (mAttachedCallbacksToRootViewImpl) {
            getViewRootImpl().removeWindowCallbacks(this);
            mAttachedCallbacksToRootViewImpl = false;
        }
    }

    public void setPhoneWindow(PhoneWindow owner, boolean showDecor, boolean windowHasShadow) {
        mOwner = owner;
        mWindowHasShadow = windowHasShadow;
@@ -122,17 +146,6 @@ public class NonClientDecorView extends LinearLayout
        // background without removing the shadow.
        mOwner.getDecorView().setOutlineProvider(ViewOutlineProvider.BOUNDS);

        if (!mAttachedCallbacksToRootViewImpl) {
            // If there is no window callback installed there was no window set before. Set it now.
            // Note that our ViewRootImpl object will not change.
            getViewRootImpl().addWindowCallbacks(this);
            mAttachedCallbacksToRootViewImpl = true;
        } else if (mFrameRendererThread != null) {
            // We are resizing and this call happened due to a configuration change. Tell the
            // renderer about it.
            mFrameRendererThread.onConfigurationChange();
        }

        findViewById(R.id.maximize_window).setOnClickListener(this);
        findViewById(R.id.close_window).setOnClickListener(this);
    }
@@ -372,10 +385,6 @@ public class NonClientDecorView extends LinearLayout
     */
    private void releaseResources() {
        releaseThreadedRenderer();
        if (mAttachedCallbacksToRootViewImpl) {
            ViewRootImpl.removeWindowCallbacks(this);
            mAttachedCallbacksToRootViewImpl = false;
        }
    }

    /**