From 284c1715a742c8bf39870e43c84144cb4ff3d6bc Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Wed, 18 Jan 2023 20:16:55 -0800 Subject: [PATCH] Use the correct time functions for tracking service startup When checking for the Idmap service startup timeout we need to ignore the time spent in sleep, and use the correct timing API - SystemClock.uptimeMillis() Bug: 258771796 Test: build + boot + overlay install Change-Id: Ib35eaa5953092177f0d043ffdfffce106ebba0e4 --- .../core/java/com/android/server/om/IdmapDaemon.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/om/IdmapDaemon.java b/services/core/java/com/android/server/om/IdmapDaemon.java index 56390a9f6b0ec..15cfca5ca5538 100644 --- a/services/core/java/com/android/server/om/IdmapDaemon.java +++ b/services/core/java/com/android/server/om/IdmapDaemon.java @@ -274,20 +274,16 @@ class IdmapDaemon { } } - final long endMillis = SystemClock.elapsedRealtime() + SERVICE_CONNECT_TIMEOUT_MS; - while (SystemClock.elapsedRealtime() <= endMillis) { + final long endMillis = SystemClock.uptimeMillis() + SERVICE_CONNECT_TIMEOUT_MS; + do { final IBinder binder = ServiceManager.getService(IDMAP_SERVICE); if (binder != null) { binder.linkToDeath( () -> Slog.w(TAG, String.format("service '%s' died", IDMAP_SERVICE)), 0); return binder; } - - try { - Thread.sleep(SERVICE_CONNECT_INTERVAL_SLEEP_MS); - } catch (InterruptedException ignored) { - } - } + SystemClock.sleep(SERVICE_CONNECT_INTERVAL_SLEEP_MS); + } while (SystemClock.uptimeMillis() <= endMillis); throw new TimeoutException( String.format("Failed to connect to '%s' in %d milliseconds", IDMAP_SERVICE,