diff options
| -rw-r--r-- | services/core/java/com/android/server/location/ContextHubService.java | 25 | ||||
| -rw-r--r-- | services/core/java/com/android/server/location/IContextHubWrapper.java | 36 |
2 files changed, 61 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java index fb23e0187ebf..b6e0bc6e069d 100644 --- a/services/core/java/com/android/server/location/ContextHubService.java +++ b/services/core/java/com/android/server/location/ContextHubService.java @@ -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()); } diff --git a/services/core/java/com/android/server/location/IContextHubWrapper.java b/services/core/java/com/android/server/location/IContextHubWrapper.java index 613964a5ed14..9ac7c6b95583 100644 --- a/services/core/java/com/android/server/location/IContextHubWrapper.java +++ b/services/core/java/com/android/server/location/IContextHubWrapper.java @@ -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); |