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

Commit 5f986095 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

APIs for activity to know when its windowing/pip modes change

Added APIs that allow activities to ask the system if they are currently
in multi-window or picture-in-picture mode and also get notified when
their modes change.

Bug: 25509834
Bug: 25683717
Change-Id: I4b8c316a49940bd6a8b31a93b345f9fd725a4721
parent c72b3101
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3411,6 +3411,8 @@ package android.app {
    method public android.view.Window getWindow();
    method public android.view.WindowManager getWindowManager();
    method public boolean hasWindowFocus();
    method public boolean inMultiWindowMode();
    method public boolean inPictureInPictureMode();
    method public void invalidateOptionsMenu();
    method public boolean isChangingConfigurations();
    method public final boolean isChild();
@@ -3461,6 +3463,7 @@ package android.app {
    method public void onLowMemory();
    method public boolean onMenuItemSelected(int, android.view.MenuItem);
    method public boolean onMenuOpened(int, android.view.Menu);
    method public void onMultiWindowModeChanged(boolean);
    method public boolean onNavigateUp();
    method public boolean onNavigateUpFromChild(android.app.Activity);
    method protected void onNewIntent(android.content.Intent);
@@ -3468,6 +3471,7 @@ package android.app {
    method public void onOptionsMenuClosed(android.view.Menu);
    method public void onPanelClosed(int, android.view.Menu);
    method protected void onPause();
    method public void onPictureInPictureModeChanged(boolean);
    method protected void onPostCreate(android.os.Bundle);
    method public void onPostCreate(android.os.Bundle, android.os.PersistableBundle);
    method protected void onPostResume();
+4 −0
Original line number Diff line number Diff line
@@ -3514,6 +3514,8 @@ package android.app {
    method public android.view.Window getWindow();
    method public android.view.WindowManager getWindowManager();
    method public boolean hasWindowFocus();
    method public boolean inMultiWindowMode();
    method public boolean inPictureInPictureMode();
    method public void invalidateOptionsMenu();
    method public boolean isBackgroundVisibleBehind();
    method public boolean isChangingConfigurations();
@@ -3566,6 +3568,7 @@ package android.app {
    method public void onLowMemory();
    method public boolean onMenuItemSelected(int, android.view.MenuItem);
    method public boolean onMenuOpened(int, android.view.Menu);
    method public void onMultiWindowModeChanged(boolean);
    method public boolean onNavigateUp();
    method public boolean onNavigateUpFromChild(android.app.Activity);
    method protected void onNewIntent(android.content.Intent);
@@ -3573,6 +3576,7 @@ package android.app {
    method public void onOptionsMenuClosed(android.view.Menu);
    method public void onPanelClosed(int, android.view.Menu);
    method protected void onPause();
    method public void onPictureInPictureModeChanged(boolean);
    method protected void onPostCreate(android.os.Bundle);
    method public void onPostCreate(android.os.Bundle, android.os.PersistableBundle);
    method protected void onPostResume();
+4 −0
Original line number Diff line number Diff line
@@ -3411,6 +3411,8 @@ package android.app {
    method public android.view.Window getWindow();
    method public android.view.WindowManager getWindowManager();
    method public boolean hasWindowFocus();
    method public boolean inMultiWindowMode();
    method public boolean inPictureInPictureMode();
    method public void invalidateOptionsMenu();
    method public boolean isChangingConfigurations();
    method public final boolean isChild();
@@ -3461,6 +3463,7 @@ package android.app {
    method public void onLowMemory();
    method public boolean onMenuItemSelected(int, android.view.MenuItem);
    method public boolean onMenuOpened(int, android.view.Menu);
    method public void onMultiWindowModeChanged(boolean);
    method public boolean onNavigateUp();
    method public boolean onNavigateUpFromChild(android.app.Activity);
    method protected void onNewIntent(android.content.Intent);
@@ -3468,6 +3471,7 @@ package android.app {
    method public void onOptionsMenuClosed(android.view.Menu);
    method public void onPanelClosed(int, android.view.Menu);
    method protected void onPause();
    method public void onPictureInPictureModeChanged(boolean);
    method protected void onPostCreate(android.os.Bundle);
    method public void onPostCreate(android.os.Bundle, android.os.PersistableBundle);
    method protected void onPostResume();
+51 −0
Original line number Diff line number Diff line
@@ -1726,6 +1726,57 @@ public class Activity extends ContextThemeWrapper
        }
    }

    /**
     * Called by the system when the activity changes from fullscreen mode to multi-window mode and
     * visa-versa.
     * @see android.R.attr#resizeableActivity
     *
     * @param multiWindowMode True if the activity is in multi-window mode.
     */
    public void onMultiWindowModeChanged(boolean multiWindowMode) {
        if (DEBUG_LIFECYCLE) Slog.v(TAG,
                "onMultiWindowModeChanged " + this + ": " + multiWindowMode);
    }

    /**
     * Returns true if the activity is currently in multi-window mode.
     * @see android.R.attr#resizeableActivity
     *
     * @return True if the activity is in multi-window mode.
     */
    public boolean inMultiWindowMode() {
        try {
            return ActivityManagerNative.getDefault().inMultiWindowMode(mToken);
        } catch (RemoteException e) {
        }
        return false;
    }

    /**
     * Called by the system when the activity changes to and from picture-in-picture mode.
     * @see android.R.attr#supportsPictureInPicture
     *
     * @param pictureInPictureMode True if the activity is in picture-in-picture mode.
     */
    public void onPictureInPictureModeChanged(boolean pictureInPictureMode) {
        if (DEBUG_LIFECYCLE) Slog.v(TAG,
                "onPictureInPictureModeChanged " + this + ": " + pictureInPictureMode);
    }

    /**
     * Returns true if the activity is currently in picture-in-picture mode.
     * @see android.R.attr#supportsPictureInPicture
     *
     * @return True if the activity is in picture-in-picture mode.
     */
    public boolean inPictureInPictureMode() {
        try {
            return ActivityManagerNative.getDefault().inPictureInPictureMode(mToken);
        } catch (RemoteException e) {
        }
        return false;
    }

    /**
     * Called by the system when the device configuration changes while your
     * activity is running.  Note that this will <em>only</em> be called if
+44 −0
Original line number Diff line number Diff line
@@ -2733,6 +2733,22 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            reply.writeInt(res);
            return true;
        }
        case IN_MULTI_WINDOW_MODE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            final IBinder token = data.readStrongBinder();
            final boolean multiWindowMode = inMultiWindowMode(token);
            reply.writeNoException();
            reply.writeInt(multiWindowMode ? 1 : 0);
            return true;
        }
        case IN_PICTURE_IN_PICTURE_MODE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            final IBinder token = data.readStrongBinder();
            final boolean pipMode = inPictureInPictureMode(token);
            reply.writeNoException();
            reply.writeInt(pipMode ? 1 : 0);
            return true;
        }
        }

        return super.onTransact(code, data, reply, flags);
@@ -6366,5 +6382,33 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }

    @Override
    public boolean inMultiWindowMode(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(IN_MULTI_WINDOW_MODE_TRANSACTION, data, reply, 0);
        reply.readException();
        final boolean multiWindowMode = reply.readInt() == 1 ? true : false;
        data.recycle();
        reply.recycle();
        return multiWindowMode;
    }

    @Override
    public boolean inPictureInPictureMode(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(IN_PICTURE_IN_PICTURE_MODE_TRANSACTION, data, reply, 0);
        reply.readException();
        final boolean pipMode = reply.readInt() == 1 ? true : false;
        data.recycle();
        reply.recycle();
        return pipMode;
    }

    private IBinder mRemote;
}
Loading