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:
@@ -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