1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| system/core/init/reboot.cpp static void DoReboot(unsigned int cmd, const std::string& reason, const std::string& reboot_target, bool run_fsck) { Timer t; LOG(INFO) << "Reboot start, reason: " << reason << ", reboot_target: " << reboot_target;
bool is_thermal_shutdown = cmd == ANDROID_RB_THERMOFF;
auto shutdown_timeout = 0ms; if (!SHUTDOWN_ZERO_TIMEOUT) { constexpr unsigned int shutdown_timeout_default = 6; constexpr unsigned int max_thermal_shutdown_timeout = 3; auto shutdown_timeout_final = android::base::GetUintProperty("ro.build.shutdown_timeout", shutdown_timeout_default); if (is_thermal_shutdown && shutdown_timeout_final > max_thermal_shutdown_timeout) { shutdown_timeout_final = max_thermal_shutdown_timeout; } shutdown_timeout = std::chrono::seconds(shutdown_timeout_final); } LOG(INFO) << "Shutdown timeout: " << shutdown_timeout.count() << " ms";
sem_t reboot_semaphore; if (sem_init(&reboot_semaphore, false, 0) == -1) { LOG(ERROR) << "sem_init() fail and RebootSystem() return!"; RebootSystem(cmd, reboot_target); }
LOG(INFO) << "Create reboot monitor thread."; bool reboot_monitor_run = true; std::thread reboot_monitor_thread(&RebootMonitorThread, cmd, reboot_target, &reboot_semaphore, shutdown_timeout, &reboot_monitor_run); reboot_monitor_thread.detach();
sem_post(&reboot_semaphore);
size_t skip = 0; std::vector<std::string> reasons = Split(reason, ","); if (reasons.size() >= 2 && reasons[0] == "reboot" && (reasons[1] == "recovery" || reasons[1] == "bootloader" || reasons[1] == "cold" || reasons[1] == "hard" || reasons[1] == "warm")) { skip = strlen("reboot,"); } PersistRebootReason(reason.c_str() + skip, true);
if (!IsDataMounted("*")) { sync(); RebootSystem(cmd, reboot_target); abort(); }
bool do_shutdown_animation = GetBoolProperty("ro.init.shutdown_animation", false); const std::set<std::string> to_starts{"watchdogd"}; std::set<std::string> stop_first; for (const auto& s : ServiceList::GetInstance()) { if (kDebuggingServices.count(s->name())) { s->SetShutdownCritical(); } else if (to_starts.count(s->name())) { if (auto result = s->Start(); !result.ok()) { LOG(ERROR) << "Could not start shutdown 'to_start' service '" << s->name() << "': " << result.error(); } s->SetShutdownCritical(); } else if (do_shutdown_animation) { continue; } else if (s->IsShutdownCritical()) { if (auto result = s->Start(); !result.ok()) { LOG(ERROR) << "Could not start shutdown critical service '" << s->name() << "': " << result.error(); } } else { stop_first.insert(s->name()); } }
if (!do_shutdown_animation && (cmd == ANDROID_RB_POWEROFF || is_thermal_shutdown)) { TurnOffBacklight(); }
Service* boot_anim = ServiceList::GetInstance().FindService("bootanim"); Service* surface_flinger = ServiceList::GetInstance().FindService("surfaceflinger"); if (boot_anim != nullptr && surface_flinger != nullptr && surface_flinger->IsRunning()) {
if (do_shutdown_animation) { SetProperty("service.bootanim.exit", "0"); SetProperty("service.bootanim.progress", "0"); boot_anim->Stop(); }
for (const auto& service : ServiceList::GetInstance()) { if (service->classnames().count("animation") == 0) { continue; }
if (do_shutdown_animation) { service->Start(); } service->SetShutdownCritical(); }
if (do_shutdown_animation) { boot_anim->Start(); surface_flinger->SetShutdownCritical(); boot_anim->SetShutdownCritical(); } }
if (shutdown_timeout > 0ms) { StopServicesAndLogViolations(stop_first, shutdown_timeout / 2, true ); } StopServicesAndLogViolations(stop_first, 0ms, false ); SubcontextTerminate(); ReapAnyOutstandingChildren();
Service* vold_service = ServiceList::GetInstance().FindService("vold"); if (vold_service != nullptr && vold_service->IsRunning()) { CallVdc("volume", "abort_fuse"); CallVdc("volume", "shutdown"); vold_service->Stop(); } else { LOG(INFO) << "vold not running, skipping vold shutdown"; } StopServices(kDebuggingServices, 0ms, false ); { Timer sync_timer; LOG(INFO) << "sync() before umount..."; sync(); LOG(INFO) << "sync() before umount took" << sync_timer; } KillZramBackingDevice();
LOG(INFO) << "Ready to unmount apexes. So far shutdown sequence took " << t; if (auto ret = UnmountAllApexes(); !ret.ok()) { LOG(ERROR) << ret.error(); } UmountStat stat = TryUmountAndFsck(cmd, run_fsck, shutdown_timeout - t.duration(), &reboot_semaphore); { Timer sync_timer; LOG(INFO) << "sync() after umount..."; sync(); LOG(INFO) << "sync() after umount took" << sync_timer; } if (!is_thermal_shutdown) std::this_thread::sleep_for(100ms); LogShutdownTime(stat, &t);
reboot_monitor_run = false; sem_post(&reboot_semaphore);
if (IsDataMounted("f2fs")) { uint32_t flag = F2FS_GOING_DOWN_FULLSYNC; unique_fd fd(TEMP_FAILURE_RETRY(open("/data", O_RDONLY))); int ret = ioctl(fd, F2FS_IOC_SHUTDOWN, &flag); if (ret) { PLOG(ERROR) << "Shutdown /data: "; } else { LOG(INFO) << "Shutdown /data"; } } RebootSystem(cmd, reboot_target); abort(); }
|