Add Context Hub HAL 1.2 in IContextHubWrapper

Bug: 166845383
Test: Flash and verify HAL 1.2 can be found if present
Change-Id: Ia8dc423f449c1e179ce450a1ee7954a964bae6cb
This commit is contained in:
Arthur Ishiguro 2020-10-14 13:39:09 -07:00
parent a708983350
commit 8368e94109
3 changed files with 87 additions and 1 deletions
Android.bp
services/core/java/com/android/server/location

@ -466,6 +466,7 @@ java_library {
"android.hardware.cas-V1.2-java", "android.hardware.cas-V1.2-java",
"android.hardware.contexthub-V1.0-java", "android.hardware.contexthub-V1.0-java",
"android.hardware.contexthub-V1.1-java", "android.hardware.contexthub-V1.1-java",
"android.hardware.contexthub-V1.2-java",
"android.hardware.gnss-V1.0-java", "android.hardware.gnss-V1.0-java",
"android.hardware.gnss-V2.1-java", "android.hardware.gnss-V2.1-java",
"android.hardware.health-V1.0-java-constants", "android.hardware.health-V1.0-java-constants",

@ -258,7 +258,10 @@ public class ContextHubService extends IContextHubService.Stub {
* @return the IContextHubWrapper interface * @return the IContextHubWrapper interface
*/ */
private IContextHubWrapper getContextHubWrapper() { private IContextHubWrapper getContextHubWrapper() {
IContextHubWrapper wrapper = IContextHubWrapper.maybeConnectTo1_1(); IContextHubWrapper wrapper = IContextHubWrapper.maybeConnectTo1_2();
if (wrapper == null) {
wrapper = IContextHubWrapper.maybeConnectTo1_1();
}
if (wrapper == null) { if (wrapper == null) {
wrapper = IContextHubWrapper.maybeConnectTo1_0(); wrapper = IContextHubWrapper.maybeConnectTo1_0();
} }

@ -67,6 +67,25 @@ public abstract class IContextHubWrapper {
return (proxy == null) ? null : 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 (proxy == null) ? null : new ContextHubWrapperV1_2(proxy);
}
/** /**
* @return A valid instance of Contexthub HAL 1.0. * @return A valid instance of Contexthub HAL 1.0.
*/ */
@ -84,6 +103,19 @@ public abstract class IContextHubWrapper {
*/ */
public abstract void onLocationSettingChanged(boolean enabled); 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 static class ContextHubWrapperV1_0 extends IContextHubWrapper {
private android.hardware.contexthub.V1_0.IContexthub mHub; private android.hardware.contexthub.V1_0.IContexthub mHub;
@ -99,7 +131,13 @@ public abstract class IContextHubWrapper {
return false; return false;
} }
public boolean supportsWifiSettingNotifications() {
return false;
}
public void onLocationSettingChanged(boolean enabled) {} public void onLocationSettingChanged(boolean enabled) {}
public void onWifiSettingChanged(boolean enabled) {}
} }
private static class ContextHubWrapperV1_1 extends IContextHubWrapper { private static class ContextHubWrapperV1_1 extends IContextHubWrapper {
@ -117,6 +155,10 @@ public abstract class IContextHubWrapper {
return true; return true;
} }
public boolean supportsWifiSettingNotifications() {
return false;
}
public void onLocationSettingChanged(boolean enabled) { public void onLocationSettingChanged(boolean enabled) {
try { try {
mHub.onSettingChanged(Setting.LOCATION, mHub.onSettingChanged(Setting.LOCATION,
@ -125,5 +167,45 @@ public abstract class IContextHubWrapper {
Log.e(TAG, "Failed to send setting change to Contexthub", 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 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_1_2(setting, newValue);
} catch (RemoteException e) {
Log.e(TAG, "Failed to send setting change to Contexthub", e);
}
}
} }
} }