diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usb-manager.cpp | 44 | ||||
-rw-r--r-- | src/usb-snap.cpp | 1 |
2 files changed, 26 insertions, 19 deletions
diff --git a/src/usb-manager.cpp b/src/usb-manager.cpp index 840a04b..f5957d9 100644 --- a/src/usb-manager.cpp +++ b/src/usb-manager.cpp @@ -39,29 +39,40 @@ public: const std::string& public_keys_filename, const std::shared_ptr<UsbMonitor>& usb_monitor ): - m_adbd_client{std::make_shared<GAdbdClient>(socket_path)}, + m_socket_path{socket_path}, m_public_keys_filename{public_keys_filename}, m_usb_monitor{usb_monitor} { m_usb_monitor->on_usb_disconnected().connect([this](const std::string& /*usb_name*/) { - m_snap.reset(); + restart(); }); + restart(); + } + + ~Impl() =default; + +private: + + void restart() + { + // clear out old state + m_snap_connections.clear(); + m_snap.reset(); + m_adbd_client.reset(); + + // add a new client + m_adbd_client.reset(new GAdbdClient{m_socket_path}); m_adbd_client->on_pk_request().connect( - [this](const AdbdClient::PKRequest& req){ + [this](const AdbdClient::PKRequest& req) { - m_snap.reset(new UsbSnap(req.fingerprint), - [this](UsbSnap* snap){ - m_snap_connections.clear(); - delete snap; - } - ); + g_debug("%s got pk request", G_STRLOC); + m_snap = std::make_shared<UsbSnap>(req.fingerprint); m_snap_connections.insert((*m_snap).on_user_response().connect( [this,req](AdbdClient::PKResponse response, bool remember_choice){ - g_message("%s user responded! response %d, remember %d", G_STRLOC, int(response), int(remember_choice)); + g_debug("%s user responded! response %d, remember %d", G_STRLOC, int(response), int(remember_choice)); req.respond(response); - g_message("%s", G_STRLOC); if (remember_choice && (response == AdbdClient::PKResponse::ALLOW)) write_public_key(req.public_key); g_idle_add([](gpointer gself){static_cast<Impl*>(gself)->m_snap.reset(); return G_SOURCE_REMOVE;}, this); @@ -69,16 +80,11 @@ public: )); } ); - } - ~Impl() =default; - -private: - void write_public_key(const std::string& public_key) { - g_message("%s writing public key '%s' to '%s'", G_STRLOC, public_key.c_str(), m_public_keys_filename.c_str()); + g_debug("%s writing public key '%s' to '%s'", G_STRLOC, public_key.c_str(), m_public_keys_filename.c_str()); // confirm the directory exists auto dirname = g_path_get_dirname(m_public_keys_filename.c_str()); @@ -107,10 +113,12 @@ private: close(fd); } - std::shared_ptr<GAdbdClient> m_adbd_client; + const std::string m_socket_path; const std::string m_public_keys_filename; + std::shared_ptr<UsbMonitor> m_usb_monitor; + std::shared_ptr<GAdbdClient> m_adbd_client; std::shared_ptr<UsbSnap> m_snap; std::set<core::ScopedConnection> m_snap_connections; }; diff --git a/src/usb-snap.cpp b/src/usb-snap.cpp index 349d80e..41c78c6 100644 --- a/src/usb-snap.cpp +++ b/src/usb-snap.cpp @@ -148,7 +148,6 @@ private: { GError* error {}; auto reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION(obus), res, &error); -g_message("%s got notify response %s", G_STRLOC, g_variant_print(reply, true)); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) g_warning("UsbSnap: Error calling Notify: %s", error->message); |