Properly handle handler registering and unregistering
In addition to now supporting unregistering, we now correctly support
multiple handlers under DBus, and correctly send initial events under
binder.
TEST=Verified update_engine_client still works as expected
Bug: None
Change-Id: I60955d4d9ca61dfe7857b9fc78f77fa4292ed218
diff --git a/client_library/client_binder.cc b/client_library/client_binder.cc
index 969c5e9..6993be1 100644
--- a/client_library/client_binder.cc
+++ b/client_library/client_binder.cc
@@ -154,9 +154,38 @@
}
handlers_.push_back(handler);
+
+ int64_t last_checked_time;
+ double progress;
+ UpdateStatus update_status;
+ string new_version;
+ int64_t new_size;
+
+ if (!GetStatus(&last_checked_time, &progress, &update_status,
+ &new_version, &new_size)) {
+ handler->IPCError("Could not get status from binder service");
+ }
+
+ handler->HandleStatusUpdate(last_checked_time, progress, update_status,
+ new_version, new_size);
+
return true;
}
+bool BinderUpdateEngineClient::UnregisterStatusUpdateHandler(
+ StatusUpdateHandler* handler) {
+ auto it = handlers_.begin();
+
+ for (; *it != handler && it != handlers_.end(); it++);
+
+ if (it != handlers_.end()) {
+ handlers_.erase(it);
+ return true;
+ }
+
+ return false;
+}
+
bool BinderUpdateEngineClient::SetTargetChannel(const string& in_target_channel,
bool allow_powerwash) {
return service_->SetChannel(String16{in_target_channel.c_str()},