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

Commit b9108227 authored by Oluwarotimi Adesina's avatar Oluwarotimi Adesina
Browse files

Add DeviceConfig listener for AFMS

Flag: android.app.appfunctions.flags.enable_app_function_manager
Test: atest CtsAppFunctionTestCases
Bug: 357551503
Change-Id: Ie65324ab48ccc5dc344393d2502b44e935841b66
parent c834ecfe
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -43,9 +43,12 @@ import java.util.concurrent.TimeUnit;
 */
public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
    private static final String TAG = AppFunctionManagerServiceImpl.class.getSimpleName();

    private final RemoteServiceCaller<IAppFunctionService> mRemoteServiceCaller;
    private final CallerValidator mCallerValidator;
    private final ServiceHelper mInternalServiceHelper;
    private final ServiceConfig mServiceConfig;


    public AppFunctionManagerServiceImpl(@NonNull Context context) {
        this(new RemoteServiceCallerImpl<>(
@@ -57,17 +60,20 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
                        /*unit=*/ TimeUnit.SECONDS,
                        /*workQueue=*/ new LinkedBlockingQueue<>())),
                new CallerValidatorImpl(context),
                new ServiceHelperImpl(context));
                new ServiceHelperImpl(context),
                new ServiceConfigImpl());
    }

    @VisibleForTesting
    AppFunctionManagerServiceImpl(RemoteServiceCaller<IAppFunctionService> remoteServiceCaller,
                                  CallerValidator callerValidator,
                                  ServiceHelper appFunctionInternalServiceHelper) {
                                  ServiceHelper appFunctionInternalServiceHelper,
                                  ServiceConfig serviceConfig) {
        mRemoteServiceCaller = Objects.requireNonNull(remoteServiceCaller);
        mCallerValidator = Objects.requireNonNull(callerValidator);
        mInternalServiceHelper =
                Objects.requireNonNull(appFunctionInternalServiceHelper);
        mServiceConfig = serviceConfig;
    }

    @Override
@@ -131,12 +137,10 @@ public class AppFunctionManagerServiceImpl extends IAppFunctionManager.Stub {
            ).build());
            return;
        }

        bindAppFunctionServiceUnchecked(requestInternal, serviceIntent, targetUser,
                safeExecuteAppFunctionCallback,
                /*bindFlags=*/ Context.BIND_AUTO_CREATE,
                // TODO(b/357551503): Make timeout configurable.
                /*timeoutInMillis=*/ 30_000L);
                /*timeoutInMillis=*/ mServiceConfig.getExecutionTimeoutConfig());
    }

    private void bindAppFunctionServiceUnchecked(
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.appfunctions;

/**
 * This interface is used to expose configs to the AppFunctionManagerService.
 */
public interface ServiceConfig {
    // TODO(b/357551503): Obtain namespace from DeviceConfig.
    String NAMESPACE_APP_FUNCTIONS = "appfunctions";

    /**
     * Returns the maximum time to wait for an app function execution to be complete.
     */
    long getExecutionTimeoutConfig();
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.appfunctions;

import android.provider.DeviceConfig;

/**
 * Implementation of {@link ServiceConfig}
 */
public class ServiceConfigImpl implements ServiceConfig {
    static final String DEVICE_CONFIG_PROPERTY_EXECUTION_TIMEOUT = "execution_timeout";
    static final long DEFAULT_EXECUTION_TIMEOUT_MS = 5000L;


    @Override
    public long getExecutionTimeoutConfig() {
        return DeviceConfig.getLong(
                NAMESPACE_APP_FUNCTIONS,
                DEVICE_CONFIG_PROPERTY_EXECUTION_TIMEOUT,
                DEFAULT_EXECUTION_TIMEOUT_MS
        );
    }
}