Skip to content

Commit

Permalink
Settings: Add an option to allow tethering while Data Saver is on
Browse files Browse the repository at this point in the history
  • Loading branch information
neelchauhan committed Dec 10, 2024
1 parent d039996 commit 7d00acd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions res-product/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@
<string name="ethernet_tethering_subtext" product="default">Share phone\u2019s internet connection via Ethernet</string>
<!-- Ethernet Tethering subtext for tablet [CHAR LIMIT=NONE]-->
<string name="ethernet_tethering_subtext" product="tablet">Share tablet\u2019s internet connection via Ethernet</string>
<!-- Data Saver Tethering subtext [CHAR LIMIT=NONE]-->
<string name="data_saver_tethering_subtext" product="default">Unconditionally allow tethering while on data saver mode</string>
<!-- Main settings screen, setting title for the user to go into the About phone screen -->
<string name="about_settings" product="tablet">About tablet</string>
<!-- Main settings screen, setting title for the user to go into the About phone screen -->
Expand Down
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,10 @@
<!-- Label for ethernet tether checkbox [CHAR LIMIT=NONE]-->
<string name="ethernet_tether_checkbox_text">Ethernet tethering</string>

<!-- Enable Tethering on Data Saver -->
<!-- Label for data saver tether checkbox [CHAR LIMIT=NONE]-->
<string name="data_saver_tether_checkbox_text">Enable tethering on data saver</string>

<!-- Tethering footer info [CHAR LIMIT=NONE]-->
<string name="tethering_footer_info">Use hotspot and tethering to provide internet to other devices through your mobile data connection. Apps can also create a hotspot to share content with nearby devices.</string>
<!-- Tethering footer info for the device which supports Wi-Fi and Wi-Fi tethering enabled at the same time [CHAR LIMIT=NONE]-->
Expand Down
6 changes: 6 additions & 0 deletions res/xml/tether_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
android:summary="@string/ethernet_tethering_subtext"
settings:keywords="@string/keywords_hotspot_tethering" />

<SwitchPreferenceCompat
android:key="enable_data_saver_tethering"
android:title="@string/data_saver_tether_checkbox_text"
android:summary="@string/data_saver_tethering_subtext"
settings:keywords="@string/keywords_hotspot_tethering" />

<com.android.settingslib.widget.FooterPreference
android:key="disabled_on_data_saver"
android:title="@string/tether_settings_disabled_on_data_saver"
Expand Down
30 changes: 20 additions & 10 deletions src/com/android/settings/network/tether/TetherSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class TetherSettings extends RestrictedSettingsFragment
@VisibleForTesting
static final String KEY_ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering";
private static final String KEY_ENABLE_ETHERNET_TETHERING = "enable_ethernet_tethering";
private static final String KEY_ENABLE_DATA_SAVER_TETHERING = "enable_data_saver_tethering";
private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver";
@VisibleForTesting
static final String KEY_TETHER_PREFS_TOP_INTRO = "tether_prefs_top_intro";
Expand All @@ -100,6 +101,8 @@ public class TetherSettings extends RestrictedSettingsFragment
TwoStatePreference mBluetoothTether;
@VisibleForTesting
TwoStatePreference mEthernetTether;
@VisibleForTesting
TwoStatePreference mDataSaverTether;

private BroadcastReceiver mTetherChangeReceiver;
private BroadcastReceiver mBluetoothStateReceiver;
Expand Down Expand Up @@ -209,6 +212,7 @@ public void onCreate(Bundle icicle) {
if (!ethernetAvailable) getPreferenceScreen().removePreference(mEthernetTether);
// Set initial state based on Data Saver mode.
onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
mDataSaverTether.setChecked(false);
}

@VisibleForTesting
Expand Down Expand Up @@ -247,15 +251,16 @@ void setupTetherPreference() {
mUsbTether = (RestrictedSwitchPreference) findPreference(KEY_USB_TETHER_SETTINGS);
mBluetoothTether = (TwoStatePreference) findPreference(KEY_ENABLE_BLUETOOTH_TETHERING);
mEthernetTether = (TwoStatePreference) findPreference(KEY_ENABLE_ETHERNET_TETHERING);
mDataSaverTether = (TwoStatePreference) findPreference(KEY_ENABLE_DATA_SAVER_TETHERING);
}

@Override
public void onDataSaverChanged(boolean isDataSaving) {
mDataSaverEnabled = isDataSaving;
mWifiTetherPreferenceController.setDataSaverEnabled(mDataSaverEnabled);
mUsbTether.setEnabled(!mDataSaverEnabled);
mBluetoothTether.setEnabled(!mDataSaverEnabled);
mEthernetTether.setEnabled(!mDataSaverEnabled);
mWifiTetherPreferenceController.setDataSaverEnabled(mDataSaverEnabled && !mDataSaverTether.isChecked());
mUsbTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mBluetoothTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mEthernetTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mDataSaverFooter.setVisible(mDataSaverEnabled);
}

Expand Down Expand Up @@ -461,7 +466,7 @@ void updateUsbState(String[] tethered) {
+ ", usbTethered : " + usbTethered);
}
if (usbTethered) {
mUsbTether.setEnabled(!mDataSaverEnabled);
mUsbTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mUsbTether.setChecked(true);
final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId());
Expand All @@ -482,7 +487,7 @@ private void updateUsbPreference() {
if (enforcedAdmin != null) {
mUsbTether.setDisabledByAdmin(enforcedAdmin);
} else if (usbAvailable) {
mUsbTether.setEnabled(!mDataSaverEnabled);
mUsbTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
} else {
mUsbTether.setEnabled(false);
}
Expand Down Expand Up @@ -520,9 +525,9 @@ private void updateBluetoothState() {
} else {
if (btState == BluetoothAdapter.STATE_ON && isBluetoothTetheringOn()) {
mBluetoothTether.setChecked(true);
mBluetoothTether.setEnabled(!mDataSaverEnabled);
mBluetoothTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
} else {
mBluetoothTether.setEnabled(!mDataSaverEnabled);
mBluetoothTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mBluetoothTether.setChecked(false);
}
}
Expand All @@ -547,10 +552,10 @@ void updateEthernetState(String[] available, String[] tethered) {
}

if (isTethered) {
mEthernetTether.setEnabled(!mDataSaverEnabled);
mEthernetTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mEthernetTether.setChecked(true);
} else if (mAvailableInterfaces.size() > 0) {
mEthernetTether.setEnabled(!mDataSaverEnabled);
mEthernetTether.setEnabled(!mDataSaverEnabled || mDataSaverTether.isChecked());
mEthernetTether.setChecked(false);
} else {
mEthernetTether.setEnabled(false);
Expand Down Expand Up @@ -659,6 +664,11 @@ public List<String> getNonIndexableKeys(Context context) {
if (!ethernetAvailable) {
keys.add(KEY_ENABLE_ETHERNET_TETHERING);
}

if (!TetherUtil.isTetherAvailable(context)) {
keys.add(KEY_ENABLE_DATA_SAVER_TETHERING);
}

return keys;
}
};
Expand Down

0 comments on commit 7d00acd

Please sign in to comment.