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

Commit 256a2266 authored by Jason Monk's avatar Jason Monk
Browse files

Turn off/on wifi to correspond with hotspot

Add logic to act the same way Settings does.  Without this sometimes
wifi is in the wrong state (on) and the hotspot wont turn on.

Bug: 16818232
Change-Id: Iaa7950a1c2097cfd798eddb604b49b3a152f1260
parent 0831de10
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -16,18 +16,20 @@

package com.android.systemui.statusbar.policy;

import java.util.ArrayList;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;

import java.util.ArrayList;

public class HotspotControllerImpl implements HotspotController {

    private static final String TAG = "HotspotController";
@@ -73,7 +75,26 @@ public class HotspotControllerImpl implements HotspotController {

    @Override
    public void setHotspotEnabled(boolean enabled) {
        final ContentResolver cr = mContext.getContentResolver();
        // This needs to be kept up to date with Settings (WifiApEnabler.setSoftapEnabled)
        // in case it is turned on in settings and off in qs (or vice versa).
        // Disable Wifi if enabling tethering.
        int wifiState = mWifiManager.getWifiState();
        if (enabled && ((wifiState == WifiManager.WIFI_STATE_ENABLING) ||
                    (wifiState == WifiManager.WIFI_STATE_ENABLED))) {
            mWifiManager.setWifiEnabled(false);
            Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 1);
        }

        mWifiManager.setWifiApEnabled(null, enabled);

        // If needed, restore Wifi on tether disable.
        if (!enabled) {
            if (Settings.Global.getInt(cr, Settings.Global.WIFI_SAVED_STATE, 0) == 1) {
                mWifiManager.setWifiEnabled(true);
                Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 0);
            }
        }
    }

    private void fireCallback(boolean isEnabled) {