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 21 #include <binder/IInterface.h> 22 #include <binder/IPermissionController.h> 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, 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 65 sp<IServiceManager> defaultServiceManager(); 66 67 template<typename INTERFACE> 68 status_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 78 bool checkCallingPermission(const String16& permission); 79 bool checkCallingPermission(const String16& permission, 80 int32_t* outPid, int32_t* outUid); 81 bool checkPermission(const String16& permission, pid_t pid, uid_t uid); 82 83 84 // ---------------------------------------------------------------------- 85 86 class BnServiceManager : public BnInterface<IServiceManager> 87 { 88 public: 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 101