The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Artur Satayev | afdb23a | 2019-12-10 17:47:53 +0000 | [diff] [blame] | 19 | import android.compat.annotation.UnsupportedAppUsage; |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Native implementation of the service manager. Most clients will only |
Steven Moreland | 3feab1b | 2019-06-21 14:51:53 -0700 | [diff] [blame] | 23 | * care about asInterface(). |
| 24 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | * @hide |
| 26 | */ |
Steven Moreland | 3feab1b | 2019-06-21 14:51:53 -0700 | [diff] [blame] | 27 | public final class ServiceManagerNative { |
| 28 | private ServiceManagerNative() {} |
| 29 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Cast a Binder object into a service manager interface, generating |
| 32 | * a proxy if needed. |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 33 | * |
| 34 | * TODO: delete this method and have clients use |
| 35 | * IServiceManager.Stub.asInterface instead |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | */ |
Andrei Onea | dcb6773 | 2019-03-18 11:37:25 +0000 | [diff] [blame] | 37 | @UnsupportedAppUsage |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 38 | public static IServiceManager asInterface(IBinder obj) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | if (obj == null) { |
| 40 | return null; |
| 41 | } |
Vishnu Nair | 0576819 | 2017-09-19 15:25:38 -0700 | [diff] [blame] | 42 | |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 43 | // ServiceManager is never local |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | return new ServiceManagerProxy(obj); |
| 45 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 48 | // This class should be deleted and replaced with IServiceManager.Stub whenever |
| 49 | // mRemote is no longer used |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | class ServiceManagerProxy implements IServiceManager { |
| 51 | public ServiceManagerProxy(IBinder remote) { |
| 52 | mRemote = remote; |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 53 | mServiceManager = IServiceManager.Stub.asInterface(remote); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | } |
Vishnu Nair | 0576819 | 2017-09-19 15:25:38 -0700 | [diff] [blame] | 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | public IBinder asBinder() { |
| 57 | return mRemote; |
| 58 | } |
Vishnu Nair | 0576819 | 2017-09-19 15:25:38 -0700 | [diff] [blame] | 59 | |
Andrei Onea | dcb6773 | 2019-03-18 11:37:25 +0000 | [diff] [blame] | 60 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | public IBinder getService(String name) throws RemoteException { |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 62 | // Same as checkService (old versions of servicemanager had both methods). |
| 63 | return mServiceManager.checkService(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | public IBinder checkService(String name) throws RemoteException { |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 67 | return mServiceManager.checkService(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Vishnu Nair | 0576819 | 2017-09-19 15:25:38 -0700 | [diff] [blame] | 70 | public void addService(String name, IBinder service, boolean allowIsolated, int dumpPriority) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | throws RemoteException { |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 72 | mServiceManager.addService(name, service, allowIsolated, dumpPriority); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | } |
Vishnu Nair | 0576819 | 2017-09-19 15:25:38 -0700 | [diff] [blame] | 74 | |
| 75 | public String[] listServices(int dumpPriority) throws RemoteException { |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 76 | return mServiceManager.listServices(dumpPriority); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Steven Moreland | 3ffad04 | 2019-08-27 17:58:17 -0700 | [diff] [blame] | 79 | public void registerForNotifications(String name, IServiceCallback cb) |
| 80 | throws RemoteException { |
| 81 | throw new RemoteException(); |
| 82 | } |
| 83 | |
| 84 | public void unregisterForNotifications(String name, IServiceCallback cb) |
| 85 | throws RemoteException { |
| 86 | throw new RemoteException(); |
| 87 | } |
| 88 | |
Steven Moreland | 2cd23b6 | 2019-10-28 11:16:17 -0700 | [diff] [blame] | 89 | public boolean isDeclared(String name) throws RemoteException { |
| 90 | throw new RemoteException(); |
| 91 | } |
| 92 | |
Jon Spivack | 1c84e7f | 2019-11-26 16:58:20 -0800 | [diff] [blame] | 93 | public void registerClientCallback(String name, IBinder service, IClientCallback cb) |
| 94 | throws RemoteException { |
| 95 | throw new RemoteException(); |
| 96 | } |
| 97 | |
| 98 | public void tryUnregisterService(String name, IBinder service) throws RemoteException { |
| 99 | throw new RemoteException(); |
| 100 | } |
| 101 | |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Same as mServiceManager but used by apps. |
| 104 | * |
| 105 | * Once this can be removed, ServiceManagerProxy should be removed entirely. |
| 106 | */ |
Andrei Onea | dcb6773 | 2019-03-18 11:37:25 +0000 | [diff] [blame] | 107 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | private IBinder mRemote; |
Steven Moreland | e17de65 | 2019-06-21 19:10:59 -0700 | [diff] [blame] | 109 | |
| 110 | private IServiceManager mServiceManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | } |