1 /*
2  * Copyright (C) 2006 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 android.os;
18 
19 import android.os.IClientCallback;
20 import android.os.IServiceCallback;
21 import android.os.ServiceDebugInfo;
22 
23 /**
24  * Basic interface for finding and publishing system services.
25  *
26  * You likely want to use android.os.ServiceManager in Java or
27  * android::IServiceManager in C++ in order to use this interface.
28  *
29  * @hide
30  */
31 interface IServiceManager {
32     /*
33      * Must update values in IServiceManager.h
34      */
35     /* Allows services to dump sections according to priorities. */
36     const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0;
37     const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1;
38     const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2;
39     /**
40      * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the
41      * same priority as NORMAL priority but the services are not called with dump priority
42      * arguments.
43      */
44     const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3;
45 
46     const int DUMP_FLAG_PRIORITY_ALL =
47              DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH
48              | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT;
49 
50     /* Allows services to dump sections in protobuf format. */
51     const int DUMP_FLAG_PROTO = 1 << 4;
52 
53     /**
54      * Retrieve an existing service called @a name from the
55      * service manager.
56      *
57      * This is the same as checkService (returns immediately) but
58      * exists for legacy purposes.
59      *
60      * Returns null if the service does not exist.
61      */
62     @UnsupportedAppUsage
getService(@tf8InCpp String name)63     @nullable IBinder getService(@utf8InCpp String name);
64 
65     /**
66      * Retrieve an existing service called @a name from the service
67      * manager. Non-blocking. Returns null if the service does not
68      * exist.
69      */
70     @UnsupportedAppUsage
checkService(@tf8InCpp String name)71     @nullable IBinder checkService(@utf8InCpp String name);
72 
73     /**
74      * Place a new @a service called @a name into the service
75      * manager.
76      */
addService(@tf8InCpp String name, IBinder service, boolean allowIsolated, int dumpPriority)77     void addService(@utf8InCpp String name, IBinder service,
78         boolean allowIsolated, int dumpPriority);
79 
80     /**
81      * Return a list of all currently running services.
82      */
listServices(int dumpPriority)83     @utf8InCpp String[] listServices(int dumpPriority);
84 
85     /**
86      * Request a callback when a service is registered.
87      */
registerForNotifications(@tf8InCpp String name, IServiceCallback callback)88     void registerForNotifications(@utf8InCpp String name, IServiceCallback callback);
89 
90     /**
91      * Unregisters all requests for notifications for a specific callback.
92      */
unregisterForNotifications(@tf8InCpp String name, IServiceCallback callback)93     void unregisterForNotifications(@utf8InCpp String name, IServiceCallback callback);
94 
95     /**
96      * Returns whether a given interface is declared on the device, even if it
97      * is not started yet. For instance, this could be a service declared in the VINTF
98      * manifest.
99      */
isDeclared(@tf8InCpp String name)100     boolean isDeclared(@utf8InCpp String name);
101 
102     /**
103      * Returns all declared instances for a particular interface.
104      *
105      * For instance, if 'android.foo.IFoo/foo' is declared, and 'android.foo.IFoo' is
106      * passed here, then ["foo"] would be returned.
107      */
getDeclaredInstances(@tf8InCpp String iface)108     @utf8InCpp String[] getDeclaredInstances(@utf8InCpp String iface);
109 
110     /**
111      * If updatable-via-apex, returns the APEX via which this is updated.
112      */
updatableViaApex(@tf8InCpp String name)113     @nullable @utf8InCpp String updatableViaApex(@utf8InCpp String name);
114 
115     /**
116      * Request a callback when the number of clients of the service changes.
117      * Used by LazyServiceRegistrar to dynamically stop services that have no clients.
118      */
registerClientCallback(@tf8InCpp String name, IBinder service, IClientCallback callback)119     void registerClientCallback(@utf8InCpp String name, IBinder service, IClientCallback callback);
120 
121     /**
122      * Attempt to unregister and remove a service. Will fail if the service is still in use.
123      */
tryUnregisterService(@tf8InCpp String name, IBinder service)124     void tryUnregisterService(@utf8InCpp String name, IBinder service);
125 
126     /**
127      * Get debug information for all currently registered services.
128      */
getServiceDebugInfo()129     ServiceDebugInfo[] getServiceDebugInfo();
130 }
131