From 0d3626bd30bcdf5fbf2c1e89e9f2695d5155c380 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Mon, 1 Nov 2021 20:50:50 +0000 Subject: [PATCH] Add logging code for Context Hub restart Bug: 194287570 Test: statsd_testdrive Change-Id: Ib3231d2b2ca94a9d844d8711841ef489375f4667 --- .../location/contexthub/ContextHubService.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubService.java b/services/core/java/com/android/server/location/contexthub/ContextHubService.java index 1c04d8cbbbdee..389adb0c91f9b 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -72,6 +72,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; /** * @hide @@ -146,6 +147,8 @@ public class ContextHubService extends IContextHubService.Stub { private final SensorPrivacyManagerInternal mSensorPrivacyManagerInternal; + private final Map mLastRestartTimestampMap = new HashMap<>(); + /** * Class extending the callback to register with a Context Hub. */ @@ -223,6 +226,9 @@ public class ContextHubService extends IContextHubService.Stub { HashMap defaultClientMap = new HashMap<>(); for (int contextHubId : mContextHubIdToInfoMap.keySet()) { + mLastRestartTimestampMap.put(contextHubId, + new AtomicLong(SystemClock.elapsedRealtimeNanos())); + ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); IContextHubClient client = mClientManager.registerClient( contextHubInfo, createDefaultClientCallback(contextHubId), @@ -700,6 +706,12 @@ public class ContextHubService extends IContextHubService.Stub { */ private void handleHubEventCallback(int contextHubId, int eventType) { if (eventType == CONTEXT_HUB_EVENT_RESTARTED) { + long now = SystemClock.elapsedRealtimeNanos(); + long lastRestartTimeNs = mLastRestartTimestampMap.get(contextHubId).getAndSet(now); + ContextHubStatsLog.write( + ContextHubStatsLog.CONTEXT_HUB_RESTARTED, now - lastRestartTimeNs, + contextHubId); + sendLocationSettingUpdate(); sendWifiSettingUpdate(true /* forceUpdate */); sendAirplaneModeSettingUpdate();