blob: 2c297d64fb510e7547204e97fe2807833028e990 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2005 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//
18#ifndef ANDROID_ISERVICE_MANAGER_H
19#define ANDROID_ISERVICE_MANAGER_H
20
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070021#include <binder/IInterface.h>
22#include <binder/IPermissionController.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Vector.h>
24#include <utils/String16.h>
25
26namespace android {
27
28// ----------------------------------------------------------------------
29
30class IServiceManager : public IInterface
31{
32public:
33 DECLARE_META_INTERFACE(ServiceManager);
34
35 /**
36 * Retrieve an existing service, blocking for a few seconds
37 * if it doesn't yet exist.
38 */
39 virtual sp<IBinder> getService( const String16& name) const = 0;
40
41 /**
42 * Retrieve an existing service, non-blocking.
43 */
44 virtual sp<IBinder> checkService( const String16& name) const = 0;
45
46 /**
47 * Register a service.
48 */
49 virtual status_t addService( const String16& name,
Dianne Hackborna94f1292012-02-09 16:12:18 -080050 const sp<IBinder>& service,
51 bool allowIsolated = false) = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052
53 /**
54 * Return list of all existing services.
55 */
56 virtual Vector<String16> listServices() = 0;
57
58 enum {
59 GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
60 CHECK_SERVICE_TRANSACTION,
61 ADD_SERVICE_TRANSACTION,
62 LIST_SERVICES_TRANSACTION,
63 };
64};
65
66sp<IServiceManager> defaultServiceManager();
67
68template<typename INTERFACE>
69status_t getService(const String16& name, sp<INTERFACE>* outService)
70{
71 const sp<IServiceManager> sm = defaultServiceManager();
72 if (sm != NULL) {
73 *outService = interface_cast<INTERFACE>(sm->getService(name));
74 if ((*outService) != NULL) return NO_ERROR;
75 }
76 return NAME_NOT_FOUND;
77}
78
79bool checkCallingPermission(const String16& permission);
80bool checkCallingPermission(const String16& permission,
81 int32_t* outPid, int32_t* outUid);
Mathias Agopian375f5632009-06-15 18:24:59 -070082bool checkPermission(const String16& permission, pid_t pid, uid_t uid);
83
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084
85// ----------------------------------------------------------------------
86
87class BnServiceManager : public BnInterface<IServiceManager>
88{
89public:
90 virtual status_t onTransact( uint32_t code,
91 const Parcel& data,
92 Parcel* reply,
93 uint32_t flags = 0);
94};
95
96// ----------------------------------------------------------------------
97
98}; // namespace android
99
100#endif // ANDROID_ISERVICE_MANAGER_H
101