1 // 2 // Copyright (C) 2015 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #include "update_engine/aosp/daemon_android.h" 18 19 #include <sysexits.h> 20 21 #include <binderwrapper/binder_wrapper.h> 22 23 #include "update_engine/aosp/daemon_state_android.h" 24 25 using std::unique_ptr; 26 27 namespace chromeos_update_engine { 28 CreateInstance()29unique_ptr<DaemonBase> DaemonBase::CreateInstance() { 30 return std::make_unique<DaemonAndroid>(); 31 } 32 OnInit()33int DaemonAndroid::OnInit() { 34 // Register the |subprocess_| singleton with this Daemon as the signal 35 // handler. 36 subprocess_.Init(this); 37 38 int exit_code = brillo::Daemon::OnInit(); 39 if (exit_code != EX_OK) 40 return exit_code; 41 42 android::BinderWrapper::Create(); 43 binder_watcher_.Init(); 44 45 DaemonStateAndroid* daemon_state_android = new DaemonStateAndroid(); 46 daemon_state_.reset(daemon_state_android); 47 LOG_IF(ERROR, !daemon_state_android->Initialize()) 48 << "Failed to initialize system state."; 49 50 auto binder_wrapper = android::BinderWrapper::Get(); 51 52 // Create the Binder Service. 53 binder_service_ = new BinderUpdateEngineAndroidService{ 54 daemon_state_android->service_delegate()}; 55 if (!binder_wrapper->RegisterService(binder_service_->ServiceName(), 56 binder_service_)) { 57 LOG(ERROR) << "Failed to register binder service."; 58 } 59 daemon_state_->AddObserver(binder_service_.get()); 60 61 // Create the stable binder service. 62 stable_binder_service_ = new BinderUpdateEngineAndroidStableService{ 63 daemon_state_android->service_delegate()}; 64 if (!binder_wrapper->RegisterService(stable_binder_service_->ServiceName(), 65 stable_binder_service_)) { 66 LOG(ERROR) << "Failed to register stable binder service."; 67 } 68 daemon_state_->AddObserver(stable_binder_service_.get()); 69 70 daemon_state_->StartUpdater(); 71 return EX_OK; 72 } 73 74 } // namespace chromeos_update_engine 75