Merge changes Ia8dc423f,I0b6ed0e6
* changes: Add Context Hub HAL 1.2 in IContextHubWrapper Simplifies Location setting handling in ContextHubService
This commit is contained in:
committed by
Android (Google) Code Review
commit
4c361bbb47
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
@@ -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),
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
@@ -126,16 +151,61 @@ public abstract class IContextHubWrapper {
|
||||
return mHub;
|
||||
}
|
||||
|
||||
public boolean supportsSettingNotifications() {
|
||||
public boolean supportsLocationSettingNotifications() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onSettingChanged(byte setting, byte newValue) {
|
||||
public boolean supportsWifiSettingNotifications() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onLocationSettingChanged(boolean enabled) {
|
||||
try {
|
||||
mHub.onSettingChanged(setting, newValue);
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user