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

Commit 2f4c6574 authored by Russell Myers's avatar Russell Myers
Browse files

Disable app_function service on Wear

This change introduces a configuration class, which allows for
customization of when the AppFunctionManager is available. At the
moment, we're using this to remove support for it on Wear, which
does not have an immediate use-case for the service.

Bug: 361300136
Test: Local boot testing on Wear
Flag: android.app.appfunctions.flags.enable_app_function_manager
Change-Id: Ia0e1e355999c5bb724f6f94cb17eafd169214abe
parent 0e0eb496
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.app.admin.IDevicePolicyManager;
import android.app.ambientcontext.AmbientContextManager;
import android.app.ambientcontext.IAmbientContextManager;
import android.app.appfunctions.AppFunctionManager;
import android.app.appfunctions.AppFunctionManagerConfiguration;
import android.app.appfunctions.IAppFunctionManager;
import android.app.appsearch.AppSearchManagerFrameworkInitializer;
import android.app.blob.BlobStoreManagerFrameworkInitializer;
@@ -937,8 +938,10 @@ public final class SystemServiceRegistry {
                        @Override
                        public AppFunctionManager createService(ContextImpl ctx)
                                throws ServiceNotFoundException {
                            if (!AppFunctionManagerConfiguration.isSupported(ctx)) {
                                return null;
                            }
                            IAppFunctionManager service;
                            //TODO(b/357551503): If the feature not present avoid look up every time
                            service = IAppFunctionManager.Stub.asInterface(
                                    ServiceManager.getServiceOrThrow(Context.APP_FUNCTION_SERVICE));
                            return new AppFunctionManager(service, ctx.getOuterContext());
+63 −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 android.app.appfunctions;

import static android.app.appfunctions.flags.Flags.enableAppFunctionManager;

import android.annotation.NonNull;
import android.content.Context;
import android.content.pm.PackageManager;

/**
 * Represents the system configuration of support for the {@code AppFunctionManager} and
 * associated systems.
 *
 * @hide
 */
public class AppFunctionManagerConfiguration {
    private final Context mContext;

    /**
     * Constructs a new instance of {@code AppFunctionManagerConfiguration}.
     * @param context context
     */
    public AppFunctionManagerConfiguration(@NonNull final Context context) {
        mContext = context;
    }

    /**
     * Indicates whether the current target is intended to support {@code AppFunctionManager}.
     * @return {@code true} if supported; otherwise {@code false}
     */
    public boolean isSupported() {
        return enableAppFunctionManager() && !isWatch();

    }

    /**
     * Indicates whether the current target is intended to support {@code AppFunctionManager}.
     * @param context context
     * @return {@code true} if supported; otherwise {@code false}
     */
    public static boolean isSupported(@NonNull final Context context) {
        return new AppFunctionManagerConfiguration(context).isSupported();
    }

    private boolean isWatch() {
        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@

package com.android.server.appfunctions;

import static android.app.appfunctions.flags.Flags.enableAppFunctionManager;

import android.app.appfunctions.AppFunctionManagerConfiguration;
import android.content.Context;

import com.android.server.SystemService;
@@ -35,7 +34,7 @@ public class AppFunctionManagerService extends SystemService {

    @Override
    public void onStart() {
        if (enableAppFunctionManager()) {
        if (AppFunctionManagerConfiguration.isSupported(getContext())) {
            publishBinderService(Context.APP_FUNCTION_SERVICE, mServiceImpl);
        }
    }
+4 −5
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server;

import static android.app.appfunctions.flags.Flags.enableAppFunctionManager;
import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH;
@@ -38,6 +37,7 @@ import android.app.ApplicationErrorReport;
import android.app.INotificationManager;
import android.app.SystemServiceRegistry;
import android.app.admin.DevicePolicySafetyChecker;
import android.app.appfunctions.AppFunctionManagerConfiguration;
import android.app.usage.UsageStatsManagerInternal;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -1743,12 +1743,11 @@ public final class SystemServer implements Dumpable {
            mSystemServiceManager.startService(LogcatManagerService.class);
            t.traceEnd();

            if (AppFunctionManagerConfiguration.isSupported(context)) {
                t.traceBegin("StartAppFunctionManager");
            if (enableAppFunctionManager()) {
                mSystemServiceManager.startService(AppFunctionManagerService.class);
            }
                t.traceEnd();

            }
        } catch (Throwable e) {
            Slog.e("System", "******************************************");
            Slog.e("System", "************ Failure starting core service");