From 75d8e9d25a93b266f71d2420749540de9f781da1 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Wed, 21 Oct 2020 16:24:06 -0700 Subject: [PATCH] Update ContextHubService to handle airplane mode settings Bug: 166845383 Test: Flash, toggle airplane mode and verify changes are propagated to CHRE Change-Id: I4b2ad6dea0bcde273338a2e41eaf4ca94a2856c4 --- .../server/location/ContextHubService.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java index fb23e0187ebf5..b6e0bc6e069de 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()); }