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

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

Merge "Log AppFunctionsRequestReported" into main

parents 47ec0bc7 1670d281
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.ICancellationSignal;
import android.os.OutcomeReceiver;
import android.os.ParcelableException;
import android.os.RemoteException;
import android.os.SystemClock;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -179,7 +180,8 @@ public final class AppFunctionManager {

        ExecuteAppFunctionAidlRequest aidlRequest =
                new ExecuteAppFunctionAidlRequest(
                        request, mContext.getUser(), mContext.getPackageName());
                        request, mContext.getUser(), mContext.getPackageName(),
                        /* requestTime= */ SystemClock.elapsedRealtime());

        try {
            ICancellationSignal cancellationTransport =
+14 −3
Original line number Diff line number Diff line
@@ -41,8 +41,9 @@ public final class ExecuteAppFunctionAidlRequest implements Parcelable {
                            ExecuteAppFunctionRequest.CREATOR.createFromParcel(in);
                    UserHandle userHandle = UserHandle.CREATOR.createFromParcel(in);
                    String callingPackage = in.readString8();
                    long requestTime = in.readLong();
                    return new ExecuteAppFunctionAidlRequest(
                            clientRequest, userHandle, callingPackage);
                            clientRequest, userHandle, callingPackage, requestTime);
                }

                @Override
@@ -60,11 +61,15 @@ public final class ExecuteAppFunctionAidlRequest implements Parcelable {
    /** The package name of the app that is requesting to execute the app function. */
    private final String mCallingPackage;

    public ExecuteAppFunctionAidlRequest(
            ExecuteAppFunctionRequest clientRequest, UserHandle userHandle, String callingPackage) {
    /** The time of calling executeAppFunction(). */
    private final long mRequestTime;

    public ExecuteAppFunctionAidlRequest(ExecuteAppFunctionRequest clientRequest,
            UserHandle userHandle, String callingPackage, long requestTime) {
        this.mClientRequest = Objects.requireNonNull(clientRequest);
        this.mUserHandle = Objects.requireNonNull(userHandle);
        this.mCallingPackage = Objects.requireNonNull(callingPackage);
        this.mRequestTime = requestTime;
    }

    @Override
@@ -77,6 +82,7 @@ public final class ExecuteAppFunctionAidlRequest implements Parcelable {
        mClientRequest.writeToParcel(dest, flags);
        mUserHandle.writeToParcel(dest, flags);
        dest.writeString8(mCallingPackage);
        dest.writeLong(mRequestTime);
    }

    /** Returns the client request to execute an app function. */
@@ -96,4 +102,9 @@ public final class ExecuteAppFunctionAidlRequest implements Parcelable {
    public String getCallingPackage() {
        return mCallingPackage;
    }

    /** Returns the time of calling executeAppFunction(). */
    public long getRequestTime() {
        return mRequestTime;
    }
}
+27 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.app.appfunctions;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.RemoteException;
import android.util.Log;

@@ -37,8 +38,16 @@ public class SafeOneTimeExecuteAppFunctionCallback {

    @NonNull private final IExecuteAppFunctionCallback mCallback;

    @Nullable CompletionCallback mCompletionCallback;

    public SafeOneTimeExecuteAppFunctionCallback(@NonNull IExecuteAppFunctionCallback callback) {
        this(callback, /* completionCallback= */ null);
    }

    public SafeOneTimeExecuteAppFunctionCallback(@NonNull IExecuteAppFunctionCallback callback,
            @Nullable CompletionCallback completionCallback) {
        mCallback = Objects.requireNonNull(callback);
        mCompletionCallback = completionCallback;
    }

    /** Invoke wrapped callback with the result. */
@@ -49,6 +58,9 @@ public class SafeOneTimeExecuteAppFunctionCallback {
        }
        try {
            mCallback.onSuccess(result);
            if (mCompletionCallback != null) {
                mCompletionCallback.finalizeOnSuccess(result);
            }
        } catch (RemoteException ex) {
            // Failed to notify the other end. Ignore.
            Log.w(TAG, "Failed to invoke the callback", ex);
@@ -63,6 +75,9 @@ public class SafeOneTimeExecuteAppFunctionCallback {
        }
        try {
            mCallback.onError(error);
            if (mCompletionCallback != null) {
                mCompletionCallback.finalizeOnError(error);
            }
        } catch (RemoteException ex) {
            // Failed to notify the other end. Ignore.
            Log.w(TAG, "Failed to invoke the callback", ex);
@@ -76,4 +91,16 @@ public class SafeOneTimeExecuteAppFunctionCallback {
    public void disable() {
        mOnResultCalled.set(true);
    }

    /**
     * Provides a hook to execute additional actions after the {@link IExecuteAppFunctionCallback}
     * has been invoked.
     */
    public interface CompletionCallback {
        /** Called after {@link IExecuteAppFunctionCallback#onSuccess}. */
        void finalizeOnSuccess(@NonNull ExecuteAppFunctionResponse result);

        /** Called after {@link IExecuteAppFunctionCallback#onError}. */
        void finalizeOnError(@NonNull AppFunctionException error);
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ java_library_static {
    defaults: ["platform_service_defaults"],
    srcs: [
        ":services.appfunctions-sources",
        ":statslog-appfunctions-java-gen",
        "java/**/*.logtags",
    ],
    libs: ["services.core"],
@@ -26,3 +27,10 @@ java_library_static {
        baseline_filename: "lint-baseline.xml",
    },
}

genrule {
    name: "statslog-appfunctions-java-gen",
    tools: ["stats-log-api-gen"],
    cmd: "$(location stats-log-api-gen) --java $(out) --module appfunctions --javaPackage com.android.server.appfunctions --javaClass AppFunctionsStatsLog --minApiLevel 35",
    out: ["java/com/android/server/appfunctions/AppFunctionsStatsLog.java"],
}
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.appfunctions;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -35,6 +37,11 @@ public final class AppFunctionExecutors {
                    /* workQueue= */ new LinkedBlockingQueue<>(),
                    new NamedThreadFactory("AppFunctionExecutors"));

    /** Executor for stats logging. */
    public static final ExecutorService LOGGING_THREAD_EXECUTOR =
            Executors.newSingleThreadExecutor(
                    new NamedThreadFactory("AppFunctionsLoggingExecutors"));

    static {
        THREAD_POOL_EXECUTOR.allowCoreThreadTimeOut(true);
    }
Loading