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

Commit aba7df49 authored by Oluwarotimi Adesina's avatar Oluwarotimi Adesina Committed by Android (Google) Code Review
Browse files

Merge "Resolve some TODOs in appfunctions" into main

parents 1370e5ef c834ecfe
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -54,9 +54,9 @@ public final class AppFunctionManager {
     *
     * @hide
     */
    public AppFunctionManager(IAppFunctionManager mService, Context context) {
        this.mService = mService;
        this.mContext = context;
    public AppFunctionManager(IAppFunctionManager service, Context context) {
        mService = service;
        mContext = context;
    }

    /**
@@ -114,7 +114,7 @@ public final class AppFunctionManager {
                        }
                    });
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ interface IAppFunctionManager {
    * @param request the request to execute an app function.
    * @param callback the callback to report the result.
    */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(anyOf = {android.Manifest.permission.EXECUTE_APP_FUNCTIONS_TRUSTED,android.Manifest.permission.EXECUTE_APP_FUNCTIONS}, conditional = true)")
    void executeAppFunction(
        in ExecuteAppFunctionAidlRequest request,
        in IExecuteAppFunctionCallback callback
+10 −13
Original line number Diff line number Diff line
@@ -23,10 +23,6 @@ import android.app.appfunctions.IAppFunctionManager;
import android.app.appfunctions.IAppFunctionService;
import android.app.appfunctions.IExecuteAppFunctionCallback;
import android.app.appfunctions.SafeOneTimeExecuteAppFunctionCallback;
import android.app.appfunctions.ServiceCallHelper;
import android.app.appfunctions.ServiceCallHelper.RunServiceCallCallback;
import android.app.appfunctions.ServiceCallHelper.ServiceUsageCompleteListener;
import android.app.appfunctions.ServiceCallHelperImpl;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
@@ -34,6 +30,8 @@ import android.text.TextUtils;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.appfunctions.RemoteServiceCaller.RunServiceCallCallback;
import com.android.server.appfunctions.RemoteServiceCaller.ServiceUsageCompleteListener;

import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
@@ -45,12 +43,12 @@ import java.util.concurrent.TimeUnit;
 */
public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
    private static final String TAG = AppFunctionManagerServiceImpl.class.getSimpleName();
    private final ServiceCallHelper<IAppFunctionService> mExternalServiceCallHelper;
    private final RemoteServiceCaller<IAppFunctionService> mRemoteServiceCaller;
    private final CallerValidator mCallerValidator;
    private final ServiceHelper mInternalServiceHelper;

    public AppFunctionManagerServiceImpl(@NonNull Context context) {
        this(new ServiceCallHelperImpl<>(
        this(new RemoteServiceCallerImpl<>(
                        context,
                        IAppFunctionService.Stub::asInterface, new ThreadPoolExecutor(
                        /*corePoolSize=*/ Runtime.getRuntime().availableProcessors(),
@@ -63,11 +61,11 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
    }

    @VisibleForTesting
    AppFunctionManagerServiceImpl(ServiceCallHelper<IAppFunctionService> serviceCallHelper,
                                  CallerValidator apiValidator,
    AppFunctionManagerServiceImpl(RemoteServiceCaller<IAppFunctionService> remoteServiceCaller,
                                  CallerValidator callerValidator,
                                  ServiceHelper appFunctionInternalServiceHelper) {
        mExternalServiceCallHelper = Objects.requireNonNull(serviceCallHelper);
        mCallerValidator = Objects.requireNonNull(apiValidator);
        mRemoteServiceCaller = Objects.requireNonNull(remoteServiceCaller);
        mCallerValidator = Objects.requireNonNull(callerValidator);
        mInternalServiceHelper =
                Objects.requireNonNull(appFunctionInternalServiceHelper);
    }
@@ -134,7 +132,6 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
            return;
        }

        // TODO(b/357551503): Offload call to async executor.
        bindAppFunctionServiceUnchecked(requestInternal, serviceIntent, targetUser,
                safeExecuteAppFunctionCallback,
                /*bindFlags=*/ Context.BIND_AUTO_CREATE,
@@ -148,12 +145,12 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
            @NonNull SafeOneTimeExecuteAppFunctionCallback
                    safeExecuteAppFunctionCallback,
            int bindFlags, long timeoutInMillis) {
        boolean bindServiceResult = mExternalServiceCallHelper.runServiceCall(
        boolean bindServiceResult = mRemoteServiceCaller.runServiceCall(
                serviceIntent,
                bindFlags,
                timeoutInMillis,
                targetUser,
                /*timeOutCallback=*/ new RunServiceCallCallback<IAppFunctionService>() {
                new RunServiceCallCallback<IAppFunctionService>() {
                    @Override
                    public void onServiceConnected(@NonNull IAppFunctionService service,
                                                   @NonNull ServiceUsageCompleteListener
+2 −2
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.app.appfunctions;
package com.android.server.appfunctions;

import android.annotation.NonNull;
import android.content.Intent;
@@ -27,7 +27,7 @@ import android.os.UserHandle;
 * @param <T> Class of wrapped service.
 * @hide
 */
public interface ServiceCallHelper<T> {
public interface RemoteServiceCaller<T> {

    /**
     * Initiates service binding and executes a provided method when the service connects. Unbinds
+11 −9
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.app.appfunctions;
package com.android.server.appfunctions;

import android.annotation.NonNull;
import android.content.ComponentName;
@@ -30,17 +30,19 @@ import java.util.concurrent.Executor;
import java.util.function.Function;

/**
 * An implementation of {@link android.app.appfunctions.ServiceCallHelper} that that is based on
 * An implementation of {@link RemoteServiceCaller} that that is based on
 * {@link Context#bindService}.
 *
 * @param <T> Class of wrapped service.
 * @hide
 */
public class ServiceCallHelperImpl<T> implements ServiceCallHelper<T> {
public class RemoteServiceCallerImpl<T> implements RemoteServiceCaller<T> {
    private static final String TAG = "AppFunctionsServiceCall";

    @NonNull private final Context mContext;
    @NonNull private final Function<IBinder, T> mInterfaceConverter;
    @NonNull
    private final Context mContext;
    @NonNull
    private final Function<IBinder, T> mInterfaceConverter;
    private final Handler mHandler = new Handler(Looper.getMainLooper());
    private final Executor mExecutor;

@@ -50,7 +52,7 @@ public class ServiceCallHelperImpl<T> implements ServiceCallHelper<T> {
     * @param executor           An Executor instance to dispatch callback.
     * @param context            The system context.
     */
    public ServiceCallHelperImpl(
    public RemoteServiceCallerImpl(
            @NonNull Context context,
            @NonNull Function<IBinder, T> interfaceConverter,
            @NonNull Executor executor) {