Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | */ |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame] | 16 | |
| 17 | #include "reboot.h" |
| 18 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 19 | #include <dirent.h> |
| 20 | #include <fcntl.h> |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 21 | #include <linux/fs.h> |
Jaegeuk Kim | 2aedc82 | 2018-11-20 13:27:06 -0800 | [diff] [blame] | 22 | #include <linux/loop.h> |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 23 | #include <mntent.h> |
| 24 | #include <semaphore.h> |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 25 | #include <stdlib.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 26 | #include <sys/cdefs.h> |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 27 | #include <sys/ioctl.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 28 | #include <sys/mount.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 29 | #include <sys/stat.h> |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 30 | #include <sys/swap.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 31 | #include <sys/syscall.h> |
| 32 | #include <sys/types.h> |
| 33 | #include <sys/wait.h> |
| 34 | |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 35 | #include <chrono> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 36 | #include <memory> |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 37 | #include <set> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 38 | #include <thread> |
| 39 | #include <vector> |
| 40 | |
Tom Cherry | ede0d53 | 2017-07-06 14:20:11 -0700 | [diff] [blame] | 41 | #include <android-base/chrono_utils.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 42 | #include <android-base/file.h> |
Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame] | 43 | #include <android-base/logging.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 44 | #include <android-base/macros.h> |
Tom Cherry | ccf2353 | 2017-03-28 16:40:41 -0700 | [diff] [blame] | 45 | #include <android-base/properties.h> |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 46 | #include <android-base/scopeguard.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 47 | #include <android-base/strings.h> |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 48 | #include <android-base/unique_fd.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 49 | #include <bootloader_message/bootloader_message.h> |
| 50 | #include <cutils/android_reboot.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 51 | #include <fs_mgr.h> |
| 52 | #include <logwrap/logwrap.h> |
Todd Poynor | fc827be | 2017-04-13 15:17:24 -0700 | [diff] [blame] | 53 | #include <private/android_filesystem_config.h> |
Tom Cherry | 0c8d6d2 | 2017-08-10 12:22:44 -0700 | [diff] [blame] | 54 | #include <selinux/selinux.h> |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 55 | |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 56 | #include "action.h" |
Tom Cherry | 7fd3bc2 | 2018-02-13 15:36:14 -0800 | [diff] [blame] | 57 | #include "action_manager.h" |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 58 | #include "builtin_arguments.h" |
Wei Wang | eeab491 | 2017-06-27 22:08:45 -0700 | [diff] [blame] | 59 | #include "init.h" |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 60 | #include "property_service.h" |
Tom Cherry | 44aceed | 2018-08-03 13:36:18 -0700 | [diff] [blame] | 61 | #include "reboot_utils.h" |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 62 | #include "service.h" |
Tom Cherry | 2aeb1ad | 2019-06-26 10:46:20 -0700 | [diff] [blame] | 63 | #include "service_list.h" |
Luis Hector Chavez | 9f97f47 | 2017-09-06 13:43:57 -0700 | [diff] [blame] | 64 | #include "sigchld_handler.h" |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 65 | #include "util.h" |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 66 | |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 67 | #define PROC_SYSRQ "/proc/sysrq-trigger" |
| 68 | |
Tom Cherry | 2436e6b | 2019-09-19 11:16:19 -0700 | [diff] [blame] | 69 | using namespace std::literals; |
| 70 | |
Tom Cherry | 4f4cacc | 2019-01-08 10:39:00 -0800 | [diff] [blame] | 71 | using android::base::GetBoolProperty; |
Mark Salyzyn | 6290982 | 2017-10-09 09:27:16 -0700 | [diff] [blame] | 72 | using android::base::Split; |
Tom Cherry | ede0d53 | 2017-07-06 14:20:11 -0700 | [diff] [blame] | 73 | using android::base::Timer; |
Jaegeuk Kim | 2aedc82 | 2018-11-20 13:27:06 -0800 | [diff] [blame] | 74 | using android::base::unique_fd; |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 75 | using android::base::WriteStringToFile; |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 76 | |
Tom Cherry | 81f5d3e | 2017-06-22 12:53:17 -0700 | [diff] [blame] | 77 | namespace android { |
| 78 | namespace init { |
| 79 | |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 80 | static bool shutting_down = false; |
| 81 | |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 82 | static const std::set<std::string> kDebuggingServices{"tombstoned", "logd", "adbd", "console"}; |
| 83 | |
| 84 | static std::vector<Service*> GetDebuggingServices(bool only_post_data) { |
| 85 | std::vector<Service*> ret; |
| 86 | ret.reserve(kDebuggingServices.size()); |
| 87 | for (const auto& s : ServiceList::GetInstance()) { |
| 88 | if (kDebuggingServices.count(s->name()) && (!only_post_data || s->is_post_data())) { |
| 89 | ret.push_back(s.get()); |
| 90 | } |
| 91 | } |
| 92 | return ret; |
| 93 | } |
| 94 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 95 | // represents umount status during reboot / shutdown. |
| 96 | enum UmountStat { |
| 97 | /* umount succeeded. */ |
| 98 | UMOUNT_STAT_SUCCESS = 0, |
| 99 | /* umount was not run. */ |
| 100 | UMOUNT_STAT_SKIPPED = 1, |
| 101 | /* umount failed with timeout. */ |
| 102 | UMOUNT_STAT_TIMEOUT = 2, |
| 103 | /* could not run due to error */ |
| 104 | UMOUNT_STAT_ERROR = 3, |
| 105 | /* not used by init but reserved for other part to use this to represent the |
| 106 | the state where umount status before reboot is not found / available. */ |
| 107 | UMOUNT_STAT_NOT_AVAILABLE = 4, |
| 108 | }; |
| 109 | |
| 110 | // Utility for struct mntent |
| 111 | class MountEntry { |
| 112 | public: |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 113 | explicit MountEntry(const mntent& entry) |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 114 | : mnt_fsname_(entry.mnt_fsname), |
| 115 | mnt_dir_(entry.mnt_dir), |
| 116 | mnt_type_(entry.mnt_type), |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 117 | mnt_opts_(entry.mnt_opts) {} |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 118 | |
Jaegeuk Kim | 0f04f72 | 2017-09-25 10:55:39 -0700 | [diff] [blame] | 119 | bool Umount(bool force) { |
Tom Cherry | c9fec9d | 2018-02-15 14:26:58 -0800 | [diff] [blame] | 120 | LOG(INFO) << "Unmounting " << mnt_fsname_ << ":" << mnt_dir_ << " opts " << mnt_opts_; |
Jaegeuk Kim | 0f04f72 | 2017-09-25 10:55:39 -0700 | [diff] [blame] | 121 | int r = umount2(mnt_dir_.c_str(), force ? MNT_FORCE : 0); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 122 | if (r == 0) { |
Tom Cherry | c9fec9d | 2018-02-15 14:26:58 -0800 | [diff] [blame] | 123 | LOG(INFO) << "Umounted " << mnt_fsname_ << ":" << mnt_dir_ << " opts " << mnt_opts_; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 124 | return true; |
| 125 | } else { |
Tom Cherry | c9fec9d | 2018-02-15 14:26:58 -0800 | [diff] [blame] | 126 | PLOG(WARNING) << "Cannot umount " << mnt_fsname_ << ":" << mnt_dir_ << " opts " |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 127 | << mnt_opts_; |
| 128 | return false; |
| 129 | } |
| 130 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 131 | |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 132 | void DoFsck() { |
| 133 | int st; |
| 134 | if (IsF2Fs()) { |
| 135 | const char* f2fs_argv[] = { |
Randall Huang | df2faa4 | 2019-01-15 15:00:56 +0800 | [diff] [blame] | 136 | "/system/bin/fsck.f2fs", |
| 137 | "-a", |
| 138 | mnt_fsname_.c_str(), |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 139 | }; |
Tom Cherry | 3a803eb | 2019-09-25 16:23:50 -0700 | [diff] [blame] | 140 | logwrap_fork_execvp(arraysize(f2fs_argv), f2fs_argv, &st, false, LOG_KLOG, true, |
| 141 | nullptr); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 142 | } else if (IsExt4()) { |
| 143 | const char* ext4_argv[] = { |
Randall Huang | df2faa4 | 2019-01-15 15:00:56 +0800 | [diff] [blame] | 144 | "/system/bin/e2fsck", |
| 145 | "-y", |
| 146 | mnt_fsname_.c_str(), |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 147 | }; |
Tom Cherry | 3a803eb | 2019-09-25 16:23:50 -0700 | [diff] [blame] | 148 | logwrap_fork_execvp(arraysize(ext4_argv), ext4_argv, &st, false, LOG_KLOG, true, |
| 149 | nullptr); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 152 | |
| 153 | static bool IsBlockDevice(const struct mntent& mntent) { |
| 154 | return android::base::StartsWith(mntent.mnt_fsname, "/dev/block"); |
| 155 | } |
| 156 | |
| 157 | static bool IsEmulatedDevice(const struct mntent& mntent) { |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 158 | return android::base::StartsWith(mntent.mnt_fsname, "/data/"); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | private: |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 162 | bool IsF2Fs() const { return mnt_type_ == "f2fs"; } |
| 163 | |
| 164 | bool IsExt4() const { return mnt_type_ == "ext4"; } |
| 165 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 166 | std::string mnt_fsname_; |
| 167 | std::string mnt_dir_; |
| 168 | std::string mnt_type_; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 169 | std::string mnt_opts_; |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | // Turn off backlight while we are performing power down cleanup activities. |
| 173 | static void TurnOffBacklight() { |
Steven Moreland | d5eccfd | 2018-01-19 13:01:53 -0800 | [diff] [blame] | 174 | Service* service = ServiceList::GetInstance().FindService("blank_screen"); |
| 175 | if (service == nullptr) { |
| 176 | LOG(WARNING) << "cannot find blank_screen in TurnOffBacklight"; |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 177 | return; |
| 178 | } |
Tom Cherry | d987264 | 2018-10-11 10:38:05 -0700 | [diff] [blame] | 179 | if (auto result = service->Start(); !result) { |
| 180 | LOG(WARNING) << "Could not start blank_screen service: " << result.error(); |
| 181 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 184 | static void ShutdownVold() { |
| 185 | const char* vdc_argv[] = {"/system/bin/vdc", "volume", "shutdown"}; |
| 186 | int status; |
Tom Cherry | 3a803eb | 2019-09-25 16:23:50 -0700 | [diff] [blame] | 187 | logwrap_fork_execvp(arraysize(vdc_argv), vdc_argv, &status, false, LOG_KLOG, true, nullptr); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void LogShutdownTime(UmountStat stat, Timer* t) { |
Tom Cherry | ede0d53 | 2017-07-06 14:20:11 -0700 | [diff] [blame] | 191 | LOG(WARNING) << "powerctl_shutdown_time_ms:" << std::to_string(t->duration().count()) << ":" |
| 192 | << stat; |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Tom Cherry | 2436e6b | 2019-09-19 11:16:19 -0700 | [diff] [blame] | 195 | static bool IsDataMounted() { |
| 196 | std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(setmntent("/proc/mounts", "re"), endmntent); |
| 197 | if (fp == nullptr) { |
| 198 | PLOG(ERROR) << "Failed to open /proc/mounts"; |
| 199 | return false; |
| 200 | } |
| 201 | mntent* mentry; |
| 202 | while ((mentry = getmntent(fp.get())) != nullptr) { |
| 203 | if (mentry->mnt_dir == "/data"s) { |
| 204 | return true; |
| 205 | } |
| 206 | } |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | // Find all read+write block devices and emulated devices in /proc/mounts and add them to |
| 211 | // the correpsponding list. |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 212 | static bool FindPartitionsToUmount(std::vector<MountEntry>* blockDevPartitions, |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 213 | std::vector<MountEntry>* emulatedPartitions, bool dump) { |
Tom Cherry | f274e78 | 2018-10-03 13:13:41 -0700 | [diff] [blame] | 214 | std::unique_ptr<std::FILE, int (*)(std::FILE*)> fp(setmntent("/proc/mounts", "re"), endmntent); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 215 | if (fp == nullptr) { |
| 216 | PLOG(ERROR) << "Failed to open /proc/mounts"; |
| 217 | return false; |
| 218 | } |
| 219 | mntent* mentry; |
| 220 | while ((mentry = getmntent(fp.get())) != nullptr) { |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 221 | if (dump) { |
| 222 | LOG(INFO) << "mount entry " << mentry->mnt_fsname << ":" << mentry->mnt_dir << " opts " |
| 223 | << mentry->mnt_opts << " type " << mentry->mnt_type; |
| 224 | } else if (MountEntry::IsBlockDevice(*mentry) && hasmntopt(mentry, "rw")) { |
Keun-young Park | 6e12b38 | 2017-07-17 12:20:33 -0700 | [diff] [blame] | 225 | std::string mount_dir(mentry->mnt_dir); |
| 226 | // These are R/O partitions changed to R/W after adb remount. |
| 227 | // Do not umount them as shutdown critical services may rely on them. |
Wei Wang | a01c27e | 2017-07-25 10:52:08 -0700 | [diff] [blame] | 228 | if (mount_dir != "/" && mount_dir != "/system" && mount_dir != "/vendor" && |
| 229 | mount_dir != "/oem") { |
Keun-young Park | 6e12b38 | 2017-07-17 12:20:33 -0700 | [diff] [blame] | 230 | blockDevPartitions->emplace(blockDevPartitions->begin(), *mentry); |
| 231 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 232 | } else if (MountEntry::IsEmulatedDevice(*mentry)) { |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 233 | emulatedPartitions->emplace(emulatedPartitions->begin(), *mentry); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | return true; |
| 237 | } |
| 238 | |
Jonglin Lee | 28a2c92 | 2019-01-15 16:38:44 -0800 | [diff] [blame] | 239 | static void DumpUmountDebuggingInfo() { |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 240 | int status; |
| 241 | if (!security_getenforce()) { |
| 242 | LOG(INFO) << "Run lsof"; |
| 243 | const char* lsof_argv[] = {"/system/bin/lsof"}; |
Tom Cherry | 3a803eb | 2019-09-25 16:23:50 -0700 | [diff] [blame] | 244 | logwrap_fork_execvp(arraysize(lsof_argv), lsof_argv, &status, false, LOG_KLOG, true, |
| 245 | nullptr); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 246 | } |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 247 | FindPartitionsToUmount(nullptr, nullptr, true); |
Jonglin Lee | 28a2c92 | 2019-01-15 16:38:44 -0800 | [diff] [blame] | 248 | // dump current CPU stack traces and uninterruptible tasks |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 249 | WriteStringToFile("l", PROC_SYSRQ); |
| 250 | WriteStringToFile("w", PROC_SYSRQ); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Tom Cherry | ede0d53 | 2017-07-06 14:20:11 -0700 | [diff] [blame] | 253 | static UmountStat UmountPartitions(std::chrono::milliseconds timeout) { |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 254 | Timer t; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 255 | /* data partition needs all pending writes to be completed and all emulated partitions |
| 256 | * umounted.If the current waiting is not good enough, give |
| 257 | * up and leave it to e2fsck after reboot to fix it. |
| 258 | */ |
| 259 | while (true) { |
| 260 | std::vector<MountEntry> block_devices; |
| 261 | std::vector<MountEntry> emulated_devices; |
| 262 | if (!FindPartitionsToUmount(&block_devices, &emulated_devices, false)) { |
| 263 | return UMOUNT_STAT_ERROR; |
| 264 | } |
| 265 | if (block_devices.size() == 0) { |
Wei Wang | 8c00e42 | 2017-08-16 14:01:46 -0700 | [diff] [blame] | 266 | return UMOUNT_STAT_SUCCESS; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 267 | } |
Wei Wang | 8c00e42 | 2017-08-16 14:01:46 -0700 | [diff] [blame] | 268 | bool unmount_done = true; |
| 269 | if (emulated_devices.size() > 0) { |
Wei Wang | 25dc30f | 2017-10-23 15:32:03 -0700 | [diff] [blame] | 270 | for (auto& entry : emulated_devices) { |
| 271 | if (!entry.Umount(false)) unmount_done = false; |
| 272 | } |
Wei Wang | 8c00e42 | 2017-08-16 14:01:46 -0700 | [diff] [blame] | 273 | if (unmount_done) { |
| 274 | sync(); |
| 275 | } |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 276 | } |
Wei Wang | 25dc30f | 2017-10-23 15:32:03 -0700 | [diff] [blame] | 277 | for (auto& entry : block_devices) { |
| 278 | if (!entry.Umount(timeout == 0ms)) unmount_done = false; |
| 279 | } |
Wei Wang | 8c00e42 | 2017-08-16 14:01:46 -0700 | [diff] [blame] | 280 | if (unmount_done) { |
| 281 | return UMOUNT_STAT_SUCCESS; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 282 | } |
Wei Wang | 8c00e42 | 2017-08-16 14:01:46 -0700 | [diff] [blame] | 283 | if ((timeout < t.duration())) { // try umount at least once |
| 284 | return UMOUNT_STAT_TIMEOUT; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 285 | } |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 286 | std::this_thread::sleep_for(100ms); |
| 287 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 288 | } |
| 289 | |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 290 | static void KillAllProcesses() { |
| 291 | WriteStringToFile("i", PROC_SYSRQ); |
| 292 | } |
| 293 | |
| 294 | // Create reboot/shutdwon monitor thread |
| 295 | void RebootMonitorThread(unsigned int cmd, const std::string& rebootTarget, sem_t* reboot_semaphore, |
| 296 | std::chrono::milliseconds shutdown_timeout, bool* reboot_monitor_run) { |
| 297 | unsigned int remaining_shutdown_time = 0; |
| 298 | |
| 299 | // 30 seconds more than the timeout passed to the thread as there is a final Umount pass |
| 300 | // after the timeout is reached. |
| 301 | constexpr unsigned int shutdown_watchdog_timeout_default = 30; |
| 302 | auto shutdown_watchdog_timeout = android::base::GetUintProperty( |
| 303 | "ro.build.shutdown.watchdog.timeout", shutdown_watchdog_timeout_default); |
| 304 | remaining_shutdown_time = shutdown_watchdog_timeout + shutdown_timeout.count() / 1000; |
| 305 | |
| 306 | while (*reboot_monitor_run == true) { |
| 307 | if (TEMP_FAILURE_RETRY(sem_wait(reboot_semaphore)) == -1) { |
| 308 | LOG(ERROR) << "sem_wait failed and exit RebootMonitorThread()"; |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | timespec shutdown_timeout_timespec; |
| 313 | if (clock_gettime(CLOCK_MONOTONIC, &shutdown_timeout_timespec) == -1) { |
| 314 | LOG(ERROR) << "clock_gettime() fail! exit RebootMonitorThread()"; |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | // If there are some remaining shutdown time left from previous round, we use |
| 319 | // remaining time here. |
| 320 | shutdown_timeout_timespec.tv_sec += remaining_shutdown_time; |
| 321 | |
| 322 | LOG(INFO) << "shutdown_timeout_timespec.tv_sec: " << shutdown_timeout_timespec.tv_sec; |
| 323 | |
| 324 | int sem_return = 0; |
| 325 | while ((sem_return = sem_timedwait_monotonic_np(reboot_semaphore, |
| 326 | &shutdown_timeout_timespec)) == -1 && |
| 327 | errno == EINTR) { |
| 328 | } |
| 329 | |
| 330 | if (sem_return == -1) { |
| 331 | LOG(ERROR) << "Reboot thread timed out"; |
| 332 | |
| 333 | if (android::base::GetBoolProperty("ro.debuggable", false) == true) { |
Tom Cherry | 2436e6b | 2019-09-19 11:16:19 -0700 | [diff] [blame] | 334 | if (false) { |
| 335 | // SEPolicy will block debuggerd from running and this is intentional. |
| 336 | // But these lines are left to be enabled during debugging. |
| 337 | LOG(INFO) << "Try to dump init process call trace:"; |
| 338 | const char* vdc_argv[] = {"/system/bin/debuggerd", "-b", "1"}; |
| 339 | int status; |
Tom Cherry | 3a803eb | 2019-09-25 16:23:50 -0700 | [diff] [blame] | 340 | logwrap_fork_execvp(arraysize(vdc_argv), vdc_argv, &status, false, LOG_KLOG, |
| 341 | true, nullptr); |
Tom Cherry | 2436e6b | 2019-09-19 11:16:19 -0700 | [diff] [blame] | 342 | } |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 343 | LOG(INFO) << "Show stack for all active CPU:"; |
| 344 | WriteStringToFile("l", PROC_SYSRQ); |
| 345 | |
| 346 | LOG(INFO) << "Show tasks that are in disk sleep(uninterruptable sleep), which are " |
| 347 | "like " |
| 348 | "blocked in mutex or hardware register access:"; |
| 349 | WriteStringToFile("w", PROC_SYSRQ); |
| 350 | } |
| 351 | |
| 352 | // In shutdown case,notify kernel to sync and umount fs to read-only before shutdown. |
| 353 | if (cmd == ANDROID_RB_POWEROFF || cmd == ANDROID_RB_THERMOFF) { |
| 354 | WriteStringToFile("s", PROC_SYSRQ); |
| 355 | |
| 356 | WriteStringToFile("u", PROC_SYSRQ); |
| 357 | |
| 358 | RebootSystem(cmd, rebootTarget); |
| 359 | } |
| 360 | |
| 361 | LOG(ERROR) << "Trigger crash at last!"; |
| 362 | WriteStringToFile("c", PROC_SYSRQ); |
| 363 | } else { |
| 364 | timespec current_time_timespec; |
| 365 | |
| 366 | if (clock_gettime(CLOCK_MONOTONIC, ¤t_time_timespec) == -1) { |
| 367 | LOG(ERROR) << "clock_gettime() fail! exit RebootMonitorThread()"; |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | remaining_shutdown_time = |
| 372 | shutdown_timeout_timespec.tv_sec - current_time_timespec.tv_sec; |
| 373 | |
| 374 | LOG(INFO) << "remaining_shutdown_time: " << remaining_shutdown_time; |
| 375 | } |
| 376 | } |
| 377 | } |
Keun-young Park | 3ee0df9 | 2017-03-27 11:21:09 -0700 | [diff] [blame] | 378 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 379 | /* Try umounting all emulated file systems R/W block device cfile systems. |
| 380 | * This will just try umount and give it up if it fails. |
| 381 | * For fs like ext4, this is ok as file system will be marked as unclean shutdown |
| 382 | * and necessary check can be done at the next reboot. |
| 383 | * For safer shutdown, caller needs to make sure that |
| 384 | * all processes / emulated partition for the target fs are all cleaned-up. |
| 385 | * |
| 386 | * return true when umount was successful. false when timed out. |
| 387 | */ |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 388 | static UmountStat TryUmountAndFsck(unsigned int cmd, const std::string& rebootTarget, bool runFsck, |
| 389 | std::chrono::milliseconds timeout, sem_t* reboot_semaphore) { |
Keun-young Park | 3ee0df9 | 2017-03-27 11:21:09 -0700 | [diff] [blame] | 390 | Timer t; |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 391 | std::vector<MountEntry> block_devices; |
| 392 | std::vector<MountEntry> emulated_devices; |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 393 | |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 394 | if (runFsck && !FindPartitionsToUmount(&block_devices, &emulated_devices, false)) { |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 395 | return UMOUNT_STAT_ERROR; |
| 396 | } |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 397 | |
Tom Cherry | ede0d53 | 2017-07-06 14:20:11 -0700 | [diff] [blame] | 398 | UmountStat stat = UmountPartitions(timeout - t.duration()); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 399 | if (stat != UMOUNT_STAT_SUCCESS) { |
| 400 | LOG(INFO) << "umount timeout, last resort, kill all and try"; |
Jonglin Lee | 28a2c92 | 2019-01-15 16:38:44 -0800 | [diff] [blame] | 401 | if (DUMP_ON_UMOUNT_FAILURE) DumpUmountDebuggingInfo(); |
Keun-young Park | 3ee0df9 | 2017-03-27 11:21:09 -0700 | [diff] [blame] | 402 | KillAllProcesses(); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 403 | // even if it succeeds, still it is timeout and do not run fsck with all processes killed |
Keun-young Park | c59b822 | 2017-07-18 18:52:25 -0700 | [diff] [blame] | 404 | UmountStat st = UmountPartitions(0ms); |
Jonglin Lee | 28a2c92 | 2019-01-15 16:38:44 -0800 | [diff] [blame] | 405 | if ((st != UMOUNT_STAT_SUCCESS) && DUMP_ON_UMOUNT_FAILURE) DumpUmountDebuggingInfo(); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 408 | if (stat == UMOUNT_STAT_SUCCESS && runFsck) { |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 409 | LOG(INFO) << "Pause reboot monitor thread before fsck"; |
| 410 | sem_post(reboot_semaphore); |
| 411 | |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 412 | // fsck part is excluded from timeout check. It only runs for user initiated shutdown |
| 413 | // and should not affect reboot time. |
| 414 | for (auto& entry : block_devices) { |
| 415 | entry.DoFsck(); |
| 416 | } |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 417 | |
| 418 | LOG(INFO) << "Resume reboot monitor thread after fsck"; |
| 419 | sem_post(reboot_semaphore); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 420 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 421 | return stat; |
| 422 | } |
| 423 | |
Jaegeuk Kim | 2aedc82 | 2018-11-20 13:27:06 -0800 | [diff] [blame] | 424 | // zram is able to use backing device on top of a loopback device. |
| 425 | // In order to unmount /data successfully, we have to kill the loopback device first |
| 426 | #define ZRAM_DEVICE "/dev/block/zram0" |
| 427 | #define ZRAM_RESET "/sys/block/zram0/reset" |
| 428 | #define ZRAM_BACK_DEV "/sys/block/zram0/backing_dev" |
| 429 | static void KillZramBackingDevice() { |
| 430 | std::string backing_dev; |
| 431 | if (!android::base::ReadFileToString(ZRAM_BACK_DEV, &backing_dev)) return; |
| 432 | |
| 433 | if (!android::base::StartsWith(backing_dev, "/dev/block/loop")) return; |
| 434 | |
| 435 | // cut the last "\n" |
| 436 | backing_dev.erase(backing_dev.length() - 1); |
| 437 | |
| 438 | // shutdown zram handle |
| 439 | Timer swap_timer; |
| 440 | LOG(INFO) << "swapoff() start..."; |
| 441 | if (swapoff(ZRAM_DEVICE) == -1) { |
| 442 | LOG(ERROR) << "zram_backing_dev: swapoff (" << backing_dev << ")" << " failed"; |
| 443 | return; |
| 444 | } |
| 445 | LOG(INFO) << "swapoff() took " << swap_timer;; |
| 446 | |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 447 | if (!WriteStringToFile("1", ZRAM_RESET)) { |
Jaegeuk Kim | 2aedc82 | 2018-11-20 13:27:06 -0800 | [diff] [blame] | 448 | LOG(ERROR) << "zram_backing_dev: reset (" << backing_dev << ")" << " failed"; |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | // clear loopback device |
| 453 | unique_fd loop(TEMP_FAILURE_RETRY(open(backing_dev.c_str(), O_RDWR | O_CLOEXEC))); |
| 454 | if (loop.get() < 0) { |
| 455 | LOG(ERROR) << "zram_backing_dev: open(" << backing_dev << ")" << " failed"; |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | if (ioctl(loop.get(), LOOP_CLR_FD, 0) < 0) { |
| 460 | LOG(ERROR) << "zram_backing_dev: loop_clear (" << backing_dev << ")" << " failed"; |
| 461 | return; |
| 462 | } |
| 463 | LOG(INFO) << "zram_backing_dev: `" << backing_dev << "` is cleared successfully."; |
| 464 | } |
| 465 | |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 466 | // Stops given services, waits for them to be stopped for |timeout| ms. |
| 467 | // If terminate is true, then SIGTERM is sent to services, otherwise SIGKILL is sent. |
| 468 | static void StopServices(const std::vector<Service*>& services, std::chrono::milliseconds timeout, |
| 469 | bool terminate) { |
| 470 | LOG(INFO) << "Stopping " << services.size() << " services by sending " |
| 471 | << (terminate ? "SIGTERM" : "SIGKILL"); |
| 472 | std::vector<pid_t> pids; |
| 473 | pids.reserve(services.size()); |
| 474 | for (const auto& s : services) { |
| 475 | if (s->pid() > 0) { |
| 476 | pids.push_back(s->pid()); |
| 477 | } |
| 478 | if (terminate) { |
| 479 | s->Terminate(); |
| 480 | } else { |
| 481 | s->Stop(); |
| 482 | } |
| 483 | } |
| 484 | if (timeout > 0ms) { |
| 485 | WaitToBeReaped(pids, timeout); |
| 486 | } else { |
| 487 | // Even if we don't to wait for services to stop, we still optimistically reap zombies. |
| 488 | ReapAnyOutstandingChildren(); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // Like StopServices, but also logs all the services that failed to stop after the provided timeout. |
| 493 | // Returns number of violators. |
| 494 | static int StopServicesAndLogViolations(const std::vector<Service*>& services, |
| 495 | std::chrono::milliseconds timeout, bool terminate) { |
| 496 | StopServices(services, timeout, terminate); |
| 497 | int still_running = 0; |
| 498 | for (const auto& s : services) { |
| 499 | if (s->IsRunning()) { |
| 500 | LOG(ERROR) << "[service-misbehaving] : service '" << s->name() << "' is still running " |
| 501 | << timeout.count() << "ms after receiving " |
| 502 | << (terminate ? "SIGTERM" : "SIGKILL"); |
| 503 | still_running++; |
| 504 | } |
| 505 | } |
| 506 | return still_running; |
| 507 | } |
| 508 | |
Tom Cherry | 44aceed | 2018-08-03 13:36:18 -0700 | [diff] [blame] | 509 | //* Reboot / shutdown the system. |
| 510 | // cmd ANDROID_RB_* as defined in android_reboot.h |
| 511 | // reason Reason string like "reboot", "shutdown,userrequested" |
| 512 | // rebootTarget Reboot target string like "bootloader". Otherwise, it should be an |
| 513 | // empty string. |
| 514 | // runFsck Whether to run fsck after umount is done. |
| 515 | // |
| 516 | static void DoReboot(unsigned int cmd, const std::string& reason, const std::string& rebootTarget, |
| 517 | bool runFsck) { |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 518 | Timer t; |
Tom Cherry | 0a72e6c | 2018-03-19 16:19:01 -0700 | [diff] [blame] | 519 | LOG(INFO) << "Reboot start, reason: " << reason << ", rebootTarget: " << rebootTarget; |
| 520 | |
Tom Cherry | 2436e6b | 2019-09-19 11:16:19 -0700 | [diff] [blame] | 521 | // If /data isn't mounted then we can skip the extra reboot steps below, since we don't need to |
| 522 | // worry about unmounting it. |
| 523 | if (!IsDataMounted()) { |
| 524 | sync(); |
| 525 | RebootSystem(cmd, rebootTarget); |
| 526 | abort(); |
| 527 | } |
| 528 | |
Tom Cherry | 0a72e6c | 2018-03-19 16:19:01 -0700 | [diff] [blame] | 529 | // Ensure last reboot reason is reduced to canonical |
| 530 | // alias reported in bootloader or system boot reason. |
| 531 | size_t skip = 0; |
| 532 | std::vector<std::string> reasons = Split(reason, ","); |
| 533 | if (reasons.size() >= 2 && reasons[0] == "reboot" && |
| 534 | (reasons[1] == "recovery" || reasons[1] == "bootloader" || reasons[1] == "cold" || |
| 535 | reasons[1] == "hard" || reasons[1] == "warm")) { |
| 536 | skip = strlen("reboot,"); |
| 537 | } |
| 538 | property_set(LAST_REBOOT_REASON_PROPERTY, reason.c_str() + skip); |
| 539 | sync(); |
| 540 | |
| 541 | bool is_thermal_shutdown = cmd == ANDROID_RB_THERMOFF; |
| 542 | |
| 543 | auto shutdown_timeout = 0ms; |
| 544 | if (!SHUTDOWN_ZERO_TIMEOUT) { |
Wei Wang | b5de088 | 2018-10-09 12:42:06 -0700 | [diff] [blame] | 545 | constexpr unsigned int shutdown_timeout_default = 6; |
| 546 | constexpr unsigned int max_thermal_shutdown_timeout = 3; |
| 547 | auto shutdown_timeout_final = android::base::GetUintProperty("ro.build.shutdown_timeout", |
| 548 | shutdown_timeout_default); |
| 549 | if (is_thermal_shutdown && shutdown_timeout_final > max_thermal_shutdown_timeout) { |
| 550 | shutdown_timeout_final = max_thermal_shutdown_timeout; |
Tom Cherry | 0a72e6c | 2018-03-19 16:19:01 -0700 | [diff] [blame] | 551 | } |
Wei Wang | b5de088 | 2018-10-09 12:42:06 -0700 | [diff] [blame] | 552 | shutdown_timeout = std::chrono::seconds(shutdown_timeout_final); |
Tom Cherry | 0a72e6c | 2018-03-19 16:19:01 -0700 | [diff] [blame] | 553 | } |
| 554 | LOG(INFO) << "Shutdown timeout: " << shutdown_timeout.count() << " ms"; |
| 555 | |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 556 | sem_t reboot_semaphore; |
| 557 | if (sem_init(&reboot_semaphore, false, 0) == -1) { |
| 558 | // These should never fail, but if they do, skip the graceful reboot and reboot immediately. |
| 559 | LOG(ERROR) << "sem_init() fail and RebootSystem() return!"; |
| 560 | RebootSystem(cmd, rebootTarget); |
| 561 | } |
| 562 | |
| 563 | // Start a thread to monitor init shutdown process |
| 564 | LOG(INFO) << "Create reboot monitor thread."; |
| 565 | bool reboot_monitor_run = true; |
| 566 | std::thread reboot_monitor_thread(&RebootMonitorThread, cmd, rebootTarget, &reboot_semaphore, |
| 567 | shutdown_timeout, &reboot_monitor_run); |
| 568 | reboot_monitor_thread.detach(); |
| 569 | |
| 570 | // Start reboot monitor thread |
| 571 | sem_post(&reboot_semaphore); |
| 572 | |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 573 | // watchdogd is a vendor specific component but should be alive to complete shutdown safely. |
Keun-young Park | cccb34f | 2017-07-05 11:38:44 -0700 | [diff] [blame] | 574 | const std::set<std::string> to_starts{"watchdogd"}; |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 575 | std::vector<Service*> stop_first; |
| 576 | stop_first.reserve(ServiceList::GetInstance().services().size()); |
Tom Cherry | 911b9b1 | 2017-07-27 16:20:58 -0700 | [diff] [blame] | 577 | for (const auto& s : ServiceList::GetInstance()) { |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 578 | if (kDebuggingServices.count(s->name())) { |
| 579 | // keep debugging tools until non critical ones are all gone. |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 580 | s->SetShutdownCritical(); |
| 581 | } else if (to_starts.count(s->name())) { |
Tom Cherry | 702ca9a | 2017-08-25 10:36:52 -0700 | [diff] [blame] | 582 | if (auto result = s->Start(); !result) { |
| 583 | LOG(ERROR) << "Could not start shutdown 'to_start' service '" << s->name() |
| 584 | << "': " << result.error(); |
| 585 | } |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 586 | s->SetShutdownCritical(); |
Keun-young Park | cccb34f | 2017-07-05 11:38:44 -0700 | [diff] [blame] | 587 | } else if (s->IsShutdownCritical()) { |
Tom Cherry | 702ca9a | 2017-08-25 10:36:52 -0700 | [diff] [blame] | 588 | // Start shutdown critical service if not started. |
| 589 | if (auto result = s->Start(); !result) { |
| 590 | LOG(ERROR) << "Could not start shutdown critical service '" << s->name() |
| 591 | << "': " << result.error(); |
| 592 | } |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 593 | } else { |
| 594 | stop_first.push_back(s.get()); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 595 | } |
Tom Cherry | 911b9b1 | 2017-07-27 16:20:58 -0700 | [diff] [blame] | 596 | } |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 597 | |
Steven Moreland | d5eccfd | 2018-01-19 13:01:53 -0800 | [diff] [blame] | 598 | // remaining operations (specifically fsck) may take a substantial duration |
Tom Cherry | 0a72e6c | 2018-03-19 16:19:01 -0700 | [diff] [blame] | 599 | if (cmd == ANDROID_RB_POWEROFF || is_thermal_shutdown) { |
Steven Moreland | d5eccfd | 2018-01-19 13:01:53 -0800 | [diff] [blame] | 600 | TurnOffBacklight(); |
| 601 | } |
| 602 | |
Tom Cherry | 911b9b1 | 2017-07-27 16:20:58 -0700 | [diff] [blame] | 603 | Service* bootAnim = ServiceList::GetInstance().FindService("bootanim"); |
| 604 | Service* surfaceFlinger = ServiceList::GetInstance().FindService("surfaceflinger"); |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 605 | if (bootAnim != nullptr && surfaceFlinger != nullptr && surfaceFlinger->IsRunning()) { |
Tom Cherry | 4f4cacc | 2019-01-08 10:39:00 -0800 | [diff] [blame] | 606 | bool do_shutdown_animation = GetBoolProperty("ro.init.shutdown_animation", false); |
| 607 | |
| 608 | if (do_shutdown_animation) { |
| 609 | property_set("service.bootanim.exit", "0"); |
| 610 | // Could be in the middle of animation. Stop and start so that it can pick |
| 611 | // up the right mode. |
| 612 | bootAnim->Stop(); |
| 613 | } |
| 614 | |
Tom Cherry | 911b9b1 | 2017-07-27 16:20:58 -0700 | [diff] [blame] | 615 | for (const auto& service : ServiceList::GetInstance()) { |
Tom Cherry | 4f4cacc | 2019-01-08 10:39:00 -0800 | [diff] [blame] | 616 | if (service->classnames().count("animation") == 0) { |
| 617 | continue; |
| 618 | } |
| 619 | |
| 620 | // start all animation classes if stopped. |
| 621 | if (do_shutdown_animation) { |
Tom Cherry | 9949ec5 | 2019-05-16 16:54:49 -0700 | [diff] [blame] | 622 | service->Start(); |
Tom Cherry | 4f4cacc | 2019-01-08 10:39:00 -0800 | [diff] [blame] | 623 | } |
| 624 | service->SetShutdownCritical(); // will not check animation class separately |
| 625 | } |
| 626 | |
| 627 | if (do_shutdown_animation) { |
Tom Cherry | 9949ec5 | 2019-05-16 16:54:49 -0700 | [diff] [blame] | 628 | bootAnim->Start(); |
Tom Cherry | 4f4cacc | 2019-01-08 10:39:00 -0800 | [diff] [blame] | 629 | surfaceFlinger->SetShutdownCritical(); |
| 630 | bootAnim->SetShutdownCritical(); |
Tom Cherry | 911b9b1 | 2017-07-27 16:20:58 -0700 | [diff] [blame] | 631 | } |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 632 | } |
Keun-young Park | 7830d59 | 2017-03-27 16:07:02 -0700 | [diff] [blame] | 633 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 634 | // optional shutdown step |
| 635 | // 1. terminate all services except shutdown critical ones. wait for delay to finish |
Keun-young Park | 3017387 | 2017-07-18 10:58:28 -0700 | [diff] [blame] | 636 | if (shutdown_timeout > 0ms) { |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 637 | StopServicesAndLogViolations(stop_first, shutdown_timeout / 2, true /* SIGTERM */); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 638 | } |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 639 | // Send SIGKILL to ones that didn't terminate cleanly. |
| 640 | StopServicesAndLogViolations(stop_first, 0ms, false /* SIGKILL */); |
Luis Hector Chavez | 92c49bc | 2018-07-27 11:19:25 -0700 | [diff] [blame] | 641 | SubcontextTerminate(); |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 642 | // Reap subcontext pids. |
Tom Cherry | eeee831 | 2017-07-28 15:22:23 -0700 | [diff] [blame] | 643 | ReapAnyOutstandingChildren(); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 644 | |
| 645 | // 3. send volume shutdown to vold |
Tom Cherry | 911b9b1 | 2017-07-27 16:20:58 -0700 | [diff] [blame] | 646 | Service* voldService = ServiceList::GetInstance().FindService("vold"); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 647 | if (voldService != nullptr && voldService->IsRunning()) { |
| 648 | ShutdownVold(); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 649 | voldService->Stop(); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 650 | } else { |
| 651 | LOG(INFO) << "vold not running, skipping vold shutdown"; |
| 652 | } |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 653 | // logcat stopped here |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 654 | StopServices(GetDebuggingServices(false /* only_post_data */), 0ms, false /* SIGKILL */); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 655 | // 4. sync, try umount, and optionally run fsck for user shutdown |
Tom Cherry | 1f9d540 | 2018-03-15 10:22:40 -0700 | [diff] [blame] | 656 | { |
| 657 | Timer sync_timer; |
| 658 | LOG(INFO) << "sync() before umount..."; |
| 659 | sync(); |
| 660 | LOG(INFO) << "sync() before umount took" << sync_timer; |
| 661 | } |
Jaegeuk Kim | 2aedc82 | 2018-11-20 13:27:06 -0800 | [diff] [blame] | 662 | // 5. drop caches and disable zram backing device, if exist |
| 663 | KillZramBackingDevice(); |
| 664 | |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 665 | UmountStat stat = TryUmountAndFsck(cmd, rebootTarget, runFsck, shutdown_timeout - t.duration(), |
| 666 | &reboot_semaphore); |
Keun-young Park | 2ba5c81 | 2017-03-29 12:54:40 -0700 | [diff] [blame] | 667 | // Follow what linux shutdown is doing: one more sync with little bit delay |
Tom Cherry | 1f9d540 | 2018-03-15 10:22:40 -0700 | [diff] [blame] | 668 | { |
| 669 | Timer sync_timer; |
| 670 | LOG(INFO) << "sync() after umount..."; |
| 671 | sync(); |
| 672 | LOG(INFO) << "sync() after umount took" << sync_timer; |
| 673 | } |
Tom Cherry | 0a72e6c | 2018-03-19 16:19:01 -0700 | [diff] [blame] | 674 | if (!is_thermal_shutdown) std::this_thread::sleep_for(100ms); |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 675 | LogShutdownTime(stat, &t); |
josephjang | aaddf28 | 2019-04-16 18:46:24 +0800 | [diff] [blame] | 676 | |
| 677 | // Send signal to terminate reboot monitor thread. |
| 678 | reboot_monitor_run = false; |
| 679 | sem_post(&reboot_semaphore); |
| 680 | |
Keun-young Park | 8d01f63 | 2017-03-13 11:54:47 -0700 | [diff] [blame] | 681 | // Reboot regardless of umount status. If umount fails, fsck after reboot will fix it. |
| 682 | RebootSystem(cmd, rebootTarget); |
| 683 | abort(); |
| 684 | } |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 685 | |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 686 | static void EnterShutdown() { |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 687 | LOG(INFO) << "Entering shutdown mode"; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 688 | shutting_down = true; |
| 689 | // Skip wait for prop if it is in progress |
| 690 | ResetWaitForProp(); |
| 691 | // Clear EXEC flag if there is one pending |
| 692 | for (const auto& s : ServiceList::GetInstance()) { |
| 693 | s->UnSetExec(); |
| 694 | } |
| 695 | // We no longer process messages about properties changing coming from property service, so we |
| 696 | // need to tell property service to stop sending us these messages, otherwise it'll fill the |
| 697 | // buffers and block indefinitely, causing future property sets, including those that init makes |
| 698 | // during shutdown in Service::NotifyStateChange() to also block indefinitely. |
| 699 | SendStopSendingMessagesMessage(); |
| 700 | } |
| 701 | |
| 702 | static void LeaveShutdown() { |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 703 | LOG(INFO) << "Leaving shutdown mode"; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 704 | shutting_down = false; |
| 705 | SendStartSendingMessagesMessage(); |
| 706 | } |
| 707 | |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 708 | static Result<void> DoUserspaceReboot() { |
| 709 | LOG(INFO) << "Userspace reboot initiated"; |
| 710 | auto guard = android::base::make_scope_guard([] { |
| 711 | // Leave shutdown so that we can handle a full reboot. |
| 712 | LeaveShutdown(); |
Tom Cherry | 0dbfea7 | 2019-10-11 13:18:44 -0700 | [diff] [blame] | 713 | TriggerShutdown("reboot,abort-userspace-reboot"); |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 714 | }); |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 715 | // Triggering userspace-reboot-requested will result in a bunch of set_prop |
| 716 | // actions. We should make sure, that all of them are propagated before |
| 717 | // proceeding with userspace reboot. |
| 718 | // TODO(b/135984674): implement proper synchronization logic. |
| 719 | std::this_thread::sleep_for(500ms); |
| 720 | EnterShutdown(); |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 721 | std::vector<Service*> stop_first; |
| 722 | // Remember the services that were enabled. We will need to manually enable them again otherwise |
| 723 | // triggers like class_start won't restart them. |
| 724 | std::vector<Service*> were_enabled; |
| 725 | stop_first.reserve(ServiceList::GetInstance().services().size()); |
| 726 | for (const auto& s : ServiceList::GetInstance().services_in_shutdown_order()) { |
| 727 | if (s->is_post_data() && !kDebuggingServices.count(s->name())) { |
| 728 | stop_first.push_back(s); |
| 729 | } |
| 730 | if (s->is_post_data() && s->IsEnabled()) { |
| 731 | were_enabled.push_back(s); |
| 732 | } |
| 733 | } |
| 734 | // TODO(b/135984674): do we need shutdown animation for userspace reboot? |
| 735 | // TODO(b/135984674): control userspace timeout via read-only property? |
| 736 | StopServicesAndLogViolations(stop_first, 10s, true /* SIGTERM */); |
| 737 | if (int r = StopServicesAndLogViolations(stop_first, 20s, false /* SIGKILL */); r > 0) { |
| 738 | // TODO(b/135984674): store information about offending services for debugging. |
| 739 | return Error() << r << " post-data services are still running"; |
| 740 | } |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 741 | // TODO(b/135984674): remount userdata |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 742 | if (int r = StopServicesAndLogViolations(GetDebuggingServices(true /* only_post_data */), 5s, |
| 743 | false /* SIGKILL */); |
| 744 | r > 0) { |
| 745 | // TODO(b/135984674): store information about offending services for debugging. |
| 746 | return Error() << r << " debugging services are still running"; |
| 747 | } |
| 748 | // TODO(b/135984674): deactivate APEX modules and switch back to bootstrap namespace. |
| 749 | // Re-enable services |
| 750 | for (const auto& s : were_enabled) { |
| 751 | LOG(INFO) << "Re-enabling service '" << s->name() << "'"; |
| 752 | s->Enable(); |
| 753 | } |
| 754 | LeaveShutdown(); |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 755 | ActionManager::GetInstance().QueueEventTrigger("userspace-reboot-resume"); |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 756 | guard.Disable(); // Go on with userspace reboot. |
| 757 | return {}; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static void HandleUserspaceReboot() { |
| 761 | LOG(INFO) << "Clearing queue and starting userspace-reboot-requested trigger"; |
| 762 | auto& am = ActionManager::GetInstance(); |
| 763 | am.ClearQueue(); |
| 764 | am.QueueEventTrigger("userspace-reboot-requested"); |
Nikita Ioffe | 3f4b0d6 | 2019-10-09 15:23:02 +0100 | [diff] [blame] | 765 | auto handler = [](const BuiltinArguments&) { return DoUserspaceReboot(); }; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 766 | am.QueueBuiltinAction(handler, "userspace-reboot"); |
| 767 | } |
| 768 | |
| 769 | void HandlePowerctlMessage(const std::string& command) { |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 770 | unsigned int cmd = 0; |
Mark Salyzyn | 6290982 | 2017-10-09 09:27:16 -0700 | [diff] [blame] | 771 | std::vector<std::string> cmd_params = Split(command, ","); |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 772 | std::string reboot_target = ""; |
| 773 | bool run_fsck = false; |
| 774 | bool command_invalid = false; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 775 | bool userspace_reboot = false; |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 776 | |
Mark Salyzyn | d7931f1 | 2019-07-10 10:33:09 -0700 | [diff] [blame] | 777 | if (cmd_params[0] == "shutdown") { |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 778 | cmd = ANDROID_RB_POWEROFF; |
Mark Salyzyn | d7931f1 | 2019-07-10 10:33:09 -0700 | [diff] [blame] | 779 | if (cmd_params.size() >= 2) { |
Mark Salyzyn | 73e6b49 | 2017-08-14 15:56:53 -0700 | [diff] [blame] | 780 | if (cmd_params[1] == "userrequested") { |
| 781 | // The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED. |
| 782 | // Run fsck once the file system is remounted in read-only mode. |
| 783 | run_fsck = true; |
| 784 | } else if (cmd_params[1] == "thermal") { |
Mark Salyzyn | bfd05b6 | 2017-09-26 11:10:12 -0700 | [diff] [blame] | 785 | // Turn off sources of heat immediately. |
| 786 | TurnOffBacklight(); |
Mark Salyzyn | 73e6b49 | 2017-08-14 15:56:53 -0700 | [diff] [blame] | 787 | // run_fsck is false to avoid delay |
| 788 | cmd = ANDROID_RB_THERMOFF; |
| 789 | } |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 790 | } |
| 791 | } else if (cmd_params[0] == "reboot") { |
| 792 | cmd = ANDROID_RB_RESTART2; |
| 793 | if (cmd_params.size() >= 2) { |
| 794 | reboot_target = cmd_params[1]; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 795 | if (reboot_target == "userspace") { |
| 796 | LOG(INFO) << "Userspace reboot requested"; |
| 797 | userspace_reboot = true; |
| 798 | } |
Hridya Valsaraju | 5425826 | 2018-09-19 21:14:18 -0700 | [diff] [blame] | 799 | // adb reboot fastboot should boot into bootloader for devices not |
| 800 | // supporting logical partitions. |
| 801 | if (reboot_target == "fastboot" && |
Yifan Hong | 0e0f818 | 2018-11-16 12:49:06 -0800 | [diff] [blame] | 802 | !android::base::GetBoolProperty("ro.boot.dynamic_partitions", false)) { |
Hridya Valsaraju | 5425826 | 2018-09-19 21:14:18 -0700 | [diff] [blame] | 803 | reboot_target = "bootloader"; |
| 804 | } |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 805 | // When rebooting to the bootloader notify the bootloader writing |
| 806 | // also the BCB. |
| 807 | if (reboot_target == "bootloader") { |
| 808 | std::string err; |
| 809 | if (!write_reboot_bootloader(&err)) { |
| 810 | LOG(ERROR) << "reboot-bootloader: Error writing " |
| 811 | "bootloader_message: " |
| 812 | << err; |
| 813 | } |
Tianjie Xu | 5e98b63 | 2019-07-18 12:48:28 -0700 | [diff] [blame] | 814 | } else if (reboot_target == "recovery") { |
| 815 | bootloader_message boot = {}; |
| 816 | if (std::string err; !read_bootloader_message(&boot, &err)) { |
| 817 | LOG(ERROR) << "Failed to read bootloader message: " << err; |
| 818 | } |
| 819 | // Update the boot command field if it's empty, and preserve |
| 820 | // the other arguments in the bootloader message. |
| 821 | if (boot.command[0] == '\0') { |
| 822 | strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); |
| 823 | if (std::string err; !write_bootloader_message(boot, &err)) { |
| 824 | LOG(ERROR) << "Failed to set bootloader message: " << err; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 825 | return; |
Tianjie Xu | 5e98b63 | 2019-07-18 12:48:28 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
Hridya Valsaraju | 71fb82a | 2018-08-02 15:02:06 -0700 | [diff] [blame] | 828 | } else if (reboot_target == "sideload" || reboot_target == "sideload-auto-reboot" || |
| 829 | reboot_target == "fastboot") { |
| 830 | std::string arg = reboot_target == "sideload-auto-reboot" ? "sideload_auto_reboot" |
| 831 | : reboot_target; |
| 832 | const std::vector<std::string> options = { |
| 833 | "--" + arg, |
| 834 | }; |
| 835 | std::string err; |
| 836 | if (!write_bootloader_message(options, &err)) { |
| 837 | LOG(ERROR) << "Failed to set bootloader message: " << err; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 838 | return; |
Hridya Valsaraju | 71fb82a | 2018-08-02 15:02:06 -0700 | [diff] [blame] | 839 | } |
| 840 | reboot_target = "recovery"; |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 841 | } |
Hridya Valsaraju | 71fb82a | 2018-08-02 15:02:06 -0700 | [diff] [blame] | 842 | |
Mark Salyzyn | d7931f1 | 2019-07-10 10:33:09 -0700 | [diff] [blame] | 843 | // If there are additional parameter, pass them along |
| 844 | for (size_t i = 2; (cmd_params.size() > i) && cmd_params[i].size(); ++i) { |
| 845 | reboot_target += "," + cmd_params[i]; |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 848 | } else { |
| 849 | command_invalid = true; |
| 850 | } |
| 851 | if (command_invalid) { |
| 852 | LOG(ERROR) << "powerctl: unrecognized command '" << command << "'"; |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 853 | return; |
| 854 | } |
| 855 | |
| 856 | if (userspace_reboot) { |
| 857 | HandleUserspaceReboot(); |
| 858 | return; |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Wei Wang | eeab491 | 2017-06-27 22:08:45 -0700 | [diff] [blame] | 861 | LOG(INFO) << "Clear action queue and start shutdown trigger"; |
| 862 | ActionManager::GetInstance().ClearQueue(); |
| 863 | // Queue shutdown trigger first |
| 864 | ActionManager::GetInstance().QueueEventTrigger("shutdown"); |
| 865 | // Queue built-in shutdown_done |
Tom Cherry | cb0f9bb | 2017-09-12 15:58:47 -0700 | [diff] [blame] | 866 | auto shutdown_handler = [cmd, command, reboot_target, run_fsck](const BuiltinArguments&) { |
Wei Wang | eeab491 | 2017-06-27 22:08:45 -0700 | [diff] [blame] | 867 | DoReboot(cmd, command, reboot_target, run_fsck); |
Tom Cherry | bbcbc2f | 2019-06-10 11:08:01 -0700 | [diff] [blame] | 868 | return Result<void>{}; |
Wei Wang | eeab491 | 2017-06-27 22:08:45 -0700 | [diff] [blame] | 869 | }; |
| 870 | ActionManager::GetInstance().QueueBuiltinAction(shutdown_handler, "shutdown_done"); |
| 871 | |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 872 | EnterShutdown(); |
| 873 | } |
Wei Wang | eeab491 | 2017-06-27 22:08:45 -0700 | [diff] [blame] | 874 | |
Nikita Ioffe | ba6968e | 2019-10-07 16:26:33 +0100 | [diff] [blame] | 875 | bool IsShuttingDown() { |
| 876 | return shutting_down; |
Tom Cherry | 98ad32a | 2017-04-17 16:34:20 -0700 | [diff] [blame] | 877 | } |
Tom Cherry | 81f5d3e | 2017-06-22 12:53:17 -0700 | [diff] [blame] | 878 | |
| 879 | } // namespace init |
| 880 | } // namespace android |