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

Commit 67a4cc7b authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Moving shared classes to common.pip package 1/N

- PipAppOpsListener is moved to common package and converted to Kotlin
- FloatingContentCoordinator exists in shell.common, move it away from
  Pip1SharedModule to WMShellBaseModule
- There is no need to reference pip.Pip, pip is referenced externally
  via PipTransitionController in DefaultMixedHandler

Bug: 293306185
Test: makepush sysuig
Test: m -j ArcSystemUI
Change-Id: I07325b8937d131fc3f649114fb15149beed4dda8
parent c152cdd1
Loading
Loading
Loading
Loading
+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
+7 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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,
@@ -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,
+1 −1
Original line number Diff line number Diff line
@@ -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;
+0 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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