The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/IInterface.h> |
| 22 | #include <binder/IPermissionController.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <utils/Vector.h> |
| 24 | #include <utils/String16.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | // ---------------------------------------------------------------------- |
| 29 | |
| 30 | class IServiceManager : public IInterface |
| 31 | { |
| 32 | public: |
| 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 Hackborn | a94f129 | 2012-02-09 16:12:18 -0800 | [diff] [blame] | 50 | const sp<IBinder>& service, |
| 51 | bool allowIsolated = false) = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
| 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 | |
| 66 | sp<IServiceManager> defaultServiceManager(); |
| 67 | |
| 68 | template<typename INTERFACE> |
| 69 | status_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 | |
| 79 | bool checkCallingPermission(const String16& permission); |
| 80 | bool checkCallingPermission(const String16& permission, |
| 81 | int32_t* outPid, int32_t* outUid); |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 82 | bool checkPermission(const String16& permission, pid_t pid, uid_t uid); |
| 83 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
| 85 | // ---------------------------------------------------------------------- |
| 86 | |
| 87 | class BnServiceManager : public BnInterface<IServiceManager> |
| 88 | { |
| 89 | public: |
| 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 | |