blob: 24e9e992cc61ad737ce0ee35ac4fba06bd57bc89 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian07952722009-05-19 19:08:10 -070021#include <binder/IInterface.h>
22#include <binder/IPermissionController.h>
The Android Open Source Project9066cfe2009-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,
50 const sp<IBinder>& service) = 0;
51
52 /**
53 * Return list of all existing services.
54 */
55 virtual Vector<String16> listServices() = 0;
56
57 enum {
58 GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
59 CHECK_SERVICE_TRANSACTION,
60 ADD_SERVICE_TRANSACTION,
61 LIST_SERVICES_TRANSACTION,
62 };
63};
64
65sp<IServiceManager> defaultServiceManager();
66
67template<typename INTERFACE>
68status_t getService(const String16& name, sp<INTERFACE>* outService)
69{
70 const sp<IServiceManager> sm = defaultServiceManager();
71 if (sm != NULL) {
72 *outService = interface_cast<INTERFACE>(sm->getService(name));
73 if ((*outService) != NULL) return NO_ERROR;
74 }
75 return NAME_NOT_FOUND;
76}
77
78bool checkCallingPermission(const String16& permission);
79bool checkCallingPermission(const String16& permission,
80 int32_t* outPid, int32_t* outUid);
Mathias Agopian151e8592009-06-15 18:24:59 -070081bool checkPermission(const String16& permission, pid_t pid, uid_t uid);
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
84// ----------------------------------------------------------------------
85
86class BnServiceManager : public BnInterface<IServiceManager>
87{
88public:
89 virtual status_t onTransact( uint32_t code,
90 const Parcel& data,
91 Parcel* reply,
92 uint32_t flags = 0);
93};
94
95// ----------------------------------------------------------------------
96
97}; // namespace android
98
99#endif // ANDROID_ISERVICE_MANAGER_H
100