blob: 78b03bde1462d407cfdf0ba33d5ce50e776e66f6 [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:
Colin Cross17576de2016-09-26 13:07:06 -070033 DECLARE_META_INTERFACE(ServiceManager)
Vishnu Nairf56042d2017-09-19 15:25:10 -070034 /*
35 * Must match values in IServiceManager.java
36 */
37 static const int DUMP_PRIORITY_CRITICAL = 1 << 0;
38 static const int DUMP_PRIORITY_HIGH = 1 << 1;
39 static const int DUMP_PRIORITY_NORMAL = 1 << 2;
40 static const int DUMP_PRIORITY_ALL =
41 DUMP_PRIORITY_CRITICAL | DUMP_PRIORITY_HIGH | DUMP_PRIORITY_NORMAL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43 /**
44 * Retrieve an existing service, blocking for a few seconds
45 * if it doesn't yet exist.
46 */
47 virtual sp<IBinder> getService( const String16& name) const = 0;
48
49 /**
50 * Retrieve an existing service, non-blocking.
51 */
52 virtual sp<IBinder> checkService( const String16& name) const = 0;
53
54 /**
55 * Register a service.
56 */
Vishnu Nairf56042d2017-09-19 15:25:10 -070057 virtual status_t addService(const String16& name, const sp<IBinder>& service,
58 bool allowIsolated = false,
59 int dumpsysPriority = DUMP_PRIORITY_NORMAL) = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060
61 /**
62 * Return list of all existing services.
63 */
Vishnu Nairf56042d2017-09-19 15:25:10 -070064 virtual Vector<String16> listServices(int dumpsysPriority = DUMP_PRIORITY_ALL) = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065
66 enum {
67 GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
68 CHECK_SERVICE_TRANSACTION,
69 ADD_SERVICE_TRANSACTION,
70 LIST_SERVICES_TRANSACTION,
71 };
72};
73
74sp<IServiceManager> defaultServiceManager();
75
76template<typename INTERFACE>
77status_t getService(const String16& name, sp<INTERFACE>* outService)
78{
79 const sp<IServiceManager> sm = defaultServiceManager();
80 if (sm != NULL) {
81 *outService = interface_cast<INTERFACE>(sm->getService(name));
82 if ((*outService) != NULL) return NO_ERROR;
83 }
84 return NAME_NOT_FOUND;
85}
86
87bool checkCallingPermission(const String16& permission);
88bool checkCallingPermission(const String16& permission,
89 int32_t* outPid, int32_t* outUid);
Mathias Agopian375f5632009-06-15 18:24:59 -070090bool checkPermission(const String16& permission, pid_t pid, uid_t uid);
91
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092}; // namespace android
93
94#endif // ANDROID_ISERVICE_MANAGER_H
95