Loading packages/SystemUI/src/com/android/systemui/pip/phone/PipAppOpsListener.java 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.pip.phone; import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE; import android.app.AppOpsManager; import android.app.AppOpsManager.OnOpChangedListener; import android.app.IActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.util.Pair; public class PipAppOpsListener { private static final String TAG = PipAppOpsListener.class.getSimpleName(); private Context mContext; private IActivityManager mActivityManager; private AppOpsManager mAppOpsManager; 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 Pair<ComponentName, Integer> topPipActivityInfo = PipUtils.getTopPinnedActivity(mContext, mActivityManager); if (topPipActivityInfo.first != null) { final ApplicationInfo appInfo = mContext.getPackageManager() .getApplicationInfoAsUser(packageName, 0, topPipActivityInfo.second); if (appInfo.packageName.equals(topPipActivityInfo.first.getPackageName()) && 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 PipAppOpsListener(Context context, IActivityManager activityManager, PipMotionHelper motionHelper) { mContext = context; mActivityManager = activityManager; mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); mMotionHelper = motionHelper; } public void onActivityPinned(String packageName) { // Register for changes to the app ops setting for this package while it is in PiP registerAppOpsListener(packageName); } public void onActivityUnpinned() { // Unregister for changes to the previously PiP'ed package unregisterAppOpsListener(); } private void registerAppOpsListener(String packageName) { mAppOpsManager.startWatchingMode(OP_PICTURE_IN_PICTURE, packageName, mAppOpsChangedListener); } private void unregisterAppOpsListener() { mAppOpsManager.stopWatchingMode(mAppOpsChangedListener); } } No newline at end of file packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ public class PipManager implements BasePipManager { private PipMenuActivityController mMenuController; private PipMediaController mMediaController; private PipTouchHandler mTouchHandler; private PipAppOpsListener mAppOpsListener; /** * Handler for system task stack changes. Loading @@ -75,6 +76,7 @@ public class PipManager implements BasePipManager { mTouchHandler.onActivityPinned(); mMediaController.onActivityPinned(); mMenuController.onActivityPinned(); mAppOpsListener.onActivityPinned(packageName); SystemServicesProxy.getInstance(mContext).setPipVisibility(true); } Loading @@ -87,6 +89,7 @@ public class PipManager implements BasePipManager { final int userId = topActivity != null ? topPipActivityInfo.second : 0; mMenuController.onActivityUnpinned(); mTouchHandler.onActivityUnpinned(topActivity); mAppOpsListener.onActivityUnpinned(); SystemServicesProxy.getInstance(mContext).setPipVisibility(topActivity != null); } Loading Loading @@ -177,6 +180,8 @@ public class PipManager implements BasePipManager { mInputConsumerController); mTouchHandler = new PipTouchHandler(context, mActivityManager, mMenuController, mInputConsumerController); mAppOpsListener = new PipAppOpsListener(context, mActivityManager, mTouchHandler.getMotionHelper()); EventBus.getDefault().register(this); } Loading Loading
packages/SystemUI/src/com/android/systemui/pip/phone/PipAppOpsListener.java 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.pip.phone; import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.OP_PICTURE_IN_PICTURE; import android.app.AppOpsManager; import android.app.AppOpsManager.OnOpChangedListener; import android.app.IActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.util.Pair; public class PipAppOpsListener { private static final String TAG = PipAppOpsListener.class.getSimpleName(); private Context mContext; private IActivityManager mActivityManager; private AppOpsManager mAppOpsManager; 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 Pair<ComponentName, Integer> topPipActivityInfo = PipUtils.getTopPinnedActivity(mContext, mActivityManager); if (topPipActivityInfo.first != null) { final ApplicationInfo appInfo = mContext.getPackageManager() .getApplicationInfoAsUser(packageName, 0, topPipActivityInfo.second); if (appInfo.packageName.equals(topPipActivityInfo.first.getPackageName()) && 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 PipAppOpsListener(Context context, IActivityManager activityManager, PipMotionHelper motionHelper) { mContext = context; mActivityManager = activityManager; mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); mMotionHelper = motionHelper; } public void onActivityPinned(String packageName) { // Register for changes to the app ops setting for this package while it is in PiP registerAppOpsListener(packageName); } public void onActivityUnpinned() { // Unregister for changes to the previously PiP'ed package unregisterAppOpsListener(); } private void registerAppOpsListener(String packageName) { mAppOpsManager.startWatchingMode(OP_PICTURE_IN_PICTURE, packageName, mAppOpsChangedListener); } private void unregisterAppOpsListener() { mAppOpsManager.stopWatchingMode(mAppOpsChangedListener); } } No newline at end of file
packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ public class PipManager implements BasePipManager { private PipMenuActivityController mMenuController; private PipMediaController mMediaController; private PipTouchHandler mTouchHandler; private PipAppOpsListener mAppOpsListener; /** * Handler for system task stack changes. Loading @@ -75,6 +76,7 @@ public class PipManager implements BasePipManager { mTouchHandler.onActivityPinned(); mMediaController.onActivityPinned(); mMenuController.onActivityPinned(); mAppOpsListener.onActivityPinned(packageName); SystemServicesProxy.getInstance(mContext).setPipVisibility(true); } Loading @@ -87,6 +89,7 @@ public class PipManager implements BasePipManager { final int userId = topActivity != null ? topPipActivityInfo.second : 0; mMenuController.onActivityUnpinned(); mTouchHandler.onActivityUnpinned(topActivity); mAppOpsListener.onActivityUnpinned(); SystemServicesProxy.getInstance(mContext).setPipVisibility(topActivity != null); } Loading Loading @@ -177,6 +180,8 @@ public class PipManager implements BasePipManager { mInputConsumerController); mTouchHandler = new PipTouchHandler(context, mActivityManager, mMenuController, mInputConsumerController); mAppOpsListener = new PipAppOpsListener(context, mActivityManager, mTouchHandler.getMotionHelper()); EventBus.getDefault().register(this); } Loading