blob: 124b6c6f73779d6abbd96f7adbdc5c0e46ec0fbe [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.os;
18
Andrei Oneadcb67732019-03-18 11:37:25 +000019import android.annotation.UnsupportedAppUsage;
Dianne Hackborna53de062012-05-08 18:53:51 -070020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021/**
22 * Native implementation of the service manager. Most clients will only
Steven Moreland3feab1b2019-06-21 14:51:53 -070023 * care about asInterface().
24 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025 * @hide
26 */
Steven Moreland3feab1b2019-06-21 14:51:53 -070027public final class ServiceManagerNative {
28 private ServiceManagerNative() {}
29
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 /**
31 * Cast a Binder object into a service manager interface, generating
32 * a proxy if needed.
Steven Morelande17de652019-06-21 19:10:59 -070033 *
34 * TODO: delete this method and have clients use
35 * IServiceManager.Stub.asInterface instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 */
Andrei Oneadcb67732019-03-18 11:37:25 +000037 @UnsupportedAppUsage
Steven Morelande17de652019-06-21 19:10:59 -070038 public static IServiceManager asInterface(IBinder obj) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 if (obj == null) {
40 return null;
41 }
Vishnu Nair05768192017-09-19 15:25:38 -070042
Steven Morelande17de652019-06-21 19:10:59 -070043 // ServiceManager is never local
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 return new ServiceManagerProxy(obj);
45 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046}
47
Steven Morelande17de652019-06-21 19:10:59 -070048// This class should be deleted and replaced with IServiceManager.Stub whenever
49// mRemote is no longer used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050class ServiceManagerProxy implements IServiceManager {
51 public ServiceManagerProxy(IBinder remote) {
52 mRemote = remote;
Steven Morelande17de652019-06-21 19:10:59 -070053 mServiceManager = IServiceManager.Stub.asInterface(remote);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 }
Vishnu Nair05768192017-09-19 15:25:38 -070055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 public IBinder asBinder() {
57 return mRemote;
58 }
Vishnu Nair05768192017-09-19 15:25:38 -070059
Andrei Oneadcb67732019-03-18 11:37:25 +000060 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 public IBinder getService(String name) throws RemoteException {
Steven Morelande17de652019-06-21 19:10:59 -070062 // Same as checkService (old versions of servicemanager had both methods).
63 return mServiceManager.checkService(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 }
65
66 public IBinder checkService(String name) throws RemoteException {
Steven Morelande17de652019-06-21 19:10:59 -070067 return mServiceManager.checkService(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 }
69
Vishnu Nair05768192017-09-19 15:25:38 -070070 public void addService(String name, IBinder service, boolean allowIsolated, int dumpPriority)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 throws RemoteException {
Steven Morelande17de652019-06-21 19:10:59 -070072 mServiceManager.addService(name, service, allowIsolated, dumpPriority);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 }
Vishnu Nair05768192017-09-19 15:25:38 -070074
75 public String[] listServices(int dumpPriority) throws RemoteException {
Steven Morelande17de652019-06-21 19:10:59 -070076 return mServiceManager.listServices(dumpPriority);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 }
78
Steven Moreland3ffad042019-08-27 17:58:17 -070079 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 Moreland2cd23b62019-10-28 11:16:17 -070089 public boolean isDeclared(String name) throws RemoteException {
90 throw new RemoteException();
91 }
92
Steven Morelande17de652019-06-21 19:10:59 -070093 /**
94 * Same as mServiceManager but used by apps.
95 *
96 * Once this can be removed, ServiceManagerProxy should be removed entirely.
97 */
Andrei Oneadcb67732019-03-18 11:37:25 +000098 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 private IBinder mRemote;
Steven Morelande17de652019-06-21 19:10:59 -0700100
101 private IServiceManager mServiceManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102}