diff options
author | Alex Vakulenko <avakulenko@google.com> | 2016-01-07 14:46:25 -0800 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-01-08 22:00:38 +0000 |
commit | 0371fea7a697a8c56ebaa2a3ab6d5e3770da341b (patch) | |
tree | 1fa2ea733bbc24a31025fca434aec63eddfdca16 | |
parent | c984451a701ab88a14ff5d911939e686f09d16a8 (diff) | |
download | weaved-0371fea7a697a8c56ebaa2a3ab6d5e3770da341b.tar.gz |
Add handling of base.reboot to weaved
Now that weaved can use binder on Brillo, add a command handler for
base.reboot command and delegate rebooting to native power manager
daemon.
BUG: 23759426
Change-Id: I88f18d953ae3072b154d6cc822d5064207316189
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | buffet/manager.cc | 22 | ||||
-rw-r--r-- | buffet/manager.h | 4 |
3 files changed, 27 insertions, 0 deletions
@@ -48,6 +48,7 @@ buffetSharedLibraries := \ libchrome-dbus \ libcutils \ libdbus \ + libnativepower \ libshill-client \ libutils \ libweave \ diff --git a/buffet/manager.cc b/buffet/manager.cc index 27610ec..1323850 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc @@ -60,6 +60,8 @@ namespace { const char kErrorDomain[] = "buffet"; const char kFileReadError[] = "file_read_error"; +const char kBaseComponent[] = "base"; +const char kRebootCommand[] = "base.reboot"; bool LoadFile(const base::FilePath& file_path, std::string* data, @@ -188,6 +190,7 @@ Manager::~Manager() { } void Manager::Start(AsyncEventSequencer* sequencer) { + power_manager_client_.Init(); RestartWeave(sequencer); } @@ -260,6 +263,10 @@ void Manager::CreateDevice() { base::Bind(&Manager::OnPairingStart, weak_ptr_factory_.GetWeakPtr()), base::Bind(&Manager::OnPairingEnd, weak_ptr_factory_.GetWeakPtr())); + device_->AddCommandHandler(kBaseComponent, kRebootCommand, + base::Bind(&Manager::OnRebootDevice, + weak_ptr_factory_.GetWeakPtr())); + CreateServicesForClients(); } @@ -339,6 +346,21 @@ void Manager::OnPairingEnd(const std::string& session_id) { NotifyServiceManagerChange(ids); } +void Manager::OnRebootDevice(const std::weak_ptr<weave::Command>& cmd) { + auto command = cmd.lock(); + if (!command || !command->Complete({}, nullptr)) + return; + + task_runner_->PostDelayedTask( + FROM_HERE, + base::Bind(&Manager::RebootDeviceNow, weak_ptr_factory_.GetWeakPtr()), + base::TimeDelta::FromSeconds(2)); +} + +void Manager::RebootDeviceNow() { + power_manager_client_.Reboot(android::RebootReason::DEFAULT); +} + android::binder::Status Manager::connect( const android::sp<android::weave::IWeaveClient>& client) { pending_clients_.push_back(client); diff --git a/buffet/manager.h b/buffet/manager.h index 18e1aea..e152e40 100644 --- a/buffet/manager.h +++ b/buffet/manager.h @@ -26,6 +26,7 @@ #include <base/values.h> #include <brillo/dbus/async_event_sequencer.h> #include <brillo/errors/error.h> +#include <nativepower/power_manager_client.h> #include <weave/device.h> #include "android/weave/BnWeaveServiceManager.h" @@ -103,6 +104,8 @@ class Manager final : public android::weave::BnWeaveServiceManager { void OnNotificationListenerDestroyed( const WeaveServiceManagerNotificationListener& notification_listener); void NotifyServiceManagerChange(const std::vector<int>& notification_ids); + void OnRebootDevice(const std::weak_ptr<weave::Command>& cmd); + void RebootDeviceNow(); Options options_; scoped_refptr<dbus::Bus> bus_; @@ -121,6 +124,7 @@ class Manager final : public android::weave::BnWeaveServiceManager { std::map<android::sp<android::weave::IWeaveClient>, android::sp<BinderWeaveService>> services_; std::set<WeaveServiceManagerNotificationListener> notification_listeners_; + android::PowerManagerClient power_manager_client_; // State properties. std::string cloud_id_; |