From b8815ef9ef02618b16b68c9c7f7768b435454634 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Thu, 9 Sep 2021 15:10:40 -0700 Subject: [PATCH] Implements settings logic for Context Hub AIDL Bug: 194285834 Test: Load on device Change-Id: Ib787f791f323f97babc0e2872fb2461ea7d6afec --- .../contexthub/ContextHubService.java | 20 +++++++-- .../contexthub/IContextHubWrapper.java | 45 ++++++++++++++++--- 2 files changed, 56 insertions(+), 9 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 a491eb753d361..a25392a0e1f4e 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubService.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubService.java @@ -137,6 +137,8 @@ public class ContextHubService extends IContextHubService.Stub { // True if WiFi is available for the Context Hub private boolean mIsWifiAvailable = false; + private boolean mIsWifiScanningEnabled = false; + private boolean mIsWifiMainEnabled = false; // Lock object for sendWifiSettingUpdate() private final Object mSendWifiSettingUpdateLock = new Object(); @@ -1064,10 +1066,20 @@ public class ContextHubService extends IContextHubService.Stub { private void sendWifiSettingUpdate(boolean forceUpdate) { synchronized (mSendWifiSettingUpdateLock) { WifiManager wifiManager = mContext.getSystemService(WifiManager.class); - boolean enabled = wifiManager.isWifiEnabled() || wifiManager.isScanAlwaysAvailable(); - if (forceUpdate || mIsWifiAvailable != enabled) { - mIsWifiAvailable = enabled; - mContextHubWrapper.onWifiSettingChanged(enabled); + boolean wifiEnabled = wifiManager.isWifiEnabled(); + boolean wifiScanEnabled = wifiManager.isScanAlwaysAvailable(); + boolean wifiAvailable = wifiEnabled || wifiScanEnabled; + if (forceUpdate || mIsWifiAvailable != wifiAvailable) { + mIsWifiAvailable = wifiAvailable; + mContextHubWrapper.onWifiSettingChanged(wifiAvailable); + } + if (forceUpdate || mIsWifiScanningEnabled != wifiScanEnabled) { + mIsWifiScanningEnabled = wifiScanEnabled; + mContextHubWrapper.onWifiScanningSettingChanged(wifiScanEnabled); + } + if (forceUpdate || mIsWifiMainEnabled != wifiEnabled) { + mIsWifiMainEnabled = wifiEnabled; + mContextHubWrapper.onWifiMainSettingChanged(wifiEnabled); } } } diff --git a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java index 6c70d9deff45a..2c82f4affdf57 100644 --- a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +++ b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java @@ -197,6 +197,20 @@ public abstract class IContextHubWrapper { */ public abstract void onWifiSettingChanged(boolean enabled); + /** + * Notifies the Contexthub implementation of a user WiFi main setting change. + * + * @param enabled true if the WiFi main setting has been enabled. + */ + public abstract void onWifiMainSettingChanged(boolean enabled); + + /** + * Notifies the Contexthub implementation of a user WiFi scanning setting change. + * + * @param enabled true if the WiFi scanning setting has been enabled. + */ + public abstract void onWifiScanningSettingChanged(boolean enabled); + /** * @return True if this version of the Contexthub HAL supports airplane mode setting * notifications. @@ -335,33 +349,43 @@ public abstract class IContextHubWrapper { return new Pair(hubInfoList, new ArrayList(supportedPermissions)); } - // TODO(b/194285834): Implement settings logic public boolean supportsLocationSettingNotifications() { - return false; + return true; } public boolean supportsWifiSettingNotifications() { - return false; + return true; } public boolean supportsAirplaneModeSettingNotifications() { - return false; + return true; } public boolean supportsMicrophoneDisableSettingNotifications() { - return false; + return true; } public void onLocationSettingChanged(boolean enabled) { + onSettingChanged(android.hardware.contexthub.Setting.LOCATION, enabled); } public void onWifiSettingChanged(boolean enabled) { } public void onAirplaneModeSettingChanged(boolean enabled) { + onSettingChanged(android.hardware.contexthub.Setting.AIRPLANE_MODE, enabled); } public void onMicrophoneDisableSettingChanged(boolean enabled) { + onSettingChanged(android.hardware.contexthub.Setting.MICROPHONE, enabled); + } + + public void onWifiMainSettingChanged(boolean enabled) { + onSettingChanged(android.hardware.contexthub.Setting.WIFI_MAIN, enabled); + } + + public void onWifiScanningSettingChanged(boolean enabled) { + onSettingChanged(android.hardware.contexthub.Setting.WIFI_SCANNING, enabled); } @ContextHubTransaction.Result @@ -414,6 +438,14 @@ public abstract class IContextHubWrapper { return success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_UNKNOWN; } + + private void onSettingChanged(byte setting, boolean enabled) { + try { + mHub.onSettingChanged(setting, enabled); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException while sending setting update"); + } + } } /** @@ -531,6 +563,9 @@ public abstract class IContextHubWrapper { mCallback = callback; mHub.registerCallback(contextHubId, mHidlCallback); } + + public void onWifiMainSettingChanged(boolean enabled) {} + public void onWifiScanningSettingChanged(boolean enabled) {} } private static class ContextHubWrapperV1_0 extends ContextHubWrapperHidl {