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

Commit 8a64b1a7 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Handle airplane settings properly

Fix bug dealing with airplane mode settings of whether wifi
is sensitive to airplane mode change and whether wifi is
allowed to override airplane mode that likely has been
broken ever since.

Bug: 8141918
Change-Id: Ia3116c9dfce2952cbe3911e9d81dbbae0430abef
parent b8c0e009
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -275,9 +275,10 @@ public final class WifiService extends IWifiManager.Stub {
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        mSettingsStore.handleAirplaneModeToggled();
                        if (mSettingsStore.handleAirplaneModeToggled()) {
                            updateWifiState();
                        }
                    }
                },
                new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED));

@@ -424,7 +425,10 @@ public final class WifiService extends IWifiManager.Stub {

        long ident = Binder.clearCallingIdentity();
        try {
            mSettingsStore.handleWifiToggled(enable);
            if (! mSettingsStore.handleWifiToggled(enable)) {
                // Nothing to do if wifi cannot be toggled
                return true;
            }
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
+16 −5
Original line number Diff line number Diff line
@@ -70,10 +70,14 @@ final class WifiSettingsStore {
       return mAirplaneModeOn;
    }

    synchronized void handleWifiToggled(boolean wifiEnabled) {
        boolean airplaneEnabled = mAirplaneModeOn && isAirplaneToggleable();
    synchronized boolean handleWifiToggled(boolean wifiEnabled) {
        // Can Wi-Fi be toggled in airplane mode ?
        if (mAirplaneModeOn && !isAirplaneToggleable()) {
            return false;
        }

        if (wifiEnabled) {
            if (airplaneEnabled) {
            if (mAirplaneModeOn) {
                persistWifiState(WIFI_ENABLED_AIRPLANE_OVERRIDE);
            } else {
                persistWifiState(WIFI_ENABLED);
@@ -85,9 +89,15 @@ final class WifiSettingsStore {
            // is handled handleAirplaneModeToggled()
            persistWifiState(WIFI_DISABLED);
        }
        return true;
    }

    synchronized boolean handleAirplaneModeToggled() {
        // Is Wi-Fi sensitive to airplane mode changes ?
        if (!isAirplaneSensitive()) {
            return false;
        }

    synchronized void handleAirplaneModeToggled() {
        mAirplaneModeOn = getPersistedAirplaneModeOn();
        if (mAirplaneModeOn) {
            // Wifi disabled due to airplane on
@@ -101,6 +111,7 @@ final class WifiSettingsStore {
                persistWifiState(WIFI_ENABLED);
            }
        }
        return true;
    }

    void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -161,7 +172,7 @@ final class WifiSettingsStore {
    }

    private boolean getPersistedAirplaneModeOn() {
        return isAirplaneSensitive() && Settings.Global.getInt(mContext.getContentResolver(),
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
    }
}