Loading Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -466,6 +466,7 @@ java_library { "android.hardware.cas-V1.2-java", "android.hardware.contexthub-V1.0-java", "android.hardware.contexthub-V1.1-java", "android.hardware.contexthub-V1.2-java", "android.hardware.gnss-V1.0-java", "android.hardware.gnss-V2.1-java", "android.hardware.health-V1.0-java-constants", Loading services/core/java/com/android/server/location/ContextHubService.java +6 −7 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ import android.hardware.contexthub.V1_0.HubAppInfo; import android.hardware.contexthub.V1_0.IContexthubCallback; import android.hardware.contexthub.V1_0.Result; import android.hardware.contexthub.V1_0.TransactionResult; import android.hardware.contexthub.V1_1.Setting; import android.hardware.contexthub.V1_1.SettingValue; import android.hardware.location.ContextHubInfo; import android.hardware.location.ContextHubMessage; import android.hardware.location.ContextHubTransaction; Loading Loading @@ -196,7 +194,7 @@ public class ContextHubService extends IContextHubService.Stub { } mDefaultClientMap = Collections.unmodifiableMap(defaultClientMap); if (mContextHubWrapper.supportsSettingNotifications()) { if (mContextHubWrapper.supportsLocationSettingNotifications()) { sendLocationSettingUpdate(); mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.LOCATION_MODE), Loading Loading @@ -260,7 +258,10 @@ public class ContextHubService extends IContextHubService.Stub { * @return the IContextHubWrapper interface */ private IContextHubWrapper getContextHubWrapper() { IContextHubWrapper wrapper = IContextHubWrapper.maybeConnectTo1_1(); IContextHubWrapper wrapper = IContextHubWrapper.maybeConnectTo1_2(); if (wrapper == null) { wrapper = IContextHubWrapper.maybeConnectTo1_1(); } if (wrapper == null) { wrapper = IContextHubWrapper.maybeConnectTo1_0(); } Loading Loading @@ -925,9 +926,7 @@ public class ContextHubService extends IContextHubService.Stub { private void sendLocationSettingUpdate() { boolean enabled = mContext.getSystemService(LocationManager.class) .isLocationEnabledForUser(UserHandle.CURRENT); mContextHubWrapper.onSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); mContextHubWrapper.onLocationSettingChanged(enabled); } private String getCallingPackageName() { Loading services/core/java/com/android/server/location/IContextHubWrapper.java +93 −23 Original line number Diff line number Diff line Loading @@ -45,12 +45,7 @@ public abstract class IContextHubWrapper { Log.i(TAG, "Context Hub HAL service not found"); } ContextHubWrapperV1_0 wrapper = null; if (proxy != null) { wrapper = new ContextHubWrapperV1_0(proxy); } return wrapper; return (proxy == null) ? null : new ContextHubWrapperV1_0(proxy); } /** Loading @@ -69,12 +64,26 @@ public abstract class IContextHubWrapper { Log.i(TAG, "Context Hub HAL service not found"); } ContextHubWrapperV1_1 wrapper = null; if (proxy != null) { wrapper = new ContextHubWrapperV1_1(proxy); return (proxy == null) ? null : new ContextHubWrapperV1_1(proxy); } /** * Attempts to connect to the Contexthub HAL 1.2 service, if it exists. * * @return A valid IContextHubWrapper if the connection was successful, null otherwise. */ @Nullable public static IContextHubWrapper maybeConnectTo1_2() { android.hardware.contexthub.V1_2.IContexthub proxy = null; try { proxy = android.hardware.contexthub.V1_2.IContexthub.getService(true /* retry */); } catch (RemoteException e) { Log.e(TAG, "RemoteException while attaching to Context Hub HAL proxy", e); } catch (NoSuchElementException e) { Log.i(TAG, "Context Hub HAL service not found"); } return wrapper; return (proxy == null) ? null : new ContextHubWrapperV1_2(proxy); } /** Loading @@ -83,19 +92,29 @@ public abstract class IContextHubWrapper { public abstract android.hardware.contexthub.V1_0.IContexthub getHub(); /** * @return True if this version of the Contexthub HAL supports setting notifications. * @return True if this version of the Contexthub HAL supports Location setting notifications. */ public abstract boolean supportsSettingNotifications(); public abstract boolean supportsLocationSettingNotifications(); /** * Notifies the Contexthub implementation of a user setting change. * Notifies the Contexthub implementation of a user Location setting change. * * @param setting The user setting that has changed. MUST be one of the values from the * {@link Setting} enum * @param newValue The value of the user setting that changed. MUST be one of the values * from the {@link SettingValue} enum. * @param enabled True if the Location setting has been enabled. */ public abstract void onSettingChanged(byte setting, byte newValue); public abstract void onLocationSettingChanged(boolean enabled); /** * @return True if this version of the Contexthub HAL supports WiFi availability setting * notifications. */ public abstract boolean supportsWifiSettingNotifications(); /** * Notifies the Contexthub implementation of a user WiFi availability setting change. * * @param enabled true if the WiFi availability setting has been enabled. */ public abstract void onWifiSettingChanged(boolean enabled); private static class ContextHubWrapperV1_0 extends IContextHubWrapper { private android.hardware.contexthub.V1_0.IContexthub mHub; Loading @@ -108,11 +127,17 @@ public abstract class IContextHubWrapper { return mHub; } public boolean supportsSettingNotifications() { public boolean supportsLocationSettingNotifications() { return false; } public void onSettingChanged(byte setting, byte newValue) {} public boolean supportsWifiSettingNotifications() { return false; } public void onLocationSettingChanged(boolean enabled) {} public void onWifiSettingChanged(boolean enabled) {} } private static class ContextHubWrapperV1_1 extends IContextHubWrapper { Loading @@ -126,13 +151,58 @@ public abstract class IContextHubWrapper { return mHub; } public boolean supportsSettingNotifications() { public boolean supportsLocationSettingNotifications() { return true; } public boolean supportsWifiSettingNotifications() { return false; } public void onLocationSettingChanged(boolean enabled) { try { mHub.onSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } catch (RemoteException e) { Log.e(TAG, "Failed to send setting change to Contexthub", e); } } public void onWifiSettingChanged(boolean enabled) {} } private static class ContextHubWrapperV1_2 extends IContextHubWrapper { private android.hardware.contexthub.V1_2.IContexthub mHub; ContextHubWrapperV1_2(android.hardware.contexthub.V1_2.IContexthub hub) { mHub = hub; } public android.hardware.contexthub.V1_0.IContexthub getHub() { return mHub; } public boolean supportsLocationSettingNotifications() { return true; } public void onSettingChanged(byte setting, byte newValue) { public boolean supportsWifiSettingNotifications() { return true; } public void onLocationSettingChanged(boolean enabled) { sendSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } public void onWifiSettingChanged(boolean enabled) { sendSettingChanged(android.hardware.contexthub.V1_2.Setting.WIFI_AVAILABLE, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } private void sendSettingChanged(byte setting, byte newValue) { try { mHub.onSettingChanged(setting, newValue); mHub.onSettingChanged_1_2(setting, newValue); } catch (RemoteException e) { Log.e(TAG, "Failed to send setting change to Contexthub", e); } Loading Loading
Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -466,6 +466,7 @@ java_library { "android.hardware.cas-V1.2-java", "android.hardware.contexthub-V1.0-java", "android.hardware.contexthub-V1.1-java", "android.hardware.contexthub-V1.2-java", "android.hardware.gnss-V1.0-java", "android.hardware.gnss-V2.1-java", "android.hardware.health-V1.0-java-constants", Loading
services/core/java/com/android/server/location/ContextHubService.java +6 −7 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ import android.hardware.contexthub.V1_0.HubAppInfo; import android.hardware.contexthub.V1_0.IContexthubCallback; import android.hardware.contexthub.V1_0.Result; import android.hardware.contexthub.V1_0.TransactionResult; import android.hardware.contexthub.V1_1.Setting; import android.hardware.contexthub.V1_1.SettingValue; import android.hardware.location.ContextHubInfo; import android.hardware.location.ContextHubMessage; import android.hardware.location.ContextHubTransaction; Loading Loading @@ -196,7 +194,7 @@ public class ContextHubService extends IContextHubService.Stub { } mDefaultClientMap = Collections.unmodifiableMap(defaultClientMap); if (mContextHubWrapper.supportsSettingNotifications()) { if (mContextHubWrapper.supportsLocationSettingNotifications()) { sendLocationSettingUpdate(); mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.LOCATION_MODE), Loading Loading @@ -260,7 +258,10 @@ public class ContextHubService extends IContextHubService.Stub { * @return the IContextHubWrapper interface */ private IContextHubWrapper getContextHubWrapper() { IContextHubWrapper wrapper = IContextHubWrapper.maybeConnectTo1_1(); IContextHubWrapper wrapper = IContextHubWrapper.maybeConnectTo1_2(); if (wrapper == null) { wrapper = IContextHubWrapper.maybeConnectTo1_1(); } if (wrapper == null) { wrapper = IContextHubWrapper.maybeConnectTo1_0(); } Loading Loading @@ -925,9 +926,7 @@ public class ContextHubService extends IContextHubService.Stub { private void sendLocationSettingUpdate() { boolean enabled = mContext.getSystemService(LocationManager.class) .isLocationEnabledForUser(UserHandle.CURRENT); mContextHubWrapper.onSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); mContextHubWrapper.onLocationSettingChanged(enabled); } private String getCallingPackageName() { Loading
services/core/java/com/android/server/location/IContextHubWrapper.java +93 −23 Original line number Diff line number Diff line Loading @@ -45,12 +45,7 @@ public abstract class IContextHubWrapper { Log.i(TAG, "Context Hub HAL service not found"); } ContextHubWrapperV1_0 wrapper = null; if (proxy != null) { wrapper = new ContextHubWrapperV1_0(proxy); } return wrapper; return (proxy == null) ? null : new ContextHubWrapperV1_0(proxy); } /** Loading @@ -69,12 +64,26 @@ public abstract class IContextHubWrapper { Log.i(TAG, "Context Hub HAL service not found"); } ContextHubWrapperV1_1 wrapper = null; if (proxy != null) { wrapper = new ContextHubWrapperV1_1(proxy); return (proxy == null) ? null : new ContextHubWrapperV1_1(proxy); } /** * Attempts to connect to the Contexthub HAL 1.2 service, if it exists. * * @return A valid IContextHubWrapper if the connection was successful, null otherwise. */ @Nullable public static IContextHubWrapper maybeConnectTo1_2() { android.hardware.contexthub.V1_2.IContexthub proxy = null; try { proxy = android.hardware.contexthub.V1_2.IContexthub.getService(true /* retry */); } catch (RemoteException e) { Log.e(TAG, "RemoteException while attaching to Context Hub HAL proxy", e); } catch (NoSuchElementException e) { Log.i(TAG, "Context Hub HAL service not found"); } return wrapper; return (proxy == null) ? null : new ContextHubWrapperV1_2(proxy); } /** Loading @@ -83,19 +92,29 @@ public abstract class IContextHubWrapper { public abstract android.hardware.contexthub.V1_0.IContexthub getHub(); /** * @return True if this version of the Contexthub HAL supports setting notifications. * @return True if this version of the Contexthub HAL supports Location setting notifications. */ public abstract boolean supportsSettingNotifications(); public abstract boolean supportsLocationSettingNotifications(); /** * Notifies the Contexthub implementation of a user setting change. * Notifies the Contexthub implementation of a user Location setting change. * * @param setting The user setting that has changed. MUST be one of the values from the * {@link Setting} enum * @param newValue The value of the user setting that changed. MUST be one of the values * from the {@link SettingValue} enum. * @param enabled True if the Location setting has been enabled. */ public abstract void onSettingChanged(byte setting, byte newValue); public abstract void onLocationSettingChanged(boolean enabled); /** * @return True if this version of the Contexthub HAL supports WiFi availability setting * notifications. */ public abstract boolean supportsWifiSettingNotifications(); /** * Notifies the Contexthub implementation of a user WiFi availability setting change. * * @param enabled true if the WiFi availability setting has been enabled. */ public abstract void onWifiSettingChanged(boolean enabled); private static class ContextHubWrapperV1_0 extends IContextHubWrapper { private android.hardware.contexthub.V1_0.IContexthub mHub; Loading @@ -108,11 +127,17 @@ public abstract class IContextHubWrapper { return mHub; } public boolean supportsSettingNotifications() { public boolean supportsLocationSettingNotifications() { return false; } public void onSettingChanged(byte setting, byte newValue) {} public boolean supportsWifiSettingNotifications() { return false; } public void onLocationSettingChanged(boolean enabled) {} public void onWifiSettingChanged(boolean enabled) {} } private static class ContextHubWrapperV1_1 extends IContextHubWrapper { Loading @@ -126,13 +151,58 @@ public abstract class IContextHubWrapper { return mHub; } public boolean supportsSettingNotifications() { public boolean supportsLocationSettingNotifications() { return true; } public boolean supportsWifiSettingNotifications() { return false; } public void onLocationSettingChanged(boolean enabled) { try { mHub.onSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } catch (RemoteException e) { Log.e(TAG, "Failed to send setting change to Contexthub", e); } } public void onWifiSettingChanged(boolean enabled) {} } private static class ContextHubWrapperV1_2 extends IContextHubWrapper { private android.hardware.contexthub.V1_2.IContexthub mHub; ContextHubWrapperV1_2(android.hardware.contexthub.V1_2.IContexthub hub) { mHub = hub; } public android.hardware.contexthub.V1_0.IContexthub getHub() { return mHub; } public boolean supportsLocationSettingNotifications() { return true; } public void onSettingChanged(byte setting, byte newValue) { public boolean supportsWifiSettingNotifications() { return true; } public void onLocationSettingChanged(boolean enabled) { sendSettingChanged(Setting.LOCATION, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } public void onWifiSettingChanged(boolean enabled) { sendSettingChanged(android.hardware.contexthub.V1_2.Setting.WIFI_AVAILABLE, enabled ? SettingValue.ENABLED : SettingValue.DISABLED); } private void sendSettingChanged(byte setting, byte newValue) { try { mHub.onSettingChanged(setting, newValue); mHub.onSettingChanged_1_2(setting, newValue); } catch (RemoteException e) { Log.e(TAG, "Failed to send setting change to Contexthub", e); } Loading