Merge changes I4b2ad6de,I9971e939

* changes:
  Update ContextHubService to handle airplane mode settings
  Adds airplane mode handing in IContextHubWrapper
This commit is contained in:
TreeHugger Robot
2020-10-22 14:39:57 +00:00
committed by Android (Google) Code Review
2 changed files with 61 additions and 0 deletions

View File

@@ -242,6 +242,18 @@ public class ContextHubService extends IContextHubService.Stub {
}
}, UserHandle.USER_ALL);
}
if (mContextHubWrapper.supportsAirplaneModeSettingNotifications()) {
mContext.getContentResolver().registerContentObserver(
Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON),
true /* notifyForDescendants */,
new ContentObserver(null /* handler */) {
@Override
public void onChange(boolean selfChange) {
sendAirplaneModeSettingUpdate();
}
}, UserHandle.USER_ALL);
}
}
/**
@@ -614,6 +626,7 @@ public class ContextHubService extends IContextHubService.Stub {
if (eventType == AsyncEventType.RESTARTED) {
sendLocationSettingUpdate();
sendWifiSettingUpdate(true /* forceUpdate */);
sendAirplaneModeSettingUpdate();
mTransactionManager.onHubReset();
queryNanoAppsInternal(contextHubId);
@@ -958,6 +971,7 @@ public class ContextHubService extends IContextHubService.Stub {
/**
* Obtains the latest WiFi availability setting value and notifies the Context Hub.
*
* @param forceUpdate True to force send update to the Context Hub, otherwise only send the
* update when the WiFi availability changes.
*/
@@ -972,6 +986,17 @@ public class ContextHubService extends IContextHubService.Stub {
}
}
/**
* Obtains the latest airplane mode setting value and notifies the Context Hub.
*/
private void sendAirplaneModeSettingUpdate() {
boolean enabled =
(Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0)
== 1);
mContextHubWrapper.onAirplaneModeSettingChanged(enabled);
}
private String getCallingPackageName() {
return mContext.getPackageManager().getNameForUid(Binder.getCallingUid());
}

View File

@@ -116,6 +116,19 @@ public abstract class IContextHubWrapper {
*/
public abstract void onWifiSettingChanged(boolean enabled);
/**
* @return True if this version of the Contexthub HAL supports airplane mode setting
* notifications.
*/
public abstract boolean supportsAirplaneModeSettingNotifications();
/**
* Notifies the Contexthub implementation of an airplane mode setting change.
*
* @param enabled true if the airplane mode setting has been enabled.
*/
public abstract void onAirplaneModeSettingChanged(boolean enabled);
private static class ContextHubWrapperV1_0 extends IContextHubWrapper {
private android.hardware.contexthub.V1_0.IContexthub mHub;
@@ -135,11 +148,18 @@ public abstract class IContextHubWrapper {
return false;
}
public boolean supportsAirplaneModeSettingNotifications() {
return false;
}
public void onLocationSettingChanged(boolean enabled) {
}
public void onWifiSettingChanged(boolean enabled) {
}
public void onAirplaneModeSettingChanged(boolean enabled) {
}
}
private static class ContextHubWrapperV1_1 extends IContextHubWrapper {
@@ -161,6 +181,10 @@ public abstract class IContextHubWrapper {
return false;
}
public boolean supportsAirplaneModeSettingNotifications() {
return false;
}
public void onLocationSettingChanged(boolean enabled) {
try {
mHub.onSettingChanged(Setting.LOCATION,
@@ -172,6 +196,9 @@ public abstract class IContextHubWrapper {
public void onWifiSettingChanged(boolean enabled) {
}
public void onAirplaneModeSettingChanged(boolean enabled) {
}
}
private static class ContextHubWrapperV1_2 extends IContextHubWrapper {
@@ -193,6 +220,10 @@ public abstract class IContextHubWrapper {
return true;
}
public boolean supportsAirplaneModeSettingNotifications() {
return true;
}
public void onLocationSettingChanged(boolean enabled) {
sendSettingChanged(Setting.LOCATION,
enabled ? SettingValue.ENABLED : SettingValue.DISABLED);
@@ -203,6 +234,11 @@ public abstract class IContextHubWrapper {
enabled ? SettingValue.ENABLED : SettingValue.DISABLED);
}
public void onAirplaneModeSettingChanged(boolean enabled) {
sendSettingChanged(android.hardware.contexthub.V1_2.Setting.AIRPLANE_MODE,
enabled ? SettingValue.ENABLED : SettingValue.DISABLED);
}
private void sendSettingChanged(byte setting, byte newValue) {
try {
mHub.onSettingChanged_1_2(setting, newValue);