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

Commit 5cdcf519 authored by Oluwarotimi Adesina's avatar Oluwarotimi Adesina
Browse files

Fix implementing AFMS.executeAppFunction

Flag: android.app.appfunctions.flags.enable_app_function_manager
Test: manual
Bug: 357551503
Change-Id: If74128b30b54e95e8ed826b675f1bad59d337583
parent a2574c97
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -20,10 +20,11 @@ import android.app.appfunctions.ExecuteAppFunctionAidlRequest;
import android.app.appfunctions.IExecuteAppFunctionCallback;

/**
* Interface between an app and the server implementation service (AppFunctionManagerService).
 * Defines the interface for apps to interact with the app function execution service
 * {@code AppFunctionManagerService} running in the system server process.
 * @hide
 */
oneway interface IAppFunctionManager {
interface IAppFunctionManager {
    /**
    * Executes an app function provided by {@link AppFunctionService} through the system.
    *
+8 −1
Original line number Diff line number Diff line
@@ -21,7 +21,14 @@ import android.app.appfunctions.IExecuteAppFunctionCallback;
import android.app.appfunctions.ExecuteAppFunctionRequest;


 /** {@hide} */
/**
 * Defines the interface for the system server to request the execution of an app function within
 * the app process.
 *
 * This interface is implemented by the app and exposed to the system server via a {@code Service}.
 *
 * @hide
 */
oneway interface IAppFunctionService {
    /**
     * Called by the system to execute a specific app function.
+18 −6
Original line number Diff line number Diff line
@@ -82,10 +82,19 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
        final SafeOneTimeExecuteAppFunctionCallback safeExecuteAppFunctionCallback =
                new SafeOneTimeExecuteAppFunctionCallback(executeAppFunctionCallback);

        String validatedCallingPackage = mCallerValidator
        String validatedCallingPackage;
        UserHandle targetUser;
        try {
            validatedCallingPackage = mCallerValidator
                    .validateCallingPackage(requestInternal.getCallingPackage());
        UserHandle targetUser = mCallerValidator.verifyTargetUserHandle(
            targetUser = mCallerValidator.verifyTargetUserHandle(
                    requestInternal.getUserHandle(), validatedCallingPackage);
        } catch (SecurityException exception) {
            safeExecuteAppFunctionCallback.onResult(new ExecuteAppFunctionResponse
                    .Builder(ExecuteAppFunctionResponse.RESULT_DENIED,
                    exception.getMessage()).build());
            return;
        }

        // TODO(b/354956319): Add and honor the new enterprise policies.
        if (mCallerValidator.isUserOrganizationManaged(targetUser)) {
@@ -107,8 +116,11 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {

        if (!mCallerValidator.verifyCallerCanExecuteAppFunction(
                validatedCallingPackage, targetPackageName)) {
            throw new SecurityException("Caller does not have permission to execute the app "
                    + "function.");
            safeExecuteAppFunctionCallback.onResult(new ExecuteAppFunctionResponse
                    .Builder(ExecuteAppFunctionResponse.RESULT_DENIED,
                    "Caller does not have permission to execute the appfunction")
                    .build());
            return;
        }

        Intent serviceIntent = mInternalServiceHelper.resolveAppFunctionService(