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

Commit 226dc6cf authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Add VDM onSecureWindowHidden API

Change-Id: I46dae82fc3f54ced57e55ecceadb3be55a33946f
Fix: 364735778
Test: presubmit
Flag: android.companion.virtualdevice.flags.activity_control_api
parent fc5a4bd1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3542,6 +3542,7 @@ package android.companion.virtual {
  public static interface VirtualDeviceManager.ActivityListener {
    method @FlaggedApi("android.companion.virtualdevice.flags.activity_control_api") public default void onActivityLaunchBlocked(int, @NonNull android.content.ComponentName, @NonNull android.os.UserHandle, @Nullable android.content.IntentSender);
    method public void onDisplayEmpty(int);
    method @FlaggedApi("android.companion.virtualdevice.flags.activity_control_api") public default void onSecureWindowHidden(int);
    method @FlaggedApi("android.companion.virtualdevice.flags.activity_control_api") public default void onSecureWindowShown(int, @NonNull android.content.ComponentName, @NonNull android.os.UserHandle);
    method @Deprecated public void onTopActivityChanged(int, @NonNull android.content.ComponentName);
    method public default void onTopActivityChanged(int, @NonNull android.content.ComponentName, int);
+7 −0
Original line number Diff line number Diff line
@@ -63,4 +63,11 @@ oneway interface IVirtualDeviceActivityListener {
     * @param user The user associated with the activity.
     */
    void onSecureWindowShown(int displayId, in ComponentName componentName, in UserHandle user);

    /**
     * Called when a secure surface is no longer shown on the device.
     *
     * @param displayId The display ID on which the secure surface was shown.
     */
    void onSecureWindowHidden(int displayId);
}
+18 −0
Original line number Diff line number Diff line
@@ -166,6 +166,20 @@ public class VirtualDeviceInternal {
                        Binder.restoreCallingIdentity(token);
                    }
                }

                @Override
                public void onSecureWindowHidden(int displayId) {
                    final long token = Binder.clearCallingIdentity();
                    try {
                        synchronized (mActivityListenersLock) {
                            for (int i = 0; i < mActivityListeners.size(); i++) {
                                mActivityListeners.valueAt(i).onSecureWindowHidden(displayId);
                            }
                        }
                    } finally {
                        Binder.restoreCallingIdentity(token);
                    }
                }
            };

    private final IVirtualDeviceSoundEffectListener mSoundEffectListener =
@@ -617,6 +631,10 @@ public class VirtualDeviceInternal {
            mExecutor.execute(() ->
                    mActivityListener.onSecureWindowShown(displayId, componentName, user));
        }

        public void onSecureWindowHidden(int displayId) {
            mExecutor.execute(() -> mActivityListener.onSecureWindowHidden(displayId));
        }
    }

    /**
+11 −0
Original line number Diff line number Diff line
@@ -1288,6 +1288,17 @@ public final class VirtualDeviceManager {
        @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_ACTIVITY_CONTROL_API)
        default void onSecureWindowShown(int displayId, @NonNull ComponentName componentName,
                @NonNull UserHandle user) {}

        /**
         * Called when a window with a secure surface is no longer shown on the device.
         *
         * @param displayId The display ID on which the window was shown before.
         *
         * @see Display#FLAG_SECURE
         * @see WindowManager.LayoutParams#FLAG_SECURE
         */
        @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_ACTIVITY_CONTROL_API)
        default void onSecureWindowHidden(int displayId) {}
    }

    /**
+17 −4
Original line number Diff line number Diff line
@@ -88,6 +88,9 @@ public class GenericWindowPolicyController extends DisplayWindowPolicyController
        /** Called when a secure window shows on the virtual display. */
        void onSecureWindowShown(int displayId, @NonNull ActivityInfo activityInfo);

        /** Called when a secure window is no longer shown on the virtual display. */
        void onSecureWindowHidden(int displayId);

        /** Returns true when an intent should be intercepted */
        boolean shouldInterceptIntent(@NonNull Intent intent);
    }
@@ -123,6 +126,9 @@ public class GenericWindowPolicyController extends DisplayWindowPolicyController
    private boolean mIsMirrorDisplay = false;
    private final CountDownLatch mDisplayIdSetLatch = new CountDownLatch(1);

    // Used for detecting changes in the window flags.
    private int mCurrentWindowFlags = 0;

    @NonNull
    @GuardedBy("mGenericWindowPolicyControllerLock")
    private final ArraySet<Integer> mRunningUids = new ArraySet<>();
@@ -371,12 +377,19 @@ public class GenericWindowPolicyController extends DisplayWindowPolicyController
    public boolean keepActivityOnWindowFlagsChanged(ActivityInfo activityInfo, int windowFlags,
            int systemWindowFlags) {
        int displayId = waitAndGetDisplayId();
        if (displayId != INVALID_DISPLAY) {
            // The callback is fired only when windowFlags are changed. To let VirtualDevice owner
            // aware that the virtual display has a secure window on top.
        if ((windowFlags & FLAG_SECURE) != 0 && displayId != INVALID_DISPLAY) {
            // Post callback on the main thread, so it doesn't block activity launching.
            mHandler.post(() -> mActivityListener.onSecureWindowShown(displayId, activityInfo));
            if ((windowFlags & FLAG_SECURE) != 0 && (mCurrentWindowFlags & FLAG_SECURE) == 0) {
                mHandler.post(
                        () -> mActivityListener.onSecureWindowShown(displayId, activityInfo));
            }
            if ((windowFlags & FLAG_SECURE) == 0 && (mCurrentWindowFlags & FLAG_SECURE) != 0) {
                mHandler.post(() -> mActivityListener.onSecureWindowHidden(displayId));
            }
        }
        mCurrentWindowFlags = windowFlags;

        if (!CompatChanges.isChangeEnabled(ALLOW_SECURE_ACTIVITY_DISPLAY_ON_REMOTE_DEVICE,
                activityInfo.packageName,
Loading