Android: Implement the update attempter for Android.
This patch implements the update workflow for non-Brillo targets. Only
the applyPayload() method is implemented here with a minimal subset of
functionally implemented in it. This new class acts as the service
delegate, handling all the binder service method calls for non-Brillo
targets.
Bug: 25631949
TEST=FEATURES=test emerge-link update_engine
TEST=`mmma system/update_engine` on aosp_arm-eng and edison-eng
TEST=Deployed on a non-Brillo device and tested with update_engine_client
Change-Id: I678cd141633bc2c0920a09ef27a02d53682d5330
diff --git a/daemon_state_android.cc b/daemon_state_android.cc
index c1d9fcc..6a5aa9f 100644
--- a/daemon_state_android.cc
+++ b/daemon_state_android.cc
@@ -16,14 +16,59 @@
#include "update_engine/daemon_state_android.h"
+#include <base/logging.h>
+
+#include "update_engine/common/boot_control.h"
+#include "update_engine/common/boot_control_stub.h"
+#include "update_engine/common/hardware.h"
+#include "update_engine/common/prefs.h"
+#include "update_engine/update_attempter_android.h"
+
namespace chromeos_update_engine {
bool DaemonStateAndroid::Initialize() {
- // TODO(deymo): Implement the Android updater state.
+ boot_control_ = boot_control::CreateBootControl();
+ if (!boot_control_) {
+ LOG(WARNING) << "Unable to create BootControl instance, using stub "
+ << "instead. All update attempts will fail.";
+ boot_control_.reset(new BootControlStub());
+ }
+
+ hardware_ = hardware::CreateHardware();
+ if (!hardware_) {
+ LOG(ERROR) << "Error intializing the HardwareInterface.";
+ return false;
+ }
+
+ LOG_IF(INFO, !hardware_->IsNormalBootMode()) << "Booted in dev mode.";
+ LOG_IF(INFO, !hardware_->IsOfficialBuild()) << "Booted non-official build.";
+
+ // Initialize prefs.
+ base::FilePath non_volatile_path;
+ // TODO(deymo): Fall back to in-memory prefs if there's no physical directory
+ // available.
+ if (!hardware_->GetNonVolatileDirectory(&non_volatile_path)) {
+ LOG(ERROR) << "Failed to get a non-volatile directory.";
+ return false;
+ }
+ Prefs* prefs = new Prefs();
+ prefs_.reset(prefs);
+ if (!prefs->Init(non_volatile_path.Append(kPrefsSubDirectory))) {
+ LOG(ERROR) << "Failed to initialize preferences.";
+ return false;
+ }
+
+ // Initialize the UpdateAttempter before the UpdateManager.
+ update_attempter_.reset(new UpdateAttempterAndroid(
+ this, prefs_.get(), boot_control_.get(), hardware_.get()));
+ update_attempter_->Init();
+
return true;
}
bool DaemonStateAndroid::StartUpdater() {
+ // The DaemonState in Android is a passive daemon. It will only start applying
+ // an update when instructed to do so from the exposed binder API.
return true;
}
@@ -36,8 +81,7 @@
}
ServiceDelegateAndroidInterface* DaemonStateAndroid::service_delegate() {
- // TODO(deymo): Implement a service delegate and return it here.
- return nullptr;
+ return update_attempter_.get();
}
} // namespace chromeos_update_engine