• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.sdksandbox;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.content.ServiceConnection;
23 
24 import com.android.sdksandbox.ISdkSandboxService;
25 
26 import java.io.PrintWriter;
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * Interface to get hold of SdkSandbox service
32  *
33  * @hide
34  */
35 public interface SdkSandboxServiceProvider {
36 
37     /** @hide */
38     @IntDef(value = {NON_EXISTENT, CREATE_PENDING, CREATED})
39     @Retention(RetentionPolicy.SOURCE)
40     @interface SandboxStatus {}
41 
42     // Represents the state of the sandbox process when it has either not yet been created or is
43     // dead.
44     int NON_EXISTENT = 1;
45 
46     // Indicates that the sandbox is either in the middle of being created (after a call to bind
47     // was performed) or being restarted.
48     int CREATE_PENDING = 2;
49 
50     // Indicates that the sandbox process is up and running.
51     int CREATED = 3;
52 
53     /** Fixed suffix which get appended to app process name to create its sandbox process name. */
54     String SANDBOX_PROCESS_NAME_SUFFIX = "_sdk_sandbox";
55 
56     /**
57      * Bind to and establish a connection with SdkSandbox service.
58      *
59      * @param callingInfo represents the calling app.
60      * @param serviceConnection receives information when service is started and stopped.
61      */
bindService(CallingInfo callingInfo, ServiceConnection serviceConnection)62     void bindService(CallingInfo callingInfo, ServiceConnection serviceConnection);
63 
64     /**
65      * Unbind the SdkSandbox service associated with the app.
66      *
67      * @param callingInfo represents the app for which the sandbox should be unbound.
68      */
unbindService(CallingInfo callingInfo)69     void unbindService(CallingInfo callingInfo);
70 
71     /**
72      * Kills the sandbox for the given app.
73      *
74      * @param callingInfo app for which the sandbox kill is being requested.
75      */
stopSandboxService(CallingInfo callingInfo)76     void stopSandboxService(CallingInfo callingInfo);
77 
78     /**
79      * Return {@link ISdkSandboxService} connected for {@code callingInfo} or otherwise {@code
80      * null}.
81      */
82     @Nullable
getSdkSandboxServiceForApp(CallingInfo callingInfo)83     ISdkSandboxService getSdkSandboxServiceForApp(CallingInfo callingInfo);
84 
85     /**
86      * Informs the provider when the sandbox service has connected.
87      *
88      * @param callingInfo represents the app for which the sandbox service has connected.
89      * @param service the binder object used to communicate with the sandbox service.
90      */
onServiceConnected(CallingInfo callingInfo, @NonNull ISdkSandboxService service)91     void onServiceConnected(CallingInfo callingInfo, @NonNull ISdkSandboxService service);
92 
93     /**
94      * Informs the provider when the sandbox service has disconnected.
95      *
96      * @param callingInfo represents the app for which the sandbox service has disconnected.
97      */
onServiceDisconnected(CallingInfo callingInfo)98     void onServiceDisconnected(CallingInfo callingInfo);
99 
100     /**
101      * Informs the provider when an app has died.
102      *
103      * @param callingInfo represents the app for which the sandbox has died.
104      */
onAppDeath(CallingInfo callingInfo)105     void onAppDeath(CallingInfo callingInfo);
106 
107     /**
108      * Informs the provider when the sandbox service has died.
109      *
110      * @param callingInfo represents the app for which the sandbox service has died.
111      */
onSandboxDeath(CallingInfo callingInfo)112     void onSandboxDeath(CallingInfo callingInfo);
113 
114     /**
115      * Returns the status of the sandbox for the given app.
116      *
117      * @param callingInfo app for which the sandbox status is being requested.
118      */
119     @SandboxStatus
getSandboxStatusForApp(CallingInfo callingInfo)120     int getSandboxStatusForApp(CallingInfo callingInfo);
121 
122     /** Dump debug information for adb shell dumpsys */
dump(PrintWriter writer)123     default void dump(PrintWriter writer) {
124     }
125 
126     /**
127      * Returns sandbox process name for the passed app package name.
128      *
129      * @param packageName app package name.
130      */
131     @NonNull
toSandboxProcessName(@onNull String packageName)132     String toSandboxProcessName(@NonNull String packageName);
133 }
134