From 96ca88699717e2ca88365fb421cffe4de0b90739 Mon Sep 17 00:00:00 2001 From: Matthew Sedam Date: Mon, 31 Oct 2022 16:40:43 +0000 Subject: [PATCH] Remove init function from ContextHubService Now that we are planning a soft reset instead of a hard reset when the underlying AIDL HAL dies, we do not need to have an explicit init() function. Bug: 246384988 Test: adb logcat | grep -iE 'contexthub|CHRE' # normal Test: adb shell dumpsys contexthub # normal Change-Id: I23e5a0a467688243db9083b56fc51b96fd6364df --- .../contexthub/ContextHubService.java | 58 ++++++++----------- 1 file changed, 23 insertions(+), 35 deletions(-) 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 51851bedba737..6232028bbabe0 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -129,7 +129,7 @@ public class ContextHubService extends IContextHubService.Stub { new RemoteCallbackList<>(); // Proxy object to communicate with the Context Hub HAL - private IContextHubWrapper mContextHubWrapper; + private final IContextHubWrapper mContextHubWrapper; // The manager for transaction queue private ContextHubTransactionManager mTransactionManager; @@ -210,8 +210,24 @@ public class ContextHubService extends IContextHubService.Stub { } public ContextHubService(Context context, IContextHubWrapper contextHubWrapper) { + Log.i(TAG, "Starting Context Hub Service init"); mContext = context; - init(contextHubWrapper, /* isFirstInit= */ true); + long startTimeNs = SystemClock.elapsedRealtimeNanos(); + mContextHubWrapper = contextHubWrapper; + if (!initContextHubServiceState(startTimeNs)) { + Log.e(TAG, "Failed to initialize the Context Hub Service"); + return; + } + initDefaultClientMap(); + + initLocationSettingNotifications(); + initWifiSettingNotifications(); + initAirplaneModeSettingNotifications(); + initMicrophoneSettingNotifications(); + initBtSettingNotifications(); + + scheduleDailyMetricSnapshot(); + Log.i(TAG, "Finished Context Hub Service init"); } /** @@ -293,11 +309,10 @@ public class ContextHubService extends IContextHubService.Stub { * Initializes the private state of the ContextHubService * * @param startTimeNs the start time when init was called - * @param isFirstInit if true, this is the first time init is called - boot time * * @return if mContextHubWrapper is not null and a full state init was done */ - private boolean initContextHubServiceState(long startTimeNs, boolean isFirstInit) { + private boolean initContextHubServiceState(long startTimeNs) { if (mContextHubWrapper == null) { mTransactionManager = null; mClientManager = null; @@ -317,12 +332,10 @@ public class ContextHubService extends IContextHubService.Stub { hubInfo = new Pair(Collections.emptyList(), Collections.emptyList()); } - if (isFirstInit) { - long bootTimeNs = SystemClock.elapsedRealtimeNanos() - startTimeNs; - int numContextHubs = hubInfo.first.size(); - ContextHubStatsLog.write(ContextHubStatsLog.CONTEXT_HUB_BOOTED, bootTimeNs, - numContextHubs); - } + long bootTimeNs = SystemClock.elapsedRealtimeNanos() - startTimeNs; + int numContextHubs = hubInfo.first.size(); + ContextHubStatsLog.write(ContextHubStatsLog.CONTEXT_HUB_BOOTED, bootTimeNs, + numContextHubs); mContextHubIdToInfoMap = Collections.unmodifiableMap( ContextHubServiceUtil.createContextHubInfoMap(hubInfo.first)); @@ -748,31 +761,6 @@ public class ContextHubService extends IContextHubService.Stub { return success ? 0 : -1; } - /** - * Handles a service restart or service init for the first time - * - * @param contextHubWrapper the Context Hub wrapper - * @param isFirstInit if true, this is the first time init is called - boot time - */ - private void init(IContextHubWrapper contextHubWrapper, boolean isFirstInit) { - Log.i(TAG, "Starting Context Hub Service init"); - long startTimeNs = SystemClock.elapsedRealtimeNanos(); - mContextHubWrapper = contextHubWrapper; - if (!initContextHubServiceState(startTimeNs, isFirstInit)) { - Log.e(TAG, "Failed to initialize the Context Hub Service"); - return; - } - initDefaultClientMap(); - - initLocationSettingNotifications(); - initWifiSettingNotifications(); - initAirplaneModeSettingNotifications(); - initMicrophoneSettingNotifications(); - initBtSettingNotifications(); - - scheduleDailyMetricSnapshot(); - } - /** * Handles a unicast or broadcast message from a nanoapp. *