Snap for 6417465 from ec9b5b345f to mainline-release
Change-Id: I862cd4a902031ce45358b7ce865754454f921b33
This commit is contained in:
@@ -3776,14 +3776,31 @@
|
|||||||
<string name="tether_settings_summary_usb_tethering_only">USB only</string>
|
<string name="tether_settings_summary_usb_tethering_only">USB only</string>
|
||||||
<!-- Tethering setting summary when only Bluetooth tethering is on [CHAR LIMIT=NONE]-->
|
<!-- Tethering setting summary when only Bluetooth tethering is on [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_settings_summary_bluetooth_tethering_only">Bluetooth only</string>
|
<string name="tether_settings_summary_bluetooth_tethering_only">Bluetooth only</string>
|
||||||
|
<!-- Tethering setting summary when only Ethernet tethering is on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_ethernet_tethering_only">Ethernet only</string>
|
||||||
<!-- Tethering setting summary when Wi-Fi hotspot and USB tethering are on [CHAR LIMIT=NONE]-->
|
<!-- Tethering setting summary when Wi-Fi hotspot and USB tethering are on [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_settings_summary_hotspot_and_usb">Hotspot, USB</string>
|
<string name="tether_settings_summary_hotspot_and_usb">Hotspot, USB</string>
|
||||||
<!-- Tethering setting summary when Wi-Fi hotspot and Bluetooth tethering are on [CHAR LIMIT=NONE]-->
|
<!-- Tethering setting summary when Wi-Fi hotspot and Bluetooth tethering are on [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_settings_summary_hotspot_and_bluetooth">Hotspot, Bluetooth</string>
|
<string name="tether_settings_summary_hotspot_and_bluetooth">Hotspot, Bluetooth</string>
|
||||||
|
<!-- Tethering setting summary when Wi-Fi hotspot and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_hotspot_and_ethernet">Hotspot, Ethernet</string>
|
||||||
<!-- Tethering setting summary when USB and Bluetooth tethering are on [CHAR LIMIT=NONE]-->
|
<!-- Tethering setting summary when USB and Bluetooth tethering are on [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_settings_summary_usb_and_bluetooth">USB, Bluetooth</string>
|
<string name="tether_settings_summary_usb_and_bluetooth">USB, Bluetooth</string>
|
||||||
|
<!-- Tethering setting summary when USB and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_usb_and_ethernet">USB, Ethernet</string>
|
||||||
|
<!-- Tethering setting summary when Bluetooth and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_bluetooth_and_ethernet">Bluetooth, Ethernet</string>
|
||||||
<!-- Tethering setting summary when Wi-Fi hotspot and USB and Bluetooth tethering are on [CHAR LIMIT=NONE]-->
|
<!-- Tethering setting summary when Wi-Fi hotspot and USB and Bluetooth tethering are on [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_settings_summary_hotspot_and_usb_and_bluetooth">Hotspot, USB, Bluetooth</string>
|
<string name="tether_settings_summary_hotspot_and_usb_and_bluetooth">Hotspot, USB, Bluetooth</string>
|
||||||
|
<!-- Tethering setting summary when Wi-Fi hotspot and USB and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_hotspot_and_usb_and_ethernet">Hotspot, USB, Ethernet</string>
|
||||||
|
<!-- Tethering setting summary when Wi-Fi hotspot and Bluetooth and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_hotspot_and_bluetooth_and_ethernet">Hotspot, Bluetooth, Ethernet</string>
|
||||||
|
<!-- Tethering setting summary when USB and Bluetooth and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_usb_and_bluetooth_and_ethernet">USB, Bluetooth, Ethernet</string>
|
||||||
|
<!-- Tethering setting summary when Wi-Fi hotspot and USB and Bluetooth and Ethernet tethering are on [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="tether_settings_summary_all">Hotspot, USB, Bluetooth, Ethernet</string>
|
||||||
|
|
||||||
<!-- Tethering setting summary when hotspot and tethering are off [CHAR LIMIT=NONE]-->
|
<!-- Tethering setting summary when hotspot and tethering are off [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_settings_summary_off">Not sharing internet with other devices</string>
|
<string name="tether_settings_summary_off">Not sharing internet with other devices</string>
|
||||||
|
|
||||||
@@ -3797,8 +3814,16 @@
|
|||||||
<string name="disable_wifi_hotspot_when_usb_on">Only share internet via USB</string>
|
<string name="disable_wifi_hotspot_when_usb_on">Only share internet via USB</string>
|
||||||
<!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering is chosen [CHAR LIMIT=NONE]-->
|
<!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering is chosen [CHAR LIMIT=NONE]-->
|
||||||
<string name="disable_wifi_hotspot_when_bluetooth_on">Only share internet via Bluetooth</string>
|
<string name="disable_wifi_hotspot_when_bluetooth_on">Only share internet via Bluetooth</string>
|
||||||
|
<!-- Don't use Wi-Fi hotspot summary when Ethernet tethering is chosen [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="disable_wifi_hotspot_when_ethernet_on">Only share internet via Ethernet</string>
|
||||||
<!-- Don't use Wi-Fi hotspot summary when USB tethering and Bluetooth tethering are chosen [CHAR LIMIT=NONE]-->
|
<!-- Don't use Wi-Fi hotspot summary when USB tethering and Bluetooth tethering are chosen [CHAR LIMIT=NONE]-->
|
||||||
<string name="disable_wifi_hotspot_when_usb_and_bluetooth_on">Only share internet via USB and Bluetooth</string>
|
<string name="disable_wifi_hotspot_when_usb_and_bluetooth_on">Only share internet via USB and Bluetooth</string>
|
||||||
|
<!-- Don't use Wi-Fi hotspot summary when USB tethering and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="disable_wifi_hotspot_when_usb_and_ethernet_on">Only share internet via USB and Ethernet</string>
|
||||||
|
<!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="disable_wifi_hotspot_when_bluetooth_and_ethernet_on">Only share internet via Bluetooth and Ethernet</string>
|
||||||
|
<!-- Don't use Wi-Fi hotspot summary when USB, Bluetooth and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on">Only share internet via USB, Bluetooth and Ethernet</string>
|
||||||
|
|
||||||
<!-- USB Tethering options -->
|
<!-- USB Tethering options -->
|
||||||
<string name="usb_title">USB</string>
|
<string name="usb_title">USB</string>
|
||||||
@@ -11921,9 +11946,11 @@
|
|||||||
<!-- Content description for the 5G limited VoLTE dialog. [CHAR LIMIT=NONE] -->
|
<!-- Content description for the 5G limited VoLTE dialog. [CHAR LIMIT=NONE] -->
|
||||||
<string name="volte_5G_limited_text">This also turns off your 5G connection.\nDuring a voice call, you can\u2019t use the internet and some apps may not work.</string>
|
<string name="volte_5G_limited_text">This also turns off your 5G connection.\nDuring a voice call, you can\u2019t use the internet and some apps may not work.</string>
|
||||||
<!-- Footer to show current limitation of 5G on DSDS mode. [CHAR LIMIT=NONE] -->
|
<!-- Footer to show current limitation of 5G on DSDS mode. [CHAR LIMIT=NONE] -->
|
||||||
<string name="no_5g_in_dsds_text" product="default">When using 2 SIMs, this phone will be limited to 4G. Learn more</string>
|
<string name="no_5g_in_dsds_text" product="default">When using 2 SIMs, this phone will be limited to 4G. <annotation id="url">Learn more</annotation>.</string>
|
||||||
<!-- Footer to show current limitation of 5G on DSDS mode for tablets. [CHAR LIMIT=NONE] -->
|
<!-- Footer to show current limitation of 5G on DSDS mode for tablets. [CHAR LIMIT=NONE] -->
|
||||||
<string name="no_5g_in_dsds_text" product="tablet">When using 2 SIMs, this tablet will be limited to 4G. Learn more</string>
|
<string name="no_5g_in_dsds_text" product="tablet">When using 2 SIMs, this tablet will be limited to 4G. <annotation id="url">Learn more</annotation>.</string>
|
||||||
<!-- Footer to show current limitation of 5G on DSDS mode for general devices. [CHAR LIMIT=NONE] -->
|
<!-- Footer to show current limitation of 5G on DSDS mode for general devices. [CHAR LIMIT=NONE] -->
|
||||||
<string name="no_5g_in_dsds_text" product="device">When using 2 SIMs, this device will be limited to 4G. Learn more</string>
|
<string name="no_5g_in_dsds_text" product="device">When using 2 SIMs, this device will be limited to 4G. <annotation id="url">Learn more</annotation>.</string>
|
||||||
|
<!-- Help URI, 5G limitation in DSDS condition. [DO NOT TRANSLATE] -->
|
||||||
|
<string name="help_uri_5g_dsds" translatable="false"></string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -71,6 +71,13 @@
|
|||||||
settings:controller="com.android.settings.network.BluetoothTetherPreferenceController"
|
settings:controller="com.android.settings.network.BluetoothTetherPreferenceController"
|
||||||
settings:keywords="@string/keywords_hotspot_tethering" />
|
settings:keywords="@string/keywords_hotspot_tethering" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="enable_ethernet_tethering_2"
|
||||||
|
android:title="@string/ethernet_tether_checkbox_text"
|
||||||
|
android:summary="@string/ethernet_tethering_subtext"
|
||||||
|
settings:controller="com.android.settings.network.EthernetTetherPreferenceController"
|
||||||
|
settings:keywords="@string/keywords_hotspot_tethering"/>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="disable_wifi_tethering"
|
android:key="disable_wifi_tethering"
|
||||||
android:title="@string/disable_wifi_hotspot_title"
|
android:title="@string/disable_wifi_hotspot_title"
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import com.android.settings.core.FeatureFlags;
|
|||||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||||
import com.android.settings.datausage.DataSaverBackend;
|
import com.android.settings.datausage.DataSaverBackend;
|
||||||
import com.android.settings.network.BluetoothTetherPreferenceController;
|
import com.android.settings.network.BluetoothTetherPreferenceController;
|
||||||
|
import com.android.settings.network.EthernetTetherPreferenceController;
|
||||||
import com.android.settings.network.TetherEnabler;
|
import com.android.settings.network.TetherEnabler;
|
||||||
import com.android.settings.network.UsbTetherPreferenceController;
|
import com.android.settings.network.UsbTetherPreferenceController;
|
||||||
import com.android.settings.network.WifiTetherDisablePreferenceController;
|
import com.android.settings.network.WifiTetherDisablePreferenceController;
|
||||||
@@ -91,12 +92,17 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
|
|
||||||
private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver" + DEDUP_POSTFIX;
|
private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver" + DEDUP_POSTFIX;
|
||||||
private static final String KEY_WIFI_TETHER_GROUP = "wifi_tether_settings_group";
|
private static final String KEY_WIFI_TETHER_GROUP = "wifi_tether_settings_group";
|
||||||
|
public static final String WIFI_TETHER_DISABLE_KEY = "disable_wifi_tethering";
|
||||||
|
public static final String USB_TETHER_KEY = "enable_usb_tethering";
|
||||||
|
public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
|
||||||
|
public static final String ETHERNET_TETHER_KEY = "enable_ethernet_tethering" + DEDUP_POSTFIX;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int EXPANDED_CHILD_COUNT_DEFAULT = 3;
|
static final int EXPANDED_CHILD_COUNT_DEFAULT = 3;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 2;
|
static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 2;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG = 3;
|
static final int EXPANDED_CHILD_COUNT_MAX = Integer.MAX_VALUE;
|
||||||
private static final String TAG = "AllInOneTetherSettings";
|
private static final String TAG = "AllInOneTetherSettings";
|
||||||
|
|
||||||
private boolean mUnavailable;
|
private boolean mUnavailable;
|
||||||
@@ -114,16 +120,17 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
private WifiTetherApBandPreferenceController mApBandPreferenceController;
|
private WifiTetherApBandPreferenceController mApBandPreferenceController;
|
||||||
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
||||||
private PreferenceGroup mWifiTetherGroup;
|
private PreferenceGroup mWifiTetherGroup;
|
||||||
private boolean mBluetoothTethering;
|
private boolean mShouldShowWifiConfig = true;
|
||||||
private boolean mUsbTethering;
|
private boolean mHasShownAdvance;
|
||||||
private boolean mWifiTethering;
|
|
||||||
private TetherEnabler mTetherEnabler;
|
private TetherEnabler mTetherEnabler;
|
||||||
private final TetherEnabler.OnTetherStateUpdateListener mStateUpdateListener =
|
@VisibleForTesting
|
||||||
|
final TetherEnabler.OnTetherStateUpdateListener mStateUpdateListener =
|
||||||
state -> {
|
state -> {
|
||||||
mBluetoothTethering = TetherEnabler.isBluetoothTethering(state);
|
mShouldShowWifiConfig = TetherEnabler.isTethering(state, TETHERING_WIFI)
|
||||||
mUsbTethering = TetherEnabler.isUsbTethering(state);
|
|| state == TetherEnabler.TETHERING_OFF;
|
||||||
mWifiTethering = TetherEnabler.isWifiTethering(state);
|
getPreferenceScreen().setInitialExpandedChildrenCount(
|
||||||
mWifiTetherGroup.setVisible(shouldShowWifiConfig());
|
getInitialExpandedChildCount());
|
||||||
|
mWifiTetherGroup.setVisible(mShouldShowWifiConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
||||||
@@ -182,13 +189,13 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
mApBandPreferenceController = use(WifiTetherApBandPreferenceController.class);
|
mApBandPreferenceController = use(WifiTetherApBandPreferenceController.class);
|
||||||
getSettingsLifecycle().addObserver(use(UsbTetherPreferenceController.class));
|
getSettingsLifecycle().addObserver(use(UsbTetherPreferenceController.class));
|
||||||
getSettingsLifecycle().addObserver(use(BluetoothTetherPreferenceController.class));
|
getSettingsLifecycle().addObserver(use(BluetoothTetherPreferenceController.class));
|
||||||
|
getSettingsLifecycle().addObserver(use(EthernetTetherPreferenceController.class));
|
||||||
getSettingsLifecycle().addObserver(use(WifiTetherDisablePreferenceController.class));
|
getSettingsLifecycle().addObserver(use(WifiTetherDisablePreferenceController.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
mDataSaverBackend = new DataSaverBackend(getContext());
|
mDataSaverBackend = new DataSaverBackend(getContext());
|
||||||
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
||||||
mDataSaverFooter = findPreference(KEY_DATA_SAVER_FOOTER);
|
mDataSaverFooter = findPreference(KEY_DATA_SAVER_FOOTER);
|
||||||
@@ -226,6 +233,7 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
getSettingsLifecycle().addObserver(mTetherEnabler);
|
getSettingsLifecycle().addObserver(mTetherEnabler);
|
||||||
use(UsbTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
use(UsbTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
use(BluetoothTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
use(BluetoothTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
|
use(EthernetTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
use(WifiTetherDisablePreferenceController.class).setTetherEnabler(mTetherEnabler);
|
use(WifiTetherDisablePreferenceController.class).setTetherEnabler(mTetherEnabler);
|
||||||
switchBar.show();
|
switchBar.show();
|
||||||
}
|
}
|
||||||
@@ -379,14 +387,11 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
mApBandPreferenceController.updateDisplay();
|
mApBandPreferenceController.updateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldShowWifiConfig() {
|
|
||||||
return mWifiTethering || (!mBluetoothTethering && !mUsbTethering);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInitialExpandedChildCount() {
|
public int getInitialExpandedChildCount() {
|
||||||
if (!shouldShowWifiConfig()) {
|
if (mHasShownAdvance || !mShouldShowWifiConfig) {
|
||||||
return EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG;
|
mHasShownAdvance = true;
|
||||||
|
return EXPANDED_CHILD_COUNT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSecurityPreferenceController == null) {
|
if (mSecurityPreferenceController == null) {
|
||||||
@@ -398,6 +403,12 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|||||||
? EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
|
? EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExpandButtonClick() {
|
||||||
|
super.onExpandButtonClick();
|
||||||
|
mHasShownAdvance = true;
|
||||||
|
}
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider(R.xml.all_tether_prefs) {
|
new BaseSearchIndexProvider(R.xml.all_tether_prefs) {
|
||||||
|
|
||||||
|
|||||||
@@ -307,11 +307,7 @@ public class AccessibilitySettings extends DashboardFragment {
|
|||||||
return context.getText(R.string.accessibility_description_state_stopped);
|
return context.getText(R.string.accessibility_description_state_stopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String description = info.loadDescription(context.getPackageManager());
|
return info.loadDescription(context.getPackageManager());
|
||||||
|
|
||||||
return TextUtils.isEmpty(description)
|
|
||||||
? context.getText(R.string.accessibility_service_default_description)
|
|
||||||
: description;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isRampingRingerEnabled(final Context context) {
|
static boolean isRampingRingerEnabled(final Context context) {
|
||||||
@@ -460,7 +456,7 @@ public class AccessibilitySettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the order of perferences in the category by matching their preference
|
* Update the order of preferences in the category by matching their preference
|
||||||
* key with the string array of preference order which is defined in the xml.
|
* key with the string array of preference order which is defined in the xml.
|
||||||
*
|
*
|
||||||
* @param categoryKey The key of the category need to update the order
|
* @param categoryKey The key of the category need to update the order
|
||||||
@@ -708,10 +704,9 @@ public class AccessibilitySettings extends DashboardFragment {
|
|||||||
CharSequence title, CharSequence summary, int imageRes, String htmlDescription,
|
CharSequence title, CharSequence summary, int imageRes, String htmlDescription,
|
||||||
ComponentName componentName) {
|
ComponentName componentName) {
|
||||||
final Bundle extras = preference.getExtras();
|
final Bundle extras = preference.getExtras();
|
||||||
|
|
||||||
extras.putString(EXTRA_PREFERENCE_KEY, prefKey);
|
extras.putString(EXTRA_PREFERENCE_KEY, prefKey);
|
||||||
extras.putString(EXTRA_TITLE, title.toString());
|
extras.putCharSequence(EXTRA_TITLE, title);
|
||||||
extras.putString(EXTRA_SUMMARY, summary.toString());
|
extras.putCharSequence(EXTRA_SUMMARY, summary);
|
||||||
extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
|
extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
|
||||||
extras.putInt(EXTRA_ANIMATED_IMAGE_RES, imageRes);
|
extras.putInt(EXTRA_ANIMATED_IMAGE_RES, imageRes);
|
||||||
extras.putString(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, htmlDescription);
|
extras.putString(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, htmlDescription);
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
protected ComponentName mComponentName;
|
protected ComponentName mComponentName;
|
||||||
protected CharSequence mPackageName;
|
protected CharSequence mPackageName;
|
||||||
protected Uri mImageUri;
|
protected Uri mImageUri;
|
||||||
|
private CharSequence mDescription;
|
||||||
protected CharSequence mHtmlDescription;
|
protected CharSequence mHtmlDescription;
|
||||||
// Used to restore the edit dialog status.
|
// Used to restore the edit dialog status.
|
||||||
protected int mUserShortcutTypesCache = UserShortcutType.EMPTY;
|
protected int mUserShortcutTypesCache = UserShortcutType.EMPTY;
|
||||||
@@ -190,7 +191,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
groupCategory.addPreference(mSettingsPreference);
|
groupCategory.addPreference(mSettingsPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHtmlDescription != null) {
|
if (!TextUtils.isEmpty(mHtmlDescription)) {
|
||||||
final PreferenceCategory introductionCategory = new PreferenceCategory(
|
final PreferenceCategory introductionCategory = new PreferenceCategory(
|
||||||
getPrefContext());
|
getPrefContext());
|
||||||
final CharSequence title = getString(R.string.accessibility_introduction_title,
|
final CharSequence title = getString(R.string.accessibility_introduction_title,
|
||||||
@@ -205,6 +206,16 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
htmlTextPreference.setSelectable(false);
|
htmlTextPreference.setSelectable(false);
|
||||||
introductionCategory.addPreference(htmlTextPreference);
|
introductionCategory.addPreference(htmlTextPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(mDescription)) {
|
||||||
|
createFooterPreference(mDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(mHtmlDescription) && TextUtils.isEmpty(mDescription)) {
|
||||||
|
final CharSequence defaultDescription = getText(
|
||||||
|
R.string.accessibility_service_default_description);
|
||||||
|
createFooterPreference(defaultDescription);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -364,9 +375,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
|
|
||||||
// Summary.
|
// Summary.
|
||||||
if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
|
if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
|
||||||
final CharSequence summary = arguments.getCharSequence(
|
mDescription = arguments.getCharSequence(AccessibilitySettings.EXTRA_SUMMARY);
|
||||||
AccessibilitySettings.EXTRA_SUMMARY);
|
|
||||||
createFooterPreference(summary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Settings html description.
|
// Settings html description.
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.content.Intent;
|
|||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.telephony.data.ApnSetting;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -76,7 +77,8 @@ public class BillingCyclePreference extends Preference
|
|||||||
private void updateEnabled() {
|
private void updateEnabled() {
|
||||||
try {
|
try {
|
||||||
setEnabled(mServices.mNetworkService.isBandwidthControlEnabled()
|
setEnabled(mServices.mNetworkService.isBandwidthControlEnabled()
|
||||||
&& mServices.mTelephonyManager.getDataEnabled(mSubId)
|
&& mServices.mTelephonyManager.createForSubscriptionId(mSubId)
|
||||||
|
.isDataEnabledForApn(ApnSetting.TYPE_DEFAULT)
|
||||||
&& mServices.mUserManager.isAdminUser());
|
&& mServices.mUserManager.isAdminUser());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
|||||||
@@ -68,13 +68,12 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
private final EntityHeaderController mEntityHeaderController;
|
private final EntityHeaderController mEntityHeaderController;
|
||||||
private final Lifecycle mLifecycle;
|
private final Lifecycle mLifecycle;
|
||||||
private final PreferenceFragmentCompat mFragment;
|
private final PreferenceFragmentCompat mFragment;
|
||||||
protected final DataUsageController mDataUsageController;
|
protected DataUsageController mDataUsageController;
|
||||||
protected final DataUsageInfoController mDataInfoController;
|
protected DataUsageInfoController mDataInfoController;
|
||||||
private final NetworkTemplate mDefaultTemplate;
|
private NetworkTemplate mDefaultTemplate;
|
||||||
protected final NetworkPolicyEditor mPolicyEditor;
|
protected NetworkPolicyEditor mPolicyEditor;
|
||||||
private final int mDataUsageTemplate;
|
private int mDataUsageTemplate;
|
||||||
private final boolean mHasMobileData;
|
private boolean mHasMobileData;
|
||||||
private final SubscriptionManager mSubscriptionManager;
|
|
||||||
|
|
||||||
/** Name of the carrier, or null if not available */
|
/** Name of the carrier, or null if not available */
|
||||||
private CharSequence mCarrierName;
|
private CharSequence mCarrierName;
|
||||||
@@ -112,29 +111,31 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
fragment, null);
|
fragment, null);
|
||||||
mLifecycle = lifecycle;
|
mLifecycle = lifecycle;
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
|
init(subscriptionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init(int subscriptionId) {
|
||||||
mSubscriptionId = subscriptionId;
|
mSubscriptionId = subscriptionId;
|
||||||
|
|
||||||
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(activity, mSubscriptionId);
|
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(mContext, mSubscriptionId);
|
||||||
NetworkPolicyManager policyManager = activity.getSystemService(NetworkPolicyManager.class);
|
final NetworkPolicyManager policyManager =
|
||||||
|
mContext.getSystemService(NetworkPolicyManager.class);
|
||||||
mPolicyEditor = new NetworkPolicyEditor(policyManager);
|
mPolicyEditor = new NetworkPolicyEditor(policyManager);
|
||||||
|
|
||||||
mHasMobileData = SubscriptionManager.isValidSubscriptionId(mSubscriptionId)
|
mHasMobileData = SubscriptionManager.isValidSubscriptionId(mSubscriptionId)
|
||||||
&& DataUsageUtils.hasMobileData(activity);
|
&& DataUsageUtils.hasMobileData(mContext);
|
||||||
|
|
||||||
mDataUsageController = new DataUsageController(activity);
|
mDataUsageController = new DataUsageController(mContext);
|
||||||
mDataUsageController.setSubscriptionId(mSubscriptionId);
|
mDataUsageController.setSubscriptionId(mSubscriptionId);
|
||||||
mDataInfoController = new DataUsageInfoController();
|
mDataInfoController = new DataUsageInfoController();
|
||||||
|
|
||||||
if (mHasMobileData) {
|
if (mHasMobileData) {
|
||||||
mDataUsageTemplate = R.string.cell_data_template;
|
mDataUsageTemplate = R.string.cell_data_template;
|
||||||
} else if (DataUsageUtils.hasWifiRadio(activity)) {
|
} else if (DataUsageUtils.hasWifiRadio(mContext)) {
|
||||||
mDataUsageTemplate = R.string.wifi_data_template;
|
mDataUsageTemplate = R.string.wifi_data_template;
|
||||||
} else {
|
} else {
|
||||||
mDataUsageTemplate = R.string.ethernet_data_template;
|
mDataUsageTemplate = R.string.ethernet_data_template;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSubscriptionManager = (SubscriptionManager)
|
|
||||||
mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -144,8 +145,6 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
NetworkTemplate defaultTemplate,
|
NetworkTemplate defaultTemplate,
|
||||||
NetworkPolicyEditor policyEditor,
|
NetworkPolicyEditor policyEditor,
|
||||||
int dataUsageTemplate,
|
int dataUsageTemplate,
|
||||||
boolean hasMobileData,
|
|
||||||
SubscriptionManager subscriptionManager,
|
|
||||||
Activity activity,
|
Activity activity,
|
||||||
Lifecycle lifecycle,
|
Lifecycle lifecycle,
|
||||||
EntityHeaderController entityHeaderController,
|
EntityHeaderController entityHeaderController,
|
||||||
@@ -157,8 +156,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
mDefaultTemplate = defaultTemplate;
|
mDefaultTemplate = defaultTemplate;
|
||||||
mPolicyEditor = policyEditor;
|
mPolicyEditor = policyEditor;
|
||||||
mDataUsageTemplate = dataUsageTemplate;
|
mDataUsageTemplate = dataUsageTemplate;
|
||||||
mHasMobileData = hasMobileData;
|
mHasMobileData = true;
|
||||||
mSubscriptionManager = subscriptionManager;
|
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mLifecycle = lifecycle;
|
mLifecycle = lifecycle;
|
||||||
mEntityHeaderController = entityHeaderController;
|
mEntityHeaderController = entityHeaderController;
|
||||||
@@ -174,24 +172,25 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setPlanValues(int dataPlanCount, long dataPlanSize, long dataPlanUse) {
|
List<SubscriptionPlan> getSubscriptionPlans(int subscriptionId) {
|
||||||
mDataplanCount = dataPlanCount;
|
return ProxySubscriptionManager.getInstance(mContext).get()
|
||||||
mDataplanSize = dataPlanSize;
|
.getSubscriptionPlans(subscriptionId);
|
||||||
mDataBarSize = dataPlanSize;
|
|
||||||
mDataplanUse = dataPlanUse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setCarrierValues(String carrierName, long snapshotTime, long cycleEnd, Intent intent) {
|
SubscriptionInfo getSubscriptionInfo(int subscriptionId) {
|
||||||
mCarrierName = carrierName;
|
return ProxySubscriptionManager.getInstance(mContext)
|
||||||
mSnapshotTime = snapshotTime;
|
.getAccessibleSubscriptionInfo(subscriptionId);
|
||||||
mCycleEnd = cycleEnd;
|
}
|
||||||
mManageSubscriptionIntent = intent;
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean hasSim() {
|
||||||
|
return DataUsageUtils.hasSim(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return DataUsageUtils.hasSim(mActivity)
|
return hasSim()
|
||||||
|| DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
|| DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +199,8 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;
|
DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;
|
||||||
|
|
||||||
final DataUsageController.DataUsageInfo info;
|
final DataUsageController.DataUsageInfo info;
|
||||||
if (DataUsageUtils.hasSim(mActivity)) {
|
final SubscriptionInfo subInfo = getSubscriptionInfo(mSubscriptionId);
|
||||||
|
if (hasSim()) {
|
||||||
info = mDataUsageController.getDataUsageInfo(mDefaultTemplate);
|
info = mDataUsageController.getDataUsageInfo(mDefaultTemplate);
|
||||||
mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(mDefaultTemplate));
|
mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(mDefaultTemplate));
|
||||||
summaryPreference.setWifiMode(/* isWifiMode */ false,
|
summaryPreference.setWifiMode(/* isWifiMode */ false,
|
||||||
@@ -223,9 +223,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSubscriptionManager != null) {
|
refreshDataplanInfo(info, subInfo);
|
||||||
refreshDataplanInfo(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info.warningLevel > 0 && info.limitLevel > 0) {
|
if (info.warningLevel > 0 && info.limitLevel > 0) {
|
||||||
summaryPreference.setLimitInfo(TextUtils.expandTemplate(
|
summaryPreference.setLimitInfo(TextUtils.expandTemplate(
|
||||||
@@ -260,7 +258,8 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
|
|
||||||
// TODO(b/70950124) add test for this method once the robolectric shadow run script is
|
// TODO(b/70950124) add test for this method once the robolectric shadow run script is
|
||||||
// completed (b/3526807)
|
// completed (b/3526807)
|
||||||
private void refreshDataplanInfo(DataUsageController.DataUsageInfo info) {
|
private void refreshDataplanInfo(DataUsageController.DataUsageInfo info,
|
||||||
|
SubscriptionInfo subInfo) {
|
||||||
// reset data before overwriting
|
// reset data before overwriting
|
||||||
mCarrierName = null;
|
mCarrierName = null;
|
||||||
mDataplanCount = 0;
|
mDataplanCount = 0;
|
||||||
@@ -271,16 +270,10 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
mCycleEnd = info.cycleEnd;
|
mCycleEnd = info.cycleEnd;
|
||||||
mSnapshotTime = -1L;
|
mSnapshotTime = -1L;
|
||||||
|
|
||||||
final ProxySubscriptionManager proxySubsciptionMgr =
|
|
||||||
ProxySubscriptionManager.getInstance(mContext);
|
|
||||||
final SubscriptionInfo subInfo = proxySubsciptionMgr
|
|
||||||
.getAccessibleSubscriptionInfo(mSubscriptionId);
|
|
||||||
if (subInfo != null && mHasMobileData) {
|
if (subInfo != null && mHasMobileData) {
|
||||||
mCarrierName = subInfo.getCarrierName();
|
mCarrierName = subInfo.getCarrierName();
|
||||||
List<SubscriptionPlan> plans = mSubscriptionManager.getSubscriptionPlans(
|
final List<SubscriptionPlan> plans = getSubscriptionPlans(mSubscriptionId);
|
||||||
mSubscriptionId);
|
final SubscriptionPlan primaryPlan = getPrimaryPlan(plans);
|
||||||
final SubscriptionPlan primaryPlan = getPrimaryPlan(mSubscriptionManager,
|
|
||||||
mSubscriptionId);
|
|
||||||
|
|
||||||
if (primaryPlan != null) {
|
if (primaryPlan != null) {
|
||||||
mDataplanCount = plans.size();
|
mDataplanCount = plans.size();
|
||||||
@@ -313,7 +306,8 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
* {@code null} if no carrier app is defined, or if the defined
|
* {@code null} if no carrier app is defined, or if the defined
|
||||||
* carrier app provides no management activity.
|
* carrier app provides no management activity.
|
||||||
*/
|
*/
|
||||||
private Intent createManageSubscriptionIntent(int subId) {
|
@VisibleForTesting
|
||||||
|
Intent createManageSubscriptionIntent(int subId) {
|
||||||
final INetworkPolicyManager iNetPolicyManager = INetworkPolicyManager.Stub.asInterface(
|
final INetworkPolicyManager iNetPolicyManager = INetworkPolicyManager.Stub.asInterface(
|
||||||
ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
|
ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
|
||||||
String owner = "";
|
String owner = "";
|
||||||
@@ -327,7 +321,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<SubscriptionPlan> plans = mSubscriptionManager.getSubscriptionPlans(subId);
|
final List<SubscriptionPlan> plans = getSubscriptionPlans(subId);
|
||||||
if (plans.isEmpty()) {
|
if (plans.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -344,8 +338,7 @@ public class DataUsageSummaryPreferenceController extends BasePreferenceControll
|
|||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SubscriptionPlan getPrimaryPlan(SubscriptionManager subManager, int primaryId) {
|
private static SubscriptionPlan getPrimaryPlan(List<SubscriptionPlan> plans) {
|
||||||
List<SubscriptionPlan> plans = subManager.getSubscriptionPlans(primaryId);
|
|
||||||
if (CollectionUtils.isEmpty(plans)) {
|
if (CollectionUtils.isEmpty(plans)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class MediaOutputGroupSlice implements CustomSliceable {
|
|||||||
IconCompat.createWithResource(mContext, R.drawable.ic_check_box_anim),
|
IconCompat.createWithResource(mContext, R.drawable.ic_check_box_anim),
|
||||||
"",
|
"",
|
||||||
selected);
|
selected);
|
||||||
if (maxVolume > 0 && !adjustVolumeUserRestriction) {
|
if (maxVolume > 0 && selected && !adjustVolumeUserRestriction) {
|
||||||
// Add InputRange row
|
// Add InputRange row
|
||||||
final ListBuilder.InputRangeBuilder builder = new ListBuilder.InputRangeBuilder()
|
final ListBuilder.InputRangeBuilder builder = new ListBuilder.InputRangeBuilder()
|
||||||
.setTitleItem(titleIcon, ListBuilder.ICON_IMAGE)
|
.setTitleItem(titleIcon, ListBuilder.ICON_IMAGE)
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ 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.TETHERING_BLUETOOTH_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
||||||
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
|
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -52,19 +57,7 @@ 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 TETHERING_TYPE_HOTSPOT_ONLY = 1;
|
private int mTetheringState;
|
||||||
private static final byte TETHERING_TYPE_USB_ONLY = 1 << 1;
|
|
||||||
private static final byte TETHERING_TYPE_BLUETOOTH_ONLY = 1 << 2;
|
|
||||||
private static final byte TETHERING_TYPE_HOTSPOT_AND_USB =
|
|
||||||
TETHERING_TYPE_HOTSPOT_ONLY | TETHERING_TYPE_USB_ONLY;
|
|
||||||
private static final byte TETHERING_TYPE_HOTSPOT_AND_BLUETOOTH =
|
|
||||||
TETHERING_TYPE_HOTSPOT_ONLY | TETHERING_TYPE_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;
|
||||||
@@ -124,32 +117,49 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (mPreference != null && mPreference.isChecked()) {
|
switch (mTetheringState) {
|
||||||
switch (mTetheringType) {
|
case TETHERING_OFF:
|
||||||
case TETHERING_TYPE_HOTSPOT_ONLY:
|
return mContext.getString(R.string.tether_settings_summary_off);
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_only);
|
case TETHERING_WIFI_ON:
|
||||||
case TETHERING_TYPE_USB_ONLY:
|
return mContext.getString(R.string.tether_settings_summary_hotspot_only);
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_tethering_only);
|
case TETHERING_USB_ON:
|
||||||
case TETHERING_TYPE_BLUETOOTH_ONLY:
|
return mContext.getString(R.string.tether_settings_summary_usb_tethering_only);
|
||||||
return mContext.getString(
|
case TETHERING_BLUETOOTH_ON:
|
||||||
R.string.tether_settings_summary_bluetooth_tethering_only);
|
return mContext.getString(
|
||||||
case TETHERING_TYPE_HOTSPOT_AND_USB:
|
R.string.tether_settings_summary_bluetooth_tethering_only);
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_and_usb);
|
case TETHERING_ETHERNET_ON:
|
||||||
case TETHERING_TYPE_HOTSPOT_AND_BLUETOOTH:
|
return mContext.getString(R.string.tether_settings_summary_ethernet_tethering_only);
|
||||||
return mContext.getString(
|
case TETHERING_WIFI_ON | TETHERING_USB_ON:
|
||||||
R.string.tether_settings_summary_hotspot_and_bluetooth);
|
return mContext.getString(R.string.tether_settings_summary_hotspot_and_usb);
|
||||||
case TETHERING_TYPE_USB_AND_BLUETOOTH:
|
case TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON:
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_and_bluetooth);
|
return mContext.getString(R.string.tether_settings_summary_hotspot_and_bluetooth);
|
||||||
case TETHERING_TYPE_HOTSPOT_AND_USB_AND_BLUETOOTH:
|
case TETHERING_WIFI_ON | TETHERING_ETHERNET_ON:
|
||||||
return mContext.getString(
|
return mContext.getString(R.string.tether_settings_summary_hotspot_and_ethernet);
|
||||||
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth);
|
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
|
||||||
default:
|
return mContext.getString(R.string.tether_settings_summary_usb_and_bluetooth);
|
||||||
Log.e(TAG, "None of the tether interfaces is chosen");
|
case TETHERING_USB_ON | TETHERING_ETHERNET_ON:
|
||||||
return mContext.getString(R.string.summary_placeholder);
|
return mContext.getString(R.string.tether_settings_summary_usb_and_ethernet);
|
||||||
}
|
case TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(R.string.tether_settings_summary_bluetooth_and_ethernet);
|
||||||
|
case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth);
|
||||||
|
case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.tether_settings_summary_hotspot_and_usb_and_ethernet);
|
||||||
|
case TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet);
|
||||||
|
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet);
|
||||||
|
case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
|
||||||
|
| TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(R.string.tether_settings_summary_all);
|
||||||
|
default:
|
||||||
|
Log.e(TAG, "Unknown tethering state");
|
||||||
|
return mContext.getString(R.string.summary_placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_off);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_CREATE)
|
@OnLifecycleEvent(Event.ON_CREATE)
|
||||||
@@ -197,11 +207,7 @@ public class AllInOneTetherPreferenceController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
|
public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
|
||||||
mTetheringType = 0;
|
mTetheringState = state;
|
||||||
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,51 +21,25 @@ 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.net.TetheringManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
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.
|
||||||
*/
|
*/
|
||||||
public final class BluetoothTetherPreferenceController extends TetherBasePreferenceController
|
public final class BluetoothTetherPreferenceController extends TetherBasePreferenceController {
|
||||||
implements LifecycleObserver {
|
|
||||||
|
|
||||||
private static final String TAG = "BluetoothTetherPreferenceController";
|
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
|
||||||
private int mBluetoothState;
|
private int mBluetoothState;
|
||||||
private boolean mBluetoothTethering;
|
|
||||||
|
|
||||||
public BluetoothTetherPreferenceController(Context context, String preferenceKey) {
|
public BluetoothTetherPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return mBluetoothTethering;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
if (mTetherEnabler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isChecked) {
|
|
||||||
mTetherEnabler.startTethering(TetheringManager.TETHERING_BLUETOOTH);
|
|
||||||
} else {
|
|
||||||
mTetherEnabler.stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mBluetoothState = BluetoothAdapter.getDefaultAdapter().getState();
|
mBluetoothState = BluetoothAdapter.getDefaultAdapter().getState();
|
||||||
@@ -79,41 +53,30 @@ public final class BluetoothTetherPreferenceController extends TetherBasePrefere
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public boolean shouldEnable() {
|
||||||
super.updateState(preference);
|
|
||||||
if (preference == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (mBluetoothState) {
|
switch (mBluetoothState) {
|
||||||
case BluetoothAdapter.STATE_ON:
|
case BluetoothAdapter.STATE_ON:
|
||||||
case BluetoothAdapter.STATE_OFF:
|
case BluetoothAdapter.STATE_OFF:
|
||||||
// fall through.
|
// fall through.
|
||||||
case BluetoothAdapter.ERROR:
|
case BluetoothAdapter.ERROR:
|
||||||
preference.setEnabled(true);
|
return true;
|
||||||
break;
|
|
||||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||||
case BluetoothAdapter.STATE_TURNING_ON:
|
case BluetoothAdapter.STATE_TURNING_ON:
|
||||||
// fall through.
|
// fall through.
|
||||||
default:
|
default:
|
||||||
preference.setEnabled(false);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public boolean shouldShow() {
|
||||||
final String[] bluetoothRegexs = mCm.getTetherableBluetoothRegexs();
|
final String[] bluetoothRegexs = mCm.getTetherableBluetoothRegexs();
|
||||||
if (bluetoothRegexs == null || bluetoothRegexs.length == 0) {
|
return bluetoothRegexs != null && bluetoothRegexs.length != 0;
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
|
||||||
} else {
|
|
||||||
return AVAILABLE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTetherStateUpdated(int state) {
|
public int getTetherType() {
|
||||||
mBluetoothTethering = TetherEnabler.isBluetoothTethering(state);
|
return ConnectivityManager.TETHERING_BLUETOOTH;
|
||||||
updateState(mPreference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.EthernetManager;
|
||||||
|
import android.net.TetheringManager;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This controller helps to manage the switch state and visibility of ethernet tether switch
|
||||||
|
* preference.
|
||||||
|
*/
|
||||||
|
public final class EthernetTetherPreferenceController extends TetherBasePreferenceController {
|
||||||
|
|
||||||
|
private final String mEthernetRegex;
|
||||||
|
private final EthernetManager mEthernetManager;
|
||||||
|
@VisibleForTesting
|
||||||
|
EthernetManager.Listener mEthernetListener;
|
||||||
|
|
||||||
|
public EthernetTetherPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mEthernetRegex = context.getString(
|
||||||
|
com.android.internal.R.string.config_ethernet_iface_regex);
|
||||||
|
mEthernetManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
public void onStart() {
|
||||||
|
mEthernetListener = new EthernetManager.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onAvailabilityChanged(String iface, boolean isAvailable) {
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> updateState(mPreference));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mEthernetManager.addListener(mEthernetListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||||
|
public void onStop() {
|
||||||
|
mEthernetManager.removeListener(mEthernetListener);
|
||||||
|
mEthernetListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldEnable() {
|
||||||
|
String[] available = mCm.getTetherableIfaces();
|
||||||
|
for (String s : available) {
|
||||||
|
if (s.matches(mEthernetRegex)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldShow() {
|
||||||
|
return !TextUtils.isEmpty(mEthernetRegex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTetherType() {
|
||||||
|
return TetheringManager.TETHERING_ETHERNET;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ package com.android.settings.network;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
@@ -27,20 +26,26 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settings.datausage.DataSaverBackend;
|
||||||
|
|
||||||
public abstract class TetherBasePreferenceController extends TogglePreferenceController
|
public abstract class TetherBasePreferenceController extends TogglePreferenceController
|
||||||
implements LifecycleObserver, TetherEnabler.OnTetherStateUpdateListener {
|
implements LifecycleObserver, DataSaverBackend.Listener,
|
||||||
|
TetherEnabler.OnTetherStateUpdateListener {
|
||||||
|
|
||||||
private static final String TAG = "TetherBasePreferenceController";
|
private static final String TAG = "TetherBasePreferenceController";
|
||||||
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
|
||||||
final ConnectivityManager mCm;
|
final ConnectivityManager mCm;
|
||||||
|
private final DataSaverBackend mDataSaverBackend;
|
||||||
|
|
||||||
TetherEnabler mTetherEnabler;
|
private TetherEnabler mTetherEnabler;
|
||||||
Preference mPreference;
|
Preference mPreference;
|
||||||
|
private boolean mDataSaverEnabled;
|
||||||
|
int mTetheringState;
|
||||||
|
|
||||||
public TetherBasePreferenceController(Context context, String preferenceKey) {
|
TetherBasePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
mCm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
mDataSaverBackend = new DataSaverBackend(context);
|
||||||
|
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,6 +62,7 @@ public abstract class TetherBasePreferenceController extends TogglePreferenceCon
|
|||||||
if (mTetherEnabler != null) {
|
if (mTetherEnabler != null) {
|
||||||
mTetherEnabler.addListener(this);
|
mTetherEnabler.addListener(this);
|
||||||
}
|
}
|
||||||
|
mDataSaverBackend.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
@@ -64,6 +70,25 @@ public abstract class TetherBasePreferenceController extends TogglePreferenceCon
|
|||||||
if (mTetherEnabler != null) {
|
if (mTetherEnabler != null) {
|
||||||
mTetherEnabler.removeListener(this);
|
mTetherEnabler.removeListener(this);
|
||||||
}
|
}
|
||||||
|
mDataSaverBackend.remListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return TetherEnabler.isTethering(mTetheringState, getTetherType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
if (mTetherEnabler == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isChecked) {
|
||||||
|
mTetherEnabler.startTethering(getTetherType());
|
||||||
|
} else {
|
||||||
|
mTetherEnabler.stopTethering(getTetherType());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,4 +96,61 @@ public abstract class TetherBasePreferenceController extends TogglePreferenceCon
|
|||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
mPreference = screen.findPreference(mPreferenceKey);
|
mPreference = screen.findPreference(mPreferenceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
if (isAvailable()) {
|
||||||
|
preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
if (!shouldShow()) {
|
||||||
|
return CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mDataSaverEnabled || !shouldEnable()) {
|
||||||
|
return DISABLED_DEPENDENT_SETTING;
|
||||||
|
}
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
|
||||||
|
mTetheringState = state;
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataSaverChanged(boolean isDataSaving) {
|
||||||
|
mDataSaverEnabled = isDataSaving;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to enable or disable the preference.
|
||||||
|
* @return true if the preference should be enabled; false otherwise.
|
||||||
|
*/
|
||||||
|
public abstract boolean shouldEnable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to determine visibility of the preference.
|
||||||
|
* @return true if the preference should be visible; false otherwise.
|
||||||
|
*/
|
||||||
|
public abstract boolean shouldShow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type of tether interface that is controlled by the preference.
|
||||||
|
* @return the tether interface, like {@link ConnectivityManager#TETHERING_WIFI}
|
||||||
|
*/
|
||||||
|
public abstract int getTetherType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ package com.android.settings.network;
|
|||||||
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
|
import static android.net.TetheringManager.TETHERING_ETHERNET;
|
||||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||||
|
|
||||||
@@ -32,8 +31,10 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.TetheringManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerExecutor;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -84,38 +85,37 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
@Retention(SOURCE)
|
@Retention(SOURCE)
|
||||||
@IntDef(
|
@IntDef(
|
||||||
flag = true,
|
flag = true,
|
||||||
value = {TETHERING_OFF, TETHERING_WIFI_ON, TETHERING_USB_ON, TETHERING_BLUETOOTH_ON}
|
value = {
|
||||||
|
TETHERING_OFF,
|
||||||
|
TETHERING_WIFI_ON,
|
||||||
|
TETHERING_USB_ON,
|
||||||
|
TETHERING_BLUETOOTH_ON,
|
||||||
|
TETHERING_ETHERNET_ON
|
||||||
|
}
|
||||||
)
|
)
|
||||||
@interface TetheringState {}
|
@interface TetheringState {}
|
||||||
@VisibleForTesting
|
public static final int TETHERING_OFF = 0;
|
||||||
static final int TETHERING_OFF = 0;
|
public static final int TETHERING_WIFI_ON = 1 << TETHERING_WIFI;
|
||||||
@VisibleForTesting
|
public static final int TETHERING_USB_ON = 1 << TETHERING_USB;
|
||||||
static final int TETHERING_WIFI_ON = 1;
|
public static final int TETHERING_BLUETOOTH_ON = 1 << TETHERING_BLUETOOTH;
|
||||||
@VisibleForTesting
|
public static final int TETHERING_ETHERNET_ON = 1 << TETHERING_ETHERNET;
|
||||||
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.
|
|
||||||
public static final String KEY_ENABLE_WIFI_TETHERING = "enable_wifi_tethering";
|
|
||||||
public static final String WIFI_TETHER_DISABLE_KEY = "disable_wifi_tethering";
|
|
||||||
public static final String USB_TETHER_KEY = "enable_usb_tethering";
|
|
||||||
public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final List<OnTetherStateUpdateListener> mListeners;
|
final List<OnTetherStateUpdateListener> mListeners;
|
||||||
|
private final Handler mMainThreadHandler;
|
||||||
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 TetheringManager mTetheringManager;
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
|
private final String mEthernetRegex;
|
||||||
private final DataSaverBackend mDataSaverBackend;
|
private final DataSaverBackend mDataSaverBackend;
|
||||||
private boolean mDataSaverEnabled;
|
private boolean mDataSaverEnabled;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mBluetoothTetheringStoppedByUser;
|
boolean mBluetoothTetheringStoppedByUser;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
@VisibleForTesting
|
||||||
|
TetheringManager.TetheringEventCallback mTetheringEventCallback;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback;
|
ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback;
|
||||||
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
||||||
@@ -129,12 +129,16 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
mDataSaverBackend = new DataSaverBackend(context);
|
mDataSaverBackend = new DataSaverBackend(context);
|
||||||
mConnectivityManager =
|
mConnectivityManager =
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
mTetheringManager = (TetheringManager) context.getSystemService(Context.TETHERING_SERVICE);
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
mBluetoothPan = bluetoothPan;
|
mBluetoothPan = bluetoothPan;
|
||||||
|
mEthernetRegex =
|
||||||
|
context.getString(com.android.internal.R.string.config_ethernet_iface_regex);
|
||||||
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
||||||
mListeners = new ArrayList<>();
|
mListeners = new ArrayList<>();
|
||||||
|
mMainThreadHandler = new Handler(Looper.getMainLooper());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
@@ -142,12 +146,20 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
mDataSaverBackend.addListener(this);
|
mDataSaverBackend.addListener(this);
|
||||||
mSwitchWidgetController.setListener(this);
|
mSwitchWidgetController.setListener(this);
|
||||||
mSwitchWidgetController.startListening();
|
mSwitchWidgetController.startListening();
|
||||||
|
|
||||||
final IntentFilter filter = new IntentFilter(
|
final IntentFilter filter = new IntentFilter(
|
||||||
ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
||||||
filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||||
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
mContext.registerReceiver(mTetherChangeReceiver, filter);
|
mContext.registerReceiver(mTetherChangeReceiver, filter);
|
||||||
|
mTetheringEventCallback =
|
||||||
|
new TetheringManager.TetheringEventCallback() {
|
||||||
|
@Override
|
||||||
|
public void onTetheredInterfacesChanged(List<String> interfaces) {
|
||||||
|
updateState(interfaces.toArray(new String[interfaces.size()]));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mTetheringManager.registerTetheringEventCallback(new HandlerExecutor(mMainThreadHandler),
|
||||||
|
mTetheringEventCallback);
|
||||||
|
|
||||||
mOnStartTetheringCallback = new OnStartTetheringCallback(this);
|
mOnStartTetheringCallback = new OnStartTetheringCallback(this);
|
||||||
updateState(null/*tethered*/);
|
updateState(null/*tethered*/);
|
||||||
@@ -159,6 +171,8 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
mDataSaverBackend.remListener(this);
|
mDataSaverBackend.remListener(this);
|
||||||
mSwitchWidgetController.stopListening();
|
mSwitchWidgetController.stopListening();
|
||||||
mContext.unregisterReceiver(mTetherChangeReceiver);
|
mContext.unregisterReceiver(mTetherChangeReceiver);
|
||||||
|
mTetheringManager.unregisterTetheringEventCallback(mTetheringEventCallback);
|
||||||
|
mTetheringEventCallback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(OnTetherStateUpdateListener listener) {
|
public void addListener(OnTetherStateUpdateListener listener) {
|
||||||
@@ -193,13 +207,19 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSwitchCheckedInternal(boolean checked) {
|
private void setSwitchCheckedInternal(boolean checked) {
|
||||||
mSwitchWidgetController.stopListening();
|
try {
|
||||||
|
mSwitchWidgetController.stopListening();
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Log.e(TAG, "failed to stop switch widget listener when set check internally");
|
||||||
|
return;
|
||||||
|
}
|
||||||
mSwitchWidgetController.setChecked(checked);
|
mSwitchWidgetController.setChecked(checked);
|
||||||
mSwitchWidgetController.startListening();
|
mSwitchWidgetController.startListening();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@TetheringState int getTetheringState(@Nullable String[] tethered) {
|
@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();
|
||||||
@@ -223,24 +243,19 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
for (String s : tethered) {
|
for (String s : tethered) {
|
||||||
for (String regex : usbRegexs) {
|
for (String regex : usbRegexs) {
|
||||||
if (s.matches(regex)) {
|
if (s.matches(regex)) {
|
||||||
return tetherState | TETHERING_USB_ON;
|
tetherState |= TETHERING_USB_ON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (s.matches(mEthernetRegex)) {
|
||||||
|
tetherState |= TETHERING_ETHERNET_ON;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tetherState;
|
return tetherState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBluetoothTethering(@TetheringState int state) {
|
public static boolean isTethering(@TetheringState int state, int choice) {
|
||||||
return (state & TETHERING_BLUETOOTH_ON) != TETHERING_OFF;
|
return (state & (1 << choice)) != 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
|
||||||
@@ -251,15 +266,14 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
stopTethering(TETHERING_USB);
|
stopTethering(TETHERING_USB);
|
||||||
stopTethering(TETHERING_WIFI);
|
stopTethering(TETHERING_WIFI);
|
||||||
stopTethering(TETHERING_BLUETOOTH);
|
stopTethering(TETHERING_BLUETOOTH);
|
||||||
|
stopTethering(TETHERING_ETHERNET);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTethering(int choice) {
|
public void stopTethering(int choice) {
|
||||||
int state = getTetheringState(null /* tethered */);
|
int state = getTetheringState(null /* tethered */);
|
||||||
if ((choice == TETHERING_WIFI && isWifiTethering(state))
|
if (isTethering(state, choice)) {
|
||||||
|| (choice == TETHERING_USB && isUsbTethering(state))
|
|
||||||
|| (choice == TETHERING_BLUETOOTH && isBluetoothTethering(state))) {
|
|
||||||
setSwitchEnabled(false);
|
setSwitchEnabled(false);
|
||||||
mConnectivityManager.stopTethering(choice);
|
mConnectivityManager.stopTethering(choice);
|
||||||
if (choice == TETHERING_BLUETOOTH) {
|
if (choice == TETHERING_BLUETOOTH) {
|
||||||
@@ -272,41 +286,35 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startTethering(int choice) {
|
public void startTethering(int choice) {
|
||||||
|
if (choice == TETHERING_BLUETOOTH) {
|
||||||
|
mBluetoothTetheringStoppedByUser = false;
|
||||||
|
}
|
||||||
int state = getTetheringState(null /* tethered */);
|
int state = getTetheringState(null /* tethered */);
|
||||||
if ((choice == TETHERING_WIFI && isWifiTethering(state))
|
if (isTethering(state, choice)) {
|
||||||
|| (choice == TETHERING_USB && isUsbTethering(state))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice == TETHERING_BLUETOOTH) {
|
if (choice == TETHERING_BLUETOOTH && mBluetoothAdapter != null
|
||||||
mBluetoothTetheringStoppedByUser = false;
|
&& mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
|
||||||
if (mBluetoothAdapter == null || isBluetoothTethering(state)) {
|
if (DEBUG) {
|
||||||
return;
|
Log.d(TAG, "Turn on bluetooth first.");
|
||||||
} else if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "Turn on bluetooth first.");
|
|
||||||
}
|
|
||||||
mBluetoothEnableForTether = true;
|
|
||||||
mBluetoothAdapter.enable();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
mBluetoothEnableForTether = true;
|
||||||
|
mBluetoothAdapter.enable();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSwitchEnabled(false);
|
setSwitchEnabled(false);
|
||||||
mConnectivityManager.startTethering(choice, true /* showProvisioningUi */,
|
mConnectivityManager.startTethering(choice, true /* showProvisioningUi */,
|
||||||
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
|
mOnStartTetheringCallback, mMainThreadHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
ArrayList<String> active = null;
|
|
||||||
boolean shouldUpdateState = false;
|
boolean shouldUpdateState = false;
|
||||||
if (TextUtils.equals(ConnectivityManager.ACTION_TETHER_STATE_CHANGED, action)) {
|
if (TextUtils.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION, action)) {
|
||||||
active = intent.getStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER);
|
|
||||||
shouldUpdateState = true;
|
|
||||||
} else if (TextUtils.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION, action)) {
|
|
||||||
shouldUpdateState = handleWifiApStateChanged(intent.getIntExtra(
|
shouldUpdateState = handleWifiApStateChanged(intent.getIntExtra(
|
||||||
WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED));
|
WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED));
|
||||||
} else if (TextUtils.equals(BluetoothAdapter.ACTION_STATE_CHANGED, action)) {
|
} else if (TextUtils.equals(BluetoothAdapter.ACTION_STATE_CHANGED, action)) {
|
||||||
@@ -315,11 +323,7 @@ public class TetherEnabler implements SwitchWidgetController.OnSwitchChangeListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldUpdateState) {
|
if (shouldUpdateState) {
|
||||||
if (active != null) {
|
updateState(null /* tethered */);
|
||||||
updateState(active.toArray(new String[0]));
|
|
||||||
} else {
|
|
||||||
updateState(null/*tethered*/);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,54 +21,32 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.net.TetheringManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class UsbTetherPreferenceController extends TetherBasePreferenceController implements
|
public final class UsbTetherPreferenceController extends TetherBasePreferenceController {
|
||||||
LifecycleObserver {
|
|
||||||
|
|
||||||
private static final String TAG = "UsbTetherPrefController";
|
private static final String TAG = "UsbTetherPrefController";
|
||||||
|
|
||||||
private boolean mUsbConnected;
|
private boolean mUsbConnected;
|
||||||
private boolean mMassStorageActive;
|
private boolean mMassStorageActive;
|
||||||
private boolean mUsbTethering;
|
|
||||||
|
|
||||||
public UsbTetherPreferenceController(Context context, String prefKey) {
|
public UsbTetherPreferenceController(Context context, String prefKey) {
|
||||||
super(context, prefKey);
|
super(context, prefKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return mUsbTethering;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
if (mTetherEnabler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isChecked) {
|
|
||||||
mTetherEnabler.startTethering(TetheringManager.TETHERING_USB);
|
|
||||||
} else {
|
|
||||||
mTetherEnabler.stopTethering(TetheringManager.TETHERING_USB);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
||||||
@@ -84,27 +62,19 @@ public final class UsbTetherPreferenceController extends TetherBasePreferenceCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public boolean shouldEnable() {
|
||||||
|
return mUsbConnected && !mMassStorageActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldShow() {
|
||||||
String[] usbRegexs = mCm.getTetherableUsbRegexs();
|
String[] usbRegexs = mCm.getTetherableUsbRegexs();
|
||||||
if (usbRegexs == null || usbRegexs.length == 0 || Utils.isMonkeyRunning()) {
|
return usbRegexs != null && usbRegexs.length != 0 && !Utils.isMonkeyRunning();
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
|
||||||
} else {
|
|
||||||
return AVAILABLE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public int getTetherType() {
|
||||||
super.updateState(preference);
|
return ConnectivityManager.TETHERING_USB;
|
||||||
if (preference != null) {
|
|
||||||
preference.setEnabled(mUsbConnected && !mMassStorageActive);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTetherStateUpdated(int state) {
|
|
||||||
mUsbTethering = TetherEnabler.isUsbTethering(state);
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -16,34 +16,31 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import android.content.Context;
|
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
import android.net.TetheringManager;
|
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.TetherUtil;
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller helps to manage the switch state and visibility of wifi tether disable switch
|
* This controller helps to manage the switch state and visibility of wifi tether disable switch
|
||||||
* preference. When the preference checked, wifi tether will be disabled.
|
* preference. When the preference checked, wifi tether will be disabled.
|
||||||
* It stores preference value when preference changed and listens to usb tether and bluetooth tether
|
|
||||||
* preferences.
|
|
||||||
*
|
*
|
||||||
* @see BluetoothTetherPreferenceController
|
* @see BluetoothTetherPreferenceController
|
||||||
* @see UsbTetherPreferenceController
|
* @see UsbTetherPreferenceController
|
||||||
*/
|
*/
|
||||||
public final class WifiTetherDisablePreferenceController extends TetherBasePreferenceController
|
public final class WifiTetherDisablePreferenceController extends TetherBasePreferenceController {
|
||||||
implements LifecycleObserver {
|
|
||||||
|
|
||||||
private static final String TAG = "WifiTetherDisablePreferenceController";
|
private static final String TAG = "WifiTetherDisablePreferenceController";
|
||||||
|
|
||||||
private boolean mBluetoothTethering;
|
|
||||||
private boolean mUsbTethering;
|
|
||||||
private boolean mWifiTethering;
|
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
public WifiTetherDisablePreferenceController(Context context, String prefKey) {
|
public WifiTetherDisablePreferenceController(Context context, String prefKey) {
|
||||||
@@ -52,48 +49,57 @@ public final class WifiTetherDisablePreferenceController extends TetherBasePrefe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return !mWifiTethering;
|
return !super.isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
if (mTetherEnabler == null) {
|
return super.setChecked(!isChecked);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isChecked) {
|
|
||||||
mTetherEnabler.stopTethering(TetheringManager.TETHERING_WIFI);
|
|
||||||
} else {
|
|
||||||
mTetherEnabler.startTethering(TetheringManager.TETHERING_WIFI);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
private int getTetheringStateOfOtherInterfaces() {
|
||||||
boolean shouldShow() {
|
return mTetheringState & (~TETHERING_WIFI_ON);
|
||||||
return mBluetoothTethering || mUsbTethering;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public boolean shouldEnable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldShow() {
|
||||||
final String[] wifiRegexs = mCm.getTetherableWifiRegexs();
|
final String[] wifiRegexs = mCm.getTetherableWifiRegexs();
|
||||||
if (wifiRegexs == null || wifiRegexs.length == 0 || !shouldShow()
|
return wifiRegexs != null && wifiRegexs.length != 0 && !Utils.isMonkeyRunning()
|
||||||
|| !TetherUtil.isTetherAvailable(mContext)) {
|
&& getTetheringStateOfOtherInterfaces() != TetherEnabler.TETHERING_OFF;
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
}
|
||||||
} else {
|
|
||||||
return AVAILABLE;
|
@Override
|
||||||
}
|
public int getTetherType() {
|
||||||
|
return ConnectivityManager.TETHERING_WIFI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (mUsbTethering && mBluetoothTethering) {
|
switch (getTetheringStateOfOtherInterfaces()) {
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
|
case TETHERING_USB_ON:
|
||||||
} 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);
|
case TETHERING_BLUETOOTH_ON:
|
||||||
} 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);
|
case TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(R.string.disable_wifi_hotspot_when_ethernet_on);
|
||||||
|
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
|
||||||
|
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
|
||||||
|
case TETHERING_USB_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_ethernet_on);
|
||||||
|
case TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on);
|
||||||
|
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on);
|
||||||
|
default:
|
||||||
|
return mContext.getString(R.string.summary_placeholder);
|
||||||
}
|
}
|
||||||
return mContext.getString(R.string.summary_placeholder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,15 +114,7 @@ public final class WifiTetherDisablePreferenceController extends TetherBasePrefe
|
|||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
setVisible(mScreen, mPreferenceKey, shouldShow());
|
preference.setVisible(isAvailable());
|
||||||
refreshSummary(preference);
|
refreshSummary(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTetherStateUpdated(int state) {
|
|
||||||
mUsbTethering = TetherEnabler.isUsbTethering(state);
|
|
||||||
mBluetoothTethering = TetherEnabler.isBluetoothTethering(state);
|
|
||||||
mWifiTethering = TetherEnabler.isWifiTethering(state);
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,25 +44,25 @@ public class DataUsagePreferenceController extends TelephonyBasePreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus(int subId) {
|
public int getAvailabilityStatus(int subId) {
|
||||||
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
return (SubscriptionManager.isValidSubscriptionId(subId))
|
||||||
? AVAILABLE
|
? AVAILABLE
|
||||||
: AVAILABLE_UNSEARCHABLE;
|
: AVAILABLE_UNSEARCHABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
mContext.startActivity(mIntent);
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
mContext.startActivity(mIntent);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
|
||||||
preference.setEnabled(false);
|
preference.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import android.graphics.drawable.ColorDrawable;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telecom.PhoneAccountHandle;
|
import android.telecom.PhoneAccountHandle;
|
||||||
@@ -70,9 +71,12 @@ import com.android.settings.core.BasePreferenceController;
|
|||||||
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
|
||||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||||
import com.android.settingslib.graph.SignalDrawable;
|
import com.android.settingslib.graph.SignalDrawable;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class MobileNetworkUtils {
|
public class MobileNetworkUtils {
|
||||||
|
|
||||||
@@ -242,6 +246,18 @@ public class MobileNetworkUtils {
|
|||||||
* the user has enabled development mode.
|
* the user has enabled development mode.
|
||||||
*/
|
*/
|
||||||
public static boolean showEuiccSettings(Context context) {
|
public static boolean showEuiccSettings(Context context) {
|
||||||
|
long timeForAccess = SystemClock.elapsedRealtime();
|
||||||
|
try {
|
||||||
|
return ((Future<Boolean>) ThreadUtils.postOnBackgroundThread(()
|
||||||
|
-> showEuiccSettingsDetecting(context))).get();
|
||||||
|
} catch (ExecutionException | InterruptedException exception) {
|
||||||
|
timeForAccess = SystemClock.elapsedRealtime() - timeForAccess;
|
||||||
|
Log.w(TAG, "Accessing Euicc takes too long: +" + timeForAccess + "ms");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean showEuiccSettingsDetecting(Context context) {
|
||||||
final EuiccManager euiccManager =
|
final EuiccManager euiccManager =
|
||||||
(EuiccManager) context.getSystemService(EuiccManager.class);
|
(EuiccManager) context.getSystemService(EuiccManager.class);
|
||||||
if (!euiccManager.isEnabled()) {
|
if (!euiccManager.isEnabled()) {
|
||||||
|
|||||||
@@ -17,10 +17,17 @@
|
|||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.utils.AnnotationSpan;
|
||||||
|
import com.android.settingslib.HelpUtils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to show the footer that can't connect to 5G when device is in DSDS mode.
|
* Class to show the footer that can't connect to 5G when device is in DSDS mode.
|
||||||
@@ -43,6 +50,29 @@ public class NrDisabledInDsdsFooterPreferenceController extends BasePreferenceCo
|
|||||||
mSubId = subId;
|
mSubId = subId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
if (preference != null) {
|
||||||
|
preference.setTitle(getFooterText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CharSequence getFooterText() {
|
||||||
|
final Intent helpIntent = HelpUtils.getHelpIntent(mContext,
|
||||||
|
mContext.getString(R.string.help_uri_5g_dsds),
|
||||||
|
mContext.getClass().getName());
|
||||||
|
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(mContext,
|
||||||
|
"url", helpIntent);
|
||||||
|
|
||||||
|
if (linkInfo.isActionable()) {
|
||||||
|
return AnnotationSpan.linkify(mContext.getText(R.string.no_5g_in_dsds_text), linkInfo);
|
||||||
|
} else {
|
||||||
|
return mContext.getText(R.string.no_5g_in_dsds_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package com.android.settings.notification.history;
|
|||||||
|
|
||||||
import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED;
|
import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED;
|
||||||
|
|
||||||
|
import static androidx.core.view.accessibility.AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.INotificationManager;
|
import android.app.INotificationManager;
|
||||||
@@ -89,15 +91,15 @@ public class NotificationHistoryActivity extends Activity {
|
|||||||
? getString(R.string.condition_expand_hide)
|
? getString(R.string.condition_expand_hide)
|
||||||
: getString(R.string.condition_expand_show));
|
: getString(R.string.condition_expand_show));
|
||||||
expand.setOnClickListener(v -> {
|
expand.setOnClickListener(v -> {
|
||||||
container.setVisibility(container.getVisibility() == View.VISIBLE
|
container.setVisibility(container.getVisibility() == View.VISIBLE
|
||||||
? View.GONE : View.VISIBLE);
|
? View.GONE : View.VISIBLE);
|
||||||
expand.setImageResource(container.getVisibility() == View.VISIBLE
|
expand.setImageResource(container.getVisibility() == View.VISIBLE
|
||||||
? R.drawable.ic_expand_less
|
? R.drawable.ic_expand_less
|
||||||
: com.android.internal.R.drawable.ic_expand_more);
|
: com.android.internal.R.drawable.ic_expand_more);
|
||||||
expand.setContentDescription(container.getVisibility() == View.VISIBLE
|
expand.setContentDescription(container.getVisibility() == View.VISIBLE
|
||||||
? getString(R.string.condition_expand_hide)
|
? getString(R.string.condition_expand_hide)
|
||||||
: getString(R.string.condition_expand_show));
|
: getString(R.string.condition_expand_show));
|
||||||
expand.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
|
expand.sendAccessibilityEvent(TYPE_VIEW_ACCESSIBILITY_FOCUSED);
|
||||||
});
|
});
|
||||||
|
|
||||||
TextView label = viewForPackage.findViewById(R.id.label);
|
TextView label = viewForPackage.findViewById(R.id.label);
|
||||||
@@ -109,7 +111,7 @@ public class NotificationHistoryActivity extends Activity {
|
|||||||
count.setText(getResources().getQuantityString(R.plurals.notification_history_count,
|
count.setText(getResources().getQuantityString(R.plurals.notification_history_count,
|
||||||
nhp.notifications.size(), nhp.notifications.size()));
|
nhp.notifications.size(), nhp.notifications.size()));
|
||||||
|
|
||||||
NotificationHistoryRecyclerView rv =
|
final NotificationHistoryRecyclerView rv =
|
||||||
viewForPackage.findViewById(R.id.notification_list);
|
viewForPackage.findViewById(R.id.notification_list);
|
||||||
rv.setAdapter(new NotificationHistoryAdapter(mNm, rv));
|
rv.setAdapter(new NotificationHistoryAdapter(mNm, rv));
|
||||||
((NotificationHistoryAdapter) rv.getAdapter()).onRebuildComplete(
|
((NotificationHistoryAdapter) rv.getAdapter()).onRebuildComplete(
|
||||||
|
|||||||
@@ -91,11 +91,12 @@ public class NotificationHistoryAdapter extends
|
|||||||
new AccessibilityNodeInfo.AccessibilityAction(
|
new AccessibilityNodeInfo.AccessibilityAction(
|
||||||
AccessibilityNodeInfo.ACTION_CLICK, description);
|
AccessibilityNodeInfo.ACTION_CLICK, description);
|
||||||
info.addAction(customClick);
|
info.addAction(customClick);
|
||||||
//info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
|
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performAccessibilityAction(View host, int action, Bundle args) {
|
public boolean performAccessibilityAction(View host, int action, Bundle args) {
|
||||||
|
super.performAccessibilityAction(host, action, args);
|
||||||
if (action == AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS.getId()) {
|
if (action == AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS.getId()) {
|
||||||
onItemSwipeDeleted(position);
|
onItemSwipeDeleted(position);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ public class MediaOutputPanel implements PanelContent, LocalMediaManager.DeviceC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getCustomizedButtonTitle() {
|
public CharSequence getCustomizedButtonTitle() {
|
||||||
return mContext.getText(R.string.media_output_panel_stop_casting_button);
|
return mContext.getText(R.string.service_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import android.net.NetworkInfo;
|
|||||||
import android.net.wifi.SupplicantState;
|
import android.net.wifi.SupplicantState;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -35,8 +33,6 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.SwitchWidgetController;
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
|
||||||
import com.android.settingslib.WirelessUtils;
|
import com.android.settingslib.WirelessUtils;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
@@ -76,9 +72,6 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String EVENT_DATA_IS_WIFI_ON = "is_wifi_on";
|
|
||||||
private static final int EVENT_UPDATE_INDEX = 0;
|
|
||||||
|
|
||||||
public WifiEnabler(Context context, SwitchWidgetController switchWidget,
|
public WifiEnabler(Context context, SwitchWidgetController switchWidget,
|
||||||
MetricsFeatureProvider metricsFeatureProvider) {
|
MetricsFeatureProvider metricsFeatureProvider) {
|
||||||
this(context, switchWidget, metricsFeatureProvider,
|
this(context, switchWidget, metricsFeatureProvider,
|
||||||
@@ -161,15 +154,6 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
|||||||
setSwitchBarChecked(false);
|
setSwitchBarChecked(false);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
|
||||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
|
||||||
mSwitchWidget.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
|
|
||||||
mContext, UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
|
||||||
mSwitchWidget.setDisabledByAdmin(admin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSwitchBarChecked(boolean checked) {
|
private void setSwitchBarChecked(boolean checked) {
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
// "forget" for normal saved network. And "disconnect" for ephemeral network because it
|
// "forget" for normal saved network. And "disconnect" for ephemeral network because it
|
||||||
// could only be disconnected and be put in blacklists so it won't be used again.
|
// could only be disconnected and be put in blacklists so it won't be used again.
|
||||||
if (mSelectedWifiEntry.canForget()) {
|
if (canForgetNetwork()) {
|
||||||
menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
|
menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,6 +507,11 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canForgetNetwork() {
|
||||||
|
return mSelectedWifiEntry.canForget() && !WifiUtils.isNetworkLockedDown(getActivity(),
|
||||||
|
mSelectedWifiEntry.getWifiConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
@@ -539,9 +544,11 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
final WifiEntry selectedEntry =
|
final WifiEntry selectedEntry =
|
||||||
((LongPressWifiEntryPreference) preference).getWifiEntry();
|
((LongPressWifiEntryPreference) preference).getWifiEntry();
|
||||||
|
|
||||||
if (selectedEntry.getWifiConfiguration() != null) {
|
// If the clicked WiFi entry is never connected, launch Wi-Fi edit UI to edit password.
|
||||||
if (!selectedEntry.getWifiConfiguration().getNetworkSelectionStatus()
|
if (selectedEntry.getSecurity() != WifiEntry.SECURITY_NONE
|
||||||
.hasEverConnected()) {
|
&& selectedEntry.getSecurity() != WifiEntry.SECURITY_OWE) {
|
||||||
|
final WifiConfiguration config = selectedEntry.getWifiConfiguration();
|
||||||
|
if (config != null && !config.getNetworkSelectionStatus().hasEverConnected()) {
|
||||||
launchConfigNewNetworkFragment(selectedEntry);
|
launchConfigNewNetworkFragment(selectedEntry);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ import android.content.pm.PackageManager;
|
|||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.settings.Utils;
|
||||||
import com.android.settingslib.wifi.AccessPoint;
|
import com.android.settingslib.wifi.AccessPoint;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -77,6 +80,7 @@ public class WifiUtils {
|
|||||||
final DevicePolicyManager dpm =
|
final DevicePolicyManager dpm =
|
||||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
final PackageManager pm = context.getPackageManager();
|
final PackageManager pm = context.getPackageManager();
|
||||||
|
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
|
|
||||||
// Check if device has DPM capability. If it has and dpm is still null, then we
|
// Check if device has DPM capability. If it has and dpm is still null, then we
|
||||||
// treat this case with suspicion and bail out.
|
// treat this case with suspicion and bail out.
|
||||||
@@ -96,6 +100,18 @@ public class WifiUtils {
|
|||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
// don't care
|
// don't care
|
||||||
}
|
}
|
||||||
|
} else if (dpm.isOrganizationOwnedDeviceWithManagedProfile()) {
|
||||||
|
int profileOwnerUserId = Utils.getManagedProfileId(um, UserHandle.myUserId());
|
||||||
|
final ComponentName profileOwner = dpm.getProfileOwnerAsUser(profileOwnerUserId);
|
||||||
|
if (profileOwner != null) {
|
||||||
|
try {
|
||||||
|
final int profileOwnerUid = pm.getPackageUidAsUser(
|
||||||
|
profileOwner.getPackageName(), profileOwnerUserId);
|
||||||
|
isConfigEligibleForLockdown = profileOwnerUid == config.creatorUid;
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
// don't care
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isConfigEligibleForLockdown) {
|
if (!isConfigEligibleForLockdown) {
|
||||||
|
|||||||
@@ -660,7 +660,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refreshButtons() {
|
private void refreshButtons() {
|
||||||
final boolean canForgetNetwork = mWifiEntry.canForget();
|
final boolean canForgetNetwork = canForgetNetwork();
|
||||||
final boolean showCaptivePortalButton = updateCaptivePortalButton();
|
final boolean showCaptivePortalButton = updateCaptivePortalButton();
|
||||||
final boolean canConnectDisconnectNetwork = mWifiEntry.canConnect()
|
final boolean canConnectDisconnectNetwork = mWifiEntry.canConnect()
|
||||||
|| mWifiEntry.canDisconnect();
|
|| mWifiEntry.canDisconnect();
|
||||||
@@ -787,6 +787,14 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
|
|||||||
&& !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration());
|
&& !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the network represented by this preference can be forgotten.
|
||||||
|
*/
|
||||||
|
public boolean canForgetNetwork() {
|
||||||
|
return mWifiEntry.canForget()
|
||||||
|
&& !WifiUtils.isNetworkLockedDown(mContext, mWifiEntry.getWifiConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the user can sign into the network represented by this preference.
|
* Returns whether the user can sign into the network represented by this preference.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.android.settings.wifi.details2;
|
|||||||
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
|
import static com.android.settings.wifi.WifiSettings.WIFI_DIALOG_ID;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
@@ -29,6 +30,8 @@ import android.os.Looper;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.SimpleClock;
|
import android.os.SimpleClock;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -36,10 +39,12 @@ import android.view.MenuItem;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.wifi.WifiConfigUiBase2;
|
import com.android.settings.wifi.WifiConfigUiBase2;
|
||||||
import com.android.settings.wifi.WifiDialog2;
|
import com.android.settings.wifi.WifiDialog2;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.wifitrackerlib.NetworkDetailsTracker;
|
import com.android.wifitrackerlib.NetworkDetailsTracker;
|
||||||
@@ -129,8 +134,18 @@ public class WifiNetworkDetailsFragment2 extends DashboardFragment implements
|
|||||||
switch (menuItem.getItemId()) {
|
switch (menuItem.getItemId()) {
|
||||||
case Menu.FIRST:
|
case Menu.FIRST:
|
||||||
if (!mWifiDetailPreferenceController2.canModifyNetwork()) {
|
if (!mWifiDetailPreferenceController2.canModifyNetwork()) {
|
||||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
|
EnforcedAdmin admin = RestrictedLockUtilsInternal.getDeviceOwner(getContext());
|
||||||
RestrictedLockUtilsInternal.getDeviceOwner(getContext()));
|
if (admin == null) {
|
||||||
|
final DevicePolicyManager dpm = (DevicePolicyManager)
|
||||||
|
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
final UserManager um = (UserManager)
|
||||||
|
getContext().getSystemService(Context.USER_SERVICE);
|
||||||
|
int profileOwnerUserId = Utils.getManagedProfileId(
|
||||||
|
um, UserHandle.myUserId());
|
||||||
|
admin = new EnforcedAdmin(dpm.getProfileOwnerAsUser(profileOwnerUserId),
|
||||||
|
null, UserHandle.of(profileOwnerUserId));
|
||||||
|
}
|
||||||
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), admin);
|
||||||
} else {
|
} else {
|
||||||
showDialog(WIFI_DIALOG_ID);
|
showDialog(WIFI_DIALOG_ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import static com.android.settings.AllInOneTetherSettings.BLUETOOTH_TETHER_KEY;
|
||||||
|
import static com.android.settings.AllInOneTetherSettings.ETHERNET_TETHER_KEY;
|
||||||
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_DEFAULT;
|
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_DEFAULT;
|
||||||
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG;
|
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_MAX;
|
||||||
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITH_SECURITY_NON;
|
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITH_SECURITY_NON;
|
||||||
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
|
import static com.android.settings.AllInOneTetherSettings.USB_TETHER_KEY;
|
||||||
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
|
import static com.android.settings.AllInOneTetherSettings.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;
|
||||||
|
|
||||||
@@ -37,6 +38,9 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceGroup;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.FeatureFlags;
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
import com.android.settings.testutils.shadow.ShadowWifiManager;
|
||||||
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
|
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
|
||||||
@@ -62,6 +66,7 @@ public class AllInOneTetherSettingsTest {
|
|||||||
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
|
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
|
||||||
private static final String[] USB_REGEXS = {"usb_regexs"};
|
private static final String[] USB_REGEXS = {"usb_regexs"};
|
||||||
private static final String[] BT_REGEXS = {"bt_regexs"};
|
private static final String[] BT_REGEXS = {"bt_regexs"};
|
||||||
|
private static final String[] ETHERNET_REGEXS = {"ethernet_regexs"};
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private AllInOneTetherSettings mAllInOneTetherSettings;
|
private AllInOneTetherSettings mAllInOneTetherSettings;
|
||||||
@@ -72,6 +77,10 @@ public class AllInOneTetherSettingsTest {
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
@Mock
|
@Mock
|
||||||
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
@Mock
|
||||||
|
private PreferenceGroup mWifiTetherGroup;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -83,14 +92,16 @@ public class AllInOneTetherSettingsTest {
|
|||||||
doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
|
doReturn(WIFI_REGEXS).when(mConnectivityManager).getTetherableWifiRegexs();
|
||||||
doReturn(USB_REGEXS).when(mConnectivityManager).getTetherableUsbRegexs();
|
doReturn(USB_REGEXS).when(mConnectivityManager).getTetherableUsbRegexs();
|
||||||
doReturn(BT_REGEXS).when(mConnectivityManager).getTetherableBluetoothRegexs();
|
doReturn(BT_REGEXS).when(mConnectivityManager).getTetherableBluetoothRegexs();
|
||||||
|
doReturn(ETHERNET_REGEXS).when(mConnectivityManager).getTetherableIfaces();
|
||||||
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
||||||
// Assume the feature is enabled for most test cases.
|
// Assume the feature is enabled for most test cases.
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
|
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
|
||||||
|
mAllInOneTetherSettings = spy(new AllInOneTetherSettings());
|
||||||
mAllInOneTetherSettings = new AllInOneTetherSettings();
|
doReturn(mPreferenceScreen).when(mAllInOneTetherSettings).getPreferenceScreen();
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mLifecycle", mock(Lifecycle.class));
|
ReflectionHelpers.setField(mAllInOneTetherSettings, "mLifecycle", mock(Lifecycle.class));
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mSecurityPreferenceController",
|
ReflectionHelpers.setField(mAllInOneTetherSettings, "mSecurityPreferenceController",
|
||||||
mSecurityPreferenceController);
|
mSecurityPreferenceController);
|
||||||
|
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTetherGroup", mWifiTetherGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -110,6 +121,7 @@ public class AllInOneTetherSettingsTest {
|
|||||||
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
||||||
assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
|
assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
|
||||||
assertThat(niks).doesNotContain(USB_TETHER_KEY);
|
assertThat(niks).doesNotContain(USB_TETHER_KEY);
|
||||||
|
assertThat(niks).doesNotContain(ETHERNET_TETHER_KEY);
|
||||||
|
|
||||||
// This key should be returned because it's not visible by default.
|
// This key should be returned because it's not visible by default.
|
||||||
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
||||||
@@ -131,6 +143,7 @@ public class AllInOneTetherSettingsTest {
|
|||||||
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
||||||
assertThat(niks).contains(BLUETOOTH_TETHER_KEY);
|
assertThat(niks).contains(BLUETOOTH_TETHER_KEY);
|
||||||
assertThat(niks).contains(USB_TETHER_KEY);
|
assertThat(niks).contains(USB_TETHER_KEY);
|
||||||
|
assertThat(niks).contains(ETHERNET_TETHER_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -149,6 +162,7 @@ public class AllInOneTetherSettingsTest {
|
|||||||
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
||||||
assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
|
assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
|
||||||
assertThat(niks).doesNotContain(USB_TETHER_KEY);
|
assertThat(niks).doesNotContain(USB_TETHER_KEY);
|
||||||
|
assertThat(niks).doesNotContain(ETHERNET_TETHER_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -167,29 +181,31 @@ public class AllInOneTetherSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInitialExpandedChildCount_shouldShowWifiConfigWithSecurity() {
|
public void getInitialChildCount_withSecurity() {
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTethering", true);
|
|
||||||
when(mSecurityPreferenceController.getSecurityType())
|
when(mSecurityPreferenceController.getSecurityType())
|
||||||
.thenReturn(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
.thenReturn(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount()).isEqualTo(
|
||||||
.isEqualTo(EXPANDED_CHILD_COUNT_DEFAULT);
|
EXPANDED_CHILD_COUNT_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInitialExpandedChildCount_shouldShowWifiConfigWithoutSecurity() {
|
public void getInitialChildCount_withoutSecurity() {
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTethering", true);
|
|
||||||
when(mSecurityPreferenceController.getSecurityType())
|
when(mSecurityPreferenceController.getSecurityType())
|
||||||
.thenReturn(SoftApConfiguration.SECURITY_TYPE_OPEN);
|
.thenReturn(SoftApConfiguration.SECURITY_TYPE_OPEN);
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount()).isEqualTo(
|
||||||
.isEqualTo(EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
|
EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInitialExpandedChildCount_shouldNotShowWifiConfig() {
|
public void getInitialExpandedChildCount_expandAllChild() {
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTethering", false);
|
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mBluetoothTethering", true);
|
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
||||||
.isEqualTo(EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG);
|
.isNotEqualTo(EXPANDED_CHILD_COUNT_MAX);
|
||||||
|
ReflectionHelpers.setField(mAllInOneTetherSettings, "mShouldShowWifiConfig", false);
|
||||||
|
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
||||||
|
.isEqualTo(EXPANDED_CHILD_COUNT_MAX);
|
||||||
|
ReflectionHelpers.setField(mAllInOneTetherSettings, "mShouldShowWifiConfig", true);
|
||||||
|
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
||||||
|
.isEqualTo(EXPANDED_CHILD_COUNT_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupIsTetherAvailable(boolean returnValue) {
|
private void setupIsTetherAvailable(boolean returnValue) {
|
||||||
|
|||||||
@@ -214,17 +214,6 @@ public class AccessibilitySettingsTest {
|
|||||||
assertThat(description).isEqualTo(DEFAULT_DESCRIPTION);
|
assertThat(description).isEqualTo(DEFAULT_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getServiceDescription_noDescription_showsDefaultString() {
|
|
||||||
doReturn(EMPTY_STRING).when(mServiceInfo).loadDescription(any());
|
|
||||||
|
|
||||||
final CharSequence description = AccessibilitySettings.getServiceDescription(mContext,
|
|
||||||
mServiceInfo, SERVICE_ENABLED);
|
|
||||||
|
|
||||||
assertThat(description).isEqualTo(
|
|
||||||
mContext.getString(R.string.accessibility_service_default_description));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createAccessibilityServicePreferenceList_hasOneInfo_containsSameKey() {
|
public void createAccessibilityServicePreferenceList_hasOneInfo_containsSameKey() {
|
||||||
final String key = DUMMY_COMPONENT_NAME.flattenToString();
|
final String key = DUMMY_COMPONENT_NAME.flattenToString();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import androidx.preference.Preference;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
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.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
@@ -35,6 +36,7 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Ignore
|
||||||
public class PaymentSettingsEnablerTest {
|
public class PaymentSettingsEnablerTest {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.nfc.NfcAdapter;
|
|||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
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;
|
||||||
@@ -62,6 +63,7 @@ public class NfcAndPaymentFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void searchIndexProvider_shouldIndexAllItems() {
|
public void searchIndexProvider_shouldIndexAllItems() {
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
|
when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import androidx.preference.PreferenceViewHolder;
|
|||||||
import com.android.settings.network.ProxySubscriptionManager;
|
import com.android.settings.network.ProxySubscriptionManager;
|
||||||
|
|
||||||
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;
|
||||||
@@ -39,6 +40,7 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Ignore
|
||||||
public class CellDataPreferenceTest {
|
public class CellDataPreferenceTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
|||||||
@@ -34,8 +34,11 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.SubscriptionPlan;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.util.RecurrenceRule;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
@@ -52,6 +55,7 @@ import com.android.settingslib.net.DataUsageController;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
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;
|
||||||
@@ -63,6 +67,10 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -86,7 +94,9 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private NetworkTemplate mNetworkTemplate;
|
private NetworkTemplate mNetworkTemplate;
|
||||||
@Mock
|
@Mock
|
||||||
private SubscriptionManager mSubscriptionManager;
|
private SubscriptionInfo mSubscriptionInfo;
|
||||||
|
@Mock
|
||||||
|
private SubscriptionPlan mSubscriptionPlan;
|
||||||
@Mock
|
@Mock
|
||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
@@ -105,6 +115,7 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private DataUsageSummaryPreferenceController mController;
|
private DataUsageSummaryPreferenceController mController;
|
||||||
private int mDefaultSubscriptionId;
|
private int mDefaultSubscriptionId;
|
||||||
|
private List<SubscriptionPlan> mSubscriptionPlans;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -112,30 +123,45 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
|
||||||
doReturn("%1$s %2%s").when(mContext)
|
doReturn("%1$s %2%s").when(mContext)
|
||||||
.getString(com.android.internal.R.string.fileSizeSuffix);
|
.getString(com.android.internal.R.string.fileSizeSuffix);
|
||||||
|
|
||||||
|
mDefaultSubscriptionId = 1234;
|
||||||
|
mSubscriptionPlans = new ArrayList<SubscriptionPlan>();
|
||||||
|
|
||||||
mFactory = FakeFeatureFactory.setupForTest();
|
mFactory = FakeFeatureFactory.setupForTest();
|
||||||
when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
|
when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
|
||||||
.thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
|
.thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
|
||||||
ShadowEntityHeaderController.setUseMock(mHeaderController);
|
ShadowEntityHeaderController.setUseMock(mHeaderController);
|
||||||
mDataInfoController = new DataUsageInfoController();
|
|
||||||
|
mDataInfoController = spy(new DataUsageInfoController());
|
||||||
|
doReturn(-1L).when(mDataInfoController).getSummaryLimit(any());
|
||||||
|
|
||||||
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
|
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
|
||||||
when(mActivity.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
doReturn(mTelephonyManager).when(mActivity).getSystemService(TelephonyManager.class);
|
||||||
|
doReturn(mTelephonyManager).when(mTelephonyManager)
|
||||||
|
.createForSubscriptionId(mDefaultSubscriptionId);
|
||||||
when(mActivity.getSystemService(Context.CONNECTIVITY_SERVICE))
|
when(mActivity.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||||
.thenReturn(mConnectivityManager);
|
.thenReturn(mConnectivityManager);
|
||||||
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
|
doReturn(TelephonyManager.SIM_STATE_READY).when(mTelephonyManager).getSimState();
|
||||||
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(false);
|
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(false);
|
||||||
mDefaultSubscriptionId = 1234;
|
|
||||||
mController = new DataUsageSummaryPreferenceController(
|
mController = spy(new DataUsageSummaryPreferenceController(
|
||||||
mDataUsageController,
|
mDataUsageController,
|
||||||
mDataInfoController,
|
mDataInfoController,
|
||||||
mNetworkTemplate,
|
mNetworkTemplate,
|
||||||
mPolicyEditor,
|
mPolicyEditor,
|
||||||
R.string.cell_data_template,
|
R.string.cell_data_template,
|
||||||
true,
|
mActivity, null, null, null, mDefaultSubscriptionId));
|
||||||
null,
|
doReturn(null).when(mController).getSubscriptionInfo(
|
||||||
mActivity, null, null, null, mDefaultSubscriptionId);
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
|
doReturn(null).when(mController).getSubscriptionPlans(
|
||||||
|
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
|
|
||||||
|
doReturn(CARRIER_NAME).when(mSubscriptionInfo).getCarrierName();
|
||||||
|
doReturn(mSubscriptionInfo).when(mController).getSubscriptionInfo(mDefaultSubscriptionId);
|
||||||
|
doReturn(mSubscriptionPlans).when(mController).getSubscriptionPlans(mDefaultSubscriptionId);
|
||||||
|
|
||||||
|
doReturn(true).when(mController).hasSim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -144,15 +170,17 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_onePlan_basic() {
|
public void testSummaryUpdate_onePlan_basic() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(1 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
createTestDataPlan(info.cycleStart, info.cycleEnd);
|
||||||
|
doReturn(intent).when(mController).createManageSubscriptionIntent(mDefaultSubscriptionId);
|
||||||
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
@@ -161,7 +189,8 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
CharSequence value = captor.getValue();
|
CharSequence value = captor.getValue();
|
||||||
assertThat(value.toString()).isEqualTo("512 MB data warning / 1.00 GB data limit");
|
assertThat(value.toString()).isEqualTo("512 MB data warning / 1.00 GB data limit");
|
||||||
|
|
||||||
verify(mSummaryPreference).setUsageInfo(info.cycleEnd, now - UPDATE_BACKOFF_MS,
|
verify(mSummaryPreference).setUsageInfo((info.cycleEnd / 1000) * 1000,
|
||||||
|
now - UPDATE_BACKOFF_MS,
|
||||||
CARRIER_NAME, 1 /* numPlans */, intent);
|
CARRIER_NAME, 1 /* numPlans */, intent);
|
||||||
verify(mSummaryPreference).setChartEnabled(true);
|
verify(mSummaryPreference).setChartEnabled(true);
|
||||||
verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
|
verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
|
||||||
@@ -169,15 +198,15 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_noPlan_basic() {
|
public void testSummaryUpdate_noPlan_basic() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
|
||||||
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
@@ -186,22 +215,27 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
CharSequence value = captor.getValue();
|
CharSequence value = captor.getValue();
|
||||||
assertThat(value.toString()).isEqualTo("512 MB data warning / 1.00 GB data limit");
|
assertThat(value.toString()).isEqualTo("512 MB data warning / 1.00 GB data limit");
|
||||||
|
|
||||||
verify(mSummaryPreference).setUsageInfo(info.cycleEnd, now - UPDATE_BACKOFF_MS,
|
verify(mSummaryPreference).setUsageInfo(
|
||||||
CARRIER_NAME, 0 /* numPlans */, intent);
|
info.cycleEnd,
|
||||||
|
-1L /* snapshotTime */,
|
||||||
|
CARRIER_NAME,
|
||||||
|
0 /* numPlans */,
|
||||||
|
null /* launchIntent */);
|
||||||
verify(mSummaryPreference).setChartEnabled(true);
|
verify(mSummaryPreference).setChartEnabled(true);
|
||||||
verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
|
verify(mSummaryPreference).setWifiMode(false /* isWifiMode */, null /* usagePeriod */,
|
||||||
false /* isSingleWifi */);
|
false /* isSingleWifi */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_noCarrier_basic() {
|
public void testSummaryUpdate_noCarrier_basic() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
doReturn(null).when(mSubscriptionInfo).getCarrierName();
|
||||||
mController.setCarrierValues(null /* carrierName */, -1L /* snapshotTime */,
|
setupTestDataUsage(LIMIT1, USAGE1, -1L /* snapshotTime */);
|
||||||
info.cycleEnd, null /* intent */);
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||||
@@ -221,15 +255,16 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_noPlanData_basic() {
|
public void testSummaryUpdate_noPlanData_basic() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
|
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, -1L /* dataPlanSize */, USAGE1);
|
doReturn(null).when(mSubscriptionInfo).getCarrierName();
|
||||||
mController.setCarrierValues(null /* carrierName */, -1L /* snapshotTime */,
|
setupTestDataUsage(-1L /* dataPlanSize */, USAGE1, -1L /* snapshotTime */);
|
||||||
info.cycleEnd, null /* intent */);
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||||
@@ -248,6 +283,7 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_noLimitNoWarning() {
|
public void testSummaryUpdate_noLimitNoWarning() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
@@ -256,15 +292,15 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
|
||||||
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
verify(mSummaryPreference).setLimitInfo(null);
|
verify(mSummaryPreference).setLimitInfo(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_warningOnly() {
|
public void testSummaryUpdate_warningOnly() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
@@ -273,9 +309,8 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
|
||||||
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
@@ -286,6 +321,7 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_limitOnly() {
|
public void testSummaryUpdate_limitOnly() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
@@ -294,9 +330,8 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
|
||||||
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
@@ -307,6 +342,7 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_limitAndWarning() {
|
public void testSummaryUpdate_limitAndWarning() {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
@@ -315,9 +351,8 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
|
||||||
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
@@ -330,7 +365,13 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testSummaryUpdate_noSim_shouldSetWifiMode() {
|
public void testSummaryUpdate_noSim_shouldSetWifiMode() {
|
||||||
|
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||||
|
mController.mDataUsageController = mDataUsageController;
|
||||||
|
doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephonyManager).getSimState();
|
||||||
|
doReturn(false).when(mController).hasSim();
|
||||||
|
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
final DataUsageController.DataUsageInfo info = createTestDataUsageInfo(now);
|
||||||
info.warningLevel = BillingCycleSettings.MIB_IN_BYTES;
|
info.warningLevel = BillingCycleSettings.MIB_IN_BYTES;
|
||||||
@@ -338,11 +379,9 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
|
||||||
when(mDataUsageController.getDataUsageInfo(any())).thenReturn(info);
|
doReturn(info).when(mDataUsageController).getDataUsageInfo(any());
|
||||||
mController.setPlanValues(0 /* dataPlanCount */, LIMIT1, USAGE1);
|
setupTestDataUsage(LIMIT1, USAGE1, now - UPDATE_BACKOFF_MS);
|
||||||
mController.setCarrierValues(CARRIER_NAME, now - UPDATE_BACKOFF_MS, info.cycleEnd, intent);
|
|
||||||
|
|
||||||
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
|
|
||||||
mController.updateState(mSummaryPreference);
|
mController.updateState(mSummaryPreference);
|
||||||
|
|
||||||
verify(mSummaryPreference).setWifiMode(true /* isWifiMode */, info.period /* usagePeriod */,
|
verify(mSummaryPreference).setWifiMode(true /* isWifiMode */, info.period /* usagePeriod */,
|
||||||
@@ -354,49 +393,31 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testMobileData_preferenceAvailable() {
|
public void testMobileData_preferenceAvailable() {
|
||||||
mController = new DataUsageSummaryPreferenceController(
|
|
||||||
mDataUsageController,
|
|
||||||
mDataInfoController,
|
|
||||||
mNetworkTemplate,
|
|
||||||
mPolicyEditor,
|
|
||||||
R.string.cell_data_template,
|
|
||||||
true,
|
|
||||||
mSubscriptionManager,
|
|
||||||
mActivity, null, null, null, mDefaultSubscriptionId);
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testMobileData_noSimNoWifi_preferenceDisabled() {
|
public void testMobileData_noSimNoWifi_preferenceDisabled() {
|
||||||
mController = new DataUsageSummaryPreferenceController(
|
final int subscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
mDataUsageController,
|
mController.init(subscriptionId);
|
||||||
mDataInfoController,
|
mController.mDataUsageController = mDataUsageController;
|
||||||
mNetworkTemplate,
|
doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephonyManager).getSimState();
|
||||||
mPolicyEditor,
|
doReturn(false).when(mController).hasSim();
|
||||||
R.string.cell_data_template,
|
|
||||||
true,
|
|
||||||
mSubscriptionManager,
|
|
||||||
mActivity, null, null, null, mDefaultSubscriptionId);
|
|
||||||
|
|
||||||
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
|
|
||||||
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(false);
|
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(false);
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testMobileData_noSimWifi_preferenceDisabled() {
|
public void testMobileData_noSimWifi_preferenceDisabled() {
|
||||||
mController = new DataUsageSummaryPreferenceController(
|
final int subscriptionId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
mDataUsageController,
|
mController.init(subscriptionId);
|
||||||
mDataInfoController,
|
mController.mDataUsageController = mDataUsageController;
|
||||||
mNetworkTemplate,
|
doReturn(TelephonyManager.SIM_STATE_ABSENT).when(mTelephonyManager).getSimState();
|
||||||
mPolicyEditor,
|
|
||||||
R.string.cell_data_template,
|
|
||||||
true,
|
|
||||||
mSubscriptionManager,
|
|
||||||
mActivity, null, null, null, mDefaultSubscriptionId);
|
|
||||||
|
|
||||||
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
|
|
||||||
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(true);
|
when(mConnectivityManager.isNetworkSupported(TYPE_WIFI)).thenReturn(true);
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
}
|
}
|
||||||
@@ -405,16 +426,14 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
public void testMobileData_entityHeaderSet() {
|
public void testMobileData_entityHeaderSet() {
|
||||||
final RecyclerView recyclerView = new RecyclerView(mActivity);
|
final RecyclerView recyclerView = new RecyclerView(mActivity);
|
||||||
|
|
||||||
mController = new DataUsageSummaryPreferenceController(
|
mController = spy(new DataUsageSummaryPreferenceController(
|
||||||
mDataUsageController,
|
mDataUsageController,
|
||||||
mDataInfoController,
|
mDataInfoController,
|
||||||
mNetworkTemplate,
|
mNetworkTemplate,
|
||||||
mPolicyEditor,
|
mPolicyEditor,
|
||||||
R.string.cell_data_template,
|
R.string.cell_data_template,
|
||||||
true,
|
|
||||||
mSubscriptionManager,
|
|
||||||
mActivity, mLifecycle, mHeaderController, mPreferenceFragment,
|
mActivity, mLifecycle, mHeaderController, mPreferenceFragment,
|
||||||
mDefaultSubscriptionId);
|
mDefaultSubscriptionId));
|
||||||
|
|
||||||
when(mPreferenceFragment.getListView()).thenReturn(recyclerView);
|
when(mPreferenceFragment.getListView()).thenReturn(recyclerView);
|
||||||
|
|
||||||
@@ -437,4 +456,21 @@ public class DataUsageSummaryPreferenceControllerTest {
|
|||||||
info.cycleEnd = info.cycleStart + CYCLE_LENGTH_MS;
|
info.cycleEnd = info.cycleStart + CYCLE_LENGTH_MS;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupTestDataUsage(long dataPlanSize, long dataUsageSize, long snapshotTime) {
|
||||||
|
doReturn(dataPlanSize).when(mSubscriptionPlan).getDataLimitBytes();
|
||||||
|
doReturn(dataUsageSize).when(mSubscriptionPlan).getDataUsageBytes();
|
||||||
|
doReturn(snapshotTime).when(mSubscriptionPlan).getDataUsageTime();
|
||||||
|
|
||||||
|
doReturn(dataPlanSize).when(mDataInfoController).getSummaryLimit(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createTestDataPlan(long startTime, long endTime) {
|
||||||
|
final RecurrenceRule recurrenceRule = new RecurrenceRule(
|
||||||
|
Instant.ofEpochMilli(startTime).atZone(ZoneId.systemDefault()),
|
||||||
|
Instant.ofEpochMilli(endTime).atZone(ZoneId.systemDefault()),
|
||||||
|
null);
|
||||||
|
doReturn(recurrenceRule).when(mSubscriptionPlan).getCycleRule();
|
||||||
|
mSubscriptionPlans.add(mSubscriptionPlan);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ public class DataUsageSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void configuration_withoutSim_shouldShowWifiSectionOnly() {
|
public void configuration_withoutSim_shouldShowWifiSectionOnly() {
|
||||||
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||||
@@ -144,6 +145,7 @@ public class DataUsageSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void configuration_withoutMobile_shouldShowWifiSectionOnly() {
|
public void configuration_withoutMobile_shouldShowWifiSectionOnly() {
|
||||||
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = false;
|
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = false;
|
||||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||||
@@ -164,6 +166,7 @@ public class DataUsageSummaryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = ShadowSubscriptionManager.class)
|
@Config(shadows = ShadowSubscriptionManager.class)
|
||||||
|
@Ignore
|
||||||
public void configuration_invalidDataSusbscription_shouldShowWifiSectionOnly() {
|
public void configuration_invalidDataSusbscription_shouldShowWifiSectionOnly() {
|
||||||
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
ShadowDataUsageUtils.IS_MOBILE_DATA_SUPPORTED = true;
|
||||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.util.DataUnit;
|
import android.util.DataUnit;
|
||||||
|
|
||||||
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;
|
||||||
@@ -76,6 +77,7 @@ public final class DataUsageUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void hasSim_simStateReady() {
|
public void hasSim_simStateReady() {
|
||||||
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
|
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
|
||||||
final boolean hasSim = DataUsageUtils.hasSim(mContext);
|
final boolean hasSim = DataUsageUtils.hasSim(mContext);
|
||||||
@@ -83,6 +85,7 @@ public final class DataUsageUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void hasSim_simStateMissing() {
|
public void hasSim_simStateMissing() {
|
||||||
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
|
when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_ABSENT);
|
||||||
final boolean hasSim = DataUsageUtils.hasSim(mContext);
|
final boolean hasSim = DataUsageUtils.hasSim(mContext);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
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;
|
||||||
@@ -74,6 +75,7 @@ public class WifiEnhancedMacRandomizationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void updateState_preferenceShouldBeChecked() {
|
public void updateState_preferenceShouldBeChecked() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 1);
|
ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 1);
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.display.ColorDisplayManager;
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.provider.Settings.Secure;
|
|
||||||
|
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
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.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -64,6 +64,7 @@ public class NightDisplayAutoModePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void onPreferenceChange_changesAutoMode() {
|
public void onPreferenceChange_changesAutoMode() {
|
||||||
mController.onPreferenceChange(null,
|
mController.onPreferenceChange(null,
|
||||||
String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT));
|
String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT));
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
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;
|
||||||
@@ -102,6 +103,7 @@ public class DarkModeScheduleSelectorControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void nightMode_selectNightMode_locationOff() {
|
public void nightMode_selectNightMode_locationOff() {
|
||||||
when(mLocationManager.isLocationEnabled()).thenReturn(false);
|
when(mLocationManager.isLocationEnabled()).thenReturn(false);
|
||||||
mController.onPreferenceChange(mPreference,
|
mController.onPreferenceChange(mPreference,
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_GROUP
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -109,6 +110,7 @@ public class MediaOutputGroupSliceTest {
|
|||||||
when(sMediaDeviceUpdateWorker.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
when(sMediaDeviceUpdateWorker.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
||||||
mDrawable = mContext.getDrawable(R.drawable.ic_check_box_blue_24dp);
|
mDrawable = mContext.getDrawable(R.drawable.ic_check_box_blue_24dp);
|
||||||
when(sMediaDeviceUpdateWorker.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
when(sMediaDeviceUpdateWorker.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||||
|
doReturn(false).when(sMediaDeviceUpdateWorker).hasAdjustVolumeUserRestriction();
|
||||||
when(mDevice1.getId()).thenReturn(TEST_DEVICE_1_ID);
|
when(mDevice1.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||||
when(mDevice1.getIcon()).thenReturn(mDrawable);
|
when(mDevice1.getIcon()).thenReturn(mDrawable);
|
||||||
when(mDevice1.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
when(mDevice1.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -101,10 +102,11 @@ public class MediaOutputSliceTest {
|
|||||||
mShadowBluetoothAdapter.setEnabled(true);
|
mShadowBluetoothAdapter.setEnabled(true);
|
||||||
|
|
||||||
mMediaOutputSlice = new MediaOutputSlice(mContext);
|
mMediaOutputSlice = new MediaOutputSlice(mContext);
|
||||||
mMediaDeviceUpdateWorker = new MediaDeviceUpdateWorker(mContext,
|
mMediaDeviceUpdateWorker = spy(new MediaDeviceUpdateWorker(mContext,
|
||||||
MEDIA_OUTPUT_SLICE_URI);
|
MEDIA_OUTPUT_SLICE_URI));
|
||||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||||
mMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
|
mMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
|
||||||
|
doReturn(false).when(mMediaDeviceUpdateWorker).hasAdjustVolumeUserRestriction();
|
||||||
mMediaOutputSlice.init(mMediaDeviceUpdateWorker);
|
mMediaOutputSlice.init(mMediaDeviceUpdateWorker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,14 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
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;
|
||||||
@@ -27,6 +35,7 @@ import android.bluetooth.BluetoothPan;
|
|||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.widget.MasterSwitchPreference;
|
import com.android.settings.widget.MasterSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -34,14 +43,72 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.ParameterizedRobolectricTestRunner;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(ParameterizedRobolectricTestRunner.class)
|
||||||
public class AllInOneTetherPreferenceControllerTest {
|
public class AllInOneTetherPreferenceControllerTest {
|
||||||
|
|
||||||
|
@ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
|
||||||
|
public static List params() {
|
||||||
|
return Arrays.asList(new Object[][] {
|
||||||
|
{TETHERING_OFF, R.string.tether_settings_summary_off},
|
||||||
|
{TETHERING_WIFI_ON, R.string.tether_settings_summary_hotspot_only},
|
||||||
|
{TETHERING_USB_ON, R.string.tether_settings_summary_usb_tethering_only},
|
||||||
|
{TETHERING_BLUETOOTH_ON, R.string.tether_settings_summary_bluetooth_tethering_only},
|
||||||
|
{TETHERING_ETHERNET_ON, R.string.tether_settings_summary_ethernet_tethering_only},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_USB_ON,
|
||||||
|
R.string.tether_settings_summary_hotspot_and_usb
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON,
|
||||||
|
R.string.tether_settings_summary_hotspot_and_bluetooth
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_hotspot_and_ethernet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
|
||||||
|
R.string.tether_settings_summary_usb_and_bluetooth
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_USB_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_usb_and_ethernet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_bluetooth_and_ethernet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
|
||||||
|
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_hotspot_and_usb_and_ethernet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
|
||||||
|
| TETHERING_ETHERNET_ON,
|
||||||
|
R.string.tether_settings_summary_all
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -50,6 +117,13 @@ public class AllInOneTetherPreferenceControllerTest {
|
|||||||
private MasterSwitchPreference mPreference;
|
private MasterSwitchPreference mPreference;
|
||||||
|
|
||||||
private AllInOneTetherPreferenceController mController;
|
private AllInOneTetherPreferenceController mController;
|
||||||
|
private final int mTetherState;
|
||||||
|
private final int mSummaryResId;
|
||||||
|
|
||||||
|
public AllInOneTetherPreferenceControllerTest(int tetherState, int summaryResId) {
|
||||||
|
mTetherState = tetherState;
|
||||||
|
mSummaryResId = summaryResId;
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -90,4 +164,10 @@ public class AllInOneTetherPreferenceControllerTest {
|
|||||||
|
|
||||||
verify(mBluetoothAdapter).closeProfileProxy(BluetoothProfile.PAN, pan);
|
verify(mBluetoothAdapter).closeProfileProxy(BluetoothProfile.PAN, pan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_afterTetherStateChanged() {
|
||||||
|
mController.onTetherStateUpdated(mTetherState);
|
||||||
|
assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -26,6 +24,7 @@ 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.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.TetheringManager;
|
import android.net.TetheringManager;
|
||||||
@@ -62,7 +61,7 @@ public class BluetoothTetherPreferenceControllerTest {
|
|||||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||||
mConnectivityManager);
|
mConnectivityManager);
|
||||||
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
|
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
|
||||||
mController = new BluetoothTetherPreferenceController(mContext, BLUETOOTH_TETHER_KEY);
|
mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
|
||||||
mController.setTetherEnabler(mTetherEnabler);
|
mController.setTetherEnabler(mTetherEnabler);
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
||||||
}
|
}
|
||||||
@@ -98,14 +97,17 @@ public class BluetoothTetherPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void display_availableChangedCorrectly() {
|
public void shouldShow_noBluetoothTetherable() {
|
||||||
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
|
|
||||||
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldEnable_transientState() {
|
||||||
|
ReflectionHelpers.setField(mController, "mBluetoothState",
|
||||||
|
BluetoothAdapter.STATE_TURNING_OFF);
|
||||||
|
assertThat(mController.shouldEnable()).isFalse();
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
public void setChecked_shouldStartBluetoothTethering() {
|
public void setChecked_shouldStartBluetoothTethering() {
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* 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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.EthernetManager;
|
||||||
|
import android.net.TetheringManager;
|
||||||
|
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class EthernetTetherPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public MockitoRule mocks = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ConnectivityManager mConnectivityManager;
|
||||||
|
@Mock
|
||||||
|
private EthernetManager mEthernetManager;
|
||||||
|
@Mock
|
||||||
|
private TetherEnabler mTetherEnabler;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private EthernetTetherPreferenceController mController;
|
||||||
|
private SwitchPreference mPreference;
|
||||||
|
private static final String ETHERNET_REGEX = "ethernet";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mPreference = spy(SwitchPreference.class);
|
||||||
|
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||||
|
.thenReturn(mConnectivityManager);
|
||||||
|
when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
|
||||||
|
when(mContext.getSystemService(Context.ETHERNET_SERVICE)).thenReturn(mEthernetManager);
|
||||||
|
mController = new EthernetTetherPreferenceController(mContext, "ethernet");
|
||||||
|
mController.setTetherEnabler(mTetherEnabler);
|
||||||
|
ReflectionHelpers.setField(mController, "mEthernetRegex", ETHERNET_REGEX);
|
||||||
|
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldRegisterReceiverOnStart() {
|
||||||
|
mController.onStart();
|
||||||
|
|
||||||
|
verify(mEthernetManager).addListener(eq(mController.mEthernetListener));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldAddListenerOnResume() {
|
||||||
|
mController.onResume();
|
||||||
|
verify(mTetherEnabler).addListener(mController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldRemoveListenerOnPause() {
|
||||||
|
mController.onPause();
|
||||||
|
verify(mTetherEnabler).removeListener(mController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
||||||
|
mController.onStart();
|
||||||
|
EthernetManager.Listener listener = mController.mEthernetListener;
|
||||||
|
mController.onStop();
|
||||||
|
|
||||||
|
verify(mEthernetManager).removeListener(eq(listener));
|
||||||
|
assertThat(mController.mEthernetListener).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldEnable_noTetherable() {
|
||||||
|
when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
|
||||||
|
assertThat(mController.shouldEnable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldShow_noEthernetInterface() {
|
||||||
|
ReflectionHelpers.setField(mController, "mEthernetRegex", "");
|
||||||
|
assertThat(mController.shouldShow()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setChecked_shouldStartEthernetTethering() {
|
||||||
|
mController.setChecked(true);
|
||||||
|
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_ETHERNET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setUnchecked_shouldStopEthernetTethering() {
|
||||||
|
mController.setChecked(false);
|
||||||
|
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_ETHERNET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switch_shouldCheckedWhenEthernetTethering() {
|
||||||
|
mController.onTetherStateUpdated(TetherEnabler.TETHERING_ETHERNET_ON);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switch_shouldUnCheckedWhenEthernetNotTethering() {
|
||||||
|
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||||
|
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||||
|
import static android.net.TetheringManager.TETHERING_ETHERNET;
|
||||||
|
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -63,6 +74,8 @@ public class TetherEnablerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
|
private TetheringManager mTetheringManager;
|
||||||
|
@Mock
|
||||||
private NetworkPolicyManager mNetworkPolicyManager;
|
private NetworkPolicyManager mNetworkPolicyManager;
|
||||||
@Mock
|
@Mock
|
||||||
private BluetoothPan mBluetoothPan;
|
private BluetoothPan mBluetoothPan;
|
||||||
@@ -85,6 +98,7 @@ public class TetherEnablerTest {
|
|||||||
when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||||
when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
|
||||||
mConnectivityManager);
|
mConnectivityManager);
|
||||||
|
when(context.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
||||||
when(context.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
|
when(context.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
|
||||||
mNetworkPolicyManager);
|
mNetworkPolicyManager);
|
||||||
when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetherableIfaces()).thenReturn(new String[0]);
|
||||||
@@ -104,6 +118,23 @@ public class TetherEnablerTest {
|
|||||||
assertThat(mSwitchBar.isChecked()).isTrue();
|
assertThat(mSwitchBar.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_onStart_shoudRegisterTetheringEventCallback() {
|
||||||
|
mEnabler.onStart();
|
||||||
|
verify(mTetheringManager).registerTetheringEventCallback(any(),
|
||||||
|
eq(mEnabler.mTetheringEventCallback));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void lifecycle_onStop_shouldUnregisterTetheringEventCallback() {
|
||||||
|
mEnabler.onStart();
|
||||||
|
TetheringManager.TetheringEventCallback callback = mEnabler.mTetheringEventCallback;
|
||||||
|
|
||||||
|
mEnabler.onStop();
|
||||||
|
verify(mTetheringManager).unregisterTetheringEventCallback(callback);
|
||||||
|
assertThat(mEnabler.mTetheringEventCallback).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lifecycle_onStop_resetBluetoothTetheringStoppedByUser() {
|
public void lifecycle_onStop_resetBluetoothTetheringStoppedByUser() {
|
||||||
mEnabler.onStart();
|
mEnabler.onStart();
|
||||||
@@ -143,13 +174,40 @@ public class TetherEnablerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSwitchToggled_onlyStartsWifiTetherWhenNeeded() {
|
public void onSwitchToggled_onlyStartsWifiTetherWhenNeeded() {
|
||||||
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
|
doReturn(TETHERING_WIFI_ON).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
mEnabler.onSwitchToggled(true);
|
mEnabler.onSwitchToggled(true);
|
||||||
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
|
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
|
||||||
|
|
||||||
doReturn(false).when(mWifiManager).isWifiApEnabled();
|
doReturn(TETHERING_OFF).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
mEnabler.onSwitchToggled(true);
|
mEnabler.onSwitchToggled(true);
|
||||||
verify(mConnectivityManager).startTethering(anyInt(), anyBoolean(), any(), any());
|
verify(mConnectivityManager).startTethering(eq(TETHERING_WIFI), anyBoolean(), any(), any());
|
||||||
|
verify(mConnectivityManager, never()).startTethering(eq(TETHERING_USB), anyBoolean(), any(),
|
||||||
|
any());
|
||||||
|
verify(mConnectivityManager, never()).startTethering(eq(TETHERING_BLUETOOTH), anyBoolean(),
|
||||||
|
any(), any());
|
||||||
|
verify(mConnectivityManager, never()).startTethering(eq(TETHERING_ETHERNET), anyBoolean(),
|
||||||
|
any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSwitchToggled_stopAllTetheringInterfaces() {
|
||||||
|
mEnabler.onStart();
|
||||||
|
|
||||||
|
doReturn(TETHERING_WIFI_ON).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
|
mEnabler.onSwitchToggled(false);
|
||||||
|
verify(mConnectivityManager).stopTethering(TETHERING_WIFI);
|
||||||
|
|
||||||
|
doReturn(TETHERING_USB_ON).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
|
mEnabler.onSwitchToggled(false);
|
||||||
|
verify(mConnectivityManager).stopTethering(TETHERING_USB);
|
||||||
|
|
||||||
|
doReturn(TETHERING_BLUETOOTH_ON).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
|
mEnabler.onSwitchToggled(false);
|
||||||
|
verify(mConnectivityManager).stopTethering(TETHERING_BLUETOOTH);
|
||||||
|
|
||||||
|
doReturn(TETHERING_ETHERNET_ON).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
|
mEnabler.onSwitchToggled(false);
|
||||||
|
verify(mConnectivityManager).stopTethering(TETHERING_ETHERNET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -169,8 +227,7 @@ public class TetherEnablerTest {
|
|||||||
public void stopTethering_setBluetoothTetheringStoppedByUserAndUpdateState() {
|
public void stopTethering_setBluetoothTetheringStoppedByUserAndUpdateState() {
|
||||||
mSwitchWidgetController.setListener(mEnabler);
|
mSwitchWidgetController.setListener(mEnabler);
|
||||||
mSwitchWidgetController.startListening();
|
mSwitchWidgetController.startListening();
|
||||||
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
|
doReturn(TETHERING_BLUETOOTH_ON).when(mEnabler).getTetheringState(null /* tethered */);
|
||||||
doReturn(state).when(mEnabler).getTetheringState(null /* tethered */);
|
|
||||||
|
|
||||||
mEnabler.stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
mEnabler.stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
||||||
assertThat(mEnabler.mBluetoothTetheringStoppedByUser).isTrue();
|
assertThat(mEnabler.mBluetoothTetheringStoppedByUser).isTrue();
|
||||||
@@ -238,4 +295,20 @@ public class TetherEnablerTest {
|
|||||||
mEnabler.removeListener(listener);
|
mEnabler.removeListener(listener);
|
||||||
assertThat(mEnabler.mListeners).doesNotContain(listener);
|
assertThat(mEnabler.mListeners).doesNotContain(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isTethering_shouldReturnCorrectly() {
|
||||||
|
assertThat(TetherEnabler.isTethering(TETHERING_WIFI_ON, TETHERING_WIFI)).isTrue();
|
||||||
|
assertThat(TetherEnabler.isTethering(~TETHERING_WIFI_ON, TETHERING_WIFI)).isFalse();
|
||||||
|
|
||||||
|
assertThat(TetherEnabler.isTethering(TETHERING_USB_ON, TETHERING_USB)).isTrue();
|
||||||
|
assertThat(TetherEnabler.isTethering(~TETHERING_USB_ON, TETHERING_USB)).isFalse();
|
||||||
|
|
||||||
|
assertThat(TetherEnabler.isTethering(TETHERING_BLUETOOTH_ON, TETHERING_BLUETOOTH)).isTrue();
|
||||||
|
assertThat(TetherEnabler.isTethering(~TETHERING_BLUETOOTH_ON, TETHERING_BLUETOOTH))
|
||||||
|
.isFalse();
|
||||||
|
|
||||||
|
assertThat(TetherEnabler.isTethering(TETHERING_ETHERNET_ON, TETHERING_ETHERNET)).isTrue();
|
||||||
|
assertThat(TetherEnabler.isTethering(~TETHERING_ETHERNET_ON, TETHERING_ETHERNET)).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -61,7 +59,7 @@ 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[]{""});
|
||||||
mController = new UsbTetherPreferenceController(mContext, USB_TETHER_KEY);
|
mController = new UsbTetherPreferenceController(mContext, "USB");
|
||||||
mController.setTetherEnabler(mTetherEnabler);
|
mController.setTetherEnabler(mTetherEnabler);
|
||||||
mSwitchPreference = spy(SwitchPreference.class);
|
mSwitchPreference = spy(SwitchPreference.class);
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
||||||
@@ -95,12 +93,15 @@ public class UsbTetherPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void display_availableChangedCorrectly() {
|
public void shouldShow_noTetherableUsb() {
|
||||||
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
|
||||||
|
|
||||||
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.shouldShow()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldEnable_noUsbConnected() {
|
||||||
|
ReflectionHelpers.setField(mController, "mUsbConnected", false);
|
||||||
|
assertThat(mController.shouldEnable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -16,13 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.network;
|
package com.android.settings.network;
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.WIFI_TETHER_DISABLE_KEY;
|
import static com.android.settings.AllInOneTetherSettings.WIFI_TETHER_DISABLE_KEY;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
||||||
|
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
||||||
|
|
||||||
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.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
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;
|
||||||
@@ -32,17 +34,48 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
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;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.ParameterizedRobolectricTestRunner;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(ParameterizedRobolectricTestRunner.class)
|
||||||
public class WifiTetherDisablePreferenceControllerTest {
|
public class WifiTetherDisablePreferenceControllerTest {
|
||||||
|
|
||||||
|
@ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
|
||||||
|
public static List params() {
|
||||||
|
return Arrays.asList(new Object[][] {
|
||||||
|
{TETHERING_OFF, R.string.summary_placeholder},
|
||||||
|
{TETHERING_USB_ON, R.string.disable_wifi_hotspot_when_usb_on},
|
||||||
|
{TETHERING_BLUETOOTH_ON, R.string.disable_wifi_hotspot_when_bluetooth_on},
|
||||||
|
{TETHERING_ETHERNET_ON, R.string.disable_wifi_hotspot_when_ethernet_on},
|
||||||
|
{
|
||||||
|
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
|
||||||
|
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_USB_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.disable_wifi_hotspot_when_usb_and_ethernet_on
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
||||||
|
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ConnectivityManager mConnectivityManager;
|
private ConnectivityManager mConnectivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -53,6 +86,13 @@ public class WifiTetherDisablePreferenceControllerTest {
|
|||||||
private SwitchPreference mPreference;
|
private SwitchPreference mPreference;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private WifiTetherDisablePreferenceController mController;
|
private WifiTetherDisablePreferenceController mController;
|
||||||
|
private final int mTetherState;
|
||||||
|
private final int mSummaryResId;
|
||||||
|
|
||||||
|
public WifiTetherDisablePreferenceControllerTest(int tetherState, int summaryResId) {
|
||||||
|
mTetherState = tetherState;
|
||||||
|
mSummaryResId = summaryResId;
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -71,21 +111,16 @@ public class WifiTetherDisablePreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void display_availableChangedCorrectly() {
|
public void shouldShow_noTetherableWifi() {
|
||||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
|
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.shouldShow()).isFalse();
|
||||||
|
|
||||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"test"});
|
|
||||||
ReflectionHelpers.setField(mController, "mBluetoothTethering", false);
|
|
||||||
ReflectionHelpers.setField(mController, "mUsbTethering", false);
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switch_shouldListenToUsbAndBluetooth() {
|
public void onTetherStateUpdated_visibilityChangeCorrectly() {
|
||||||
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
|
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
|
||||||
mController.onTetherStateUpdated(state);
|
mController.onTetherStateUpdated(state);
|
||||||
verify(mPreference).setVisible(eq(true));
|
assertThat(mController.shouldShow()).isTrue();
|
||||||
|
|
||||||
state |= TetherEnabler.TETHERING_USB_ON;
|
state |= TetherEnabler.TETHERING_USB_ON;
|
||||||
mController.onTetherStateUpdated(state);
|
mController.onTetherStateUpdated(state);
|
||||||
@@ -97,6 +132,12 @@ public class WifiTetherDisablePreferenceControllerTest {
|
|||||||
|
|
||||||
state = TetherEnabler.TETHERING_OFF;
|
state = TetherEnabler.TETHERING_OFF;
|
||||||
mController.onTetherStateUpdated(state);
|
mController.onTetherStateUpdated(state);
|
||||||
verify(mPreference).setVisible(eq(false));
|
assertThat(mController.shouldShow()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_onTetherStateUpdated() {
|
||||||
|
mController.onTetherStateUpdated(mTetherState);
|
||||||
|
assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import android.content.Context;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
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;
|
||||||
@@ -59,6 +60,7 @@ public class NrDisabledInDsdsFooterPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void isAvailable_dataOnAndDsdsAnd5GSupported_Available() {
|
public void isAvailable_dataOnAndDsdsAnd5GSupported_Available() {
|
||||||
when(mTelephonyManager.getSupportedRadioAccessFamily())
|
when(mTelephonyManager.getSupportedRadioAccessFamily())
|
||||||
.thenReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR);
|
.thenReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.android.settings.testutils.shadow.ShadowUtils;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -102,6 +103,7 @@ public class RedactionInterstitialTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void managedProfileNoRestrictionsTest() {
|
public void managedProfileNoRestrictionsTest() {
|
||||||
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
final ShadowUserManager sum =
|
final ShadowUserManager sum =
|
||||||
@@ -115,6 +117,7 @@ public class RedactionInterstitialTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void managedProfileUnredactedRestrictionTest() {
|
public void managedProfileUnredactedRestrictionTest() {
|
||||||
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||||
final ShadowUserManager sum =
|
final ShadowUserManager sum =
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.notification.zen.ZenModeSettings;
|
import com.android.settings.notification.zen.ZenModeSettings;
|
||||||
|
|
||||||
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.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
@@ -70,9 +71,10 @@ public class ZenModeSettingsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testGetCallsSettingSummary_none() {
|
public void testGetCallsSettingSummary_none() {
|
||||||
Policy policy = new Policy(0, 0, 0, 0);
|
Policy policy = new Policy(0, 0, 0, 0);
|
||||||
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("Don\u2019t allow any calls");
|
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user