From bb877e273b651aab6238f0320b4c2cac64f97a94 Mon Sep 17 00:00:00 2001 From: Dong Jinguang Date: Tue, 2 Jan 2018 23:19:57 +0800 Subject: [PATCH] system property: property set without time spent asleep There is a 2s timeout for system property set that currently uses boot_clock as its clock source. If the system goes to sleep during a property set, it may erroneously cause the timeout to be reached as boot_clock increments during sleep. This patch changes from boot_clock to steady_clock to ignore time spent asleep when determining this timeout. bug: 71497234 Test: 1. System service process try to set a system property with timeout 2s 2. At the same time, the system go into sleep mode more than 2s 3. System property set will be ok. Change-Id: I808b9af16974a0f4de60a4ca30ae64d095a13422 --- init/property_service.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/init/property_service.cpp b/init/property_service.cpp index 4b6c502c0..439ab3994 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -350,13 +350,15 @@ class SocketConnection { ufds[0].events = POLLIN; ufds[0].revents = 0; while (*timeout_ms > 0) { - Timer timer; - int nr = poll(ufds, 1, *timeout_ms); - uint64_t millis = timer.duration().count(); - *timeout_ms = (millis > *timeout_ms) ? 0 : *timeout_ms - millis; + auto start_time = std::chrono::steady_clock::now(); + int nr = poll(ufds, 1, *timeout_ms); + auto now = std::chrono::steady_clock::now(); + auto time_elapsed = std::chrono::duration_cast(now - start_time); + uint64_t millis = time_elapsed.count(); + *timeout_ms = (millis > *timeout_ms) ? 0 : *timeout_ms - millis; - if (nr > 0) { - return true; + if (nr > 0) { + return true; } if (nr == 0) {