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

Commit 14200e38 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Watch AppOp mode for SYSTEM_APPLICATION_OVERLAY" into main

parents f7468497 2509f169
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
    boolean mCanForceShowingInsets;
    private final boolean mCanStartTasksFromRecents;

    final boolean mCanCreateSystemApplicationOverlay;
    private boolean mCanCreateSystemApplicationOverlay;
    final boolean mCanHideNonSystemOverlayWindows;
    final boolean mCanSetUnrestrictedGestureExclusion;
    final boolean mCanAlwaysUpdateWallpaper;
@@ -157,15 +157,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
                HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED
                || service.mContext.checkCallingOrSelfPermission(HIDE_OVERLAY_WINDOWS)
                == PERMISSION_GRANTED;
        mCanCreateSystemApplicationOverlay =
                com.android.media.projection.flags.Flags.recordingOverlay()
                ? service.mContext.getSystemService(
                        PermissionManager.class).checkPermissionForPreflight(
                        Manifest.permission.SYSTEM_APPLICATION_OVERLAY,
                        new AttributionSource(mUid, mPackageName, null))
                        == PermissionManager.PERMISSION_GRANTED
                : service.mContext.checkCallingOrSelfPermission(SYSTEM_APPLICATION_OVERLAY)
                        == PERMISSION_GRANTED;
        updateCanCreateSystemApplicationOverlay(service.mPermissionManager);
        mCanStartTasksFromRecents = service.mContext.checkCallingOrSelfPermission(
                START_TASKS_FROM_RECENTS) == PERMISSION_GRANTED;
        mSetsUnrestrictedKeepClearAreas =
@@ -203,6 +195,23 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
        }
    }

    boolean canCreateSystemApplicationOverlay() {
        return mCanCreateSystemApplicationOverlay;
    }

    void updateCanCreateSystemApplicationOverlay(PermissionManager permissionManager) {
        if (com.android.media.projection.flags.Flags.recordingOverlay()) {
            mCanCreateSystemApplicationOverlay = permissionManager.checkPermissionForPreflight(
                    Manifest.permission.SYSTEM_APPLICATION_OVERLAY,
                    new AttributionSource(mUid, mPackageName, null))
                    == PermissionManager.PERMISSION_GRANTED;
        } else {
            mCanCreateSystemApplicationOverlay = mService.mContext.checkCallingOrSelfPermission(
                    SYSTEM_APPLICATION_OVERLAY)
                    == PERMISSION_GRANTED;
        }
    }

    @Override
    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
            throws RemoteException {
+29 −6
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ import android.os.SystemProperties;
import android.os.SystemService;
import android.os.Trace;
import android.os.UserHandle;
import android.permission.PermissionManager;
import android.provider.DeviceConfigInterface;
import android.provider.Settings;
import android.service.vr.IVrManager;
@@ -605,6 +606,7 @@ public class WindowManagerService extends IWindowManager.Stub
    final ActivityManagerInternal mAmInternal;
    final UserManagerInternal mUmInternal;

    final PermissionManager mPermissionManager;
    final AppOpsManager mAppOps;
    final PackageManagerInternal mPmInternal;
    private final TestUtilityService mTestUtilityService;
@@ -1418,15 +1420,36 @@ public class WindowManagerService extends IWindowManager.Stub
        mActivityManager = ActivityManager.getService();
        mAmInternal = LocalServices.getService(ActivityManagerInternal.class);
        mUmInternal = LocalServices.getService(UserManagerInternal.class);
        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
        AppOpsManager.OnOpChangedInternalListener opListener =
        mPermissionManager = context.getSystemService(PermissionManager.class);
        mAppOps = context.getSystemService(AppOpsManager.class);
        mAppOps.startWatchingMode(OP_SYSTEM_ALERT_WINDOW, null,
                new AppOpsManager.OnOpChangedInternalListener() {
                    @Override public void onOpChanged(int op, String packageName) {
                    @Override
                    public void onOpChanged(int op, String packageName) {
                        updateAppOpsState();
                    }
                };
        mAppOps.startWatchingMode(OP_SYSTEM_ALERT_WINDOW, null, opListener);
        mAppOps.startWatchingMode(AppOpsManager.OP_TOAST_WINDOW, null, opListener);
                });
        mAppOps.startWatchingMode(AppOpsManager.OP_TOAST_WINDOW, null,
                new AppOpsManager.OnOpChangedInternalListener() {
                    @Override
                    public void onOpChanged(int op, String packageName) {
                        updateAppOpsState();
                    }
                });
        mAppOps.startWatchingMode(AppOpsManager.OPSTR_SYSTEM_APPLICATION_OVERLAY, null,
                new AppOpsManager.OnOpChangedInternalListener() {
                    @Override
                    public void onOpChanged(int op, String packageName) {
                        if (op == AppOpsManager.OP_SYSTEM_APPLICATION_OVERLAY) {
                            synchronized (mGlobalLock) {
                                for (Session session : mSessions) {
                                    session.updateCanCreateSystemApplicationOverlay(
                                            mPermissionManager);
                                }
                            }
                        }
                    }
                });

        mPmInternal = LocalServices.getService(PackageManagerInternal.class);
        mTestUtilityService = LocalServices.getService(TestUtilityService.class);
+2 −2
Original line number Diff line number Diff line
@@ -1151,7 +1151,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            return true;
        }
        if (((mAttrs.privateFlags & PRIVATE_FLAG_SYSTEM_APPLICATION_OVERLAY) != 0
                && mSession.mCanCreateSystemApplicationOverlay)) {
                && mSession.canCreateSystemApplicationOverlay())) {
            return true;
        }
        return false;
@@ -3055,7 +3055,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }

        if (baseType == TYPE_APPLICATION_OVERLAY && mAttrs.isSystemApplicationOverlay()
                && mSession.mCanCreateSystemApplicationOverlay) {
                && mSession.canCreateSystemApplicationOverlay()) {
            return;
        }