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