1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.am; 18 19 import android.annotation.NonNull; 20 import android.annotation.SuppressLint; 21 import android.annotation.SystemApi; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.ServiceConnection; 25 import android.os.RemoteException; 26 27 /** 28 * Interface for in-process calls into 29 * {@link android.content.Context#ACTIVITY_SERVICE ActivityManager system service}. 30 * 31 * @hide 32 */ 33 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER) 34 public interface ActivityManagerLocal { 35 /** 36 * Checks whether an app will be able to start a foreground service or not. 37 * 38 * @param pid The process id belonging to the app to be checked. 39 * @param uid The UID of the app to be checked. 40 * @param packageName The package name of the app to be checked. 41 * @return whether the app will be able to start a foreground service or not. 42 */ canStartForegroundService(int pid, int uid, @NonNull String packageName)43 boolean canStartForegroundService(int pid, int uid, @NonNull String packageName); 44 45 /** 46 * Returns {@code true} if a foreground service started by an uid is allowed to have 47 * while-in-use permissions. 48 * 49 * @param pid The process id belonging to the app to be checked. 50 * @param uid The UID of the app to be checked. 51 * @param packageName The package name of the app to be checked. 52 * @return whether the foreground service is allowed to have while-in-use permissions. 53 * @hide 54 */ canAllowWhileInUsePermissionInFgs(int pid, int uid, @NonNull String packageName)55 boolean canAllowWhileInUsePermissionInFgs(int pid, int uid, @NonNull String packageName); 56 57 /** 58 * Temporarily allow foreground service started by an uid to have while-in-use permission 59 * for durationMs. 60 * 61 * @param uid The UID of the app that starts the foreground service. 62 * @param durationMs elapsedRealTime duration in milliseconds. 63 * @hide 64 */ tempAllowWhileInUsePermissionInFgs(int uid, long durationMs)65 void tempAllowWhileInUsePermissionInFgs(int uid, long durationMs); 66 67 /** 68 * Binds to a sdk sandbox service, creating it if needed. You can through the arguments 69 * here have the system bring up multiple concurrent processes hosting their own instance of 70 * that service. The {@code processName} you provide here identifies the different instances. 71 * 72 * @param service Identifies the sdk sandbox process service to connect to. The Intent must 73 * specify an explicit component name. This value cannot be null. 74 * @param conn Receives information as the service is started and stopped. 75 * This must be a valid ServiceConnection object; it must not be null. 76 * @param clientAppUid Uid of the app for which the sdk sandbox process needs to be spawned. 77 * @param clientAppPackage Package of the app for which the sdk sandbox process needs to 78 * be spawned. This package must belong to the clientAppUid. 79 * @param processName Unique identifier for the service instance. Each unique name here will 80 * result in a different service instance being created. Identifiers must only contain 81 * ASCII letters, digits, underscores, and periods. 82 * @param flags Operation options provided by Context class for the binding. 83 * @return {@code true} if the system is in the process of bringing up a 84 * service that your client has permission to bind to; {@code false} 85 * if the system couldn't find the service or if your client doesn't 86 * have permission to bind to it. 87 * @throws RemoteException If the service could not be brought up. 88 * @see Context#bindService(Intent, ServiceConnection, int) 89 */ 90 @SuppressLint("RethrowRemoteException") bindSdkSandboxService(@onNull Intent service, @NonNull ServiceConnection conn, int clientAppUid, @NonNull String clientAppPackage, @NonNull String processName, @Context.BindServiceFlags int flags)91 boolean bindSdkSandboxService(@NonNull Intent service, @NonNull ServiceConnection conn, 92 int clientAppUid, @NonNull String clientAppPackage, @NonNull String processName, 93 @Context.BindServiceFlags int flags) 94 throws RemoteException; 95 } 96