1 
2 package com.android.settings;
3 
4 import android.content.BroadcastReceiver;
5 import android.content.Context;
6 import android.content.Intent;
7 import android.net.ConnectivityManager;
8 import android.net.wifi.WifiManager;
9 import android.util.Log;
10 
11 import com.android.settingslib.TetherUtil;
12 
13 /**
14  * This receiver catches when quick settings turns off the hotspot, so we can
15  * cancel the alarm in that case.  All other cancels are handled in tethersettings.
16  */
17 public class HotspotOffReceiver extends BroadcastReceiver {
18 
19     private static final String TAG = "HotspotOffReceiver";
20     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
21 
22     @Override
onReceive(Context context, Intent intent)23     public void onReceive(Context context, Intent intent) {
24         if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
25             WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
26             if (wifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED) {
27                 if (DEBUG) Log.d(TAG, "TetherService.cancelRecheckAlarmIfNecessary called");
28                 // The hotspot has been turned off, we don't need to recheck tethering.
29                 TetherService.cancelRecheckAlarmIfNecessary(
30                         context, ConnectivityManager.TETHERING_WIFI);
31             }
32         }
33     }
34 }
35