Merge "Remove hotspot receiver from manifest." into oc-dev
am: 44cfdcc9a7
Change-Id: If2461a2b66be0dbc76d6504dc4a8dca12782c86b
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,6 @@ import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settingslib.TetherUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -69,6 +68,7 @@ public class TetherService extends Service {
|
||||
private UsageStatsManagerWrapper mUsageManagerWrapper;
|
||||
private ArrayList<Integer> mCurrentTethers;
|
||||
private ArrayMap<Integer, List<ResultReceiver>> mPendingCallbacks;
|
||||
private HotspotOffReceiver mHotspotReceiver;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
@@ -94,6 +94,7 @@ public class TetherService extends Service {
|
||||
if (mUsageManagerWrapper == null) {
|
||||
mUsageManagerWrapper = new UsageStatsManagerWrapper(this);
|
||||
}
|
||||
mHotspotReceiver = new HotspotOffReceiver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,6 +182,11 @@ public class TetherService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setHotspotOffReceiver(HotspotOffReceiver receiver) {
|
||||
mHotspotReceiver = receiver;
|
||||
}
|
||||
|
||||
private ArrayList<Integer> stringToTethers(String tethersStr) {
|
||||
ArrayList<Integer> ret = new ArrayList<Integer>();
|
||||
if (TextUtils.isEmpty(tethersStr)) return ret;
|
||||
@@ -276,7 +282,8 @@ public class TetherService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleAlarm() {
|
||||
@VisibleForTesting
|
||||
void scheduleAlarm() {
|
||||
Intent intent = new Intent(this, TetherService.class);
|
||||
intent.putExtra(ConnectivityManager.EXTRA_RUN_PROVISION, true);
|
||||
|
||||
@@ -289,6 +296,7 @@ public class TetherService extends Service {
|
||||
if (DEBUG) Log.d(TAG, "Scheduling alarm at interval " + periodMs);
|
||||
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, firstTime, periodMs,
|
||||
pendingIntent);
|
||||
mHotspotReceiver.register();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -302,7 +310,8 @@ public class TetherService extends Service {
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
private void cancelAlarmIfNecessary() {
|
||||
@VisibleForTesting
|
||||
void cancelAlarmIfNecessary() {
|
||||
if (mCurrentTethers.size() != 0) {
|
||||
if (DEBUG) Log.d(TAG, "Tethering still active, not cancelling alarm");
|
||||
return;
|
||||
@@ -312,6 +321,7 @@ public class TetherService extends Service {
|
||||
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
||||
alarmManager.cancel(pendingIntent);
|
||||
if (DEBUG) Log.d(TAG, "Tethering no longer active, canceling recheck");
|
||||
mHotspotReceiver.unregister();
|
||||
}
|
||||
|
||||
private void fireCallbacksForType(int type, int result) {
|
||||
|
Reference in New Issue
Block a user