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