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

Commit d6973860 authored by Mathew Inwood's avatar Mathew Inwood
Browse files

Move WindowControllerCallback methods into a delagate.

Adding @hide public methods to commonly subclassed classes like Activity
is never safe, as they can clash with existing methods in apps. Moving
@hide interface implementations into an inner class avoids the need to
add new @hide public methods in many cases.

Bug: 144361565
Test: Build, flash, boot device.
Change-Id: Ie8459c5a542e6ff4058d4ce783e27ebcf9c41dbb
parent 40067bbc
Loading
Loading
Loading
Loading
+59 −51
Original line number Diff line number Diff line
@@ -726,7 +726,7 @@ public class Activity extends ContextThemeWrapper
        implements LayoutInflater.Factory2,
        Window.Callback, KeyEvent.Callback,
        OnCreateContextMenuListener, ComponentCallbacks2,
        Window.OnWindowDismissedCallback, WindowControllerCallback,
        Window.OnWindowDismissedCallback,
        AutofillManager.AutofillClient, ContentCaptureManager.ContentCaptureClient {
    private static final String TAG = "Activity";
    private static final boolean DEBUG_LIFECYCLE = false;
@@ -938,6 +938,62 @@ public class Activity extends ContextThemeWrapper
    private Boolean mLastDispatchedIsInMultiWindowMode;
    private Boolean mLastDispatchedIsInPictureInPictureMode;

    private final WindowControllerCallback mWindowControllerCallback =
            new WindowControllerCallback() {
        /**
         * Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing
         * mode and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}.
         *
         * @hide
         */
        @Override
        public void toggleFreeformWindowingMode() throws RemoteException {
            ActivityTaskManager.getService().toggleFreeformWindowingMode(mToken);
        }

        /**
         * Puts the activity in picture-in-picture mode if the activity supports.
         * @see android.R.attr#supportsPictureInPicture
         * @hide
         */
        @Override
        public void enterPictureInPictureModeIfPossible() {
            if (mActivityInfo.supportsPictureInPicture()) {
                enterPictureInPictureMode();
            }
        }

        @Override
        public boolean isTaskRoot() {
            try {
                return ActivityTaskManager.getService().getTaskForActivity(mToken, true) >= 0;
            } catch (RemoteException e) {
                return false;
            }
        }

        /**
         * Update the forced status bar color.
         * @hide
         */
        @Override
        public void updateStatusBarColor(int color) {
            mTaskDescription.setStatusBarColor(color);
            setTaskDescription(mTaskDescription);
        }

        /**
         * Update the forced navigation bar color.
         * @hide
         */
        @Override
        public void updateNavigationBarColor(int color) {
            mTaskDescription.setNavigationBarColor(color);
            setTaskDescription(mTaskDescription);
        }

    };

    private static native String getDlWarning();

    /** Return the intent that started this activity. */
@@ -3914,49 +3970,6 @@ public class Activity extends ContextThemeWrapper
    }


    /**
     * Moves the activity between {@link WindowConfiguration#WINDOWING_MODE_FREEFORM} windowing mode
     * and {@link WindowConfiguration#WINDOWING_MODE_FULLSCREEN}.
     *
     * @hide
     */
    @Override
    public void toggleFreeformWindowingMode() throws RemoteException {
        ActivityTaskManager.getService().toggleFreeformWindowingMode(mToken);
    }

    /**
     * Update the forced status bar color.
     * @hide
     */
    @Override
    public void updateStatusBarColor(int color) {
        mTaskDescription.setStatusBarColor(color);
        setTaskDescription(mTaskDescription);
    }

    /**
     * Update the forced navigation bar color.
     * @hide
     */
    @Override
    public void updateNavigationBarColor(int color) {
        mTaskDescription.setNavigationBarColor(color);
        setTaskDescription(mTaskDescription);
    }

    /**
     * Puts the activity in picture-in-picture mode if the activity supports.
     * @see android.R.attr#supportsPictureInPicture
     * @hide
     */
    @Override
    public void enterPictureInPictureModeIfPossible() {
        if (mActivityInfo.supportsPictureInPicture()) {
            enterPictureInPictureMode();
        }
    }

    /**
     * Called to process key events.  You can override this to intercept all
     * key events before they are dispatched to the window.  Be sure to call
@@ -6603,13 +6616,8 @@ public class Activity extends ContextThemeWrapper
     *
     * @return True if this is the root activity, else false.
     */
    @Override
    public boolean isTaskRoot() {
        try {
            return ActivityTaskManager.getService().getTaskForActivity(mToken, true) >= 0;
        } catch (RemoteException e) {
            return false;
        }
        return mWindowControllerCallback.isTaskRoot();
    }

    /**
@@ -7801,7 +7809,7 @@ public class Activity extends ContextThemeWrapper
        mFragments.attachHost(null /*parent*/);

        mWindow = new PhoneWindow(this, window, activityConfigCallback);
        mWindow.setWindowControllerCallback(this);
        mWindow.setWindowControllerCallback(mWindowControllerCallback);
        mWindow.setCallback(this);
        mWindow.setOnWindowDismissedCallback(this);
        mWindow.getLayoutInflater().setPrivateFactory(this);