Vitaly Buka | cad20f0 | 2015-10-16 17:27:15 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 14 | |
| 15 | #ifndef BUFFET_MANAGER_H_ |
| 16 | #define BUFFET_MANAGER_H_ |
| 17 | |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 18 | #include <memory> |
Vitaly Buka | da2312c | 2015-06-23 20:11:36 -0700 | [diff] [blame] | 19 | #include <set> |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 20 | #include <string> |
Alex Vakulenko | acec6aa | 2015-04-20 11:00:54 -0700 | [diff] [blame] | 21 | #include <vector> |
Alex Vakulenko | 24aa122 | 2014-05-12 15:55:25 -0700 | [diff] [blame] | 22 | |
Christopher Wiley | 357deca | 2015-02-07 18:29:32 -0800 | [diff] [blame] | 23 | #include <base/files/file_path.h> |
Alex Vakulenko | 274226b | 2014-09-04 08:59:43 -0700 | [diff] [blame] | 24 | #include <base/macros.h> |
Christopher Wiley | d71774f | 2014-05-07 09:58:45 -0700 | [diff] [blame] | 25 | #include <base/memory/weak_ptr.h> |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 26 | #include <base/values.h> |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 27 | #include <brillo/dbus/async_event_sequencer.h> |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 28 | #include <brillo/errors/error.h> |
Alex Vakulenko | 0371fea | 2016-01-07 14:46:25 -0800 | [diff] [blame] | 29 | #include <nativepower/power_manager_client.h> |
Vitaly Buka | e2713ac | 2015-08-03 13:50:01 -0700 | [diff] [blame] | 30 | #include <weave/device.h> |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 31 | |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 32 | #include "android/weave/BnWeaveServiceManager.h" |
| 33 | #include "buffet/binder_weave_service.h" |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame] | 34 | #include "buffet/buffet_config.h" |
Christopher Wiley | 1aa980e | 2014-08-11 10:51:20 -0700 | [diff] [blame] | 35 | |
Vitaly Buka | 3b08631 | 2015-07-09 14:59:23 -0700 | [diff] [blame] | 36 | namespace buffet { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 37 | |
Robert Ginda | f86123d | 2015-09-11 16:10:43 -0700 | [diff] [blame] | 38 | class BluetoothClient; |
Vitaly Buka | 00882b7 | 2015-08-06 00:32:11 -0700 | [diff] [blame] | 39 | class HttpTransportClient; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 40 | class MdnsClient; |
Peter Qiu | 786a906 | 2015-10-02 11:45:01 -0700 | [diff] [blame] | 41 | class ShillClient; |
Alex Vakulenko | 1642bec | 2015-08-19 09:34:58 -0700 | [diff] [blame] | 42 | class WebServClient; |
Vitaly Buka | a0305d3 | 2015-07-27 16:08:51 -0700 | [diff] [blame] | 43 | |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 44 | // The Manager is responsible for global state of Buffet. It exposes |
| 45 | // interfaces which affect the entire device such as device registration and |
| 46 | // device state. |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 47 | class Manager final : public android::weave::BnWeaveServiceManager { |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 48 | public: |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame] | 49 | struct Options { |
| 50 | bool xmpp_enabled = true; |
| 51 | bool disable_privet = false; |
| 52 | bool enable_ping = false; |
Alex Vakulenko | 2915a7b | 2015-10-07 17:04:00 -0700 | [diff] [blame] | 53 | std::set<std::string> device_whitelist; |
| 54 | |
| 55 | BuffetConfig::Options config_options; |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 58 | Manager(const Options& options, const scoped_refptr<dbus::Bus>& bus); |
| 59 | ~Manager() override; |
Alex Vakulenko | ecf961a | 2014-10-28 13:50:16 -0700 | [diff] [blame] | 60 | |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 61 | void Start(brillo::dbus_utils::AsyncEventSequencer* sequencer); |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 62 | void Stop(); |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 63 | |
| 64 | private: |
Alex Vakulenko | 4170585 | 2015-10-13 10:12:06 -0700 | [diff] [blame] | 65 | void RestartWeave(brillo::dbus_utils::AsyncEventSequencer* sequencer); |
Alex Vakulenko | be39e93 | 2015-10-09 08:10:36 -0700 | [diff] [blame] | 66 | void CreateDevice(); |
Alex Vakulenko | 2915a7b | 2015-10-07 17:04:00 -0700 | [diff] [blame] | 67 | |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 68 | // Binder methods for IWeaveServiceManager: |
| 69 | using WeaveServiceManagerNotificationListener = |
| 70 | android::sp<android::weave::IWeaveServiceManagerNotificationListener>; |
| 71 | android::binder::Status connect( |
| 72 | const android::sp<android::weave::IWeaveClient>& client) override; |
| 73 | android::binder::Status registerNotificationListener( |
| 74 | const WeaveServiceManagerNotificationListener& listener) override; |
| 75 | android::binder::Status getDeviceId(android::String16* id) override; |
| 76 | android::binder::Status getCloudId(android::String16* id) override; |
| 77 | android::binder::Status getDeviceName(android::String16* name) override; |
| 78 | android::binder::Status getDeviceDescription( |
| 79 | android::String16* description) override; |
| 80 | android::binder::Status getDeviceLocation( |
| 81 | android::String16* location) override; |
| 82 | android::binder::Status getOemName(android::String16* name) override; |
| 83 | android::binder::Status getModelName(android::String16* name) override; |
| 84 | android::binder::Status getModelId(android::String16* id) override; |
| 85 | android::binder::Status getPairingSessionId(android::String16* id) override; |
| 86 | android::binder::Status getPairingMode(android::String16* mode) override; |
| 87 | android::binder::Status getPairingCode(android::String16* code) override; |
| 88 | android::binder::Status getState(android::String16* state) override; |
| 89 | android::binder::Status getTraits(android::String16* traits) override; |
| 90 | android::binder::Status getComponents(android::String16* components) override; |
Vitaly Buka | 84fd6dd | 2015-06-09 17:22:18 -0700 | [diff] [blame] | 91 | |
Alex Vakulenko | 14b3e6e | 2015-12-10 10:01:36 -0800 | [diff] [blame] | 92 | void OnTraitDefsChanged(); |
| 93 | void OnComponentTreeChanged(); |
Alex Vakulenko | 0022b75 | 2015-10-02 11:09:59 -0700 | [diff] [blame] | 94 | void OnGcdStateChanged(weave::GcdState state); |
Vitaly Buka | 00b8349 | 2015-07-20 00:37:48 -0700 | [diff] [blame] | 95 | void OnConfigChanged(const weave::Settings& settings); |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 96 | void OnPairingStart(const std::string& session_id, |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 97 | weave::PairingType pairing_type, |
Vitaly Buka | 7b3ba79 | 2015-06-09 17:01:54 -0700 | [diff] [blame] | 98 | const std::vector<uint8_t>& code); |
| 99 | void OnPairingEnd(const std::string& session_id); |
Christopher Wiley | 2f77293 | 2015-02-15 15:42:04 -0800 | [diff] [blame] | 100 | |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 101 | void CreateServicesForClients(); |
| 102 | void OnClientDisconnected( |
| 103 | const android::sp<android::weave::IWeaveClient>& client); |
| 104 | void OnNotificationListenerDestroyed( |
| 105 | const WeaveServiceManagerNotificationListener& notification_listener); |
| 106 | void NotifyServiceManagerChange(const std::vector<int>& notification_ids); |
Alex Vakulenko | 0371fea | 2016-01-07 14:46:25 -0800 | [diff] [blame] | 107 | void OnRebootDevice(const std::weak_ptr<weave::Command>& cmd); |
| 108 | void RebootDeviceNow(); |
Alex Vakulenko | 94f8eba | 2015-10-14 08:52:45 -0700 | [diff] [blame] | 109 | |
Alex Vakulenko | 2915a7b | 2015-10-07 17:04:00 -0700 | [diff] [blame] | 110 | Options options_; |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 111 | scoped_refptr<dbus::Bus> bus_; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 112 | |
Vitaly Buka | e74c872 | 2015-08-13 00:33:00 -0700 | [diff] [blame] | 113 | class TaskRunner; |
| 114 | std::unique_ptr<TaskRunner> task_runner_; |
Robert Ginda | f86123d | 2015-09-11 16:10:43 -0700 | [diff] [blame] | 115 | std::unique_ptr<BluetoothClient> bluetooth_client_; |
Alex Vakulenko | 2915a7b | 2015-10-07 17:04:00 -0700 | [diff] [blame] | 116 | std::unique_ptr<BuffetConfig> config_; |
Vitaly Buka | 00882b7 | 2015-08-06 00:32:11 -0700 | [diff] [blame] | 117 | std::unique_ptr<HttpTransportClient> http_client_; |
Peter Qiu | 786a906 | 2015-10-02 11:45:01 -0700 | [diff] [blame] | 118 | std::unique_ptr<ShillClient> shill_client_; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 119 | std::unique_ptr<MdnsClient> mdns_client_; |
Alex Vakulenko | 1642bec | 2015-08-19 09:34:58 -0700 | [diff] [blame] | 120 | std::unique_ptr<WebServClient> web_serv_client_; |
Vitaly Buka | 0c6dcd2 | 2015-07-10 00:12:25 -0700 | [diff] [blame] | 121 | std::unique_ptr<weave::Device> device_; |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 122 | |
| 123 | std::vector<android::sp<android::weave::IWeaveClient>> pending_clients_; |
| 124 | std::map<android::sp<android::weave::IWeaveClient>, |
| 125 | android::sp<BinderWeaveService>> services_; |
| 126 | std::set<WeaveServiceManagerNotificationListener> notification_listeners_; |
Alex Vakulenko | 0371fea | 2016-01-07 14:46:25 -0800 | [diff] [blame] | 127 | android::PowerManagerClient power_manager_client_; |
Alex Vakulenko | ae29f7d | 2015-12-21 16:30:37 -0800 | [diff] [blame] | 128 | |
| 129 | // State properties. |
| 130 | std::string cloud_id_; |
| 131 | std::string device_id_; |
| 132 | std::string device_name_; |
| 133 | std::string device_description_; |
| 134 | std::string device_location_; |
| 135 | std::string oem_name_; |
| 136 | std::string model_name_; |
| 137 | std::string model_id_; |
| 138 | std::string pairing_session_id_; |
| 139 | std::string pairing_mode_; |
| 140 | std::string pairing_code_; |
| 141 | std::string state_; |
Alex Vakulenko | f3d77e5 | 2014-04-15 11:36:32 -0700 | [diff] [blame] | 142 | |
Vitaly Buka | e43871f | 2015-05-11 15:41:33 -0700 | [diff] [blame] | 143 | base::WeakPtrFactory<Manager> weak_ptr_factory_{this}; |
Christopher Wiley | 4b5f04c | 2014-03-27 14:45:37 -0700 | [diff] [blame] | 144 | DISALLOW_COPY_AND_ASSIGN(Manager); |
| 145 | }; |
| 146 | |
| 147 | } // namespace buffet |
| 148 | |
| 149 | #endif // BUFFET_MANAGER_H_ |