Merge "Fix crash when device doesn\'t support picture-in-picture" into nyc-dev
am: bfa0f48407
* commit 'bfa0f48407e70099c2558983b19163c1d92d063b':
Fix crash when device doesn't support picture-in-picture
Change-Id: Icbbe69970e5f43387323b5ed810ebc11b1cf77b1
This commit is contained in:
@@ -2974,6 +2974,18 @@ public class Activity extends ContextThemeWrapper
|
|||||||
return ActivityManagerNative.getDefault().getActivityStackId(mToken);
|
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
|
* 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
|
* key events before they are dispatched to the window. Be sure to call
|
||||||
|
|||||||
@@ -593,6 +593,12 @@ public abstract class Window {
|
|||||||
*/
|
*/
|
||||||
void exitFreeformMode() throws RemoteException;
|
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. */
|
/** Returns the current stack Id for the window. */
|
||||||
int getWindowStackId() throws RemoteException;
|
int getWindowStackId() throws RemoteException;
|
||||||
}
|
}
|
||||||
@@ -1256,18 +1262,6 @@ public abstract class Window {
|
|||||||
return getDecorView().findViewById(id);
|
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
|
* Convenience for
|
||||||
* {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
|
* {@link #setContentView(View, android.view.ViewGroup.LayoutParams)}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.internal.policy;
|
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.MATCH_PARENT;
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
import static android.view.WindowManager.LayoutParams.*;
|
import static android.view.WindowManager.LayoutParams.*;
|
||||||
@@ -80,6 +81,7 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.transition.Scene;
|
import android.transition.Scene;
|
||||||
import android.transition.Transition;
|
import android.transition.Transition;
|
||||||
import android.transition.TransitionInflater;
|
import android.transition.TransitionInflater;
|
||||||
@@ -204,6 +206,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
*/
|
*/
|
||||||
int mPanelChordingKey;
|
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 mLeftIconView;
|
||||||
|
|
||||||
private ImageView mRightIconView;
|
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.
|
// the token will not be updated as for a new window.
|
||||||
getAttributes().token = preservedWindow.getAttributes().token;
|
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
|
@Override
|
||||||
@@ -2004,8 +2016,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case KeyEvent.KEYCODE_WINDOW: {
|
case KeyEvent.KEYCODE_WINDOW: {
|
||||||
if (!event.isCanceled()) {
|
if (mSupportsPictureInPicture && !event.isCanceled()) {
|
||||||
enterPictureInPictureMode();
|
getWindowControllerCallback().enterPictureInPictureModeIfPossible();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user