Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07a2295a authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

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
parent f2b0fdb2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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.
+55 −4
Original line number Diff line number Diff line
@@ -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);