blob: 313d7ddce507b1666417c77d9dfa20acaf1d1711 [file] [log] [blame]
Amin Hassani565331e2019-06-24 14:11:29 -07001//
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/daemon_android.h"
18
19#include <sysexits.h>
20
21#include <binderwrapper/binder_wrapper.h>
22
23#include "update_engine/daemon_state_android.h"
24
25using std::unique_ptr;
26
27namespace chromeos_update_engine {
28
29unique_ptr<DaemonBase> DaemonBase::CreateInstance() {
30 return std::make_unique<DaemonAndroid>();
31}
32
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
Yifan Hong2562cf22020-07-21 19:28:44 -070050 auto binder_wrapper = android::BinderWrapper::Get();
51
Amin Hassani565331e2019-06-24 14:11:29 -070052 // Create the Binder Service.
53 binder_service_ = new BinderUpdateEngineAndroidService{
54 daemon_state_android->service_delegate()};
Amin Hassani565331e2019-06-24 14:11:29 -070055 if (!binder_wrapper->RegisterService(binder_service_->ServiceName(),
56 binder_service_)) {
57 LOG(ERROR) << "Failed to register binder service.";
58 }
Amin Hassani565331e2019-06-24 14:11:29 -070059 daemon_state_->AddObserver(binder_service_.get());
Yifan Hong2562cf22020-07-21 19:28:44 -070060
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
Amin Hassani565331e2019-06-24 14:11:29 -070070 daemon_state_->StartUpdater();
71 return EX_OK;
72}
73
74} // namespace chromeos_update_engine