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.Service; 22 import android.os.ServiceDebugInfo; 23 import android.os.ConnectionInfo; 24 25 /** 26 * Basic interface for finding and publishing system services. 27 * 28 * You likely want to use android.os.ServiceManager in Java or 29 * android::IServiceManager in C++ in order to use this interface. 30 * 31 * @hide 32 */ 33 interface IServiceManager { 34 /* 35 * Must update values in IServiceManager.h 36 */ 37 /* Allows services to dump sections according to priorities. */ 38 const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0; 39 const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1; 40 const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2; 41 /** 42 * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the 43 * same priority as NORMAL priority but the services are not called with dump priority 44 * arguments. 45 */ 46 const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3; 47 48 const int DUMP_FLAG_PRIORITY_ALL = 49 DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_HIGH 50 | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; 51 52 const int FLAG_IS_LAZY_SERVICE = 1 << 30; 53 54 /* Allows services to dump sections in protobuf format. */ 55 const int DUMP_FLAG_PROTO = 1 << 4; 56 57 /** 58 * Retrieve an existing service called @a name from the 59 * service manager. 60 * 61 * This is the same as checkService (returns immediately) but 62 * exists for legacy purposes. 63 * 64 * Returns null if the service does not exist. 65 * 66 * @deprecated TODO(b/355394904): Use getService2 instead. This does not return metadata 67 * that is included in ServiceWithMetadata 68 */ 69 @UnsupportedAppUsage getService(@tf8InCpp String name)70 @nullable IBinder getService(@utf8InCpp String name); 71 72 /** 73 * Retrieve an existing service called @a name from the 74 * service manager. 75 * 76 * This is the same as checkService (returns immediately) but 77 * exists for legacy purposes. 78 * 79 * Returns an enum Service that can be of different types. The 80 * enum value is null if the service does not exist. 81 */ getService2(@tf8InCpp String name)82 Service getService2(@utf8InCpp String name); 83 84 /** 85 * Retrieve an existing service called @a name from the service 86 * manager. Non-blocking. Returns null if the service does not exist. 87 * 88 * @deprecated TODO(b/355394904): Use checkService2 instead. This does not 89 * return metadata that is included in ServiceWithMetadata 90 */ 91 @UnsupportedAppUsage checkService(@tf8InCpp String name)92 @nullable IBinder checkService(@utf8InCpp String name); 93 94 /** 95 * Retrieve an existing service called @a name from the service 96 * manager. Non-blocking. Returns null if the service does not 97 * exist. 98 */ checkService2(@tf8InCpp String name)99 Service checkService2(@utf8InCpp String name); 100 101 /** 102 * Place a new @a service called @a name into the service 103 * manager. 104 */ addService(@tf8InCpp String name, IBinder service, boolean allowIsolated, int dumpPriority)105 void addService(@utf8InCpp String name, IBinder service, 106 boolean allowIsolated, int dumpPriority); 107 108 /** 109 * Return a list of all currently running services. 110 */ listServices(int dumpPriority)111 @utf8InCpp String[] listServices(int dumpPriority); 112 113 /** 114 * Request a callback when a service is registered. 115 */ registerForNotifications(@tf8InCpp String name, IServiceCallback callback)116 void registerForNotifications(@utf8InCpp String name, IServiceCallback callback); 117 118 /** 119 * Unregisters all requests for notifications for a specific callback. 120 */ unregisterForNotifications(@tf8InCpp String name, IServiceCallback callback)121 void unregisterForNotifications(@utf8InCpp String name, IServiceCallback callback); 122 123 /** 124 * Returns whether a given interface is declared on the device, even if it 125 * is not started yet. For instance, this could be a service declared in the VINTF 126 * manifest. 127 */ isDeclared(@tf8InCpp String name)128 boolean isDeclared(@utf8InCpp String name); 129 130 /** 131 * Returns all declared instances for a particular interface. 132 * 133 * For instance, if 'android.foo.IFoo/foo' is declared, and 'android.foo.IFoo' is 134 * passed here, then ["foo"] would be returned. 135 */ getDeclaredInstances(@tf8InCpp String iface)136 @utf8InCpp String[] getDeclaredInstances(@utf8InCpp String iface); 137 138 /** 139 * If updatable-via-apex, returns the APEX via which this is updated. 140 */ updatableViaApex(@tf8InCpp String name)141 @nullable @utf8InCpp String updatableViaApex(@utf8InCpp String name); 142 143 /** 144 * Returns all instances which are updatable via the APEX. Instance names are fully qualified 145 * like `pack.age.IFoo/default`. 146 */ getUpdatableNames(@tf8InCpp String apexName)147 @utf8InCpp String[] getUpdatableNames(@utf8InCpp String apexName); 148 149 /** 150 * If connection info is available for the given instance, returns the ConnectionInfo 151 */ getConnectionInfo(@tf8InCpp String name)152 @nullable ConnectionInfo getConnectionInfo(@utf8InCpp String name); 153 154 /** 155 * Request a callback when the number of clients of the service changes. 156 * Used by LazyServiceRegistrar to dynamically stop services that have no clients. 157 */ registerClientCallback(@tf8InCpp String name, IBinder service, IClientCallback callback)158 void registerClientCallback(@utf8InCpp String name, IBinder service, IClientCallback callback); 159 160 /** 161 * Attempt to unregister and remove a service. Will fail if the service is still in use. 162 */ tryUnregisterService(@tf8InCpp String name, IBinder service)163 void tryUnregisterService(@utf8InCpp String name, IBinder service); 164 165 /** 166 * Get debug information for all currently registered services. 167 */ getServiceDebugInfo()168 ServiceDebugInfo[] getServiceDebugInfo(); 169 } 170