• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.car.builtin.os;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.RequiresApi;
22 import android.annotation.SystemApi;
23 import android.car.builtin.annotation.AddedIn;
24 import android.car.builtin.annotation.PlatformVersion;
25 import android.os.Build;
26 import android.os.IBinder;
27 import android.os.ServiceManager;
28 
29 /**
30  * Helper class for {@code ServiceManager} API
31  *
32  * @hide
33  */
34 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
35 public final class ServiceManagerHelper {
36 
ServiceManagerHelper()37     private ServiceManagerHelper()  {
38         throw new UnsupportedOperationException();
39     }
40 
41     /** Check {@link ServiceManager#getService(String)} */
42     @Nullable
43     @AddedIn(PlatformVersion.TIRAMISU_0)
getService(@onNull String name)44     public static IBinder getService(@NonNull String name) {
45         return ServiceManager.getService(name);
46     }
47 
48     /** Check {@link ServiceManager#checkService(String)} */
49     @Nullable
50     @AddedIn(PlatformVersion.TIRAMISU_0)
checkService(@onNull String name)51     public static IBinder checkService(@NonNull String name) {
52         return ServiceManager.checkService(name);
53     }
54 
55     /** Check {@link ServiceManager#waitForDeclaredService(String)} */
56     @Nullable
57     @AddedIn(PlatformVersion.TIRAMISU_0)
waitForDeclaredService(@onNull String name)58     public static IBinder waitForDeclaredService(@NonNull String name) {
59         return ServiceManager.waitForDeclaredService(name);
60     }
61 
62     /** Check {@link ServiceManager#addService(String, IBinder)} */
63     @AddedIn(PlatformVersion.TIRAMISU_0)
addService(@onNull String name, @NonNull IBinder service)64     public static void addService(@NonNull String name, @NonNull IBinder service) {
65         ServiceManager.addService(name, service);
66     }
67 
68     /** Check {@link ServiceManager#getDeclaredInstances(String)} */
69     @Nullable
70     @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
71     @AddedIn(PlatformVersion.UPSIDE_DOWN_CAKE_0)
getDeclaredInstances(@onNull String iface)72     public static String[] getDeclaredInstances(@NonNull String iface) {
73         return ServiceManager.getDeclaredInstances(iface);
74     }
75 }
76