Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 1 | #ifndef ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |
| 2 | #define ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 3 | |
| 4 | #include <android/hidl/manager/1.0/IServiceManager.h> |
| 5 | #include <hidl/Status.h> |
| 6 | #include <hidl/MQDescriptor.h> |
Steven Moreland | 6d7e500 | 2017-01-20 15:21:48 -0800 | [diff] [blame] | 7 | #include <map> |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 8 | |
Martijn Coenen | 7ce83be | 2017-04-07 16:19:32 -0700 | [diff] [blame^] | 9 | #include "AccessControl.h" |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 10 | #include "HidlService.h" |
| 11 | |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 12 | namespace android { |
| 13 | namespace hidl { |
| 14 | namespace manager { |
| 15 | namespace V1_0 { |
| 16 | namespace implementation { |
| 17 | |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 18 | using ::android::hardware::hidl_death_recipient; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 19 | using ::android::hardware::hidl_vec; |
| 20 | using ::android::hardware::hidl_string; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 21 | using ::android::hardware::Return; |
| 22 | using ::android::hardware::Void; |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 23 | using ::android::hidl::base::V1_0::IBase; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 24 | using ::android::hidl::manager::V1_0::IServiceManager; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 25 | using ::android::hidl::manager::V1_0::IServiceNotification; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 26 | using ::android::sp; |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 27 | using ::android::wp; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 28 | |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 29 | struct ServiceManager : public IServiceManager, hidl_death_recipient { |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 30 | // Methods from ::android::hidl::manager::V1_0::IServiceManager follow. |
Martijn Coenen | 7b02bf9 | 2017-01-02 15:17:58 +0100 | [diff] [blame] | 31 | Return<sp<IBase>> get(const hidl_string& fqName, |
Steven Moreland | 37aed80 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 32 | const hidl_string& name) override; |
Martijn Coenen | 1a5da1c | 2017-03-06 13:05:39 +0100 | [diff] [blame] | 33 | Return<bool> add(const hidl_string& name, |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 34 | const sp<IBase>& service) override; |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 35 | |
Steven Moreland | 37aed80 | 2017-04-06 09:16:42 -0700 | [diff] [blame] | 36 | Return<Transport> getTransport(const hidl_string& fqName, |
| 37 | const hidl_string& name); |
| 38 | |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame] | 39 | Return<void> list(list_cb _hidl_cb) override; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 40 | Return<void> listByInterface(const hidl_string& fqInstanceName, |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame] | 41 | listByInterface_cb _hidl_cb) override; |
| 42 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 43 | Return<bool> registerForNotifications(const hidl_string& fqName, |
| 44 | const hidl_string& name, |
| 45 | const sp<IServiceNotification>& callback) override; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 46 | |
Yifan Hong | 83c49f6 | 2017-01-25 14:16:34 -0800 | [diff] [blame] | 47 | Return<void> debugDump(debugDump_cb _cb) override; |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 48 | Return<void> registerPassthroughClient(const hidl_string &fqName, |
| 49 | const hidl_string &name, int32_t pid) override; |
Yifan Hong | 83c49f6 | 2017-01-25 14:16:34 -0800 | [diff] [blame] | 50 | |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 51 | virtual void serviceDied(uint64_t cookie, const wp<IBase>& who); |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 52 | private: |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 53 | bool remove(const wp<IBase>& who); |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 54 | bool removePackageListener(const wp<IBase>& who); |
| 55 | bool removeServiceListener(const wp<IBase>& who); |
Yifan Hong | 83c49f6 | 2017-01-25 14:16:34 -0800 | [diff] [blame] | 56 | size_t countExistingService() const; |
| 57 | void forEachExistingService(std::function<void(const HidlService *)> f) const; |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 58 | void forEachServiceEntry(std::function<void(const HidlService *)> f) const; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 59 | |
Steven Moreland | 6d7e500 | 2017-01-20 15:21:48 -0800 | [diff] [blame] | 60 | using InstanceMap = std::map< |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 61 | std::string, // instance name e.x. "manager" |
| 62 | std::unique_ptr<HidlService> |
| 63 | >; |
| 64 | |
| 65 | struct PackageInterfaceMap { |
| 66 | InstanceMap &getInstanceMap(); |
| 67 | const InstanceMap &getInstanceMap() const; |
| 68 | |
| 69 | /** |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 70 | * Finds a HidlService with the desired name. If none, |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 71 | * returns nullptr. HidlService::getService() might also be nullptr |
| 72 | * if there are registered IServiceNotification objects for it. Return |
| 73 | * value should be treated as a temporary reference. |
| 74 | */ |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 75 | HidlService *lookup( |
| 76 | const std::string &name); |
| 77 | const HidlService *lookup( |
| 78 | const std::string &name) const; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 79 | |
| 80 | void insertService(std::unique_ptr<HidlService> &&service); |
| 81 | |
| 82 | void addPackageListener(sp<IServiceNotification> listener); |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 83 | bool removePackageListener(const wp<IBase>& who); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 84 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 85 | void sendPackageRegistrationNotification( |
| 86 | const hidl_string &fqName, |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 87 | const hidl_string &instanceName); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 88 | |
Steven Moreland | 978473f | 2016-11-28 14:51:07 -0800 | [diff] [blame] | 89 | private: |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 90 | InstanceMap mInstanceMap{}; |
| 91 | |
| 92 | std::vector<sp<IServiceNotification>> mPackageListeners{}; |
| 93 | }; |
| 94 | |
Martijn Coenen | 7ce83be | 2017-04-07 16:19:32 -0700 | [diff] [blame^] | 95 | AccessControl mAcl; |
| 96 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Access to this map doesn't need to be locked, since hwservicemanager |
| 99 | * is single-threaded. |
| 100 | * |
| 101 | * e.x. |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 102 | * mServiceMap["android.hidl.manager@1.0::IServiceManager"]["manager"] |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 103 | * -> HidlService object |
| 104 | */ |
Steven Moreland | 6d7e500 | 2017-01-20 15:21:48 -0800 | [diff] [blame] | 105 | std::map< |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 106 | std::string, // package::interface e.x. "android.hidl.manager@1.0::IServiceManager" |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 107 | PackageInterfaceMap |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 108 | > mServiceMap; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } // namespace implementation |
| 112 | } // namespace V1_0 |
| 113 | } // namespace manager |
| 114 | } // namespace hidl |
| 115 | } // namespace android |
| 116 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 117 | #endif // ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |