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

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

Merge "Allow launching applications not pre-declared in ComputerControlSession." into main

parents e95de5ae 0a956a61
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -159,9 +159,7 @@ public final class ComputerControlSession implements AutoCloseable {
    /**
     * Launches an application's launcher activity in the computer control session.
     *
     * <p>The application with the given package name must have a launcher activity and the
     * package name must have been declared during the session creation.</p>
     *
     * @throws IllegalArgumentException if the package does not have a launcher activity.
     * @see ComputerControlSessionParams#getTargetPackageNames()
     */
    public void launchApplication(@NonNull String packageName) {
+1 −3
Original line number Diff line number Diff line
@@ -106,9 +106,7 @@ public final class ComputerControlSession implements AutoCloseable {
    /**
     * Launches an application's launcher activity in the computer control session.
     *
     * <p>The application with the given package name must have a launcher activity and the
     * package name must have been included during the session creation.</p>
     *
     * @throws IllegalArgumentException if the package does not have a launcher activity.
     * @see Params#getTargetPackageNames()
     */
    public void launchApplication(@NonNull String packageName) {
+7 −4
Original line number Diff line number Diff line
@@ -320,10 +320,13 @@ final class ComputerControlSessionImpl extends IComputerControlSession.Stub
        return mOwnerPackageName;
    }

    public void launchApplication(@NonNull String packageName) {
        if (!mParams.getTargetPackageNames().contains(Objects.requireNonNull(packageName))) {
            throw new IllegalArgumentException(
                    "Package " + packageName + " is not allowed to be launched in this session.");
    @Override
    public void launchApplication(@NonNull String packageName) throws RemoteException {
        if (Flags.computerControlActivityPolicyStrict()) {
            // TODO(b/444600407): Remove this once the consent model is per-target app. While the
            // consent is general, the caller can extend the list of target packages dynamically.
            mVirtualDevice.addActivityPolicyExemption(
                    new ActivityPolicyExemption.Builder().setPackageName(packageName).build());
        }
        final UserHandle user = UserHandle.of(UserHandle.getUserId(Binder.getCallingUid()));
        Binder.withCleanCallingIdentity(() -> mInjector.launchApplicationOnDisplayAsUser(
+17 −4
Original line number Diff line number Diff line
@@ -271,7 +271,7 @@ public class ComputerControlSessionTest {
    }

    @Test
    public void launchApplication_launchesApplication() {
    public void launchApplication_launchesApplication() throws RemoteException {
        createComputerControlSession(mDefaultParams);
        mSession.launchApplication(TARGET_PACKAGE_1);
        verify(mInjector).launchApplicationOnDisplayAsUser(
@@ -279,10 +279,23 @@ public class ComputerControlSessionTest {
    }

    @Test
    public void launchApplication_undeclaredPackage_throws() {
    @DisableFlags(Flags.FLAG_COMPUTER_CONTROL_ACTIVITY_POLICY_STRICT)
    public void launchApplication_noActivityPolicy_launchesApplication() throws RemoteException {
        createComputerControlSession(mDefaultParams);
        assertThrows(IllegalArgumentException.class,
                () -> mSession.launchApplication(UNDECLARED_TARGET_PACKAGE));
        mSession.launchApplication(UNDECLARED_TARGET_PACKAGE);
        verify(mInjector).launchApplicationOnDisplayAsUser(
                eq(UNDECLARED_TARGET_PACKAGE), eq(VIRTUAL_DISPLAY_ID), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_COMPUTER_CONTROL_ACTIVITY_POLICY_STRICT)
    public void launchApplication_strictActivityPolicy_addsExemption() throws RemoteException {
        createComputerControlSession(mDefaultParams);
        mSession.launchApplication(UNDECLARED_TARGET_PACKAGE);
        verify(mVirtualDevice).addActivityPolicyExemption(
                argThat(new MatchesActivityPolicyExcemption(UNDECLARED_TARGET_PACKAGE)));
        verify(mInjector).launchApplicationOnDisplayAsUser(
                eq(UNDECLARED_TARGET_PACKAGE), eq(VIRTUAL_DISPLAY_ID), any());
    }

    @Test