1 // 2 // Copyright (C) 2015 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 #ifndef SHILL_DBUS_CHROMEOS_MANAGER_DBUS_ADAPTOR_H_ 18 #define SHILL_DBUS_CHROMEOS_MANAGER_DBUS_ADAPTOR_H_ 19 20 #include <map> 21 #include <string> 22 #include <vector> 23 24 #include <base/macros.h> 25 #include <gtest/gtest_prod.h> // for FRIEND_TEST 26 27 #include "dbus_bindings/org.chromium.flimflam.Manager.h" 28 #include "shill/adaptor_interfaces.h" 29 #include "shill/dbus/chromeos_dbus_adaptor.h" 30 #include "shill/dbus/chromeos_dbus_service_watcher.h" 31 32 namespace shill { 33 34 class DBusServiceWatcherFactory; 35 class Manager; 36 37 // Subclass of DBusAdaptor for Manager objects 38 // There is a 1:1 mapping between Manager and ChromeosManagerDBusAdaptor 39 // instances. Furthermore, the Manager owns the ChromeosManagerDBusAdaptor 40 // and manages its lifetime, so we're OK with ChromeosManagerDBusAdaptor 41 // having a bare pointer to its owner manager. 42 class ChromeosManagerDBusAdaptor 43 : public org::chromium::flimflam::ManagerAdaptor, 44 public org::chromium::flimflam::ManagerInterface, 45 public ChromeosDBusAdaptor, 46 public ManagerAdaptorInterface { 47 public: 48 static const char kPath[]; 49 50 ChromeosManagerDBusAdaptor(const scoped_refptr<dbus::Bus>& adaptor_bus, 51 const scoped_refptr<dbus::Bus> proxy_bus, 52 Manager* manager); 53 ~ChromeosManagerDBusAdaptor() override; 54 55 // Implementation of ManagerAdaptorInterface. 56 void RegisterAsync( 57 const base::Callback<void(bool)>& completion_callback) override; 58 const std::string& GetRpcIdentifier() override { return dbus_path().value(); } 59 void EmitBoolChanged(const std::string& name, bool value) override; 60 void EmitUintChanged(const std::string& name, uint32_t value) override; 61 void EmitIntChanged(const std::string& name, int value) override; 62 void EmitStringChanged(const std::string& name, 63 const std::string& value) override; 64 void EmitStringsChanged(const std::string& name, 65 const std::vector<std::string>& value) override; 66 void EmitRpcIdentifierChanged( 67 const std::string& name, const std::string& value) override; 68 void EmitRpcIdentifierArrayChanged( 69 const std::string& name, const std::vector<std::string>& value) override; 70 71 // Implementation of Manager_adaptor 72 bool GetProperties(brillo::ErrorPtr* error, 73 brillo::VariantDictionary* properties) override; 74 bool SetProperty(brillo::ErrorPtr* error, 75 const std::string& name, 76 const brillo::Any& value) override; 77 bool GetState(brillo::ErrorPtr* error, std::string* state) override; 78 bool CreateProfile(brillo::ErrorPtr* error, 79 const std::string& name, 80 dbus::ObjectPath* profile_path) override; 81 bool RemoveProfile(brillo::ErrorPtr* error, 82 const std::string& name) override; 83 bool PushProfile(brillo::ErrorPtr* error, 84 const std::string& name, 85 dbus::ObjectPath* profile_path) override; 86 bool InsertUserProfile(brillo::ErrorPtr* error, 87 const std::string& name, 88 const std::string& user_hash, 89 dbus::ObjectPath* profile_path) override; 90 bool PopProfile(brillo::ErrorPtr* error, const std::string& name) override; 91 bool PopAnyProfile(brillo::ErrorPtr* error) override; 92 bool PopAllUserProfiles(brillo::ErrorPtr* error) override; 93 bool RecheckPortal(brillo::ErrorPtr* error) override; 94 bool RequestScan(brillo::ErrorPtr* error, 95 const std::string& technology) override; 96 void EnableTechnology(DBusMethodResponsePtr<> response, 97 const std::string& technology_namer) override; 98 void DisableTechnology(DBusMethodResponsePtr<> response, 99 const std::string& technology_name) override; 100 bool GetService(brillo::ErrorPtr* error, 101 const brillo::VariantDictionary& args, 102 dbus::ObjectPath* service_path) override; 103 bool GetVPNService(brillo::ErrorPtr* error, 104 const brillo::VariantDictionary& args, 105 dbus::ObjectPath* service_path) override; 106 bool GetWifiService(brillo::ErrorPtr* error, 107 const brillo::VariantDictionary& args, 108 dbus::ObjectPath* service_path) override; 109 bool ConfigureService(brillo::ErrorPtr* error, 110 const brillo::VariantDictionary& args, 111 dbus::ObjectPath* service_path) override; 112 bool ConfigureServiceForProfile(brillo::ErrorPtr* error, 113 const dbus::ObjectPath& profile_rpcid, 114 const brillo::VariantDictionary& args, 115 dbus::ObjectPath* service_path) override; 116 bool FindMatchingService(brillo::ErrorPtr* error, 117 const brillo::VariantDictionary& args, 118 dbus::ObjectPath* service_path) override; 119 bool GetDebugLevel(brillo::ErrorPtr* error, 120 int32_t* level) override; 121 bool SetDebugLevel(brillo::ErrorPtr* error, int32_t level) override; 122 bool GetServiceOrder(brillo::ErrorPtr* error, std::string* order) override; 123 bool SetServiceOrder(brillo::ErrorPtr* error, 124 const std::string& order) override; 125 bool GetDebugTags(brillo::ErrorPtr* error, std::string* tags) override; 126 bool SetDebugTags(brillo::ErrorPtr* error, 127 const std::string& tags) override; 128 bool ListDebugTags(brillo::ErrorPtr* error, std::string* tags) override; 129 bool GetNetworksForGeolocation( 130 brillo::ErrorPtr* error, 131 brillo::VariantDictionary* networks) override; 132 void VerifyDestination(DBusMethodResponsePtr<bool> response, 133 const std::string& certificate, 134 const std::string& public_key, 135 const std::string& nonce, 136 const std::string& signed_data, 137 const std::string& destination_udn, 138 const std::string& hotspot_ssid, 139 const std::string& hotspot_bssid) override; 140 void VerifyAndEncryptCredentials(DBusMethodResponsePtr<std::string> response, 141 const std::string& certificate, 142 const std::string& public_key, 143 const std::string& nonce, 144 const std::string& signed_data, 145 const std::string& destination_udn, 146 const std::string& hotspot_ssid, 147 const std::string& hotspot_bssid, 148 const dbus::ObjectPath& network) override; 149 void VerifyAndEncryptData(DBusMethodResponsePtr<std::string> response, 150 const std::string& certificate, 151 const std::string& public_key, 152 const std::string& nonce, 153 const std::string& signed_data, 154 const std::string& destination_udn, 155 const std::string& hotspot_ssid, 156 const std::string& hotspot_bssid, 157 const std::string& data) override; 158 bool ConnectToBestServices(brillo::ErrorPtr* error) override; 159 bool CreateConnectivityReport(brillo::ErrorPtr* error) override; 160 bool ClaimInterface(brillo::ErrorPtr* error, 161 dbus::Message* message, 162 const std::string& claimer_name, 163 const std::string& interface_name) override; 164 bool ReleaseInterface(brillo::ErrorPtr* error, 165 dbus::Message* message, 166 const std::string& claimer_name, 167 const std::string& interface_name) override; 168 bool SetSchedScan(brillo::ErrorPtr* error, bool enable) override; 169 bool SetupApModeInterface(brillo::ErrorPtr* error, 170 dbus::Message* message, 171 std::string* out_interface_name) override; 172 bool SetupStationModeInterface(brillo::ErrorPtr* error, 173 std::string* out_interface_name) override; 174 175 private: 176 friend class ChromeosManagerDBusAdaptorTest; 177 // Tests that require access to |watcher_for_device_claimer_|. 178 FRIEND_TEST(ChromeosManagerDBusAdaptorTest, ClaimInterface); 179 FRIEND_TEST(ChromeosManagerDBusAdaptorTest, OnDeviceClaimerVanished); 180 FRIEND_TEST(ChromeosManagerDBusAdaptorTest, ReleaseInterface); 181 // Tests that require access to |watcher_for_ap_mode_setter_|. 182 FRIEND_TEST(ChromeosManagerDBusAdaptorTest, OnApModeSetterVanished); 183 FRIEND_TEST(ChromeosManagerDBusAdaptorTest, SetupApModeInterface); 184 FRIEND_TEST(ChromeosManagerDBusAdaptorTest, SetupStationModeInterface); 185 186 void OnApModeSetterVanished(); 187 void OnDeviceClaimerVanished(); 188 189 Manager* manager_; 190 // We store a pointer to |proxy_bus_| in order to create a 191 // ChromeosDBusServiceWatcher objects. 192 scoped_refptr<dbus::Bus> proxy_bus_; 193 DBusServiceWatcherFactory* dbus_service_watcher_factory_; 194 std::unique_ptr<ChromeosDBusServiceWatcher> watcher_for_device_claimer_; 195 std::unique_ptr<ChromeosDBusServiceWatcher> watcher_for_ap_mode_setter_; 196 197 DISALLOW_COPY_AND_ASSIGN(ChromeosManagerDBusAdaptor); 198 }; 199 200 } // namespace shill 201 202 #endif // SHILL_DBUS_CHROMEOS_MANAGER_DBUS_ADAPTOR_H_ 203