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, 51 bool allowIsolated = false) = 0; 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); 82 bool checkPermission(const String16& permission, pid_t pid, uid_t uid); 83 84 }; // namespace android 85 86 #endif // ANDROID_ISERVICE_MANAGER_H 87 88