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