Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 1 | /* |
| 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 Gampe | e1a4039 | 2018-11-30 09:47:17 -0800 | [diff] [blame] | 19 | #include <strings.h> |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 20 | |
| 21 | #include <android-base/logging.h> |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 22 | |
Andreas Gampe | e1a4039 | 2018-11-30 09:47:17 -0800 | [diff] [blame] | 23 | #include "apexd.h" |
Andreas Gampe | 6aaa2fe | 2019-03-29 14:13:59 -0700 | [diff] [blame] | 24 | #include "apexd_checkpoint_vold.h" |
Andreas Gampe | f766355 | 2019-01-03 09:22:11 -0800 | [diff] [blame] | 25 | #include "apexd_prepostinstall.h" |
Martijn Coenen | 95da273 | 2019-02-13 16:32:07 +0100 | [diff] [blame] | 26 | #include "apexd_prop.h" |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 27 | #include "apexservice.h" |
Andreas Gampe | 6aaa2fe | 2019-03-29 14:13:59 -0700 | [diff] [blame] | 28 | #include "status_or.h" |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 29 | |
Jiyong Park | 4d0f832 | 2019-02-02 19:45:57 +0900 | [diff] [blame] | 30 | #include <android-base/properties.h> |
| 31 | |
Andreas Gampe | e1a4039 | 2018-11-30 09:47:17 -0800 | [diff] [blame] | 32 | namespace { |
| 33 | |
| 34 | int 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 Gampe | f766355 | 2019-01-03 09:22:11 -0800 | [diff] [blame] | 40 | if (strcmp("--post-install", argv[1]) == 0) { |
| 41 | LOG(INFO) << "Postinstall subcommand detected"; |
| 42 | return android::apex::RunPostInstall(argv); |
| 43 | } |
| 44 | |
Jiyong Park | 715e23d | 2019-02-22 22:14:37 +0900 | [diff] [blame] | 45 | if (strcmp("--bootstrap", argv[1]) == 0) { |
| 46 | LOG(INFO) << "Bootstrap subcommand detected"; |
| 47 | return android::apex::onBootstrap(); |
| 48 | } |
| 49 | |
Andreas Gampe | e1a4039 | 2018-11-30 09:47:17 -0800 | [diff] [blame] | 50 | LOG(ERROR) << "Unknown subcommand: " << argv[1]; |
| 51 | return 1; |
| 52 | } |
| 53 | |
Andreas Gampe | cb62648 | 2019-01-23 12:45:37 -0800 | [diff] [blame] | 54 | struct 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 Gampe | e1a4039 | 2018-11-30 09:47:17 -0800 | [diff] [blame] | 67 | } // namespace |
| 68 | |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 69 | int main(int /*argc*/, char** argv) { |
Andreas Gampe | cb62648 | 2019-01-23 12:45:37 -0800 | [diff] [blame] | 70 | // Use CombinedLogger to also log to the kernel log. |
| 71 | android::base::InitLogging(argv, CombinedLogger()); |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 72 | |
Andreas Gampe | e1a4039 | 2018-11-30 09:47:17 -0800 | [diff] [blame] | 73 | if (argv[1] != nullptr) { |
| 74 | return HandleSubcommand(argv); |
| 75 | } |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 76 | // TODO: add a -v flag or an external setting to change LogSeverity. |
| 77 | android::base::SetMinimumLogSeverity(android::base::VERBOSE); |
| 78 | |
Andreas Gampe | 6aaa2fe | 2019-03-29 14:13:59 -0700 | [diff] [blame] | 79 | 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 Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 90 | android::apex::binder::CreateAndRegisterService(); |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 91 | android::apex::binder::StartThreadPool(); |
Jiyong Park | 715e23d | 2019-02-22 22:14:37 +0900 | [diff] [blame] | 92 | |
Dario Freni | f9a2a04 | 2019-02-14 14:47:07 +0000 | [diff] [blame] | 93 | // 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 Coenen | 95da273 | 2019-02-13 16:32:07 +0100 | [diff] [blame] | 98 | |
Martijn Coenen | 44de00c | 2019-03-22 09:13:17 +0100 | [diff] [blame] | 99 | android::apex::waitForBootStatus( |
Jooyung Han | f707829 | 2019-04-19 01:40:38 +0900 | [diff] [blame] | 100 | android::apex::rollbackActiveSessionAndReboot, |
| 101 | android::apex::unmountDanglingMounts); |
Martijn Coenen | 95da273 | 2019-02-13 16:32:07 +0100 | [diff] [blame] | 102 | |
Andreas Gampe | 602ef78 | 2018-11-12 16:51:31 -0800 | [diff] [blame] | 103 | android::apex::binder::JoinThreadPool(); |
Andreas Gampe | 9d016d5 | 2018-10-19 18:56:50 -0700 | [diff] [blame] | 104 | return 1; |
| 105 | } |