aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/usb-manager.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/usb-manager.cpp b/src/usb-manager.cpp
index 4fdfdc1..656b6a0 100644
--- a/src/usb-manager.cpp
+++ b/src/usb-manager.cpp
@@ -50,7 +50,7 @@ public:
});
m_greeter->is_active().changed().connect([this](bool /*is_active*/) {
- restart();
+ maybe_snap();
});
restart();
@@ -68,6 +68,7 @@ private:
// clear out old state
m_snap_connections.clear();
m_snap.reset();
+ m_req = decltype(m_req){};
m_adbd_client.reset();
}
@@ -75,30 +76,38 @@ private:
{
clear();
- // don't prompt in the greeter!
- if (m_greeter->is_active().get())
- return;
-
// set a new client
-g_message("creating a new adbd client");
m_adbd_client.reset(new GAdbdClient{m_socket_path});
m_adbd_client->on_pk_request().connect(
[this](const AdbdClient::PKRequest& req) {
- 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_debug("%s user responded! response %d, remember %d", G_STRLOC, int(response), int(remember_choice));
- req.respond(response);
- if (remember_choice && (response == AdbdClient::PKResponse::ALLOW))
- write_public_key(req.public_key);
- g_idle_add([](gpointer gself){static_cast<Impl*>(gself)->restart(); return G_SOURCE_REMOVE;}, this);
- }
- ));
+ g_debug("%s got pk request: %s", G_STRLOC, req.fingerprint.c_str());
+ m_req = req;
+ maybe_snap();
}
);
}
+ void maybe_snap()
+ {
+ // don't prompt in the greeter!
+ if (!m_req.public_key.empty() && !m_greeter->is_active().get())
+ snap();
+ }
+
+ void snap()
+ {
+ m_snap = std::make_shared<UsbSnap>(m_req.fingerprint);
+ m_snap_connections.insert((*m_snap).on_user_response().connect(
+ [this](AdbdClient::PKResponse response, bool remember_choice){
+ g_debug("%s user responded! response %d, remember %d", G_STRLOC, int(response), int(remember_choice));
+ m_req.respond(response);
+ if (remember_choice && (response == AdbdClient::PKResponse::ALLOW))
+ write_public_key(m_req.public_key);
+ g_idle_add([](gpointer gself){static_cast<Impl*>(gself)->restart(); return G_SOURCE_REMOVE;}, this);
+ }
+ ));
+ }
+
void write_public_key(const std::string& public_key)
{
g_debug("%s writing public key '%s' to '%s'", G_STRLOC, public_key.c_str(), m_public_keys_filename.c_str());
@@ -136,6 +145,7 @@ g_message("creating a new adbd client");
const std::shared_ptr<Greeter> m_greeter;
std::shared_ptr<GAdbdClient> m_adbd_client;
+ AdbdClient::PKRequest m_req;
std::shared_ptr<UsbSnap> m_snap;
std::set<core::ScopedConnection> m_snap_connections;
};