blob: e5d8ea67de86f6deb1bfdc1ab83b35644f04a831 [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>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <utils/Vector.h>
23#include <utils/String16.h>
24
25namespace android {
26
27// ----------------------------------------------------------------------
28
29class IServiceManager : public IInterface
30{
31public:
Colin Cross17576de2016-09-26 13:07:06 -070032 DECLARE_META_INTERFACE(ServiceManager)
Vishnu Nair64afc022018-02-01 15:29:34 -080033 /**
Vishnu Nairf56042d2017-09-19 15:25:10 -070034 * Must match values in IServiceManager.java
35 */
Vishnu Nair64afc022018-02-01 15:29:34 -080036 /* Allows services to dump sections according to priorities. */
Vishnu Nair6a408532017-10-24 09:11:27 -070037 static const int DUMP_FLAG_PRIORITY_CRITICAL = 1 << 0;
38 static const int DUMP_FLAG_PRIORITY_HIGH = 1 << 1;
39 static const int DUMP_FLAG_PRIORITY_NORMAL = 1 << 2;
Vishnu Nair64afc022018-02-01 15:29:34 -080040 /**
41 * Services are by default registered with a DEFAULT dump priority. DEFAULT priority has the
42 * same priority as NORMAL priority but the services are not called with dump priority
43 * arguments.
44 */
45 static const int DUMP_FLAG_PRIORITY_DEFAULT = 1 << 3;
46 static const int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL |
47 DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT;
48 static const int DUMP_FLAG_PROTO = 1 << 4;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049
50 /**
51 * Retrieve an existing service, blocking for a few seconds
52 * if it doesn't yet exist.
53 */
54 virtual sp<IBinder> getService( const String16& name) const = 0;
55
56 /**
57 * Retrieve an existing service, non-blocking.
58 */
59 virtual sp<IBinder> checkService( const String16& name) const = 0;
60
61 /**
62 * Register a service.
63 */
Jiyong Parkb86c8662018-10-29 23:01:57 +090064 // NOLINTNEXTLINE(google-default-arguments)
Vishnu Nairf56042d2017-09-19 15:25:10 -070065 virtual status_t addService(const String16& name, const sp<IBinder>& service,
66 bool allowIsolated = false,
Vishnu Nair64afc022018-02-01 15:29:34 -080067 int dumpsysFlags = DUMP_FLAG_PRIORITY_DEFAULT) = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068
69 /**
70 * Return list of all existing services.
71 */
Jiyong Parkb86c8662018-10-29 23:01:57 +090072 // NOLINTNEXTLINE(google-default-arguments)
Vishnu Nair6a408532017-10-24 09:11:27 -070073 virtual Vector<String16> listServices(int dumpsysFlags = DUMP_FLAG_PRIORITY_ALL) = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074
75 enum {
76 GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
77 CHECK_SERVICE_TRANSACTION,
78 ADD_SERVICE_TRANSACTION,
79 LIST_SERVICES_TRANSACTION,
80 };
81};
82
83sp<IServiceManager> defaultServiceManager();
84
85template<typename INTERFACE>
86status_t getService(const String16& name, sp<INTERFACE>* outService)
87{
88 const sp<IServiceManager> sm = defaultServiceManager();
Yi Kong87d465c2018-07-24 01:14:06 -070089 if (sm != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090 *outService = interface_cast<INTERFACE>(sm->getService(name));
91 if ((*outService) != NULL) return NO_ERROR;
92 }
93 return NAME_NOT_FOUND;
94}
95
96bool checkCallingPermission(const String16& permission);
97bool checkCallingPermission(const String16& permission,
98 int32_t* outPid, int32_t* outUid);
Mathias Agopian375f5632009-06-15 18:24:59 -070099bool checkPermission(const String16& permission, pid_t pid, uid_t uid);
100
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101}; // namespace android
102
103#endif // ANDROID_ISERVICE_MANAGER_H
104