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

Commit 0ba97ecb authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Pass IntentSender to VDM's onActivityLaunchBlocked

Null if there's an activity result requested.

Fix: 333443509
Test: CTS
Flag: android.companion.virtualdevice.flags.activity_control_api

Change-Id: Ia230e49180efbc47f130c85454e06da37968e88a
parent 73a1f209
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3448,7 +3448,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, int);
    method @FlaggedApi("android.companion.virtualdevice.flags.activity_control_api") public default void onActivityLaunchBlocked(int, @NonNull android.content.ComponentName, int, @Nullable android.content.IntentSender);
    method public void onDisplayEmpty(int);
    method @Deprecated public void onTopActivityChanged(int, @NonNull android.content.ComponentName);
    method public default void onTopActivityChanged(int, @NonNull android.content.ComponentName, int);
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.companion.virtual;

import android.content.ComponentName;
import android.content.IntentSender;

/**
 * Interface to listen for activity changes in a virtual device.
@@ -48,6 +49,8 @@ oneway interface IVirtualDeviceActivityListener {
     * @param displayId The display ID on which the activity tried to launch.
     * @param componentName The component name of the blocked activity.
     * @param userId The user ID associated with the blocked activity.
     * @param intentSender The original sender of the intent.
     */
    void onActivityLaunchBlocked(int displayId, in ComponentName componentName, int userId);
    void onActivityLaunchBlocked(int displayId, in ComponentName componentName, int userId,
            in IntentSender intentSender);
}
+7 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.hardware.display.DisplayManagerGlobal;
import android.hardware.display.IVirtualDisplayCallback;
import android.hardware.display.VirtualDisplay;
@@ -135,13 +136,14 @@ public class VirtualDeviceInternal {

                @Override
                public void onActivityLaunchBlocked(int displayId, ComponentName componentName,
                        @UserIdInt int userId) {
                        @UserIdInt int userId, IntentSender intentSender) {
                    final long token = Binder.clearCallingIdentity();
                    try {
                        synchronized (mActivityListenersLock) {
                            for (int i = 0; i < mActivityListeners.size(); i++) {
                                mActivityListeners.valueAt(i)
                                        .onActivityLaunchBlocked(displayId, componentName, userId);
                                        .onActivityLaunchBlocked(
                                                displayId, componentName, userId, intentSender);
                            }
                        }
                    } finally {
@@ -593,9 +595,10 @@ public class VirtualDeviceInternal {
        }

        public void onActivityLaunchBlocked(int displayId, ComponentName componentName,
                @UserIdInt int userId) {
                @UserIdInt int userId, IntentSender intentSender) {
            mExecutor.execute(() ->
                    mActivityListener.onActivityLaunchBlocked(displayId, componentName, userId));
                    mActivityListener.onActivityLaunchBlocked(
                            displayId, componentName, userId, intentSender));
        }
    }

+7 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.VirtualDisplayFlag;
@@ -1250,13 +1251,18 @@ public final class VirtualDeviceManager {
         * @param displayId The display ID on which the activity tried to launch.
         * @param componentName The component name of the blocked activity.
         * @param userId The user ID associated with the blocked activity.
         * @param intentSender The original sender of the intent. May be {@code null} if the sender
         *   expects an activity result to be reported. In that case
         *   {@link android.app.Activity#RESULT_CANCELED} was already reported back because the
         *   launch was blocked. This {@link IntentSender} can be used to relaunch the blocked
         *   activity to a different display.
         *
         * @see VirtualDeviceParams#POLICY_TYPE_ACTIVITY
         * @see VirtualDevice#addActivityPolicyExemption(ComponentName)
         */
        @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_ACTIVITY_CONTROL_API)
        default void onActivityLaunchBlocked(int displayId, @NonNull ComponentName componentName,
                @UserIdInt int userId) {}
                @UserIdInt int userId, @Nullable IntentSender intentSender) {}
    }

    /**
+7 −1
Original line number Diff line number Diff line
@@ -25,12 +25,14 @@ import android.annotation.UserIdInt;
import android.app.WindowConfiguration;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.ActivityInfo;
import android.util.ArraySet;

import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

/**
 * Abstract class to control the policies of the windows that can be displayed on the virtual
@@ -136,10 +138,14 @@ public abstract class DisplayWindowPolicyController {
     * Returns {@code true} if the given activity can be launched on this virtual display in the
     * configuration defined by the rest of the arguments. If the given intent would be intercepted
     * by the display owner then this means that the activity cannot be launched.
     *
     * The intentSender argument can provide an IntentSender for the original intent to be passed
     * to any activity listeners, in case the activity cannot be launched.
     */
    public abstract boolean canActivityBeLaunched(@NonNull ActivityInfo activityInfo,
            @Nullable Intent intent, @WindowConfiguration.WindowingMode int windowingMode,
            int launchingFromDisplayId, boolean isNewTask);
            int launchingFromDisplayId, boolean isNewTask, boolean isResultExpected,
            @Nullable Supplier<IntentSender> intentSender);

    /**
     * Returns {@code true} if the given activity can be launched on this virtual display in the
Loading