From 07a2295a4dbce33f1913f942fa9733b016ab398a Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Wed, 27 Mar 2013 13:27:39 -0700 Subject: [PATCH] Notify user only when device provisioned Make sure the notification about scan mode being availabe is only shown when device is already provisioned Bug: 8482739 Change-Id: If8a76ffcc0401b846e39b02a55ea69743303c93d --- .../java/com/android/server/wifi/README.txt | 7 +++ .../com/android/server/wifi/WifiService.java | 59 +++++++++++++++++-- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/services/java/com/android/server/wifi/README.txt b/services/java/com/android/server/wifi/README.txt index c03bff5a1ef6d..39e14751ab132 100644 --- a/services/java/com/android/server/wifi/README.txt +++ b/services/java/com/android/server/wifi/README.txt @@ -10,3 +10,10 @@ WifiNotificationController: Controls whether the open network notification is di WifiStateMachine: Tracks the various states on STA and AP connectivity and handles bring up and shut down. + +Feature description: + +Scan-only mode with Wi-Fi turned off: + - Setup wizard opts user into allowing scanning for improved location. We show no further dialogs in setup wizard since the user has just opted into the feature. This is the reason WifiService listens to DEVICE_PROVISIONED setting. + - Once the user has his device provisioned, turning off Wi-Fi from settings or from a third party app will show up a dialog reminding the user that scan mode will be on even though Wi-Fi is being turned off. The user has the choice to turn this notification off. + - In the scan mode, the device continues to allow scanning from any app with Wi-Fi turned off. This is done by disabling all networks and allowing only scans to be passed. diff --git a/services/java/com/android/server/wifi/WifiService.java b/services/java/com/android/server/wifi/WifiService.java index 9dde58f759758..f8d5d2ef8fc01 100644 --- a/services/java/com/android/server/wifi/WifiService.java +++ b/services/java/com/android/server/wifi/WifiService.java @@ -58,6 +58,7 @@ import java.net.InetAddress; import java.net.Inet4Address; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import com.android.internal.R; import com.android.internal.app.IBatteryStats; @@ -101,6 +102,9 @@ public final class WifiService extends IWifiManager.Stub { private int mMulticastEnabled; private int mMulticastDisabled; + private AtomicBoolean mDeviceProvisioned = new AtomicBoolean(); + private AtomicBoolean mNotifyScanMode = new AtomicBoolean(); + private final IBatteryStats mBatteryStats; private final AppOpsManager mAppOps; @@ -245,6 +249,8 @@ public final class WifiService extends IWifiManager.Stub { mWifiController.start(); registerForScanModeChange(); + registerForDeviceProvisionedChange(); + registerForNotifyUserOnScanModeChange(); mContext.registerReceiver( new BroadcastReceiver() { @Override @@ -399,10 +405,8 @@ public final class WifiService extends IWifiManager.Stub { /* Turning off Wi-Fi when scans are still available */ if (!enable && isScanningAlwaysAvailable()) { - /* This can be changed by user in the app to not be notified again */ - boolean notifyUser = (Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.WIFI_NOTIFY_SCAN_ALWAYS_AVAILABLE, 1) == 1); - if (notifyUser) { + /* Notify if device is provisioned and user has not opted out of the notification */ + if (mNotifyScanMode.get() && mDeviceProvisioned.get()) { Intent intent = new Intent(WifiManager.ACTION_NOTIFY_SCAN_ALWAYS_AVAILABLE); mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); } @@ -875,6 +879,51 @@ public final class WifiService extends IWifiManager.Stub { false, contentObserver); } + private void getPersistedDeviceProvisioned() { + mDeviceProvisioned.set(Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.DEVICE_PROVISIONED, 0) != 0); + } + + private void getPersistedNotifyScanMode() { + mNotifyScanMode.set(Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.WIFI_NOTIFY_SCAN_ALWAYS_AVAILABLE, 1) == 1); + } + + /** + * Observes settings changes to notify the user when scan mode is active and + * Wi-Fi is turned off + */ + private void registerForNotifyUserOnScanModeChange() { + ContentObserver contentObserver = new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + getPersistedNotifyScanMode(); + } + }; + + getPersistedNotifyScanMode(); + mContext.getContentResolver().registerContentObserver( + Settings.Global.getUriFor(Settings.Global.WIFI_NOTIFY_SCAN_ALWAYS_AVAILABLE), + false, contentObserver); + } + + /* + * Observes settings changes device provisioned status + */ + private void registerForDeviceProvisionedChange() { + ContentObserver contentObserver = new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + getPersistedDeviceProvisioned(); + } + }; + + getPersistedDeviceProvisioned(); + mContext.getContentResolver().registerContentObserver( + Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), + false, contentObserver); + } + private void registerForBroadcasts() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_SCREEN_ON); @@ -899,6 +948,8 @@ public final class WifiService extends IWifiManager.Stub { pw.println("Stay-awake conditions: " + Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0)); + pw.println("mDeviceProvisioned " + mDeviceProvisioned.get()); + pw.println("mNotifyScanMode " + mNotifyScanMode.get()); pw.println("mMulticastEnabled " + mMulticastEnabled); pw.println("mMulticastDisabled " + mMulticastDisabled); mWifiController.dump(fd, pw, args);