123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include "update_engine/daemon.h"
- #include <sysexits.h>
- #include <base/bind.h>
- #include <base/location.h>
- #if USE_BINDER
- #include <binderwrapper/binder_wrapper.h>
- #endif
- #if USE_OMAHA
- #include "update_engine/real_system_state.h"
- #else
- #include "update_engine/daemon_state_android.h"
- #endif
- namespace chromeos_update_engine {
- int UpdateEngineDaemon::OnInit() {
-
-
- subprocess_.Init(this);
- int exit_code = Daemon::OnInit();
- if (exit_code != EX_OK)
- return exit_code;
- #if USE_BINDER
- android::BinderWrapper::Create();
- binder_watcher_.Init();
- #endif
- #if USE_OMAHA
-
-
-
-
- RealSystemState* real_system_state = new RealSystemState();
- daemon_state_.reset(real_system_state);
- LOG_IF(ERROR, !real_system_state->Initialize())
- << "Failed to initialize system state.";
- #else
- DaemonStateAndroid* daemon_state_android = new DaemonStateAndroid();
- daemon_state_.reset(daemon_state_android);
- LOG_IF(ERROR, !daemon_state_android->Initialize())
- << "Failed to initialize system state.";
- #endif
- #if USE_BINDER
-
- #if USE_OMAHA
- binder_service_ = new BinderUpdateEngineBrilloService{real_system_state};
- #else
- binder_service_ = new BinderUpdateEngineAndroidService{
- daemon_state_android->service_delegate()};
- #endif
- auto binder_wrapper = android::BinderWrapper::Get();
- if (!binder_wrapper->RegisterService(binder_service_->ServiceName(),
- binder_service_)) {
- LOG(ERROR) << "Failed to register binder service.";
- }
- daemon_state_->AddObserver(binder_service_.get());
- #endif
- #if USE_DBUS
-
- dbus_adaptor_.reset(new UpdateEngineAdaptor(real_system_state));
- daemon_state_->AddObserver(dbus_adaptor_.get());
- dbus_adaptor_->RegisterAsync(base::Bind(&UpdateEngineDaemon::OnDBusRegistered,
- base::Unretained(this)));
- LOG(INFO) << "Waiting for DBus object to be registered.";
- #else
- daemon_state_->StartUpdater();
- #endif
- return EX_OK;
- }
- #if USE_DBUS
- void UpdateEngineDaemon::OnDBusRegistered(bool succeeded) {
- if (!succeeded) {
- LOG(ERROR) << "Registering the UpdateEngineAdaptor";
- QuitWithExitCode(1);
- return;
- }
-
-
-
- if (!dbus_adaptor_->RequestOwnership()) {
- LOG(ERROR) << "Unable to take ownership of the DBus service, is there "
- << "other update_engine daemon running?";
- QuitWithExitCode(1);
- return;
- }
- daemon_state_->StartUpdater();
- }
- #endif
- }
|