From 256a22663dbeb31cf4f4a6e295e0c74d80e4fecb Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 5 Aug 2014 16:24:22 -0400 Subject: [PATCH] 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 --- .../policy/HotspotControllerImpl.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java index eea8396c49593..dd706bb949f63 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java @@ -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) {