1 /*
2  * Copyright (C) 2009 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.content.Context;
20 
21 import java.util.Map;
22 
23 public final class ServiceManager {
24 
25     /**
26      * Returns a reference to a service with the given name.
27      *
28      * @param name the name of the service to get
29      * @return a reference to the service, or <code>null</code> if the service doesn't exist
30      */
getService(String name)31     public static IBinder getService(String name) {
32         return null;
33     }
34 
35     /**
36      * Is not supposed to return null, but that is fine for layoutlib.
37      */
getServiceOrThrow(String name)38     public static IBinder getServiceOrThrow(String name) throws ServiceNotFoundException {
39         if (Context.UI_MODE_SERVICE.equals(name)) {
40             // Avoid exception in constructor of UiModeManager
41             return null;
42         }
43         return null;
44     }
45 
46     /**
47      * Place a new @a service called @a name into the service
48      * manager.
49      *
50      * @param name the name of the new service
51      * @param service the service object
52      */
addService(String name, IBinder service)53     public static void addService(String name, IBinder service) {
54         // pass
55     }
56 
57     /**
58      * Retrieve an existing service called @a name from the
59      * service manager.  Non-blocking.
60      */
checkService(String name)61     public static IBinder checkService(String name) {
62         return null;
63     }
64 
65     /**
66      * Return a list of all currently running services.
67      * @return an array of all currently running services, or <code>null</code> in
68      * case of an exception
69      */
listServices()70     public static String[] listServices() {
71         // actual implementation returns null sometimes, so it's ok
72         // to return null instead of an empty list.
73         return null;
74     }
75 
76     /**
77      * This is only intended to be called when the process is first being brought
78      * up and bound by the activity manager. There is only one thread in the process
79      * at that time, so no locking is done.
80      *
81      * @param cache the cache of service references
82      * @hide
83      */
initServiceCache(Map<String, IBinder> cache)84     public static void initServiceCache(Map<String, IBinder> cache) {
85         // pass
86     }
87 
88     /**
89      * Exception thrown when no service published for given name. This might be
90      * thrown early during boot before certain services have published
91      * themselves.
92      *
93      * @hide
94      */
95     public static class ServiceNotFoundException extends Exception {
96         // identical to the original implementation
ServiceNotFoundException(String name)97         public ServiceNotFoundException(String name) {
98             super("No service published for: " + name);
99         }
100     }
101 }
102