Remove hotspot receiver from manifest.

The hotspot receiver if used to cancel any tethering alarm set when wifi
ap state changes. Removing it from the manifest, and only register the
receiver when we schedule the tethering alarm.

Change-Id: I97c3be6e2a374949208bbdd4ac5ccc2fabf0291a
Fix: 35968322
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2017-03-30 14:40:25 -07:00
parent f84c8d3480
commit f94401b06d
4 changed files with 123 additions and 12 deletions

View File

@@ -4,12 +4,11 @@ package com.android.settings;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.util.Log;
import com.android.settingslib.TetherUtil;
/**
* This receiver catches when quick settings turns off the hotspot, so we can
* cancel the alarm in that case. All other cancels are handled in tethersettings.
@@ -19,6 +18,13 @@ public class HotspotOffReceiver extends BroadcastReceiver {
private static final String TAG = "HotspotOffReceiver";
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
private Context mContext;
private boolean mRegistered;
public HotspotOffReceiver(Context context) {
mContext = context;
}
@Override
public void onReceive(Context context, Intent intent) {
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
@@ -31,4 +37,19 @@ public class HotspotOffReceiver extends BroadcastReceiver {
}
}
}
public void register() {
if (!mRegistered) {
mContext.registerReceiver(this,
new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION));
mRegistered = true;
}
}
public void unregister() {
if (mRegistered) {
mContext.unregisterReceiver(this);
mRegistered = false;
}
}
}