Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 1 | |
| 2 | package com.android.settings; |
| 3 | |
| 4 | import android.content.BroadcastReceiver; |
| 5 | import android.content.Context; |
| 6 | import android.content.Intent; |
Doris Ling | f94401b | 2017-03-30 14:40:25 -0700 | [diff] [blame] | 7 | import android.content.IntentFilter; |
Jeremy Klein | 8a93476 | 2016-01-22 16:14:05 -0800 | [diff] [blame] | 8 | import android.net.ConnectivityManager; |
Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 9 | import android.net.wifi.WifiManager; |
Hyejin | 5565b5c | 2015-09-10 23:26:53 -0700 | [diff] [blame] | 10 | import android.util.Log; |
Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 11 | |
| 12 | /** |
| 13 | * This receiver catches when quick settings turns off the hotspot, so we can |
| 14 | * cancel the alarm in that case. All other cancels are handled in tethersettings. |
| 15 | */ |
| 16 | public class HotspotOffReceiver extends BroadcastReceiver { |
| 17 | |
Hyejin | 5565b5c | 2015-09-10 23:26:53 -0700 | [diff] [blame] | 18 | private static final String TAG = "HotspotOffReceiver"; |
| 19 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 20 | |
Doris Ling | f94401b | 2017-03-30 14:40:25 -0700 | [diff] [blame] | 21 | private Context mContext; |
| 22 | private boolean mRegistered; |
| 23 | |
| 24 | public HotspotOffReceiver(Context context) { |
| 25 | mContext = context; |
| 26 | } |
| 27 | |
Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 28 | @Override |
| 29 | public void onReceive(Context context, Intent intent) { |
| 30 | if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) { |
| 31 | WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); |
| 32 | if (wifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED) { |
Hyejin | 5565b5c | 2015-09-10 23:26:53 -0700 | [diff] [blame] | 33 | if (DEBUG) Log.d(TAG, "TetherService.cancelRecheckAlarmIfNecessary called"); |
Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 34 | // The hotspot has been turned off, we don't need to recheck tethering. |
Jeremy Klein | 8a93476 | 2016-01-22 16:14:05 -0800 | [diff] [blame] | 35 | TetherService.cancelRecheckAlarmIfNecessary( |
| 36 | context, ConnectivityManager.TETHERING_WIFI); |
Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | } |
Doris Ling | f94401b | 2017-03-30 14:40:25 -0700 | [diff] [blame] | 40 | |
| 41 | public void register() { |
| 42 | if (!mRegistered) { |
| 43 | mContext.registerReceiver(this, |
| 44 | new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)); |
| 45 | mRegistered = true; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public void unregister() { |
| 50 | if (mRegistered) { |
| 51 | mContext.unregisterReceiver(this); |
| 52 | mRegistered = false; |
| 53 | } |
| 54 | } |
Jason Monk | 37832d6 | 2014-12-10 17:21:51 -0500 | [diff] [blame] | 55 | } |