blob: 03c721357c9e43bfa8098082ea4d3c48612355ef [file] [log] [blame]
Andreas Gampe9d016d52018-10-19 18:56:50 -07001/*
2 * Copyright (C) 2018 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#define LOG_TAG "apexd"
18
Andreas Gampee1a40392018-11-30 09:47:17 -080019#include <strings.h>
Andreas Gampe9d016d52018-10-19 18:56:50 -070020
21#include <android-base/logging.h>
Andreas Gampe9d016d52018-10-19 18:56:50 -070022
Andreas Gampee1a40392018-11-30 09:47:17 -080023#include "apexd.h"
Andreas Gampe6aaa2fe2019-03-29 14:13:59 -070024#include "apexd_checkpoint_vold.h"
Andreas Gampef7663552019-01-03 09:22:11 -080025#include "apexd_prepostinstall.h"
Martijn Coenen95da2732019-02-13 16:32:07 +010026#include "apexd_prop.h"
Andreas Gampe9d016d52018-10-19 18:56:50 -070027#include "apexservice.h"
Andreas Gampe6aaa2fe2019-03-29 14:13:59 -070028#include "status_or.h"
Andreas Gampe9d016d52018-10-19 18:56:50 -070029
Jiyong Park4d0f8322019-02-02 19:45:57 +090030#include <android-base/properties.h>
31
Andreas Gampee1a40392018-11-30 09:47:17 -080032namespace {
33
34int HandleSubcommand(char** argv) {
35 if (strcmp("--pre-install", argv[1]) == 0) {
36 LOG(INFO) << "Preinstall subcommand detected";
37 return android::apex::RunPreInstall(argv);
38 }
39
Andreas Gampef7663552019-01-03 09:22:11 -080040 if (strcmp("--post-install", argv[1]) == 0) {
41 LOG(INFO) << "Postinstall subcommand detected";
42 return android::apex::RunPostInstall(argv);
43 }
44
Jiyong Park715e23d2019-02-22 22:14:37 +090045 if (strcmp("--bootstrap", argv[1]) == 0) {
46 LOG(INFO) << "Bootstrap subcommand detected";
47 return android::apex::onBootstrap();
48 }
49
Andreas Gampee1a40392018-11-30 09:47:17 -080050 LOG(ERROR) << "Unknown subcommand: " << argv[1];
51 return 1;
52}
53
Andreas Gampecb626482019-01-23 12:45:37 -080054struct CombinedLogger {
55 android::base::LogdLogger logd;
56
57 CombinedLogger() {}
58
59 void operator()(android::base::LogId id, android::base::LogSeverity severity,
60 const char* tag, const char* file, unsigned int line,
61 const char* message) {
62 logd(id, severity, tag, file, line, message);
63 KernelLogger(id, severity, tag, file, line, message);
64 }
65};
66
Andreas Gampee1a40392018-11-30 09:47:17 -080067} // namespace
68
Andreas Gampe9d016d52018-10-19 18:56:50 -070069int main(int /*argc*/, char** argv) {
Andreas Gampecb626482019-01-23 12:45:37 -080070 // Use CombinedLogger to also log to the kernel log.
71 android::base::InitLogging(argv, CombinedLogger());
Andreas Gampe9d016d52018-10-19 18:56:50 -070072
Andreas Gampee1a40392018-11-30 09:47:17 -080073 if (argv[1] != nullptr) {
74 return HandleSubcommand(argv);
75 }
Andreas Gampe9d016d52018-10-19 18:56:50 -070076 // TODO: add a -v flag or an external setting to change LogSeverity.
77 android::base::SetMinimumLogSeverity(android::base::VERBOSE);
78
Andreas Gampe6aaa2fe2019-03-29 14:13:59 -070079 android::apex::StatusOr<android::apex::VoldCheckpointInterface>
80 vold_service_st = android::apex::VoldCheckpointInterface::Create();
81 android::apex::VoldCheckpointInterface* vold_service = nullptr;
82 if (!vold_service_st.Ok()) {
83 LOG(ERROR) << "Could not retrieve vold service: "
84 << vold_service_st.ErrorMessage();
85 } else {
86 vold_service = &*vold_service_st;
87 }
88
89 android::apex::onStart(vold_service);
Andreas Gampe602ef782018-11-12 16:51:31 -080090 android::apex::binder::CreateAndRegisterService();
Zimuzo9cc0be42019-01-09 11:37:34 +000091 android::apex::binder::StartThreadPool();
Jiyong Park715e23d2019-02-22 22:14:37 +090092
Dario Frenif9a2a042019-02-14 14:47:07 +000093 // Notify other components (e.g. init) that all APEXs are correctly mounted
94 // and are ready to be used. Note that it's important that the binder service
95 // is registered at this point, since other system services might depend on
96 // it.
97 android::apex::onAllPackagesReady();
Martijn Coenen95da2732019-02-13 16:32:07 +010098
Martijn Coenen44de00c2019-03-22 09:13:17 +010099 android::apex::waitForBootStatus(
Jooyung Hanf7078292019-04-19 01:40:38 +0900100 android::apex::rollbackActiveSessionAndReboot,
101 android::apex::unmountDanglingMounts);
Martijn Coenen95da2732019-02-13 16:32:07 +0100102
Andreas Gampe602ef782018-11-12 16:51:31 -0800103 android::apex::binder::JoinThreadPool();
Andreas Gampe9d016d52018-10-19 18:56:50 -0700104 return 1;
105}