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

Commit 6e256cca authored by Oluwarotimi Adesina's avatar Oluwarotimi Adesina Committed by Desh
Browse files

Respect enterprise policy in AppFunctions

Flag: android.app.appfunctions.flags.enable_app_function_manager
Test: atest CtsAppFunctionTestCases -c
Bug: 380442826
Change-Id: I277df0eade4787f906d426cfa5572f441747ad39
parent 7a4b6865
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8878,6 +8878,7 @@ package android.app.appfunctions {
    field public static final int ERROR_CATEGORY_UNKNOWN = 0; // 0x0
    field public static final int ERROR_DENIED = 1000; // 0x3e8
    field public static final int ERROR_DISABLED = 1002; // 0x3ea
    field public static final int ERROR_ENTERPRISE_POLICY_DISALLOWED = 2002; // 0x7d2
    field public static final int ERROR_FUNCTION_NOT_FOUND = 1003; // 0x3eb
    field public static final int ERROR_INVALID_ARGUMENT = 1001; // 0x3e9
    field public static final int ERROR_SYSTEM_ERROR = 2000; // 0x7d0
+11 −3
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ import java.util.Objects;
/**
 * Represents an app function related error.
 *
 * <p>This exception may include an {@link AppFunctionException#getExtras() Bundle}
 * containing additional error-specific metadata.
 * <p>This exception may include an {@link AppFunctionException#getExtras() Bundle} containing
 * additional error-specific metadata.
 *
 * <p>The AppFunction SDK can expose structured APIs by packing and unpacking this Bundle.
 */
@@ -84,6 +84,13 @@ public final class AppFunctionException extends Exception implements Parcelable
     */
    public static final int ERROR_CANCELLED = 2001;

    /**
     * The operation was disallowed by enterprise policy.
     *
     * <p>This error is in the {@link #ERROR_CATEGORY_SYSTEM} category.
     */
    public static final int ERROR_ENTERPRISE_POLICY_DISALLOWED = 2002;

    /**
     * An unknown error occurred while processing the call in the AppFunctionService.
     *
@@ -231,7 +238,8 @@ public final class AppFunctionException extends Exception implements Parcelable
                ERROR_SYSTEM_ERROR,
                ERROR_INVALID_ARGUMENT,
                ERROR_DISABLED,
                ERROR_CANCELLED
                ERROR_CANCELLED,
                ERROR_ENTERPRISE_POLICY_DISALLOWED
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ErrorCode {}
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package com.android.extensions.appfunctions {
    field public static final int ERROR_CATEGORY_UNKNOWN = 0; // 0x0
    field public static final int ERROR_DENIED = 1000; // 0x3e8
    field public static final int ERROR_DISABLED = 1002; // 0x3ea
    field public static final int ERROR_ENTERPRISE_POLICY_DISALLOWED = 2002; // 0x7d2
    field public static final int ERROR_FUNCTION_NOT_FOUND = 1003; // 0x3eb
    field public static final int ERROR_INVALID_ARGUMENT = 1001; // 0x3e9
    field public static final int ERROR_SYSTEM_ERROR = 2000; // 0x7d0
+9 −1
Original line number Diff line number Diff line
@@ -70,6 +70,13 @@ public final class AppFunctionException extends Exception {
     */
    public static final int ERROR_CANCELLED = 2001;

    /**
     * The operation was disallowed by enterprise policy.
     *
     * <p>This error is in the {@link #ERROR_CATEGORY_SYSTEM} category.
     */
    public static final int ERROR_ENTERPRISE_POLICY_DISALLOWED = 2002;

    /**
     * An unknown error occurred while processing the call in the AppFunctionService.
     *
@@ -189,7 +196,8 @@ public final class AppFunctionException extends Exception {
                ERROR_SYSTEM_ERROR,
                ERROR_INVALID_ARGUMENT,
                ERROR_DISABLED,
                ERROR_CANCELLED
                ERROR_CANCELLED,
                ERROR_ENTERPRISE_POLICY_DISALLOWED
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ErrorCode {}
+10 −11
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@ import static com.android.server.appfunctions.AppFunctionExecutors.THREAD_POOL_E
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.WorkerThread;
import android.app.appfunctions.AppFunctionException;
import android.app.appfunctions.AppFunctionManager;
import android.app.appfunctions.AppFunctionManagerHelper;
import android.app.appfunctions.AppFunctionRuntimeMetadata;
import android.app.appfunctions.AppFunctionStaticMetadataHelper;
import android.app.appfunctions.ExecuteAppFunctionAidlRequest;
import android.app.appfunctions.AppFunctionException;
import android.app.appfunctions.IAppFunctionEnabledCallback;
import android.app.appfunctions.IAppFunctionManager;
import android.app.appfunctions.IAppFunctionService;
@@ -158,8 +158,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
        } catch (SecurityException exception) {
            safeExecuteAppFunctionCallback.onError(
                    new AppFunctionException(
                            AppFunctionException.ERROR_DENIED,
                            exception.getMessage()));
                            AppFunctionException.ERROR_DENIED, exception.getMessage()));
            return null;
        }

@@ -195,12 +194,12 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
            @NonNull SafeOneTimeExecuteAppFunctionCallback safeExecuteAppFunctionCallback,
            @NonNull IBinder callerBinder) {
        UserHandle targetUser = requestInternal.getUserHandle();
        // TODO(b/354956319): Add and honor the new enterprise policies.
        if (mCallerValidator.isUserOrganizationManaged(targetUser)) {
        UserHandle callingUser = UserHandle.getUserHandleForUid(callingUid);
        if (!mCallerValidator.verifyEnterprisePolicyIsAllowed(callingUser, targetUser)) {
            safeExecuteAppFunctionCallback.onError(
                    new AppFunctionException(AppFunctionException.ERROR_SYSTEM_ERROR,
                            "Cannot run on a device with a device owner or from the managed"
                                    + " profile."));
                    new AppFunctionException(
                            AppFunctionException.ERROR_ENTERPRISE_POLICY_DISALLOWED,
                            "Cannot run on a user with a restricted enterprise policy"));
            return;
        }

@@ -442,7 +441,8 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
        if (!bindServiceResult) {
            Slog.e(TAG, "Failed to bind to the AppFunctionService");
            safeExecuteAppFunctionCallback.onError(
                    new AppFunctionException(AppFunctionException.ERROR_SYSTEM_ERROR,
                    new AppFunctionException(
                            AppFunctionException.ERROR_SYSTEM_ERROR,
                            "Failed to bind the AppFunctionService."));
        }
    }
@@ -495,8 +495,7 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
            return;
        }
        FutureGlobalSearchSession futureGlobalSearchSession =
                new FutureGlobalSearchSession(
                        perUserAppSearchManager, AppFunctionExecutors.THREAD_POOL_EXECUTOR);
                new FutureGlobalSearchSession(perUserAppSearchManager, THREAD_POOL_EXECUTOR);
        AppFunctionMetadataObserver appFunctionMetadataObserver =
                new AppFunctionMetadataObserver(
                        user.getUserHandle(),
Loading