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

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

Merge "Improve the appfunctions shell commands" into main

parents 3a0cc824 42494f0d
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -162,9 +162,8 @@ public final class AppFunctionException extends Exception implements Parcelable
    }

    private AppFunctionException(@NonNull Parcel in) {
        mErrorCode = in.readInt();
        mErrorMessage = in.readString8();
        mExtras = Objects.requireNonNull(in.readBundle(getClass().getClassLoader()));
        this(/* errorCode= */ in.readInt(), /* errorMessage= */ in.readString8(),
                /* extras= */Objects.requireNonNull(in.readBundle(Bundle.class.getClassLoader())));
    }

    /** Returns one of the {@code ERROR} constants. */
@@ -224,6 +223,11 @@ public final class AppFunctionException extends Exception implements Parcelable
        dest.writeBundle(mExtras);
    }

    @Override
    public @NonNull String getMessage() {
        return super.getMessage() + " (code " + mErrorCode + ")";
    }

    /**
     * Error codes.
     *
+47 −31
Original line number Diff line number Diff line
@@ -108,12 +108,15 @@ public class AppFunctionManagerServiceShellCommand extends ShellCommand {
                        + ". Defaults to the current user.");

        pw.println();

        if (accessCheckFlagsEnabled()) {
            pw.println(
                    "  grant-app-function-access --agent-package <AGENT_PACKAGE_NAME> "
                            + "--target-package <TARGET_PACKAGE_NAME> [--agent-user <USER_ID>] "
                            + "[--target-user <USER_ID>]");
            pw.println("    Grants an agent package access to an app's functions.");
        pw.println("    --agent-package <AGENT_PACKAGE_NAME>: The agent package to grant access.");
            pw.println(
                    "    --agent-package <AGENT_PACKAGE_NAME>: The agent package to grant access.");
            pw.println("    --target-package <TARGET_PACKAGE_NAME>: The target package.");
            pw.println(
                    "    --agent-user <USER_ID> (optional): The user ID for the agent package. "
@@ -137,9 +140,9 @@ public class AppFunctionManagerServiceShellCommand extends ShellCommand {
            pw.println(
                    "    --target-user <USER_ID> (optional): The user ID for the target package. "
                            + "Defaults to the current user.");

            pw.println();
        }
    }

    @Override
    public int onCommand(String cmd) {
@@ -156,8 +159,14 @@ public class AppFunctionManagerServiceShellCommand extends ShellCommand {
                case "set-enabled":
                    return runSetAppFunctionEnabled();
                case "grant-app-function-access":
                    if (!accessCheckFlagsEnabled()) {
                        return -1;
                    }
                    return runGrantAppFunctionAccess();
                case "revoke-app-function-access":
                    if (!accessCheckFlagsEnabled()) {
                        return -1;
                    }
                    return runRevokeAppFunctionAccess();
                default:
                    return handleDefaultCommands(cmd);
@@ -388,7 +397,9 @@ public class AppFunctionManagerServiceShellCommand extends ShellCommand {
                    @Override
                    public void onError(AppFunctionException e) {
                        Log.d(TAG, "onError: ", e);
                        pw.println("Error executing app function: " + e.getErrorCode() + " - " + e);
                        pw.printf(
                                "Error executing app function: %s. See logcat for more details. %n",
                                e);
                        resultCode.set(-1);
                        countDownLatch.countDown();
                    }
@@ -507,4 +518,9 @@ public class AppFunctionManagerServiceShellCommand extends ShellCommand {
            default -> throw new IllegalAccessError("Only allow shell or root");
        };
    }

    private boolean accessCheckFlagsEnabled() {
        return android.permission.flags.Flags.appFunctionAccessApiEnabled()
                && android.permission.flags.Flags.appFunctionAccessServiceEnabled();
    }
}