• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Nullable;
21 import android.annotation.SuppressLint;
22 import android.annotation.SystemApi;
23 import android.content.ComponentName;
24 import android.content.Context;
25 import android.content.Context.BindServiceFlags;
26 import android.content.Context.BindServiceFlagsBits;
27 import android.content.Intent;
28 import android.content.ServiceConnection;
29 import android.os.IBinder;
30 import android.os.RemoteException;
31 
32 /**
33  * Interface for in-process calls into
34  * {@link android.content.Context#ACTIVITY_SERVICE ActivityManager system service}.
35  *
36  * @hide
37  */
38 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER)
39 public interface ActivityManagerLocal {
40     /**
41      * Checks whether an app will be able to start a foreground service or not.
42      *
43      * @param pid The process id belonging to the app to be checked.
44      * @param uid The UID of the app to be checked.
45      * @param packageName The package name of the app to be checked.
46      * @return whether the app will be able to start a foreground service or not.
47      */
canStartForegroundService(int pid, int uid, @NonNull String packageName)48     boolean canStartForegroundService(int pid, int uid, @NonNull String packageName);
49 
50     /**
51      * Returns {@code true} if a foreground service started by an uid is allowed to have
52      * while-in-use permissions.
53      *
54      * @param pid The process id belonging to the app to be checked.
55      * @param uid The UID of the app to be checked.
56      * @param packageName The package name of the app to be checked.
57      * @return whether the foreground service is allowed to have while-in-use permissions.
58      * @hide
59      */
canAllowWhileInUsePermissionInFgs(int pid, int uid, @NonNull String packageName)60     boolean canAllowWhileInUsePermissionInFgs(int pid, int uid, @NonNull String packageName);
61 
62     /**
63      * Temporarily allow foreground service started by an uid to have while-in-use permission
64      * for durationMs.
65      *
66      * @param uid The UID of the app that starts the foreground service.
67      * @param durationMs elapsedRealTime duration in milliseconds.
68      * @hide
69      */
tempAllowWhileInUsePermissionInFgs(int uid, long durationMs)70     void tempAllowWhileInUsePermissionInFgs(int uid, long durationMs);
71 
72     /**
73      * Requests that an SDK sandbox service be started. If this service is not already running,
74      * it will be instantiated and started (creating a process for it if needed). You can through
75      * the arguments here have the system bring up multiple concurrent processes hosting their own
76      * instance of that service. Each instance is identified by the {@code processName} provided
77      * here.
78      *
79      * @param service Identifies the sdk sandbox process service to connect to. The Intent must
80      *                specify an explicit component name. This value cannot be null.
81      * @param clientAppUid Uid of the app for which the sdk sandbox process needs to be spawned.
82      * @param clientAppPackage Package of the app for which the sdk sandbox process needs to
83      *        be spawned. This package must belong to the clientAppUid.
84      * @param processName Unique identifier for the service instance. Each unique name here will
85      *        result in a different service instance being created. Identifiers must only contain
86      *        ASCII letters, digits, underscores, and periods.
87      *
88      * @throws RemoteException If the service could not be started.
89      * @return If the service is being started or is already running, the {@link ComponentName} of
90      * the actual service that was started is returned; else if the service does not exist null is
91      * returned.
92      */
93     @Nullable
94     @SuppressLint("RethrowRemoteException")
startSdkSandboxService(@onNull Intent service, int clientAppUid, @NonNull String clientAppPackage, @NonNull String processName)95     ComponentName startSdkSandboxService(@NonNull Intent service, int clientAppUid,
96             @NonNull String clientAppPackage, @NonNull String processName)
97             throws RemoteException;
98 
99     // TODO(b/269592470): What if the sandbox is stopped while there is an active binding to it?
100     /**
101      * Requests that an SDK sandbox service with a given {@code processName} be stopped.
102      *
103      * @param service Identifies the sdk sandbox process service to connect to. The Intent must
104      *        specify an explicit component name. This value cannot be null.
105      * @param clientAppUid Uid of the app for which the sdk sandbox process needs to be stopped.
106      * @param clientAppPackage Package of the app for which the sdk sandbox process needs to
107      *        be stopped. This package must belong to the clientAppUid.
108      * @param processName Unique identifier for the service instance. Each unique name here will
109      *        result in a different service instance being created. Identifiers must only contain
110      *        ASCII letters, digits, underscores, and periods.
111      *
112      * @return If there is a service matching the given Intent that is already running, then it is
113      *         stopped and true is returned; else false is returned.
114      */
stopSdkSandboxService(@onNull Intent service, int clientAppUid, @NonNull String clientAppPackage, @NonNull String processName)115     boolean stopSdkSandboxService(@NonNull Intent service, int clientAppUid,
116             @NonNull String clientAppPackage, @NonNull String processName);
117 
118     /**
119      * Binds to an SDK sandbox service for a given client application.
120      *
121      * @param service Identifies the sdk sandbox process service to connect to. The Intent must
122      *        specify an explicit component name. This value cannot be null.
123      * @param conn Receives information as the service is started and stopped.
124      *        This must be a valid ServiceConnection object; it must not be null.
125      * @param clientAppUid Uid of the app for which the sdk sandbox process needs to be spawned.
126      * @param clientAppProcessToken process token used to uniquely identify the client app
127      *        process binding to the SDK sandbox. This is obtained using
128      *        {@link Context#getProcessToken()}.
129      * @param clientAppPackage Package of the app for which the sdk sandbox process needs to
130      *        be spawned. This package must belong to the clientAppUid.
131      * @param processName Unique identifier for the service instance. Each unique name here will
132      *        result in a different service instance being created. Identifiers must only contain
133      *        ASCII letters, digits, underscores, and periods.
134      * @param flags Operation options provided by Context class for the binding.
135      * @return {@code true} if the system is in the process of bringing up a
136      *         service that your client has permission to bind to; {@code false}
137      *         if the system couldn't find the service or if your client doesn't
138      *         have permission to bind to it.
139      * @throws RemoteException If the service could not be bound to.
140      * @see Context#bindService(Intent, ServiceConnection, int)
141      */
142     @SuppressLint("RethrowRemoteException")
bindSdkSandboxService(@onNull Intent service, @NonNull ServiceConnection conn, int clientAppUid, @NonNull IBinder clientAppProcessToken, @NonNull String clientAppPackage, @NonNull String processName, @BindServiceFlagsBits int flags)143     boolean bindSdkSandboxService(@NonNull Intent service, @NonNull ServiceConnection conn,
144             int clientAppUid, @NonNull IBinder clientAppProcessToken,
145             @NonNull String clientAppPackage, @NonNull String processName,
146             @BindServiceFlagsBits int flags)
147             throws RemoteException;
148 
149     /**
150      * See {@link #bindSdkSandboxService(Intent, ServiceConnection, int, IBinder, String, String,
151      *       int)}
152      */
153     @SuppressLint("RethrowRemoteException")
bindSdkSandboxService(@onNull Intent service, @NonNull ServiceConnection conn, int clientAppUid, @NonNull IBinder clientAppProcessToken, @NonNull String clientAppPackage, @NonNull String processName, @NonNull BindServiceFlags flags)154     boolean bindSdkSandboxService(@NonNull Intent service, @NonNull ServiceConnection conn,
155             int clientAppUid, @NonNull IBinder clientAppProcessToken,
156             @NonNull String clientAppPackage, @NonNull String processName,
157             @NonNull BindServiceFlags flags)
158             throws RemoteException;
159 
160     /**
161      * @deprecated Please use
162      * {@link #bindSdkSandboxService(Intent, ServiceConnection, int, IBinder, String, String,
163      *       BindServiceFlags)}
164      *
165      * This API can't be deleted yet because it can be used by early AdService module versions.
166      */
167     @SuppressLint("RethrowRemoteException")
bindSdkSandboxService(@onNull Intent service, @NonNull ServiceConnection conn, int clientAppUid, @NonNull String clientAppPackage, @NonNull String processName, @BindServiceFlagsBits int flags)168     boolean bindSdkSandboxService(@NonNull Intent service, @NonNull ServiceConnection conn,
169             int clientAppUid, @NonNull String clientAppPackage, @NonNull String processName,
170             @BindServiceFlagsBits int flags)
171             throws RemoteException;
172 
173     /**
174      * Kill an app process associated with an SDK sandbox.
175      *
176      * @param clientAppProcessToken process token used to uniquely identify the client app
177      *        process associated with an SDK sandbox. This is obtained using
178      *        {@link Context#getProcessToken()}.
179      */
killSdkSandboxClientAppProcess(@onNull IBinder clientAppProcessToken)180     void killSdkSandboxClientAppProcess(@NonNull IBinder clientAppProcessToken);
181 }
182