Merge "Add tether preferences into AllInOneTetherSettings"
This commit is contained in:
@@ -120,22 +120,23 @@ public final class AllInOneTetherSettings extends RestrictedDashboardFragment
|
||||
public void onReceive(Context content, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(TAG, "updating display config due to receiving broadcast action " + action);
|
||||
Log.d(TAG,
|
||||
"updating display config due to receiving broadcast action " + action);
|
||||
}
|
||||
updateDisplayWithNewConfig();
|
||||
if (TextUtils.equals(action, ACTION_TETHER_STATE_CHANGED)) {
|
||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
mTetherEnabler.startTethering(TETHERING_WIFI);
|
||||
}
|
||||
restartWifiTetherIfNeed(mWifiManager.getWifiApState());
|
||||
} else if (TextUtils.equals(action, WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||
int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0);
|
||||
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
mTetherEnabler.startTethering(TETHERING_WIFI);
|
||||
}
|
||||
restartWifiTetherIfNeed(intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private void restartWifiTetherIfNeed(int state) {
|
||||
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mWifiTetherChosen
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
mTetherEnabler.startTethering(TETHERING_WIFI);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -418,7 +419,7 @@ public final class AllInOneTetherSettings extends RestrictedDashboardFragment
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context, null /* AllTetherSettings */);
|
||||
return buildPreferenceControllers(context, null /*listener*/);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -20,6 +20,8 @@ import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||
|
||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothPan;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -34,6 +36,7 @@ import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
@@ -50,9 +53,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* TetherEnabler is a helper to manage Tethering switch on/off state. It turns on/off
|
||||
* different types of tethering based on stored values in {@link SharedPreferences} and ensures
|
||||
* tethering state updated by data saver state.
|
||||
*
|
||||
* This class is not designed for extending. It's extendable solely for the test purpose.
|
||||
*/
|
||||
|
||||
public final class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListener,
|
||||
public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListener,
|
||||
DataSaverBackend.Listener, LifecycleObserver,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@@ -63,12 +68,9 @@ public final class TetherEnabler implements SwitchWidgetController.OnSwitchChang
|
||||
|
||||
// This KEY is used for a shared preference value, not for any displayed preferences.
|
||||
public static final String KEY_ENABLE_WIFI_TETHERING = "enable_wifi_tethering";
|
||||
@VisibleForTesting
|
||||
static final String WIFI_TETHER_DISABLE_KEY = "disable_wifi_tethering";
|
||||
@VisibleForTesting
|
||||
static final String USB_TETHER_KEY = "enable_usb_tethering";
|
||||
@VisibleForTesting
|
||||
static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering";
|
||||
public static final String WIFI_TETHER_DISABLE_KEY = "disable_wifi_tethering";
|
||||
public static final String USB_TETHER_KEY = "enable_usb_tethering";
|
||||
public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
|
||||
|
||||
private final SwitchWidgetController mSwitchWidgetController;
|
||||
private final WifiManager mWifiManager;
|
||||
@@ -113,7 +115,7 @@ public final class TetherEnabler implements SwitchWidgetController.OnSwitchChang
|
||||
mContext.registerReceiver(mTetherChangeReceiver, filter);
|
||||
|
||||
mOnStartTetheringCallback = new OnStartTetheringCallback(this);
|
||||
updateState();
|
||||
updateState(null/*tethered*/);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
@@ -133,14 +135,20 @@ public final class TetherEnabler implements SwitchWidgetController.OnSwitchChang
|
||||
mContext.unregisterReceiver(mTetherChangeReceiver);
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
mSwitchWidgetController.setChecked(isTethering());
|
||||
@VisibleForTesting
|
||||
void updateState(@Nullable String[] tethered) {
|
||||
boolean isTethering = tethered == null ? isTethering() : isTethering(tethered);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "updateState: " + isTethering);
|
||||
}
|
||||
setSwitchCheckedInternal(isTethering);
|
||||
mSwitchWidgetController.setEnabled(!mDataSaverEnabled);
|
||||
}
|
||||
|
||||
private void updateState(String[] tethered) {
|
||||
mSwitchWidgetController.setChecked(isTethering(tethered));
|
||||
mSwitchWidgetController.setEnabled(!mDataSaverEnabled);
|
||||
private void setSwitchCheckedInternal(boolean checked) {
|
||||
mSwitchWidgetController.stopListening();
|
||||
mSwitchWidgetController.setChecked(checked);
|
||||
mSwitchWidgetController.startListening();
|
||||
}
|
||||
|
||||
private boolean isTethering() {
|
||||
@@ -269,7 +277,7 @@ public final class TetherEnabler implements SwitchWidgetController.OnSwitchChang
|
||||
if (active != null) {
|
||||
updateState(active.toArray(new String[0]));
|
||||
} else {
|
||||
updateState();
|
||||
updateState(null/*tethered*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -371,7 +379,7 @@ public final class TetherEnabler implements SwitchWidgetController.OnSwitchChang
|
||||
private void update() {
|
||||
TetherEnabler enabler = mTetherEnabler.get();
|
||||
if (enabler != null) {
|
||||
enabler.updateState();
|
||||
enabler.updateState(null/*tethered*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.TetherUtil;
|
||||
|
||||
/**
|
||||
* This controller helps to manage the switch state and visibility of wifi tether disable switch
|
||||
@@ -84,7 +85,8 @@ public final class WifiTetherDisablePreferenceController extends BasePreferenceC
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final String[] wifiRegexs = mCm.getTetherableWifiRegexs();
|
||||
if (wifiRegexs == null || wifiRegexs.length == 0 || !shouldShow()) {
|
||||
if (wifiRegexs == null || wifiRegexs.length == 0 || !shouldShow()
|
||||
|| !TetherUtil.isTetherAvailable(mContext)) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
|
Reference in New Issue
Block a user