Merge "Dismiss the PiP if user changes setting while PiP is open." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
477b1b0361
@@ -172,7 +172,8 @@ public class PipManager implements BasePipManager {
|
|||||||
mInputConsumerController);
|
mInputConsumerController);
|
||||||
mTouchHandler = new PipTouchHandler(context, mActivityManager, mMenuController,
|
mTouchHandler = new PipTouchHandler(context, mActivityManager, mMenuController,
|
||||||
mInputConsumerController);
|
mInputConsumerController);
|
||||||
mNotificationController = new PipNotificationController(context, mActivityManager);
|
mNotificationController = new PipNotificationController(context, mActivityManager,
|
||||||
|
mTouchHandler.getMotionHelper());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,11 +16,15 @@
|
|||||||
|
|
||||||
package com.android.systemui.pip.phone;
|
package com.android.systemui.pip.phone;
|
||||||
|
|
||||||
|
import static android.app.AppOpsManager.MODE_ALLOWED;
|
||||||
|
import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE;
|
||||||
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
|
import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
import static android.provider.Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS;
|
import static android.provider.Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS;
|
||||||
|
|
||||||
|
import android.app.AppOpsManager;
|
||||||
|
import android.app.AppOpsManager.OnOpChangedListener;
|
||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
@@ -51,12 +55,36 @@ public class PipNotificationController {
|
|||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private IActivityManager mActivityManager;
|
private IActivityManager mActivityManager;
|
||||||
|
private AppOpsManager mAppOpsManager;
|
||||||
private NotificationManager mNotificationManager;
|
private NotificationManager mNotificationManager;
|
||||||
|
|
||||||
public PipNotificationController(Context context, IActivityManager activityManager) {
|
private PipMotionHelper mMotionHelper;
|
||||||
|
|
||||||
|
private AppOpsManager.OnOpChangedListener mAppOpsChangedListener = new OnOpChangedListener() {
|
||||||
|
@Override
|
||||||
|
public void onOpChanged(String op, String packageName) {
|
||||||
|
try {
|
||||||
|
// Dismiss the PiP once the user disables the app ops setting for that package
|
||||||
|
final ApplicationInfo appInfo = mContext.getPackageManager().getApplicationInfo(
|
||||||
|
packageName, 0);
|
||||||
|
if (mAppOpsManager.checkOpNoThrow(OP_PICTURE_IN_PICTURE, appInfo.uid, packageName)
|
||||||
|
!= MODE_ALLOWED) {
|
||||||
|
mMotionHelper.dismissPip();
|
||||||
|
}
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
// Unregister the listener if the package can't be found
|
||||||
|
unregisterAppOpsListener();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public PipNotificationController(Context context, IActivityManager activityManager,
|
||||||
|
PipMotionHelper motionHelper) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mActivityManager = activityManager;
|
mActivityManager = activityManager;
|
||||||
|
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||||
mNotificationManager = NotificationManager.from(context);
|
mNotificationManager = NotificationManager.from(context);
|
||||||
|
mMotionHelper = motionHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onActivityPinned(String packageName) {
|
public void onActivityPinned(String packageName) {
|
||||||
@@ -77,9 +105,15 @@ public class PipNotificationController {
|
|||||||
// Show the new notification
|
// Show the new notification
|
||||||
mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build());
|
mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register for changes to the app ops setting for this package while it is in PiP
|
||||||
|
registerAppOpsListener(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onActivityUnpinned() {
|
public void onActivityUnpinned() {
|
||||||
|
// Unregister for changes to the previously PiP'ed package
|
||||||
|
unregisterAppOpsListener();
|
||||||
|
|
||||||
ComponentName topPipActivity = PipUtils.getTopPinnedActivity(mContext, mActivityManager);
|
ComponentName topPipActivity = PipUtils.getTopPinnedActivity(mContext, mActivityManager);
|
||||||
if (topPipActivity != null) {
|
if (topPipActivity != null) {
|
||||||
onActivityPinned(topPipActivity.getPackageName());
|
onActivityPinned(topPipActivity.getPackageName());
|
||||||
@@ -123,4 +157,13 @@ public class PipNotificationController {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerAppOpsListener(String packageName) {
|
||||||
|
mAppOpsManager.startWatchingMode(OP_PICTURE_IN_PICTURE, packageName,
|
||||||
|
mAppOpsChangedListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterAppOpsListener() {
|
||||||
|
mAppOpsManager.stopWatchingMode(mAppOpsChangedListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user