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

Commit 503f651c authored by Jaewan Kim's avatar Jaewan Kim Committed by The Android Automerger
Browse files

Fix crash when device doesn't support picture-in-picture

Bug: 28512987
Change-Id: Ic8287d70fed491d7493d443ba7d9633b7d9aaea9
parent b7b94c76
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -2974,6 +2974,18 @@ public class Activity extends ContextThemeWrapper
        return ActivityManagerNative.getDefault().getActivityStackId(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.resizeMode == ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE) {
            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
+6 −12
Original line number Diff line number Diff line
@@ -593,6 +593,12 @@ public abstract class Window {
         */
        void exitFreeformMode() throws RemoteException;

        /**
         * Puts the activity in picture-in-picture mode if the activity supports.
         * @see android.R.attr#supportsPictureInPicture
         */
        void enterPictureInPictureModeIfPossible();

        /** Returns the current stack Id for the window. */
        int getWindowStackId() throws RemoteException;
    }
@@ -1256,18 +1262,6 @@ public abstract class Window {
        return getDecorView().findViewById(id);
    }

    /**
     * Puts the activity in picture-in-picture mode.
     * @see android.R.attr#supportsPictureInPicture
     * @hide
     */
    protected void enterPictureInPictureMode() {
        try {
            ActivityManagerNative.getDefault().enterPictureInPictureMode(mAppToken);
        } catch (IllegalArgumentException|RemoteException e) {
        }
    }

    /**
     * Convenience for
     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
+14 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.policy;

import static android.provider.Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.WindowManager.LayoutParams.*;
@@ -80,6 +81,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.transition.Scene;
import android.transition.Transition;
import android.transition.TransitionInflater;
@@ -204,6 +206,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
     */
    int mPanelChordingKey;

    // This stores if the system supports Picture-in-Picture
    // to see if KEYCODE_WINDOW should be handled here or not.
    private boolean mSupportsPictureInPicture;

    private ImageView mLeftIconView;

    private ImageView mRightIconView;
@@ -313,6 +319,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            // the token will not be updated as for a new window.
            getAttributes().token = preservedWindow.getAttributes().token;
        }
        // Even though the device doesn't support picture-in-picture mode,
        // an user can force using it through developer options.
        boolean forceResizable = Settings.Global.getInt(context.getContentResolver(),
                DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0;
        mSupportsPictureInPicture = forceResizable || context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_PICTURE_IN_PICTURE);
    }

    @Override
@@ -2004,8 +2016,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            }

            case KeyEvent.KEYCODE_WINDOW: {
                if (!event.isCanceled()) {
                    enterPictureInPictureMode();
                if (mSupportsPictureInPicture && !event.isCanceled()) {
                    getWindowControllerCallback().enterPictureInPictureModeIfPossible();
                }
                return true;
            }