Snap for 6334680 from 3b57d68796 to mainline-release
Change-Id: I7e4c467a1db5e7bd1910464b71ddb0b8a266490b
This commit is contained in:
@@ -21,24 +21,36 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<CheckBox
|
<LinearLayout
|
||||||
android:id="@+id/checkbox"
|
android:id="@+id/container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
android:paddingStart="12dp"
|
android:orientation="vertical">
|
||||||
android:saveEnabled="false"
|
|
||||||
android:textColor="?android:attr/textColorAlertDialogListItem"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
|
|
||||||
<TextView
|
<CheckBox
|
||||||
android:id="@+id/summary"
|
android:id="@+id/checkbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="8dp"
|
android:background="@null"
|
||||||
android:paddingStart="44dp"
|
android:clickable="false"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
android:focusable="false"
|
||||||
android:textColor="?android:attr/textColorSecondary" />
|
android:focusableInTouchMode="false"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:saveEnabled="false"
|
||||||
|
android:textColor="?android:attr/textColorAlertDialogListItem"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/summary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingStart="44dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
|
|||||||
@@ -7073,6 +7073,8 @@
|
|||||||
<string name="help_uri_storage" translatable="false"></string>
|
<string name="help_uri_storage" translatable="false"></string>
|
||||||
<!-- Help URI, Accessibility [DO NOT TRANSLATE] -->
|
<!-- Help URI, Accessibility [DO NOT TRANSLATE] -->
|
||||||
<string name="help_uri_accessibility" translatable="false"></string>
|
<string name="help_uri_accessibility" translatable="false"></string>
|
||||||
|
<!-- Help URI, Vibration [DO NOT TRANSLATE] -->
|
||||||
|
<string name="help_uri_accessibility_vibration" translatable="false"></string>
|
||||||
<!-- Help URI, Printing [DO NOT TRANSLATE] -->
|
<!-- Help URI, Printing [DO NOT TRANSLATE] -->
|
||||||
<string name="help_uri_printing" translatable="false"></string>
|
<string name="help_uri_printing" translatable="false"></string>
|
||||||
<!-- Help URI, About phone [DO NOT TRANSLATE] -->
|
<!-- Help URI, About phone [DO NOT TRANSLATE] -->
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
|
|||||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
|
import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.KEY_ENABLE_WIFI_TETHERING;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothPan;
|
import android.bluetooth.BluetoothPan;
|
||||||
@@ -30,7 +28,6 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.wifi.SoftApConfiguration;
|
import android.net.wifi.SoftApConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -74,8 +71,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
||||||
implements DataSaverBackend.Listener,
|
implements DataSaverBackend.Listener,
|
||||||
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener,
|
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener {
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
|
||||||
|
|
||||||
// TODO(b/148622133): Should clean up the postfix once this fragment replaced TetherSettings.
|
// TODO(b/148622133): Should clean up the postfix once this fragment replaced TetherSettings.
|
||||||
public static final String DEDUP_POSTFIX = "_2";
|
public static final String DEDUP_POSTFIX = "_2";
|
||||||
@@ -114,9 +110,18 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
private WifiTetherApBandPreferenceController mApBandPreferenceController;
|
private WifiTetherApBandPreferenceController mApBandPreferenceController;
|
||||||
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
||||||
private PreferenceGroup mWifiTetherGroup;
|
private PreferenceGroup mWifiTetherGroup;
|
||||||
private SharedPreferences mSharedPreferences;
|
private boolean mBluetoothTethering;
|
||||||
private boolean mWifiTetherChosen;
|
private boolean mUsbTethering;
|
||||||
|
private boolean mWifiTethering;
|
||||||
private TetherEnabler mTetherEnabler;
|
private TetherEnabler mTetherEnabler;
|
||||||
|
private final TetherEnabler.OnTetherStateUpdateListener mStateUpdateListener =
|
||||||
|
state -> {
|
||||||
|
mBluetoothTethering = TetherEnabler.isBluetoothTethering(state);
|
||||||
|
mUsbTethering = TetherEnabler.isUsbTethering(state);
|
||||||
|
mWifiTethering = TetherEnabler.isWifiTethering(state);
|
||||||
|
mWifiTetherGroup.setVisible(shouldShowWifiConfig());
|
||||||
|
reConfigInitialExpandedChildCount();
|
||||||
|
};
|
||||||
|
|
||||||
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -136,7 +141,6 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
private void restartWifiTetherIfNeed(int state) {
|
private void restartWifiTetherIfNeed(int state) {
|
||||||
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
||||||
&& mWifiTetherChosen
|
|
||||||
&& mRestartWifiApAfterConfigChange) {
|
&& mRestartWifiApAfterConfigChange) {
|
||||||
mRestartWifiApAfterConfigChange = false;
|
mRestartWifiApAfterConfigChange = false;
|
||||||
mTetherEnabler.startTethering(TETHERING_WIFI);
|
mTetherEnabler.startTethering(TETHERING_WIFI);
|
||||||
@@ -168,8 +172,6 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
mSharedPreferences =
|
|
||||||
context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
|
|
||||||
|
|
||||||
mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class);
|
mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class);
|
||||||
mSecurityPreferenceController = use(WifiTetherSecurityPreferenceController.class);
|
mSecurityPreferenceController = use(WifiTetherSecurityPreferenceController.class);
|
||||||
@@ -199,9 +201,6 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
// Set initial state based on Data Saver mode.
|
// Set initial state based on Data Saver mode.
|
||||||
onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
|
onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
|
||||||
|
|
||||||
// Set initial state based on SharedPreferences value.
|
|
||||||
onSharedPreferenceChanged(mSharedPreferences, KEY_ENABLE_WIFI_TETHERING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -222,6 +221,9 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
mTetherEnabler = new TetherEnabler(activity,
|
mTetherEnabler = new TetherEnabler(activity,
|
||||||
new SwitchBarController(switchBar), mBluetoothPan);
|
new SwitchBarController(switchBar), mBluetoothPan);
|
||||||
getSettingsLifecycle().addObserver(mTetherEnabler);
|
getSettingsLifecycle().addObserver(mTetherEnabler);
|
||||||
|
use(UsbTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
|
use(BluetoothTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
|
use(WifiTetherDisablePreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
switchBar.show();
|
switchBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,18 +249,31 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
if (mUnavailable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mTetherEnabler != null) {
|
||||||
|
mTetherEnabler.addListener(mStateUpdateListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
if (mUnavailable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mTetherEnabler != null) {
|
||||||
|
mTetherEnabler.removeListener(mStateUpdateListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
if (mUnavailable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.unregisterReceiver(mTetherChangeReceiver);
|
context.unregisterReceiver(mTetherChangeReceiver);
|
||||||
@@ -365,13 +380,8 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
mApBandPreferenceController.updateDisplay();
|
mApBandPreferenceController.updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private boolean shouldShowWifiConfig() {
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
return mWifiTethering || (!mBluetoothTethering && !mUsbTethering);
|
||||||
if (TextUtils.equals(key, KEY_ENABLE_WIFI_TETHERING)) {
|
|
||||||
mWifiTetherChosen = sharedPreferences.getBoolean(KEY_ENABLE_WIFI_TETHERING, true);
|
|
||||||
mWifiTetherGroup.setVisible(mWifiTetherChosen);
|
|
||||||
reConfigInitialExpandedChildCount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reConfigInitialExpandedChildCount() {
|
private void reConfigInitialExpandedChildCount() {
|
||||||
@@ -380,7 +390,7 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInitialExpandedChildCount() {
|
public int getInitialExpandedChildCount() {
|
||||||
if (!mWifiTetherChosen) {
|
if (!shouldShowWifiConfig()) {
|
||||||
// Expand all preferences in the screen.
|
// Expand all preferences in the screen.
|
||||||
return getPreferenceScreen().getPreferenceCount();
|
return getPreferenceScreen().getPreferenceCount();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -452,12 +452,23 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDialogTextAreaClickListener(View dialogView, CheckBox checkBox) {
|
||||||
|
final View dialogTextArea = dialogView.findViewById(R.id.container);
|
||||||
|
dialogTextArea.setOnClickListener(v -> {
|
||||||
|
checkBox.toggle();
|
||||||
|
updateUserShortcutType(/* saveChanges= */ false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeDialogCheckBox(Dialog dialog) {
|
private void initializeDialogCheckBox(Dialog dialog) {
|
||||||
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
||||||
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
||||||
|
setDialogTextAreaClickListener(dialogSoftwareView, mSoftwareTypeCheckBox);
|
||||||
|
|
||||||
final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
|
final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
|
||||||
mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
|
mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
|
||||||
|
setDialogTextAreaClickListener(dialogHardwareView, mHardwareTypeCheckBox);
|
||||||
|
|
||||||
updateAlertDialogCheckState();
|
updateAlertDialogCheckState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,9 +479,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
|
|
||||||
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
||||||
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
||||||
checkBox.setOnClickListener(v -> {
|
|
||||||
updateUserShortcutType(/* saveChanges= */ false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserShortcutType(boolean saveChanges) {
|
private void updateUserShortcutType(boolean saveChanges) {
|
||||||
|
|||||||
@@ -246,13 +246,27 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDialogTextAreaClickListener(View dialogView, CheckBox checkBox) {
|
||||||
|
final View dialogTextArea = dialogView.findViewById(R.id.container);
|
||||||
|
dialogTextArea.setOnClickListener(v -> {
|
||||||
|
checkBox.toggle();
|
||||||
|
updateUserShortcutType(/* saveChanges= */ false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeDialogCheckBox(AlertDialog dialog) {
|
private void initializeDialogCheckBox(AlertDialog dialog) {
|
||||||
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
final View dialogSoftwareView = dialog.findViewById(R.id.software_shortcut);
|
||||||
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
mSoftwareTypeCheckBox = dialogSoftwareView.findViewById(R.id.checkbox);
|
||||||
|
setDialogTextAreaClickListener(dialogSoftwareView, mSoftwareTypeCheckBox);
|
||||||
|
|
||||||
final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
|
final View dialogHardwareView = dialog.findViewById(R.id.hardware_shortcut);
|
||||||
mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
|
mHardwareTypeCheckBox = dialogHardwareView.findViewById(R.id.checkbox);
|
||||||
|
setDialogTextAreaClickListener(dialogHardwareView, mHardwareTypeCheckBox);
|
||||||
|
|
||||||
final View dialogTripleTapView = dialog.findViewById(R.id.triple_tap_shortcut);
|
final View dialogTripleTapView = dialog.findViewById(R.id.triple_tap_shortcut);
|
||||||
mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox);
|
mTripleTapTypeCheckBox = dialogTripleTapView.findViewById(R.id.checkbox);
|
||||||
|
setDialogTextAreaClickListener(dialogTripleTapView, mTripleTapTypeCheckBox);
|
||||||
|
|
||||||
final View advancedView = dialog.findViewById(R.id.advanced_shortcut);
|
final View advancedView = dialog.findViewById(R.id.advanced_shortcut);
|
||||||
updateAlertDialogCheckState();
|
updateAlertDialogCheckState();
|
||||||
|
|
||||||
@@ -276,9 +290,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
|
|
||||||
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
private void updateCheckStatus(CheckBox checkBox, @UserShortcutType int type) {
|
||||||
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
checkBox.setChecked((mUserShortcutTypeCache & type) == type);
|
||||||
checkBox.setOnClickListener(v -> {
|
|
||||||
updateUserShortcutType(/* saveChanges= */ false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserShortcutType(boolean saveChanges) {
|
private void updateUserShortcutType(boolean saveChanges) {
|
||||||
|
|||||||
@@ -17,17 +17,12 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accessibility settings for the vibration.
|
* Accessibility settings for the vibration.
|
||||||
*/
|
*/
|
||||||
@@ -41,6 +36,11 @@ public class VibrationSettings extends DashboardFragment {
|
|||||||
return SettingsEnums.ACCESSIBILITY_VIBRATION;
|
return SettingsEnums.ACCESSIBILITY_VIBRATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHelpResource() {
|
||||||
|
return R.string.help_uri_accessibility_vibration;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.accessibility_vibration_settings;
|
return R.xml.accessibility_vibration_settings;
|
||||||
|
|||||||
@@ -17,16 +17,12 @@ package com.android.settings.network;
|
|||||||
|
|
||||||
import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
|
import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
|
|
||||||
import static com.android.settings.network.TetherEnabler.KEY_ENABLE_WIFI_TETHERING;
|
|
||||||
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
|
|
||||||
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
|
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothPan;
|
import android.bluetooth.BluetoothPan;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -56,19 +52,23 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
LifecycleObserver, TetherEnabler.OnTetherStateUpdateListener {
|
LifecycleObserver, TetherEnabler.OnTetherStateUpdateListener {
|
||||||
private static final String TAG = "AllInOneTetherPreferenceController";
|
private static final String TAG = "AllInOneTetherPreferenceController";
|
||||||
|
|
||||||
private static final byte HOTSPOT_ONLY = 1;
|
private static final byte TETHERING_TYPE_HOTSPOT_ONLY = 1;
|
||||||
private static final byte USB_ONLY = 1 << 1;
|
private static final byte TETHERING_TYPE_USB_ONLY = 1 << 1;
|
||||||
private static final byte BLUETOOTH_ONLY = 1 << 2;
|
private static final byte TETHERING_TYPE_BLUETOOTH_ONLY = 1 << 2;
|
||||||
private static final byte HOTSPOT_AND_USB = HOTSPOT_ONLY | USB_ONLY;
|
private static final byte TETHERING_TYPE_HOTSPOT_AND_USB =
|
||||||
private static final byte HOTSPOT_AND_BLUETOOTH = HOTSPOT_ONLY | BLUETOOTH_ONLY;
|
TETHERING_TYPE_HOTSPOT_ONLY | TETHERING_TYPE_USB_ONLY;
|
||||||
private static final byte USB_AND_BLUETOOTH = USB_ONLY | BLUETOOTH_ONLY;
|
private static final byte TETHERING_TYPE_HOTSPOT_AND_BLUETOOTH =
|
||||||
private static final byte HOTSPOT_AND_USB_AND_BLUETOOTH =
|
TETHERING_TYPE_HOTSPOT_ONLY | TETHERING_TYPE_BLUETOOTH_ONLY;
|
||||||
HOTSPOT_ONLY | USB_ONLY | BLUETOOTH_ONLY;
|
private static final byte TETHERING_TYPE_USB_AND_BLUETOOTH =
|
||||||
|
TETHERING_TYPE_USB_ONLY | TETHERING_TYPE_BLUETOOTH_ONLY;
|
||||||
|
private static final byte TETHERING_TYPE_HOTSPOT_AND_USB_AND_BLUETOOTH =
|
||||||
|
TETHERING_TYPE_HOTSPOT_ONLY | TETHERING_TYPE_USB_ONLY | TETHERING_TYPE_BLUETOOTH_ONLY;
|
||||||
|
// A bitwise value that stands for the current tethering interface type.
|
||||||
|
private int mTetheringType;
|
||||||
|
|
||||||
private final boolean mAdminDisallowedTetherConfig;
|
private final boolean mAdminDisallowedTetherConfig;
|
||||||
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
||||||
private final BluetoothAdapter mBluetoothAdapter;
|
private final BluetoothAdapter mBluetoothAdapter;
|
||||||
private final SharedPreferences mTetherEnablerSharedPreferences;
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final BluetoothProfile.ServiceListener mBtProfileServiceListener =
|
final BluetoothProfile.ServiceListener mBtProfileServiceListener =
|
||||||
new BluetoothProfile.ServiceListener() {
|
new BluetoothProfile.ServiceListener() {
|
||||||
@@ -92,7 +92,6 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
mAdminDisallowedTetherConfig = false;
|
mAdminDisallowedTetherConfig = false;
|
||||||
mBluetoothPan = new AtomicReference<>();
|
mBluetoothPan = new AtomicReference<>();
|
||||||
mBluetoothAdapter = null;
|
mBluetoothAdapter = null;
|
||||||
mTetherEnablerSharedPreferences = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AllInOneTetherPreferenceController(Context context, String key) {
|
public AllInOneTetherPreferenceController(Context context, String key) {
|
||||||
@@ -101,8 +100,6 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
mAdminDisallowedTetherConfig = checkIfRestrictionEnforced(
|
mAdminDisallowedTetherConfig = checkIfRestrictionEnforced(
|
||||||
context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
|
context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
|
||||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
mTetherEnablerSharedPreferences =
|
|
||||||
context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,29 +125,22 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (mPreference != null && mPreference.isChecked()) {
|
if (mPreference != null && mPreference.isChecked()) {
|
||||||
int chosenType = 0;
|
switch (mTetheringType) {
|
||||||
chosenType |= mTetherEnablerSharedPreferences
|
case TETHERING_TYPE_HOTSPOT_ONLY:
|
||||||
.getBoolean(KEY_ENABLE_WIFI_TETHERING, true) ? HOTSPOT_ONLY : 0;
|
|
||||||
chosenType |= mTetherEnablerSharedPreferences.getBoolean(USB_TETHER_KEY, false)
|
|
||||||
? USB_ONLY : 0;
|
|
||||||
chosenType |= mTetherEnablerSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)
|
|
||||||
? BLUETOOTH_ONLY : 0;
|
|
||||||
switch (chosenType) {
|
|
||||||
case HOTSPOT_ONLY:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_only);
|
return mContext.getString(R.string.tether_settings_summary_hotspot_only);
|
||||||
case USB_ONLY:
|
case TETHERING_TYPE_USB_ONLY:
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_tethering_only);
|
return mContext.getString(R.string.tether_settings_summary_usb_tethering_only);
|
||||||
case BLUETOOTH_ONLY:
|
case TETHERING_TYPE_BLUETOOTH_ONLY:
|
||||||
return mContext.getString(
|
return mContext.getString(
|
||||||
R.string.tether_settings_summary_bluetooth_tethering_only);
|
R.string.tether_settings_summary_bluetooth_tethering_only);
|
||||||
case HOTSPOT_AND_USB:
|
case TETHERING_TYPE_HOTSPOT_AND_USB:
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_and_usb);
|
return mContext.getString(R.string.tether_settings_summary_hotspot_and_usb);
|
||||||
case HOTSPOT_AND_BLUETOOTH:
|
case TETHERING_TYPE_HOTSPOT_AND_BLUETOOTH:
|
||||||
return mContext.getString(
|
return mContext.getString(
|
||||||
R.string.tether_settings_summary_hotspot_and_bluetooth);
|
R.string.tether_settings_summary_hotspot_and_bluetooth);
|
||||||
case USB_AND_BLUETOOTH:
|
case TETHERING_TYPE_USB_AND_BLUETOOTH:
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_and_bluetooth);
|
return mContext.getString(R.string.tether_settings_summary_usb_and_bluetooth);
|
||||||
case HOTSPOT_AND_USB_AND_BLUETOOTH:
|
case TETHERING_TYPE_HOTSPOT_AND_USB_AND_BLUETOOTH:
|
||||||
return mContext.getString(
|
return mContext.getString(
|
||||||
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth);
|
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth);
|
||||||
default:
|
default:
|
||||||
@@ -174,14 +164,14 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
@OnLifecycleEvent(Event.ON_RESUME)
|
@OnLifecycleEvent(Event.ON_RESUME)
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
if (mTetherEnabler != null) {
|
if (mTetherEnabler != null) {
|
||||||
mTetherEnabler.setListener(this);
|
mTetherEnabler.addListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_PAUSE)
|
@OnLifecycleEvent(Event.ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
if (mTetherEnabler != null) {
|
if (mTetherEnabler != null) {
|
||||||
mTetherEnabler.setListener(null);
|
mTetherEnabler.removeListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +196,12 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTetherStateUpdated(boolean isTethering) {
|
public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
|
||||||
|
mTetheringType = 0;
|
||||||
|
mTetheringType |= TetherEnabler.isBluetoothTethering(state) ? TETHERING_TYPE_BLUETOOTH_ONLY
|
||||||
|
: 0;
|
||||||
|
mTetheringType |= TetherEnabler.isWifiTethering(state) ? TETHERING_TYPE_HOTSPOT_ONLY : 0;
|
||||||
|
mTetheringType |= TetherEnabler.isUsbTethering(state) ? TETHERING_TYPE_USB_ONLY : 0;
|
||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.net.TetheringManager;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -30,9 +29,6 @@ import androidx.lifecycle.Lifecycle;
|
|||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
@@ -40,36 +36,33 @@ import com.google.common.annotations.VisibleForTesting;
|
|||||||
* This controller helps to manage the switch state and visibility of bluetooth tether switch
|
* This controller helps to manage the switch state and visibility of bluetooth tether switch
|
||||||
* preference. It stores preference value when preference changed.
|
* preference. It stores preference value when preference changed.
|
||||||
*/
|
*/
|
||||||
public final class BluetoothTetherPreferenceController extends TogglePreferenceController
|
public final class BluetoothTetherPreferenceController extends TetherBasePreferenceController
|
||||||
implements LifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener {
|
implements LifecycleObserver {
|
||||||
|
|
||||||
private static final String TAG = "BluetoothTetherPreferenceController";
|
private static final String TAG = "BluetoothTetherPreferenceController";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
private final ConnectivityManager mCm;
|
|
||||||
private int mBluetoothState;
|
private int mBluetoothState;
|
||||||
private Preference mPreference;
|
private boolean mBluetoothTethering;
|
||||||
private final SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
public BluetoothTetherPreferenceController(Context context, String prefKey) {
|
public BluetoothTetherPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, prefKey);
|
super(context, preferenceKey);
|
||||||
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
mSharedPreferences =
|
|
||||||
context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return mSharedPreferences.getBoolean(mPreferenceKey, false);
|
return mBluetoothTethering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
if (DEBUG) {
|
if (mTetherEnabler == null) {
|
||||||
Log.d(TAG, "preference changing to " + isChecked);
|
return false;
|
||||||
|
}
|
||||||
|
if (isChecked) {
|
||||||
|
mTetherEnabler.startTethering(TetheringManager.TETHERING_BLUETOOTH);
|
||||||
|
} else {
|
||||||
|
mTetherEnabler.stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
||||||
}
|
}
|
||||||
final SharedPreferences.Editor editor = mSharedPreferences.edit();
|
|
||||||
editor.putBoolean(mPreferenceKey, isChecked);
|
|
||||||
editor.apply();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,27 +73,11 @@ public final class BluetoothTetherPreferenceController extends TogglePreferenceC
|
|||||||
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mContext.unregisterReceiver(mBluetoothChangeReceiver);
|
mContext.unregisterReceiver(mBluetoothChangeReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mPreference = screen.findPreference(mPreferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
@@ -133,6 +110,12 @@ public final class BluetoothTetherPreferenceController extends TogglePreferenceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTetherStateUpdated(int state) {
|
||||||
|
mBluetoothTethering = TetherEnabler.isBluetoothTethering(state);
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final BroadcastReceiver mBluetoothChangeReceiver = new BroadcastReceiver() {
|
final BroadcastReceiver mBluetoothChangeReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -144,11 +127,4 @@ public final class BluetoothTetherPreferenceController extends TogglePreferenceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
if (TextUtils.equals(mPreferenceKey, key)) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
|
public abstract class TetherBasePreferenceController extends TogglePreferenceController
|
||||||
|
implements LifecycleObserver, TetherEnabler.OnTetherStateUpdateListener {
|
||||||
|
|
||||||
|
private static final String TAG = "TetherBasePreferenceController";
|
||||||
|
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
final ConnectivityManager mCm;
|
||||||
|
|
||||||
|
TetherEnabler mTetherEnabler;
|
||||||
|
Preference mPreference;
|
||||||
|
|
||||||
|
public TetherBasePreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set TetherEnabler for the controller. Call this method to initialize the controller.
|
||||||
|
* @param tetherEnabler The tetherEnabler to set for the controller.
|
||||||
|
*/
|
||||||
|
public void setTetherEnabler(TetherEnabler tetherEnabler) {
|
||||||
|
mTetherEnabler = tetherEnabler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
|
public void onResume() {
|
||||||
|
// Must call setEnabler() before
|
||||||
|
if (mTetherEnabler != null) {
|
||||||
|
mTetherEnabler.addListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
|
public void onPause() {
|
||||||
|
if (mTetherEnabler != null) {
|
||||||
|
mTetherEnabler.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(mPreferenceKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,11 +31,11 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -51,21 +51,19 @@ import com.android.settings.widget.SwitchWidgetController;
|
|||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TetherEnabler is a helper to manage Tethering switch on/off state. It turns on/off
|
* TetherEnabler is a helper to manage Tethering switch on/off state. It offers helper functions to
|
||||||
* different types of tethering based on stored values in {@link SharedPreferences} and ensures
|
* turn on/off different types of tethering interfaces and ensures tethering state updated by data
|
||||||
* tethering state updated by data saver state.
|
* saver state.
|
||||||
*
|
*
|
||||||
* This class is not designed for extending. It's extendable solely for the test purpose.
|
* This class is not designed for extending. It's extendable solely for the test purpose.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListener,
|
public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListener,
|
||||||
DataSaverBackend.Listener, LifecycleObserver,
|
DataSaverBackend.Listener, LifecycleObserver {
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
|
||||||
|
|
||||||
private OnTetherStateUpdateListener mListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface definition for a callback to be invoked when the tethering has been updated.
|
* Interface definition for a callback to be invoked when the tethering has been updated.
|
||||||
@@ -74,9 +72,9 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
/**
|
/**
|
||||||
* Called when the tethering state has changed.
|
* Called when the tethering state has changed.
|
||||||
*
|
*
|
||||||
* @param isTethering The new tethering state.
|
* @param state The new tethering state.
|
||||||
*/
|
*/
|
||||||
void onTetherStateUpdated(boolean isTethering);
|
void onTetherStateUpdated(@TetheringState int state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String TAG = "TetherEnabler";
|
private static final String TAG = "TetherEnabler";
|
||||||
@@ -89,12 +87,14 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
value = {TETHERING_OFF, TETHERING_WIFI_ON, TETHERING_USB_ON, TETHERING_BLUETOOTH_ON}
|
value = {TETHERING_OFF, TETHERING_WIFI_ON, TETHERING_USB_ON, TETHERING_BLUETOOTH_ON}
|
||||||
)
|
)
|
||||||
@interface TetheringState {}
|
@interface TetheringState {}
|
||||||
private static final int TETHERING_OFF = 0;
|
@VisibleForTesting
|
||||||
private static final int TETHERING_WIFI_ON = 1;
|
static final int TETHERING_OFF = 0;
|
||||||
private static final int TETHERING_USB_ON = 1 << 1;
|
@VisibleForTesting
|
||||||
private static final int TETHERING_BLUETOOTH_ON = 1 << 2;
|
static final int TETHERING_WIFI_ON = 1;
|
||||||
|
@VisibleForTesting
|
||||||
public static final String SHARED_PREF = "tether_options";
|
static final int TETHERING_USB_ON = 1 << 1;
|
||||||
|
@VisibleForTesting
|
||||||
|
static final int TETHERING_BLUETOOTH_ON = 1 << 2;
|
||||||
|
|
||||||
// This KEY is used for a shared preference value, not for any displayed preferences.
|
// 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";
|
public static final String KEY_ENABLE_WIFI_TETHERING = "enable_wifi_tethering";
|
||||||
@@ -102,19 +102,23 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
public static final String USB_TETHER_KEY = "enable_usb_tethering";
|
public static final String USB_TETHER_KEY = "enable_usb_tethering";
|
||||||
public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
|
public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
final List<OnTetherStateUpdateListener> mListeners;
|
||||||
private final SwitchWidgetController mSwitchWidgetController;
|
private final SwitchWidgetController mSwitchWidgetController;
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
private final ConnectivityManager mConnectivityManager;
|
private final ConnectivityManager mConnectivityManager;
|
||||||
|
private final UserManager mUserManager;
|
||||||
|
|
||||||
private final DataSaverBackend mDataSaverBackend;
|
private final DataSaverBackend mDataSaverBackend;
|
||||||
private boolean mDataSaverEnabled;
|
private boolean mDataSaverEnabled;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mBluetoothTetheringStoppedByUser;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback;
|
ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback;
|
||||||
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
||||||
private final SharedPreferences mSharedPreferences;
|
|
||||||
private boolean mBluetoothEnableForTether;
|
private boolean mBluetoothEnableForTether;
|
||||||
private final BluetoothAdapter mBluetoothAdapter;
|
private final BluetoothAdapter mBluetoothAdapter;
|
||||||
|
|
||||||
@@ -123,13 +127,14 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mSwitchWidgetController = switchWidgetController;
|
mSwitchWidgetController = switchWidgetController;
|
||||||
mDataSaverBackend = new DataSaverBackend(context);
|
mDataSaverBackend = new DataSaverBackend(context);
|
||||||
mSharedPreferences = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
|
|
||||||
mConnectivityManager =
|
mConnectivityManager =
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
mBluetoothPan = bluetoothPan;
|
mBluetoothPan = bluetoothPan;
|
||||||
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
||||||
|
mListeners = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
@@ -148,38 +153,42 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
updateState(null/*tethered*/);
|
updateState(null/*tethered*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
|
mBluetoothTetheringStoppedByUser = false;
|
||||||
mDataSaverBackend.remListener(this);
|
mDataSaverBackend.remListener(this);
|
||||||
mSwitchWidgetController.stopListening();
|
mSwitchWidgetController.stopListening();
|
||||||
mContext.unregisterReceiver(mTetherChangeReceiver);
|
mContext.unregisterReceiver(mTetherChangeReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(@Nullable OnTetherStateUpdateListener listener) {
|
public void addListener(OnTetherStateUpdateListener listener) {
|
||||||
mListener = listener;
|
if (listener != null && !mListeners.contains(listener)) {
|
||||||
|
listener.onTetherStateUpdated(getTetheringState(null /* tethered */));
|
||||||
|
mListeners.add(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeListener(OnTetherStateUpdateListener listener) {
|
||||||
|
if (listener != null) {
|
||||||
|
mListeners.remove(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSwitchEnabled(boolean enabled) {
|
||||||
|
mSwitchWidgetController.setEnabled(
|
||||||
|
enabled && !mDataSaverEnabled && mUserManager.isAdminUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateState(@Nullable String[] tethered) {
|
void updateState(@Nullable String[] tethered) {
|
||||||
int tetherState = getTetheringState(tethered);
|
int state = getTetheringState(tethered);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "updateState: " + tetherState);
|
Log.d(TAG, "updateState: " + state);
|
||||||
}
|
}
|
||||||
setSwitchCheckedInternal(tetherState != TETHERING_OFF);
|
setSwitchCheckedInternal(state != TETHERING_OFF);
|
||||||
setSharedPreferencesInternal(tetherState);
|
setSwitchEnabled(true);
|
||||||
mSwitchWidgetController.setEnabled(!mDataSaverEnabled);
|
for (int i = 0, size = mListeners.size(); i < size; ++i) {
|
||||||
if (mListener != null) {
|
mListeners.get(i).onTetherStateUpdated(state);
|
||||||
mListener.onTetherStateUpdated(tetherState != TETHERING_OFF);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,33 +198,24 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
mSwitchWidgetController.startListening();
|
mSwitchWidgetController.startListening();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSharedPreferencesInternal(@TetheringState int tetherState) {
|
@VisibleForTesting
|
||||||
if (tetherState == TETHERING_OFF) {
|
@TetheringState int getTetheringState(@Nullable String[] tethered) {
|
||||||
// We don't override user's preferences when tethering off.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
final SharedPreferences.Editor editor = mSharedPreferences.edit();
|
|
||||||
editor.putBoolean(KEY_ENABLE_WIFI_TETHERING, (tetherState & TETHERING_WIFI_ON) != 0);
|
|
||||||
editor.putBoolean(USB_TETHER_KEY, (tetherState & TETHERING_USB_ON) != 0);
|
|
||||||
editor.putBoolean(BLUETOOTH_TETHER_KEY, (tetherState & TETHERING_BLUETOOTH_ON) != 0);
|
|
||||||
editor.commit();
|
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private @TetheringState int getTetheringState(@Nullable String[] tethered) {
|
|
||||||
int tetherState = TETHERING_OFF;
|
int tetherState = TETHERING_OFF;
|
||||||
if (tethered == null) {
|
if (tethered == null) {
|
||||||
tethered = mConnectivityManager.getTetheredIfaces();
|
tethered = mConnectivityManager.getTetheredIfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
|
if (mWifiManager.isWifiApEnabled()) {
|
||||||
tetherState |= TETHERING_WIFI_ON;
|
tetherState |= TETHERING_WIFI_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BluetoothPan pan = mBluetoothPan.get();
|
// Only check bluetooth tethering state if not stopped by user already.
|
||||||
if (pan != null && pan.isTetheringOn()) {
|
if (!mBluetoothTetheringStoppedByUser) {
|
||||||
tetherState |= TETHERING_BLUETOOTH_ON;
|
final BluetoothPan pan = mBluetoothPan.get();
|
||||||
|
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON
|
||||||
|
&& pan != null && pan.isTetheringOn()) {
|
||||||
|
tetherState |= TETHERING_BLUETOOTH_ON;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] usbRegexs = mConnectivityManager.getTetherableUsbRegexs();
|
String[] usbRegexs = mConnectivityManager.getTetherableUsbRegexs();
|
||||||
@@ -230,79 +230,58 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
return tetherState;
|
return tetherState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isBluetoothTethering(@TetheringState int state) {
|
||||||
|
return (state & TETHERING_BLUETOOTH_ON) != TETHERING_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUsbTethering(@TetheringState int state) {
|
||||||
|
return (state & TETHERING_USB_ON) != TETHERING_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWifiTethering(@TetheringState int state) {
|
||||||
|
return (state & TETHERING_WIFI_ON) != TETHERING_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSwitchToggled(boolean isChecked) {
|
public boolean onSwitchToggled(boolean isChecked) {
|
||||||
if (isChecked && getTetheringState(null /* tethered */) == TETHERING_OFF) {
|
if (isChecked) {
|
||||||
startTether();
|
startTethering(TETHERING_WIFI);
|
||||||
}
|
} else {
|
||||||
|
stopTethering(TETHERING_USB);
|
||||||
if (!isChecked && getTetheringState(null /* tethered */) != TETHERING_OFF) {
|
stopTethering(TETHERING_WIFI);
|
||||||
stopTether();
|
stopTethering(TETHERING_BLUETOOTH);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopTether() {
|
|
||||||
|
|
||||||
// Wi-Fi tether is selected by default.
|
|
||||||
if (mSharedPreferences.getBoolean(KEY_ENABLE_WIFI_TETHERING, true)) {
|
|
||||||
stopTethering(TETHERING_WIFI);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSharedPreferences.getBoolean(USB_TETHER_KEY, false)) {
|
|
||||||
stopTethering(TETHERING_USB);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)) {
|
|
||||||
stopTethering(TETHERING_BLUETOOTH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this method to stop a single choice of tethering.
|
|
||||||
*
|
|
||||||
* @param choice The choice of tethering to stop.
|
|
||||||
*/
|
|
||||||
public void stopTethering(int choice) {
|
public void stopTethering(int choice) {
|
||||||
mConnectivityManager.stopTethering(choice);
|
int state = getTetheringState(null /* tethered */);
|
||||||
}
|
if ((choice == TETHERING_WIFI && isWifiTethering(state))
|
||||||
|
|| (choice == TETHERING_USB && isUsbTethering(state))
|
||||||
@VisibleForTesting
|
|| (choice == TETHERING_BLUETOOTH && isBluetoothTethering(state))) {
|
||||||
void startTether() {
|
setSwitchEnabled(false);
|
||||||
|
mConnectivityManager.stopTethering(choice);
|
||||||
// Wi-Fi tether is selected by default.
|
if (choice == TETHERING_BLUETOOTH) {
|
||||||
if (mSharedPreferences.getBoolean(KEY_ENABLE_WIFI_TETHERING, true)) {
|
// Stop bluetooth tether won't invoke tether state changed callback, so we need this
|
||||||
startTethering(TETHERING_WIFI);
|
// boolean to remember the user action and update UI state immediately.
|
||||||
}
|
mBluetoothTetheringStoppedByUser = true;
|
||||||
|
updateState(null /* tethered */);
|
||||||
if (mSharedPreferences.getBoolean(USB_TETHER_KEY, false)) {
|
|
||||||
startTethering(TETHERING_USB);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)) {
|
|
||||||
startTethering(TETHERING_BLUETOOTH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this method to start a single choice of tethering.
|
|
||||||
* For bluetooth tethering, it will first turn on bluetooth if bluetooth is off.
|
|
||||||
* For Wi-Fi tethering, it will be no-op if Wi-Fi tethering already active.
|
|
||||||
*
|
|
||||||
* @param choice The choice of tethering to start.
|
|
||||||
*/
|
|
||||||
public void startTethering(int choice) {
|
|
||||||
mSwitchWidgetController.setEnabled(false);
|
|
||||||
|
|
||||||
if (choice == TETHERING_WIFI && mWifiManager.isWifiApEnabled()) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "Wifi tether already active!");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startTethering(int choice) {
|
||||||
|
int state = getTetheringState(null /* tethered */);
|
||||||
|
if ((choice == TETHERING_WIFI && isWifiTethering(state))
|
||||||
|
|| (choice == TETHERING_USB && isUsbTethering(state))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice == TETHERING_BLUETOOTH) {
|
if (choice == TETHERING_BLUETOOTH) {
|
||||||
if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
|
mBluetoothTetheringStoppedByUser = false;
|
||||||
|
if (isBluetoothTethering(state)) {
|
||||||
|
return;
|
||||||
|
} else if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Turn on bluetooth first.");
|
Log.d(TAG, "Turn on bluetooth first.");
|
||||||
}
|
}
|
||||||
@@ -312,6 +291,7 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSwitchEnabled(false);
|
||||||
mConnectivityManager.startTethering(choice, true /* showProvisioningUi */,
|
mConnectivityManager.startTethering(choice, true /* showProvisioningUi */,
|
||||||
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
|
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
@@ -379,7 +359,7 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
@Override
|
@Override
|
||||||
public void onDataSaverChanged(boolean isDataSaving) {
|
public void onDataSaverChanged(boolean isDataSaving) {
|
||||||
mDataSaverEnabled = isDataSaving;
|
mDataSaverEnabled = isDataSaving;
|
||||||
mSwitchWidgetController.setEnabled(!isDataSaving);
|
setSwitchEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -392,32 +372,6 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
// we don't care, since we just want to read the value
|
// we don't care, since we just want to read the value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
if (!mSwitchWidgetController.isChecked()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (TextUtils.equals(KEY_ENABLE_WIFI_TETHERING, key)) {
|
|
||||||
if (sharedPreferences.getBoolean(key, true)) {
|
|
||||||
startTethering(TETHERING_WIFI);
|
|
||||||
} else {
|
|
||||||
mConnectivityManager.stopTethering(TETHERING_WIFI);
|
|
||||||
}
|
|
||||||
} else if (TextUtils.equals(USB_TETHER_KEY, key)) {
|
|
||||||
if (sharedPreferences.getBoolean(key, false)) {
|
|
||||||
startTethering(TETHERING_USB);
|
|
||||||
} else {
|
|
||||||
mConnectivityManager.stopTethering(TETHERING_USB);
|
|
||||||
}
|
|
||||||
} else if (TextUtils.equals(BLUETOOTH_TETHER_KEY, key)) {
|
|
||||||
if (sharedPreferences.getBoolean(key, false)) {
|
|
||||||
startTethering(TETHERING_BLUETOOTH);
|
|
||||||
} else {
|
|
||||||
mConnectivityManager.stopTethering(TETHERING_BLUETOOTH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class OnStartTetheringCallback extends
|
private static final class OnStartTetheringCallback extends
|
||||||
ConnectivityManager.OnStartTetheringCallback {
|
ConnectivityManager.OnStartTetheringCallback {
|
||||||
final WeakReference<TetherEnabler> mTetherEnabler;
|
final WeakReference<TetherEnabler> mTetherEnabler;
|
||||||
|
|||||||
@@ -20,60 +20,52 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.TetheringManager;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller helps to manage the switch state and visibility of USB tether switch
|
* This controller helps to manage the switch state and visibility of USB tether switch
|
||||||
* preference. It stores preference values when preference changed.
|
* preference. It stores preference values when preference changed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class UsbTetherPreferenceController extends TogglePreferenceController implements
|
public final class UsbTetherPreferenceController extends TetherBasePreferenceController implements
|
||||||
LifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener {
|
LifecycleObserver {
|
||||||
|
|
||||||
private static final String TAG = "UsbTetherPrefController";
|
private static final String TAG = "UsbTetherPrefController";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
|
||||||
|
|
||||||
private final ConnectivityManager mCm;
|
|
||||||
private boolean mUsbConnected;
|
private boolean mUsbConnected;
|
||||||
private boolean mMassStorageActive;
|
private boolean mMassStorageActive;
|
||||||
private Preference mPreference;
|
private boolean mUsbTethering;
|
||||||
private final SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
public UsbTetherPreferenceController(Context context, String prefKey) {
|
public UsbTetherPreferenceController(Context context, String prefKey) {
|
||||||
super(context, prefKey);
|
super(context, prefKey);
|
||||||
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
mSharedPreferences =
|
|
||||||
context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return mSharedPreferences.getBoolean(mPreferenceKey, false);
|
return mUsbTethering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
if (DEBUG) {
|
if (mTetherEnabler == null) {
|
||||||
Log.d(TAG, "preference changing to " + isChecked);
|
return false;
|
||||||
|
}
|
||||||
|
if (isChecked) {
|
||||||
|
mTetherEnabler.startTethering(TetheringManager.TETHERING_USB);
|
||||||
|
} else {
|
||||||
|
mTetherEnabler.stopTethering(TetheringManager.TETHERING_USB);
|
||||||
}
|
}
|
||||||
final SharedPreferences.Editor editor = mSharedPreferences.edit();
|
|
||||||
editor.putBoolean(mPreferenceKey, isChecked);
|
|
||||||
editor.apply();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,17 +78,6 @@ public final class UsbTetherPreferenceController extends TogglePreferenceControl
|
|||||||
mContext.registerReceiver(mUsbChangeReceiver, filter);
|
mContext.registerReceiver(mUsbChangeReceiver, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mContext.unregisterReceiver(mUsbChangeReceiver);
|
mContext.unregisterReceiver(mUsbChangeReceiver);
|
||||||
@@ -112,12 +93,6 @@ public final class UsbTetherPreferenceController extends TogglePreferenceControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mPreference = screen.findPreference(mPreferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
@@ -126,6 +101,12 @@ public final class UsbTetherPreferenceController extends TogglePreferenceControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTetherStateUpdated(int state) {
|
||||||
|
mUsbTethering = TetherEnabler.isUsbTethering(state);
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final BroadcastReceiver mUsbChangeReceiver = new BroadcastReceiver() {
|
final BroadcastReceiver mUsbChangeReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -141,11 +122,4 @@ public final class UsbTetherPreferenceController extends TogglePreferenceControl
|
|||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
|
||||||
if (TextUtils.equals(mPreferenceKey, key)) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,21 +17,14 @@
|
|||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.net.TetheringManager;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
import com.android.settingslib.TetherUtil;
|
import com.android.settingslib.TetherUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,61 +36,41 @@ import com.android.settingslib.TetherUtil;
|
|||||||
* @see BluetoothTetherPreferenceController
|
* @see BluetoothTetherPreferenceController
|
||||||
* @see UsbTetherPreferenceController
|
* @see UsbTetherPreferenceController
|
||||||
*/
|
*/
|
||||||
public final class WifiTetherDisablePreferenceController extends TogglePreferenceController
|
public final class WifiTetherDisablePreferenceController extends TetherBasePreferenceController
|
||||||
implements LifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener {
|
implements LifecycleObserver {
|
||||||
|
|
||||||
private static final String TAG = "WifiTetherDisablePreferenceController";
|
private static final String TAG = "WifiTetherDisablePreferenceController";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
|
||||||
|
|
||||||
private final ConnectivityManager mCm;
|
private boolean mBluetoothTethering;
|
||||||
private boolean mBluetoothTetherEnabled;
|
private boolean mUsbTethering;
|
||||||
private boolean mUSBTetherEnabled;
|
private boolean mWifiTethering;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private Preference mPreference;
|
|
||||||
private final SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
public WifiTetherDisablePreferenceController(Context context, String prefKey) {
|
public WifiTetherDisablePreferenceController(Context context, String prefKey) {
|
||||||
super(context, prefKey);
|
super(context, prefKey);
|
||||||
mSharedPreferences =
|
|
||||||
context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE);
|
|
||||||
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
mUSBTetherEnabled = mSharedPreferences.getBoolean(
|
|
||||||
TetherEnabler.USB_TETHER_KEY, false);
|
|
||||||
mBluetoothTetherEnabled = mSharedPreferences.getBoolean(
|
|
||||||
TetherEnabler.BLUETOOTH_TETHER_KEY, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return !mSharedPreferences.getBoolean(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, true);
|
return !mWifiTethering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
// The shared preference's value is in the opposite of this preference's value.
|
if (mTetherEnabler == null) {
|
||||||
final boolean enableWifi = !isChecked;
|
return false;
|
||||||
if (DEBUG) {
|
}
|
||||||
Log.d(TAG, "check state changing to " + isChecked);
|
if (isChecked) {
|
||||||
|
mTetherEnabler.stopTethering(TetheringManager.TETHERING_WIFI);
|
||||||
|
} else {
|
||||||
|
mTetherEnabler.startTethering(TetheringManager.TETHERING_WIFI);
|
||||||
}
|
}
|
||||||
final SharedPreferences.Editor editor = mSharedPreferences.edit();
|
|
||||||
editor.putBoolean(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, enableWifi);
|
|
||||||
editor.apply();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean shouldShow() {
|
boolean shouldShow() {
|
||||||
return mBluetoothTetherEnabled || mUSBTetherEnabled;
|
return mBluetoothTethering || mUsbTethering;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,11 +86,11 @@ public final class WifiTetherDisablePreferenceController extends TogglePreferenc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (mUSBTetherEnabled && mBluetoothTetherEnabled) {
|
if (mUsbTethering && mBluetoothTethering) {
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
|
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
|
||||||
} else if (mUSBTetherEnabled) {
|
} else if (mUsbTethering) {
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_on);
|
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_on);
|
||||||
} else if (mBluetoothTetherEnabled) {
|
} else if (mBluetoothTethering) {
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_bluetooth_on);
|
return mContext.getString(R.string.disable_wifi_hotspot_when_bluetooth_on);
|
||||||
}
|
}
|
||||||
return mContext.getString(R.string.summary_placeholder);
|
return mContext.getString(R.string.summary_placeholder);
|
||||||
@@ -127,7 +100,6 @@ public final class WifiTetherDisablePreferenceController extends TogglePreferenc
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mScreen = screen;
|
mScreen = screen;
|
||||||
mPreference = screen.findPreference(mPreferenceKey);
|
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mPreference.setOnPreferenceChangeListener(this);
|
mPreference.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
@@ -141,42 +113,10 @@ public final class WifiTetherDisablePreferenceController extends TogglePreferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
public void onTetherStateUpdated(int state) {
|
||||||
String key) {
|
mUsbTethering = TetherEnabler.isUsbTethering(state);
|
||||||
final boolean shouldShowBefore = shouldShow();
|
mBluetoothTethering = TetherEnabler.isBluetoothTethering(state);
|
||||||
if (TextUtils.equals(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, key) && shouldShowBefore) {
|
mWifiTethering = TetherEnabler.isWifiTethering(state);
|
||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldUpdateState = false;
|
|
||||||
if (TextUtils.equals(TetherEnabler.USB_TETHER_KEY, key)) {
|
|
||||||
mUSBTetherEnabled = sharedPreferences.getBoolean(key, false);
|
|
||||||
shouldUpdateState = true;
|
|
||||||
} else if (TextUtils.equals(TetherEnabler.BLUETOOTH_TETHER_KEY, key)) {
|
|
||||||
mBluetoothTetherEnabled = sharedPreferences.getBoolean(key, false);
|
|
||||||
shouldUpdateState = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we are hiding this preference. If so, make sure the preference is set to
|
|
||||||
// unchecked to enable wifi tether.
|
|
||||||
if (mPreference != null && mPreference instanceof SwitchPreference
|
|
||||||
&& shouldShowBefore && !shouldShow()) {
|
|
||||||
final SwitchPreference switchPreference = (SwitchPreference) mPreference;
|
|
||||||
if (switchPreference.isChecked()) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG,
|
|
||||||
"All other types are unchecked, wifi tether enabled automatically");
|
|
||||||
}
|
|
||||||
// Need to call this method before internal state set.
|
|
||||||
if (switchPreference.callChangeListener(false)) {
|
|
||||||
switchPreference.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUpdateState) {
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.provider.Settings;
|
|||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.ims.ImsRcsManager;
|
import android.telephony.ims.ImsRcsManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
|
|
||||||
@@ -56,6 +57,9 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
ProxySubscriptionManager mProxySubscriptionMgr;
|
ProxySubscriptionManager mProxySubscriptionMgr;
|
||||||
private int mCurSubscriptionId;
|
private int mCurSubscriptionId;
|
||||||
|
// To avoid from Preference Controller to have a complex design for the case of Activity
|
||||||
|
// restart. mIsEffectiveSubId is designed to force recreate of Preference Controller(s).
|
||||||
|
private boolean mIsEffectiveSubId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
@@ -69,6 +73,7 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
}
|
}
|
||||||
int oldSubId = mCurSubscriptionId;
|
int oldSubId = mCurSubscriptionId;
|
||||||
mCurSubscriptionId = updateSubscriptionIndex;
|
mCurSubscriptionId = updateSubscriptionIndex;
|
||||||
|
mIsEffectiveSubId = (mCurSubscriptionId != SUB_ID_NULL);
|
||||||
updateSubscriptions(getSubscription());
|
updateSubscriptions(getSubscription());
|
||||||
|
|
||||||
// If the subscription has changed or the new intent doesnt contain the opt in action,
|
// If the subscription has changed or the new intent doesnt contain the opt in action,
|
||||||
@@ -103,7 +108,7 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
registerActiveSubscriptionsListener();
|
getProxySubscriptionManager().setLifecycle(getLifecycle());
|
||||||
|
|
||||||
final Intent startIntent = getIntent();
|
final Intent startIntent = getIntent();
|
||||||
validate(startIntent);
|
validate(startIntent);
|
||||||
@@ -112,17 +117,28 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
: ((startIntent != null)
|
: ((startIntent != null)
|
||||||
? startIntent.getIntExtra(Settings.EXTRA_SUB_ID, SUB_ID_NULL)
|
? startIntent.getIntExtra(Settings.EXTRA_SUB_ID, SUB_ID_NULL)
|
||||||
: SUB_ID_NULL);
|
: SUB_ID_NULL);
|
||||||
|
mIsEffectiveSubId = (mCurSubscriptionId != SUB_ID_NULL);
|
||||||
|
|
||||||
final SubscriptionInfo subscription = getSubscription();
|
final SubscriptionInfo subscription = getSubscription();
|
||||||
updateTitleAndNavigation(subscription);
|
updateTitleAndNavigation(subscription);
|
||||||
maybeShowContactDiscoveryDialog(mCurSubscriptionId);
|
maybeShowContactDiscoveryDialog(mCurSubscriptionId);
|
||||||
|
|
||||||
|
// Since onChanged() will take place immediately when addActiveSubscriptionsListener(),
|
||||||
|
// perform registration after mCurSubscriptionId been configured.
|
||||||
|
registerActiveSubscriptionsListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
ProxySubscriptionManager getProxySubscriptionManager() {
|
||||||
|
if (mProxySubscriptionMgr == null) {
|
||||||
|
mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(this);
|
||||||
|
}
|
||||||
|
return mProxySubscriptionMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void registerActiveSubscriptionsListener() {
|
void registerActiveSubscriptionsListener() {
|
||||||
mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(this);
|
getProxySubscriptionManager().addActiveSubscriptionsListener(this);
|
||||||
mProxySubscriptionMgr.setLifecycle(getLifecycle());
|
|
||||||
mProxySubscriptionMgr.addActiveSubscriptionsListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,7 +161,7 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
mProxySubscriptionMgr.setLifecycle(getLifecycle());
|
getProxySubscriptionManager().setLifecycle(getLifecycle());
|
||||||
super.onStart();
|
super.onStart();
|
||||||
// updateSubscriptions doesn't need to be called, onChanged will always be called after we
|
// updateSubscriptions doesn't need to be called, onChanged will always be called after we
|
||||||
// register a listener.
|
// register a listener.
|
||||||
@@ -191,6 +207,7 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
switchFragment(subscription);
|
switchFragment(subscription);
|
||||||
|
|
||||||
mCurSubscriptionId = subscriptionIndex;
|
mCurSubscriptionId = subscriptionIndex;
|
||||||
|
mIsEffectiveSubId = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -200,20 +217,23 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
SubscriptionInfo getSubscription() {
|
SubscriptionInfo getSubscription() {
|
||||||
if (mCurSubscriptionId != SUB_ID_NULL) {
|
if (mIsEffectiveSubId && (mCurSubscriptionId != SUB_ID_NULL)) {
|
||||||
final SubscriptionInfo subInfo = SubscriptionUtil.getAvailableSubscription(
|
return getSubscriptionForSubId(mCurSubscriptionId);
|
||||||
this, mProxySubscriptionMgr, mCurSubscriptionId);
|
|
||||||
if (subInfo != null) {
|
|
||||||
return subInfo;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final List<SubscriptionInfo> subInfos = mProxySubscriptionMgr.getActiveSubscriptionsInfo();
|
final List<SubscriptionInfo> subInfos = getProxySubscriptionManager()
|
||||||
|
.getActiveSubscriptionsInfo();
|
||||||
if (CollectionUtils.isEmpty(subInfos)) {
|
if (CollectionUtils.isEmpty(subInfos)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return subInfos.get(0);
|
return subInfos.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
SubscriptionInfo getSubscriptionForSubId(int subId) {
|
||||||
|
return SubscriptionUtil.getAvailableSubscription(this,
|
||||||
|
getProxySubscriptionManager(), subId);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void switchFragment(SubscriptionInfo subInfo) {
|
void switchFragment(SubscriptionInfo subInfo) {
|
||||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
@@ -223,9 +243,18 @@ public class MobileNetworkActivity extends SettingsBaseActivity
|
|||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putInt(Settings.EXTRA_SUB_ID, subId);
|
bundle.putInt(Settings.EXTRA_SUB_ID, subId);
|
||||||
|
|
||||||
|
final String fragmentTag = buildFragmentTag(subId);
|
||||||
|
if (fragmentManager.findFragmentByTag(fragmentTag) != null) {
|
||||||
|
if (mIsEffectiveSubId) {
|
||||||
|
Log.d(TAG, "Keep current fragment: " + fragmentTag);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.d(TAG, "Construct fragment: " + fragmentTag);
|
||||||
|
}
|
||||||
|
|
||||||
final Fragment fragment = new MobileNetworkSettings();
|
final Fragment fragment = new MobileNetworkSettings();
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
fragmentTransaction.replace(R.id.content_frame, fragment, buildFragmentTag(subId));
|
fragmentTransaction.replace(R.id.content_frame, fragment, fragmentTag);
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,8 @@ public class HandsFreeProfileOutputPreferenceController extends AudioSwitchPrefe
|
|||||||
if (hapProfile != null && hfpProfile != null && device == null) {
|
if (hapProfile != null && hfpProfile != null && device == null) {
|
||||||
hfpProfile.setActiveDevice(null);
|
hfpProfile.setActiveDevice(null);
|
||||||
hapProfile.setActiveDevice(null);
|
hapProfile.setActiveDevice(null);
|
||||||
} else if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) {
|
} else if (hapProfile != null && device != null
|
||||||
|
&& hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) {
|
||||||
hapProfile.setActiveDevice(device);
|
hapProfile.setActiveDevice(device);
|
||||||
} else if (hfpProfile != null) {
|
} else if (hfpProfile != null) {
|
||||||
hfpProfile.setActiveDevice(device);
|
hfpProfile.setActiveDevice(device);
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.InstrumentedFragment;
|
import com.android.settings.core.InstrumentedFragment;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detail page for configuring Wi-Fi network.
|
* Detail page for configuring Wi-Fi network.
|
||||||
*
|
*
|
||||||
@@ -113,7 +113,7 @@ public class ConfigureAccessPointFragment extends InstrumentedFragment implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispatchSubmit() {
|
public void dispatchSubmit() {
|
||||||
// Do nothing
|
handleSubmitAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ public class ConfigureWifiEntryFragment extends InstrumentedFragment implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispatchSubmit() {
|
public void dispatchSubmit() {
|
||||||
// Do nothing
|
handleSubmitAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import com.android.settingslib.fuelgauge.Estimate;
|
|||||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
@@ -572,6 +573,7 @@ public class BatteryUtilsTest {
|
|||||||
assertThat(mBatteryUtils.isPreOApp(new String[]{})).isFalse();
|
assertThat(mBatteryUtils.isPreOApp(new String[]{})).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSetForceAppStandby_forcePreOApp_forceTwoRestrictions() {
|
public void testSetForceAppStandby_forcePreOApp_forceTwoRestrictions() {
|
||||||
mBatteryUtils.setForceAppStandby(UID, LOW_SDK_PACKAGE, AppOpsManager.MODE_IGNORED);
|
mBatteryUtils.setForceAppStandby(UID, LOW_SDK_PACKAGE, AppOpsManager.MODE_IGNORED);
|
||||||
@@ -583,6 +585,7 @@ public class BatteryUtilsTest {
|
|||||||
AppOpsManager.MODE_IGNORED);
|
AppOpsManager.MODE_IGNORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testSetForceAppStandby_forceOApp_forceOneRestriction() {
|
public void testSetForceAppStandby_forceOApp_forceOneRestriction() {
|
||||||
mBatteryUtils.setForceAppStandby(UID, HIGH_SDK_PACKAGE, AppOpsManager.MODE_IGNORED);
|
mBatteryUtils.setForceAppStandby(UID, HIGH_SDK_PACKAGE, AppOpsManager.MODE_IGNORED);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.bluetooth.BluetoothPan;
|
import android.bluetooth.BluetoothPan;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
import com.android.settings.widget.MasterSwitchPreference;
|
import com.android.settings.widget.MasterSwitchPreference;
|
||||||
|
|
||||||
@@ -49,8 +48,6 @@ public class AllInOneTetherPreferenceControllerTest {
|
|||||||
private BluetoothAdapter mBluetoothAdapter;
|
private BluetoothAdapter mBluetoothAdapter;
|
||||||
@Mock
|
@Mock
|
||||||
private MasterSwitchPreference mPreference;
|
private MasterSwitchPreference mPreference;
|
||||||
@Mock
|
|
||||||
private SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
private AllInOneTetherPreferenceController mController;
|
private AllInOneTetherPreferenceController mController;
|
||||||
|
|
||||||
@@ -61,8 +58,6 @@ public class AllInOneTetherPreferenceControllerTest {
|
|||||||
ReflectionHelpers.setField(mController, "mContext", mContext);
|
ReflectionHelpers.setField(mController, "mContext", mContext);
|
||||||
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
|
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
||||||
ReflectionHelpers
|
|
||||||
.setField(mController, "mTetherEnablerSharedPreferences", mSharedPreferences);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.TetheringManager;
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -47,7 +47,7 @@ public class BluetoothTetherPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
private SharedPreferences mSharedPreferences;
|
private TetherEnabler mTetherEnabler;
|
||||||
|
|
||||||
private SwitchPreference mSwitchPreference;
|
private SwitchPreference mSwitchPreference;
|
||||||
private BluetoothTetherPreferenceController mController;
|
private BluetoothTetherPreferenceController mController;
|
||||||
@@ -61,10 +61,9 @@ public class BluetoothTetherPreferenceControllerTest {
|
|||||||
mSwitchPreference = spy(SwitchPreference.class);
|
mSwitchPreference = spy(SwitchPreference.class);
|
||||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||||
mConnectivityManager);
|
mConnectivityManager);
|
||||||
when(mContext.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
|
|
||||||
.thenReturn(mSharedPreferences);
|
|
||||||
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
|
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
|
||||||
mController = new BluetoothTetherPreferenceController(mContext, BLUETOOTH_TETHER_KEY);
|
mController = new BluetoothTetherPreferenceController(mContext, BLUETOOTH_TETHER_KEY);
|
||||||
|
mController.setTetherEnabler(mTetherEnabler);
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +76,18 @@ public class BluetoothTetherPreferenceControllerTest {
|
|||||||
any());
|
any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldAddListenerOnResume() {
|
||||||
|
mController.onResume();
|
||||||
|
verify(mTetherEnabler).addListener(mController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldRemoveListenrOnPause() {
|
||||||
|
mController.onPause();
|
||||||
|
verify(mTetherEnabler).removeListener(mController);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
||||||
mController.onStart();
|
mController.onStart();
|
||||||
@@ -96,18 +107,26 @@ public class BluetoothTetherPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switch_shouldCheckedWhenSharedPreferenceIsTrue() {
|
public void setChecked_shouldStartBluetoothTethering() {
|
||||||
when(mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)).thenReturn(true);
|
mController.setChecked(true);
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, BLUETOOTH_TETHER_KEY);
|
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_BLUETOOTH);
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switch_shouldUnCheckedWhenSharedPreferenceIsFalse() {
|
public void setUnchecked_shouldStopBluetoothTethering() {
|
||||||
when(mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)).thenReturn(false);
|
mController.setChecked(false);
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, BLUETOOTH_TETHER_KEY);
|
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
||||||
|
}
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(false);
|
@Test
|
||||||
|
public void switch_shouldCheckedWhenBluetoothTethering() {
|
||||||
|
mController.onTetherStateUpdated(TetherEnabler.TETHERING_BLUETOOTH_ON);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switch_shouldUnCheckedWhenBluetoothNotTethering() {
|
||||||
|
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothPan;
|
import android.bluetooth.BluetoothPan;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
|
import android.net.TetheringManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.network.TetherEnabler.OnTetherStateUpdateListener;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settings.widget.SwitchBarController;
|
import com.android.settings.widget.SwitchBarController;
|
||||||
import com.android.settings.widget.SwitchWidgetController;
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
@@ -51,6 +52,8 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -64,7 +67,7 @@ public class TetherEnablerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private BluetoothPan mBluetoothPan;
|
private BluetoothPan mBluetoothPan;
|
||||||
@Mock
|
@Mock
|
||||||
private SharedPreferences mSharedPreferences;
|
private BluetoothAdapter mBluetoothAdapter;
|
||||||
|
|
||||||
private SwitchBar mSwitchBar;
|
private SwitchBar mSwitchBar;
|
||||||
private TetherEnabler mEnabler;
|
private TetherEnabler mEnabler;
|
||||||
@@ -88,22 +91,8 @@ public class TetherEnablerTest {
|
|||||||
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
|
||||||
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
||||||
panReference.set(mBluetoothPan);
|
panReference.set(mBluetoothPan);
|
||||||
when(context.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
|
|
||||||
.thenReturn(mSharedPreferences);
|
|
||||||
SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
|
|
||||||
when(mSharedPreferences.edit()).thenReturn(editor);
|
|
||||||
mEnabler = spy(new TetherEnabler(context, mSwitchWidgetController, panReference));
|
mEnabler = spy(new TetherEnabler(context, mSwitchWidgetController, panReference));
|
||||||
}
|
ReflectionHelpers.setField(mEnabler, "mBluetoothAdapter", mBluetoothAdapter);
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_onPause_unRegisterSharedPreferenceListener() {
|
|
||||||
mEnabler.onResume();
|
|
||||||
verify(mSharedPreferences).registerOnSharedPreferenceChangeListener(
|
|
||||||
eq(mEnabler));
|
|
||||||
|
|
||||||
mEnabler.onPause();
|
|
||||||
verify(mSharedPreferences).unregisterOnSharedPreferenceChangeListener(
|
|
||||||
eq(mEnabler));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -115,11 +104,20 @@ public class TetherEnablerTest {
|
|||||||
assertThat(mSwitchBar.isChecked()).isTrue();
|
assertThat(mSwitchBar.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_onStop_resetBluetoothTetheringStoppedByUser() {
|
||||||
|
mEnabler.onStart();
|
||||||
|
mEnabler.mBluetoothTetheringStoppedByUser = true;
|
||||||
|
|
||||||
|
mEnabler.onStop();
|
||||||
|
assertThat(mEnabler.mBluetoothTetheringStoppedByUser).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startTether_fail_resetSwitchBar() {
|
public void startTether_fail_resetSwitchBar() {
|
||||||
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
|
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
|
||||||
mEnabler.onStart();
|
mEnabler.onStart();
|
||||||
mEnabler.startTether();
|
mEnabler.startTethering(TetheringManager.TETHERING_WIFI);
|
||||||
|
|
||||||
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetheredIfaces()).thenReturn(new String[0]);
|
||||||
mEnabler.mOnStartTetheringCallback.onTetheringFailed();
|
mEnabler.mOnStartTetheringCallback.onTetheringFailed();
|
||||||
@@ -145,8 +143,6 @@ public class TetherEnablerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSwitchToggled_onlyStartsWifiTetherWhenNeeded() {
|
public void onSwitchToggled_onlyStartsWifiTetherWhenNeeded() {
|
||||||
when(mSharedPreferences.getBoolean(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, true))
|
|
||||||
.thenReturn(true);
|
|
||||||
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
|
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
|
||||||
mEnabler.onSwitchToggled(true);
|
mEnabler.onSwitchToggled(true);
|
||||||
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
|
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
|
||||||
@@ -157,36 +153,28 @@ public class TetherEnablerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSwitchToggled_shouldStartUSBTetherWhenSelected() {
|
public void startTethering_startsBluetoothTetherWhenOff() {
|
||||||
SharedPreferences preference = mock(SharedPreferences.class);
|
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
|
||||||
ReflectionHelpers.setField(mEnabler, "mSharedPreferences", preference);
|
|
||||||
when(preference.getBoolean(TetherEnabler.KEY_ENABLE_WIFI_TETHERING, true))
|
|
||||||
.thenReturn(false);
|
|
||||||
when(preference.getBoolean(TetherEnabler.USB_TETHER_KEY, false)).thenReturn(true);
|
|
||||||
when(preference.getBoolean(TetherEnabler.BLUETOOTH_TETHER_KEY, true)).thenReturn(false);
|
|
||||||
|
|
||||||
mEnabler.startTether();
|
mEnabler.startTethering(ConnectivityManager.TETHERING_BLUETOOTH);
|
||||||
|
verify(mBluetoothAdapter).enable();
|
||||||
|
|
||||||
|
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
|
||||||
|
mEnabler.startTethering(ConnectivityManager.TETHERING_BLUETOOTH);
|
||||||
verify(mConnectivityManager).startTethering(
|
verify(mConnectivityManager).startTethering(
|
||||||
eq(ConnectivityManager.TETHERING_USB), anyBoolean(), any(), any());
|
|
||||||
verify(mConnectivityManager, never())
|
|
||||||
.startTethering(eq(ConnectivityManager.TETHERING_WIFI), anyBoolean(), any(), any());
|
|
||||||
verify(mConnectivityManager, never()).startTethering(
|
|
||||||
eq(ConnectivityManager.TETHERING_BLUETOOTH), anyBoolean(), any(), any());
|
eq(ConnectivityManager.TETHERING_BLUETOOTH), anyBoolean(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void startTether_startsBluetoothTetherWhenOff() {
|
public void stopTethering_setBluetoothTetheringStoppedByUserAndUpdateState() {
|
||||||
BluetoothAdapter adapter = mock(BluetoothAdapter.class);
|
mSwitchWidgetController.setListener(mEnabler);
|
||||||
ReflectionHelpers.setField(mEnabler, "mBluetoothAdapter", adapter);
|
mSwitchWidgetController.startListening();
|
||||||
when(adapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
|
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
|
doReturn(state).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
|
|
||||||
mEnabler.startTethering(ConnectivityManager.TETHERING_BLUETOOTH);
|
mEnabler.stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
||||||
verify(adapter).enable();
|
assertThat(mEnabler.mBluetoothTetheringStoppedByUser).isTrue();
|
||||||
|
verify(mEnabler).updateState(null);
|
||||||
when(adapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
|
|
||||||
mEnabler.startTethering(ConnectivityManager.TETHERING_BLUETOOTH);
|
|
||||||
verify(mConnectivityManager).startTethering(
|
|
||||||
eq(ConnectivityManager.TETHERING_BLUETOOTH), anyBoolean(), any(), any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -210,35 +198,44 @@ public class TetherEnablerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_shouldEnableSwitchBarTethering() {
|
public void updateState_shouldEnableSwitchBarTethering() {
|
||||||
|
when(mConnectivityManager.getTetheredIfaces()).thenReturn(USB_TETHERED);
|
||||||
|
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
|
||||||
|
|
||||||
mSwitchWidgetController.setListener(mEnabler);
|
mSwitchWidgetController.setListener(mEnabler);
|
||||||
mSwitchWidgetController.startListening();
|
mSwitchWidgetController.startListening();
|
||||||
|
|
||||||
ReflectionHelpers.setField(mEnabler, "mDataSaverEnabled", false);
|
ReflectionHelpers.setField(mEnabler, "mDataSaverEnabled", false);
|
||||||
mEnabler.updateState(new String[]{""});
|
mEnabler.updateState(null/*tethered*/);
|
||||||
verify(mSwitchBar).setEnabled(true);
|
verify(mSwitchBar).setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_onSharedPreferencesChangeNeverCalled() {
|
public void updateState_shouldCallListener() {
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(mEnabler);
|
OnTetherStateUpdateListener listener = mock(
|
||||||
|
OnTetherStateUpdateListener.class);
|
||||||
|
List<OnTetherStateUpdateListener> listeners = new ArrayList<>();
|
||||||
|
listeners.add(listener);
|
||||||
|
ReflectionHelpers.setField(mEnabler, "mListeners", listeners);
|
||||||
mSwitchWidgetController.setListener(mEnabler);
|
mSwitchWidgetController.setListener(mEnabler);
|
||||||
mSwitchWidgetController.startListening();
|
mSwitchWidgetController.startListening();
|
||||||
|
|
||||||
mEnabler.updateState(null /* tethered */);
|
mEnabler.updateState(null /* tethered */);
|
||||||
verify(mEnabler, never()).onSharedPreferenceChanged(eq(mSharedPreferences), any());
|
verify(listener).onTetherStateUpdated(anyInt());
|
||||||
verify(mEnabler, never()).onSharedPreferenceChanged(eq(mSharedPreferences), any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_setSharedPreferencesOnlyWhenNeeded() {
|
public void addListener_listenerShouldAdded() {
|
||||||
mSwitchWidgetController.setListener(mEnabler);
|
OnTetherStateUpdateListener listener = mock(
|
||||||
mSwitchWidgetController.startListening();
|
OnTetherStateUpdateListener.class);
|
||||||
|
mEnabler.addListener(listener);
|
||||||
mEnabler.updateState(null /* tethered */);
|
assertThat(mEnabler.mListeners).contains(listener);
|
||||||
verify(mSharedPreferences, never()).edit();
|
|
||||||
|
|
||||||
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(USB_TETHERED);
|
|
||||||
mSharedPreferences.registerOnSharedPreferenceChangeListener(mEnabler);
|
|
||||||
mEnabler.updateState(USB_TETHERED);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void remListener_listenerShouldBeRemoved() {
|
||||||
|
OnTetherStateUpdateListener listener = mock(
|
||||||
|
OnTetherStateUpdateListener.class);
|
||||||
|
mEnabler.removeListener(listener);
|
||||||
|
assertThat(mEnabler.mListeners).doesNotContain(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,8 +27,8 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.TetheringManager;
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -47,7 +47,7 @@ public class UsbTetherPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
private SharedPreferences mSharedPreferences;
|
private TetherEnabler mTetherEnabler;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private UsbTetherPreferenceController mController;
|
private UsbTetherPreferenceController mController;
|
||||||
@@ -61,9 +61,8 @@ public class UsbTetherPreferenceControllerTest {
|
|||||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||||
mConnectivityManager);
|
mConnectivityManager);
|
||||||
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
|
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
|
||||||
when(mContext.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
|
|
||||||
.thenReturn(mSharedPreferences);
|
|
||||||
mController = new UsbTetherPreferenceController(mContext, USB_TETHER_KEY);
|
mController = new UsbTetherPreferenceController(mContext, USB_TETHER_KEY);
|
||||||
|
mController.setTetherEnabler(mTetherEnabler);
|
||||||
mSwitchPreference = spy(SwitchPreference.class);
|
mSwitchPreference = spy(SwitchPreference.class);
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
||||||
}
|
}
|
||||||
@@ -75,6 +74,18 @@ public class UsbTetherPreferenceControllerTest {
|
|||||||
verify(mContext).registerReceiver(eq(mController.mUsbChangeReceiver), any());
|
verify(mContext).registerReceiver(eq(mController.mUsbChangeReceiver), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldAddListenerOnResume() {
|
||||||
|
mController.onResume();
|
||||||
|
verify(mTetherEnabler).addListener(mController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldRemoveListenrOnPause() {
|
||||||
|
mController.onPause();
|
||||||
|
verify(mTetherEnabler).removeListener(mController);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
||||||
mController.onStart();
|
mController.onStart();
|
||||||
@@ -93,18 +104,26 @@ public class UsbTetherPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switch_shouldCheckedWhenSharedPreferencesIsTrue() {
|
public void setChecked_shouldStartUsbTethering() {
|
||||||
when(mSharedPreferences.getBoolean(USB_TETHER_KEY, false)).thenReturn(true);
|
mController.setChecked(true);
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, USB_TETHER_KEY);
|
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_USB);
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switch_shouldUnCheckedWhenSharedPreferencesIsFalse() {
|
public void setUnchecked_shouldStopUsbTethering() {
|
||||||
when(mSharedPreferences.getBoolean(USB_TETHER_KEY, false)).thenReturn(false);
|
mController.setChecked(false);
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, USB_TETHER_KEY);
|
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_USB);
|
||||||
|
}
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(false);
|
@Test
|
||||||
|
public void switch_shouldCheckedWhenUsbTethering() {
|
||||||
|
mController.onTetherStateUpdated(TetherEnabler.TETHERING_USB_ON);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switch_shouldUnCheckedWhenUsbNotTethering() {
|
||||||
|
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,16 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
|
|
||||||
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
|
|
||||||
import static com.android.settings.network.TetherEnabler.WIFI_TETHER_DISABLE_KEY;
|
import static com.android.settings.network.TetherEnabler.WIFI_TETHER_DISABLE_KEY;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -50,9 +46,9 @@ public class WifiTetherDisablePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
private SharedPreferences mSharedPreferences;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
@Mock
|
||||||
|
private TetherEnabler mTetherEnabler;
|
||||||
|
|
||||||
private SwitchPreference mPreference;
|
private SwitchPreference mPreference;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -67,60 +63,40 @@ public class WifiTetherDisablePreferenceControllerTest {
|
|||||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||||
mConnectivityManager);
|
mConnectivityManager);
|
||||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
|
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
|
||||||
when(mContext.getSharedPreferences(TetherEnabler.SHARED_PREF, Context.MODE_PRIVATE))
|
|
||||||
.thenReturn(mSharedPreferences);
|
|
||||||
mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
|
mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
|
||||||
|
mController.setTetherEnabler(mTetherEnabler);
|
||||||
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
|
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
||||||
when(mPreferenceScreen.findPreference(WIFI_TETHER_DISABLE_KEY)).thenReturn(mPreference);
|
when(mPreferenceScreen.findPreference(WIFI_TETHER_DISABLE_KEY)).thenReturn(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
|
|
||||||
public void lifecycle_shouldRegisterReceiverOnResume() {
|
|
||||||
mController.onResume();
|
|
||||||
|
|
||||||
verify(mSharedPreferences).registerOnSharedPreferenceChangeListener(eq(mController));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
|
||||||
mController.onResume();
|
|
||||||
mController.onPause();
|
|
||||||
|
|
||||||
verify(mSharedPreferences).unregisterOnSharedPreferenceChangeListener(eq(mController));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void display_availableChangedCorrectly() {
|
public void display_availableChangedCorrectly() {
|
||||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
|
||||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"test"});
|
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"test"});
|
||||||
ReflectionHelpers.setField(mController, "mBluetoothTetherEnabled", false);
|
ReflectionHelpers.setField(mController, "mBluetoothTethering", false);
|
||||||
ReflectionHelpers.setField(mController, "mUSBTetherEnabled", false);
|
ReflectionHelpers.setField(mController, "mUsbTethering", false);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switch_shouldListenToUsbAndBluetooth() {
|
public void switch_shouldListenToUsbAndBluetooth() {
|
||||||
when(mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)).thenReturn(true);
|
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, BLUETOOTH_TETHER_KEY);
|
mController.onTetherStateUpdated(state);
|
||||||
verify(mPreference).setVisible(eq(true));
|
verify(mPreference).setVisible(eq(true));
|
||||||
|
|
||||||
when(mSharedPreferences.getBoolean(USB_TETHER_KEY, false)).thenReturn(true);
|
state |= TetherEnabler.TETHERING_USB_ON;
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, USB_TETHER_KEY);
|
mController.onTetherStateUpdated(state);
|
||||||
assertThat(mController.shouldShow()).isTrue();
|
assertThat(mController.shouldShow()).isTrue();
|
||||||
|
|
||||||
when(mSharedPreferences.getBoolean(USB_TETHER_KEY, false)).thenReturn(false);
|
state = TetherEnabler.TETHERING_USB_ON;
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, USB_TETHER_KEY);
|
mController.onTetherStateUpdated(state);
|
||||||
assertThat(mController.shouldShow()).isTrue();
|
assertThat(mController.shouldShow()).isTrue();
|
||||||
|
|
||||||
when(mSharedPreferences.getBoolean(BLUETOOTH_TETHER_KEY, false)).thenReturn(false);
|
state = TetherEnabler.TETHERING_OFF;
|
||||||
when(mSharedPreferences.edit()).thenReturn(mock(SharedPreferences.Editor.class));
|
mController.onTetherStateUpdated(state);
|
||||||
when(mPreference.isChecked()).thenReturn(true);
|
|
||||||
mController.onSharedPreferenceChanged(mSharedPreferences, BLUETOOTH_TETHER_KEY);
|
|
||||||
verify(mPreference).setChecked(eq(false));
|
|
||||||
verify(mPreference).setVisible(eq(false));
|
verify(mPreference).setVisible(eq(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,9 +111,16 @@ public class MobileNetworkActivityTest {
|
|||||||
|
|
||||||
private SubscriptionInfo mSubscriptionInFragment;
|
private SubscriptionInfo mSubscriptionInFragment;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
ProxySubscriptionManager getProxySubscriptionManager() {
|
||||||
|
if (mProxySubscriptionMgr == null) {
|
||||||
|
mProxySubscriptionMgr = mock(ProxySubscriptionManager.class);
|
||||||
|
}
|
||||||
|
return mProxySubscriptionMgr;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void registerActiveSubscriptionsListener() {
|
void registerActiveSubscriptionsListener() {
|
||||||
mProxySubscriptionMgr = mock(ProxySubscriptionManager.class);
|
|
||||||
onChanged();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import com.android.settings.widget.EntityHeaderController;
|
|||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -91,13 +90,6 @@ public class MobileNetworkSettingsTest {
|
|||||||
mNetworkPolicyManager);
|
mNetworkPolicyManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore
|
|
||||||
public void onAttach_noCrash() {
|
|
||||||
mFragment.onAttach(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createPreferenceControllers_createsDataUsageSummaryController() {
|
public void createPreferenceControllers_createsDataUsageSummaryController() {
|
||||||
final List<AbstractPreferenceController> controllers =
|
final List<AbstractPreferenceController> controllers =
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.telephony.TelephonyScanManager;
|
import android.telephony.TelephonyScanManager;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -71,6 +70,17 @@ public class NetworkScanHelperTest {
|
|||||||
|
|
||||||
private NetworkScan mNetworkScan;
|
private NetworkScan mNetworkScan;
|
||||||
|
|
||||||
|
private class NetworkScanMock extends NetworkScan {
|
||||||
|
NetworkScanMock(int scanId, int subId) {
|
||||||
|
super(scanId, subId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopScan() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -80,7 +90,7 @@ public class NetworkScanHelperTest {
|
|||||||
mNetworkScanHelper = new NetworkScanHelper(mTelephonyManager,
|
mNetworkScanHelper = new NetworkScanHelper(mTelephonyManager,
|
||||||
mNetworkScanCallback, mNetworkScanExecutor);
|
mNetworkScanCallback, mNetworkScanExecutor);
|
||||||
|
|
||||||
mNetworkScan = spy(new NetworkScan(SCAN_ID, SUB_ID));
|
mNetworkScan = spy(new NetworkScanMock(SCAN_ID, SUB_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,7 +153,6 @@ public class NetworkScanHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void startNetworkScan_incrementalAndAbort_doStop() {
|
public void startNetworkScan_incrementalAndAbort_doStop() {
|
||||||
doReturn(mNetworkScan).when(mTelephonyManager).requestNetworkScan(
|
doReturn(mNetworkScan).when(mTelephonyManager).requestNetworkScan(
|
||||||
any(NetworkScanRequest.class), any(Executor.class),
|
any(NetworkScanRequest.class), any(Executor.class),
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ public class ConfigureAccessPointFragmentTest {
|
|||||||
verify(mConfigureAccessPointFragment).handleSubmitAction();
|
verify(mConfigureAccessPointFragment).handleSubmitAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dispatchSubmit_shouldHandleSubmitAction() {
|
||||||
|
mConfigureAccessPointFragment.dispatchSubmit();
|
||||||
|
|
||||||
|
verify(mConfigureAccessPointFragment).handleSubmitAction();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onClickCancelButton_shouldHandleCancelAction() {
|
public void onClickCancelButton_shouldHandleCancelAction() {
|
||||||
mConfigureAccessPointFragment.getCancelButton().performClick();
|
mConfigureAccessPointFragment.getCancelButton().performClick();
|
||||||
|
|||||||
@@ -88,6 +88,13 @@ public class ConfigureWifiEntryFragmentTest {
|
|||||||
verify(mConfigureWifiEntryFragment).handleSubmitAction();
|
verify(mConfigureWifiEntryFragment).handleSubmitAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dispatchSubmit_shouldHandleSubmitAction() {
|
||||||
|
mConfigureWifiEntryFragment.dispatchSubmit();
|
||||||
|
|
||||||
|
verify(mConfigureWifiEntryFragment).handleSubmitAction();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onClickCancelButton_shouldHandleCancelAction() {
|
public void onClickCancelButton_shouldHandleCancelAction() {
|
||||||
mConfigureWifiEntryFragment.getCancelButton().performClick();
|
mConfigureWifiEntryFragment.getCancelButton().performClick();
|
||||||
|
|||||||
Reference in New Issue
Block a user