Make WifiTether listen to datasaver

Wifi Tethering is already turned off when appropriate. However
if you re-enable it you still can't toggle the tether switchbar.
This CL makes it so that if you disable data saver the toggle
becomes enabled again.

Test: robotests
Bug: 77860936
Change-Id: I03fa74c21674678a90cde7bd20fa68167f02ae3c
This commit is contained in:
Salvador Martinez
2018-04-17 17:32:16 -07:00
committed by Andrew Sapperstein
parent 8a3bcaa3e3
commit 7ba65c39ae
2 changed files with 37 additions and 2 deletions

View File

@@ -36,15 +36,17 @@ import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
public class WifiTetherSwitchBarController implements SwitchWidgetController.OnSwitchChangeListener,
LifecycleObserver, OnStart, OnStop {
LifecycleObserver, OnStart, OnStop, DataSaverBackend.Listener {
private static final IntentFilter WIFI_INTENT_FILTER;
private final Context mContext;
private final SwitchWidgetController mSwitchBar;
private final ConnectivityManager mConnectivityManager;
private final DataSaverBackend mDataSaverBackend;
private final WifiManager mWifiManager;
@VisibleForTesting
final DataSaverBackend mDataSaverBackend;
@VisibleForTesting
final ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback =
new ConnectivityManager.OnStartTetheringCallback() {
@@ -75,12 +77,14 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
@Override
public void onStart() {
mDataSaverBackend.addListener(this);
mSwitchBar.startListening();
mContext.registerReceiver(mReceiver, WIFI_INTENT_FILTER);
}
@Override
public void onStop() {
mDataSaverBackend.remListener(this);
mSwitchBar.stopListening();
mContext.unregisterReceiver(mReceiver);
}
@@ -157,4 +161,19 @@ public class WifiTetherSwitchBarController implements SwitchWidgetController.OnS
mSwitchBar.setEnabled(false);
}
}
@Override
public void onDataSaverChanged(boolean isDataSaving) {
updateWifiSwitch();
}
@Override
public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
// we don't care, since we just want to read the value
}
@Override
public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
// we don't care, since we just want to read the value
}
}