Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipAppOpsListener.kt 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.wm.shell.common.pip import android.app.AppOpsManager import android.content.Context import android.content.pm.PackageManager import com.android.wm.shell.common.ShellExecutor import com.android.wm.shell.pip.PipUtils class PipAppOpsListener( private val mContext: Context, private val mCallback: Callback, private val mMainExecutor: ShellExecutor ) { private val mAppOpsManager: AppOpsManager = checkNotNull( mContext.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager) private val mAppOpsChangedListener = AppOpsManager.OnOpChangedListener { _, packageName -> try { // Dismiss the PiP once the user disables the app ops setting for that package val topPipActivityInfo = PipUtils.getTopPipActivity(mContext) val componentName = topPipActivityInfo.first ?: return@OnOpChangedListener val userId = topPipActivityInfo.second val appInfo = mContext.packageManager .getApplicationInfoAsUser(packageName, 0, userId) if (appInfo.packageName == componentName.packageName && mAppOpsManager.checkOpNoThrow( AppOpsManager.OP_PICTURE_IN_PICTURE, appInfo.uid, packageName ) != AppOpsManager.MODE_ALLOWED ) { mMainExecutor.execute { mCallback.dismissPip() } } } catch (e: PackageManager.NameNotFoundException) { // Unregister the listener if the package can't be found unregisterAppOpsListener() } } fun onActivityPinned(packageName: String) { // Register for changes to the app ops setting for this package while it is in PiP registerAppOpsListener(packageName) } fun onActivityUnpinned() { // Unregister for changes to the previously PiP'ed package unregisterAppOpsListener() } private fun registerAppOpsListener(packageName: String) { mAppOpsManager.startWatchingMode( AppOpsManager.OP_PICTURE_IN_PICTURE, packageName, mAppOpsChangedListener ) } private fun unregisterAppOpsListener() { mAppOpsManager.stopWatchingMode(mAppOpsChangedListener) } /** Callback for PipAppOpsListener to request changes to the PIP window. */ interface Callback { /** Dismisses the PIP window. */ fun dismissPip() } } No newline at end of file libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +7 −2 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.LaunchAdjacentController; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; Loading Loading @@ -73,7 +74,6 @@ import com.android.wm.shell.keyguard.KeyguardTransitionHandler; import com.android.wm.shell.keyguard.KeyguardTransitions; import com.android.wm.shell.onehanded.OneHanded; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.recents.RecentTasks; import com.android.wm.shell.recents.RecentTasksController; import com.android.wm.shell.recents.RecentsTransitionHandler; Loading Loading @@ -120,6 +120,12 @@ public abstract class WMShellBaseModule { // Internal common - Components used internally by multiple shell features // @WMSingleton @Provides static FloatingContentCoordinator provideFloatingContentCoordinator() { return new FloatingContentCoordinator(); } @WMSingleton @Provides static DisplayController provideDisplayController(Context context, Loading Loading @@ -797,7 +803,6 @@ public abstract class WMShellBaseModule { ShellTaskOrganizer shellTaskOrganizer, Optional<BubbleController> bubblesOptional, Optional<SplitScreenController> splitScreenOptional, Optional<Pip> pipOptional, FullscreenTaskListener fullscreenTaskListener, Optional<UnfoldAnimationController> unfoldAnimationController, Optional<UnfoldTransitionHandler> unfoldTransitionHandler, Loading libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1Module.java +1 −1 Original line number Diff line number Diff line Loading @@ -31,13 +31,13 @@ import com.android.wm.shell.common.TabletopModeController; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; import com.android.wm.shell.common.pip.PipAppOpsListener; import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.dagger.WMShellBaseModule; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; import com.android.wm.shell.pip.PipAppOpsListener; import com.android.wm.shell.pip.PipBoundsAlgorithm; import com.android.wm.shell.pip.PipBoundsState; import com.android.wm.shell.pip.PipDisplayLayoutState; Loading libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1SharedModule.java +0 −7 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.pm.PackageManager; import android.os.Handler; import com.android.internal.logging.UiEventLogger; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip.PipMediaController; Loading @@ -37,12 +36,6 @@ import dagger.Provides; */ @Module public abstract class Pip1SharedModule { @WMSingleton @Provides static FloatingContentCoordinator provideFloatingContentCoordinator() { return new FloatingContentCoordinator(); } // Needs handler for registering broadcast receivers @WMSingleton @Provides Loading libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/TvPipModule.java +1 −1 Original line number Diff line number Diff line Loading @@ -29,12 +29,12 @@ import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.pip.LegacySizeSpecSource; import com.android.wm.shell.common.pip.PipAppOpsListener; import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.dagger.WMShellBaseModule; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; import com.android.wm.shell.pip.PipAppOpsListener; import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipMediaController; import com.android.wm.shell.pip.PipParamsChangedForwarder; Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipAppOpsListener.kt 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.wm.shell.common.pip import android.app.AppOpsManager import android.content.Context import android.content.pm.PackageManager import com.android.wm.shell.common.ShellExecutor import com.android.wm.shell.pip.PipUtils class PipAppOpsListener( private val mContext: Context, private val mCallback: Callback, private val mMainExecutor: ShellExecutor ) { private val mAppOpsManager: AppOpsManager = checkNotNull( mContext.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager) private val mAppOpsChangedListener = AppOpsManager.OnOpChangedListener { _, packageName -> try { // Dismiss the PiP once the user disables the app ops setting for that package val topPipActivityInfo = PipUtils.getTopPipActivity(mContext) val componentName = topPipActivityInfo.first ?: return@OnOpChangedListener val userId = topPipActivityInfo.second val appInfo = mContext.packageManager .getApplicationInfoAsUser(packageName, 0, userId) if (appInfo.packageName == componentName.packageName && mAppOpsManager.checkOpNoThrow( AppOpsManager.OP_PICTURE_IN_PICTURE, appInfo.uid, packageName ) != AppOpsManager.MODE_ALLOWED ) { mMainExecutor.execute { mCallback.dismissPip() } } } catch (e: PackageManager.NameNotFoundException) { // Unregister the listener if the package can't be found unregisterAppOpsListener() } } fun onActivityPinned(packageName: String) { // Register for changes to the app ops setting for this package while it is in PiP registerAppOpsListener(packageName) } fun onActivityUnpinned() { // Unregister for changes to the previously PiP'ed package unregisterAppOpsListener() } private fun registerAppOpsListener(packageName: String) { mAppOpsManager.startWatchingMode( AppOpsManager.OP_PICTURE_IN_PICTURE, packageName, mAppOpsChangedListener ) } private fun unregisterAppOpsListener() { mAppOpsManager.stopWatchingMode(mAppOpsChangedListener) } /** Callback for PipAppOpsListener to request changes to the PIP window. */ interface Callback { /** Dismisses the PIP window. */ fun dismissPip() } } No newline at end of file
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +7 −2 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.wm.shell.common.DisplayImeController; import com.android.wm.shell.common.DisplayInsetsController; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.DockStateReader; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.LaunchAdjacentController; import com.android.wm.shell.common.ShellExecutor; import com.android.wm.shell.common.SyncTransactionQueue; Loading Loading @@ -73,7 +74,6 @@ import com.android.wm.shell.keyguard.KeyguardTransitionHandler; import com.android.wm.shell.keyguard.KeyguardTransitions; import com.android.wm.shell.onehanded.OneHanded; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.recents.RecentTasks; import com.android.wm.shell.recents.RecentTasksController; import com.android.wm.shell.recents.RecentsTransitionHandler; Loading Loading @@ -120,6 +120,12 @@ public abstract class WMShellBaseModule { // Internal common - Components used internally by multiple shell features // @WMSingleton @Provides static FloatingContentCoordinator provideFloatingContentCoordinator() { return new FloatingContentCoordinator(); } @WMSingleton @Provides static DisplayController provideDisplayController(Context context, Loading Loading @@ -797,7 +803,6 @@ public abstract class WMShellBaseModule { ShellTaskOrganizer shellTaskOrganizer, Optional<BubbleController> bubblesOptional, Optional<SplitScreenController> splitScreenOptional, Optional<Pip> pipOptional, FullscreenTaskListener fullscreenTaskListener, Optional<UnfoldAnimationController> unfoldAnimationController, Optional<UnfoldTransitionHandler> unfoldTransitionHandler, Loading
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1Module.java +1 −1 Original line number Diff line number Diff line Loading @@ -31,13 +31,13 @@ import com.android.wm.shell.common.TabletopModeController; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.pip.PhoneSizeSpecSource; import com.android.wm.shell.common.pip.PipAppOpsListener; import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.dagger.WMShellBaseModule; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; import com.android.wm.shell.pip.PipAppOpsListener; import com.android.wm.shell.pip.PipBoundsAlgorithm; import com.android.wm.shell.pip.PipBoundsState; import com.android.wm.shell.pip.PipDisplayLayoutState; Loading
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/Pip1SharedModule.java +0 −7 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.pm.PackageManager; import android.os.Handler; import com.android.internal.logging.UiEventLogger; import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip.PipMediaController; Loading @@ -37,12 +36,6 @@ import dagger.Provides; */ @Module public abstract class Pip1SharedModule { @WMSingleton @Provides static FloatingContentCoordinator provideFloatingContentCoordinator() { return new FloatingContentCoordinator(); } // Needs handler for registering broadcast receivers @WMSingleton @Provides Loading
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/pip/TvPipModule.java +1 −1 Original line number Diff line number Diff line Loading @@ -29,12 +29,12 @@ import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TaskStackListenerImpl; import com.android.wm.shell.common.annotations.ShellMainThread; import com.android.wm.shell.common.pip.LegacySizeSpecSource; import com.android.wm.shell.common.pip.PipAppOpsListener; import com.android.wm.shell.common.pip.SizeSpecSource; import com.android.wm.shell.dagger.WMShellBaseModule; import com.android.wm.shell.dagger.WMSingleton; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipAnimationController; import com.android.wm.shell.pip.PipAppOpsListener; import com.android.wm.shell.pip.PipDisplayLayoutState; import com.android.wm.shell.pip.PipMediaController; import com.android.wm.shell.pip.PipParamsChangedForwarder; Loading