Loading res/xml/tether_prefs.xml +8 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,12 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto"> <Preference android:key="wifi_tether" android:title="@string/wifi_tether_checkbox_text" android:summary="@string/summary_placeholder" android:fragment="com.android.settings.wifi.tether.WifiTetherSettings" /> <SwitchPreference android:key="usb_tether_settings" android:title="@string/usb_tethering_button_text" Loading res/xml/wifi_tether_settings.xml 0 → 100644 +33 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_name" android:title="@string/wifi_ssid" android:summary="@string/summary_placeholder" /> <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_password" android:title="@string/wifi_password" /> <ListPreference android:key="wifi_tether_network_ap_band" android:title="@string/wifi_ap_band_config" android:summary="@string/summary_placeholder" /> </PreferenceScreen> No newline at end of file src/com/android/settings/TetherSettings.java +23 −11 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.datausage.DataSaverBackend; import com.android.settings.wifi.WifiApDialog; import com.android.settings.wifi.WifiApEnabler; import com.android.settings.wifi.tether.WifiTetherPreferenceController; import com.android.settings.wifi.tether.WifiTetherSettings; import com.android.settingslib.TetherUtil; import java.lang.ref.WeakReference; Loading @@ -63,7 +65,6 @@ public class TetherSettings extends RestrictedSettingsFragment private static final String USB_TETHER_SETTINGS = "usb_tether_settings"; private static final String ENABLE_WIFI_AP = "enable_wifi_ap"; private static final String ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering"; private static final String TETHER_CHOICE = "TETHER_TYPE"; private static final String DATA_SAVER_FOOTER = "disabled_on_data_saver"; private static final int DIALOG_AP_SETTINGS = 1; Loading Loading @@ -100,17 +101,14 @@ public class TetherSettings extends RestrictedSettingsFragment private WifiConfiguration mWifiConfig = null; private ConnectivityManager mCm; private WifiTetherPreferenceController mWifiTetherPreferenceController; private boolean mRestartWifiApAfterConfigChange; private boolean mUsbConnected; private boolean mMassStorageActive; private boolean mBluetoothEnableForTether; /* Stores the package name and the class name of the provisioning app */ private String[] mProvisionApp; private static final int PROVISION_REQUEST = 0; private boolean mUnavailable; private DataSaverBackend mDataSaverBackend; Loading @@ -126,6 +124,13 @@ public class TetherSettings extends RestrictedSettingsFragment super(UserManager.DISALLOW_CONFIG_TETHERING); } @Override public void onAttach(Context context) { super.onAttach(context); mWifiTetherPreferenceController = new WifiTetherPreferenceController(context, getLifecycle()); } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Loading Loading @@ -154,6 +159,7 @@ public class TetherSettings extends RestrictedSettingsFragment mEnableWifiAp = (SwitchPreference) findPreference(ENABLE_WIFI_AP); Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY); mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS); mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING); Loading @@ -175,6 +181,11 @@ public class TetherSettings extends RestrictedSettingsFragment getPreferenceScreen().removePreference(mUsbTether); } mWifiTetherPreferenceController.displayPreference(getPreferenceScreen()); if (WifiTetherSettings.isTetherSettingPageEnabled()) { removePreference(ENABLE_WIFI_AP); removePreference(WIFI_AP_SSID_AND_SECURITY); } else { if (wifiAvailable && !Utils.isMonkeyRunning()) { mWifiApEnabler = new WifiApEnabler(activity, mDataSaverBackend, mEnableWifiAp); initWifiTethering(); Loading @@ -182,6 +193,7 @@ public class TetherSettings extends RestrictedSettingsFragment getPreferenceScreen().removePreference(mEnableWifiAp); getPreferenceScreen().removePreference(wifiApSettings); } } if (!bluetoothAvailable) { getPreferenceScreen().removePreference(mBluetoothTether); Loading src/com/android/settings/widget/ValidatedEditTextPreference.java 0 → 100644 +111 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 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.widget; import android.app.AlertDialog; import android.content.Context; import android.support.annotation.VisibleForTesting; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; import android.util.AttributeSet; import android.view.View; import android.widget.EditText; import com.android.settings.CustomEditTextPreference; /** * {@code EditTextPreference} that supports input validation. */ public class ValidatedEditTextPreference extends CustomEditTextPreference { public interface Validator { boolean isTextValid(String value); } private final EditTextWatcher mTextWatcher = new EditTextWatcher(); private Validator mValidator; private boolean mIsPassword; public ValidatedEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public ValidatedEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public ValidatedEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public ValidatedEditTextPreference(Context context) { super(context); } @Override protected void onBindDialogView(View view) { super.onBindDialogView(view); if (mValidator != null) { final EditText editText = view.findViewById(android.R.id.edit); if (editText != null) { editText.removeTextChangedListener(mTextWatcher); if (mIsPassword) { editText.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); editText.setMaxLines(1); } editText.addTextChangedListener(mTextWatcher); } } } public void setIsPassword(boolean isPassword) { mIsPassword = isPassword; } @VisibleForTesting(otherwise = VisibleForTesting.NONE) public boolean isPassword() { return mIsPassword; } public void setValidator(Validator validator) { mValidator = validator; } private class EditTextWatcher implements TextWatcher { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { final EditText editText = getEditText(); if (mValidator != null && editText != null) { final AlertDialog dialog = (AlertDialog) getDialog(); final boolean valid = mValidator.isTextValid(editText.getText().toString()); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(valid); } } } } src/com/android/settings/wifi/WifiApEnabler.java +4 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,10 @@ import com.android.settings.datausage.DataSaverBackend; import java.util.ArrayList; /** * @deprecated in favor of WifiTetherPreferenceController and WifiTetherSettings */ @Deprecated public class WifiApEnabler { private final Context mContext; private final SwitchPreference mSwitch; Loading Loading
res/xml/tether_prefs.xml +8 −2 Original line number Diff line number Diff line Loading @@ -17,6 +17,12 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto"> <Preference android:key="wifi_tether" android:title="@string/wifi_tether_checkbox_text" android:summary="@string/summary_placeholder" android:fragment="com.android.settings.wifi.tether.WifiTetherSettings" /> <SwitchPreference android:key="usb_tether_settings" android:title="@string/usb_tethering_button_text" Loading
res/xml/wifi_tether_settings.xml 0 → 100644 +33 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_name" android:title="@string/wifi_ssid" android:summary="@string/summary_placeholder" /> <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_password" android:title="@string/wifi_password" /> <ListPreference android:key="wifi_tether_network_ap_band" android:title="@string/wifi_ap_band_config" android:summary="@string/summary_placeholder" /> </PreferenceScreen> No newline at end of file
src/com/android/settings/TetherSettings.java +23 −11 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.datausage.DataSaverBackend; import com.android.settings.wifi.WifiApDialog; import com.android.settings.wifi.WifiApEnabler; import com.android.settings.wifi.tether.WifiTetherPreferenceController; import com.android.settings.wifi.tether.WifiTetherSettings; import com.android.settingslib.TetherUtil; import java.lang.ref.WeakReference; Loading @@ -63,7 +65,6 @@ public class TetherSettings extends RestrictedSettingsFragment private static final String USB_TETHER_SETTINGS = "usb_tether_settings"; private static final String ENABLE_WIFI_AP = "enable_wifi_ap"; private static final String ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering"; private static final String TETHER_CHOICE = "TETHER_TYPE"; private static final String DATA_SAVER_FOOTER = "disabled_on_data_saver"; private static final int DIALOG_AP_SETTINGS = 1; Loading Loading @@ -100,17 +101,14 @@ public class TetherSettings extends RestrictedSettingsFragment private WifiConfiguration mWifiConfig = null; private ConnectivityManager mCm; private WifiTetherPreferenceController mWifiTetherPreferenceController; private boolean mRestartWifiApAfterConfigChange; private boolean mUsbConnected; private boolean mMassStorageActive; private boolean mBluetoothEnableForTether; /* Stores the package name and the class name of the provisioning app */ private String[] mProvisionApp; private static final int PROVISION_REQUEST = 0; private boolean mUnavailable; private DataSaverBackend mDataSaverBackend; Loading @@ -126,6 +124,13 @@ public class TetherSettings extends RestrictedSettingsFragment super(UserManager.DISALLOW_CONFIG_TETHERING); } @Override public void onAttach(Context context) { super.onAttach(context); mWifiTetherPreferenceController = new WifiTetherPreferenceController(context, getLifecycle()); } @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Loading Loading @@ -154,6 +159,7 @@ public class TetherSettings extends RestrictedSettingsFragment mEnableWifiAp = (SwitchPreference) findPreference(ENABLE_WIFI_AP); Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY); mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS); mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING); Loading @@ -175,6 +181,11 @@ public class TetherSettings extends RestrictedSettingsFragment getPreferenceScreen().removePreference(mUsbTether); } mWifiTetherPreferenceController.displayPreference(getPreferenceScreen()); if (WifiTetherSettings.isTetherSettingPageEnabled()) { removePreference(ENABLE_WIFI_AP); removePreference(WIFI_AP_SSID_AND_SECURITY); } else { if (wifiAvailable && !Utils.isMonkeyRunning()) { mWifiApEnabler = new WifiApEnabler(activity, mDataSaverBackend, mEnableWifiAp); initWifiTethering(); Loading @@ -182,6 +193,7 @@ public class TetherSettings extends RestrictedSettingsFragment getPreferenceScreen().removePreference(mEnableWifiAp); getPreferenceScreen().removePreference(wifiApSettings); } } if (!bluetoothAvailable) { getPreferenceScreen().removePreference(mBluetoothTether); Loading
src/com/android/settings/widget/ValidatedEditTextPreference.java 0 → 100644 +111 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 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.widget; import android.app.AlertDialog; import android.content.Context; import android.support.annotation.VisibleForTesting; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; import android.util.AttributeSet; import android.view.View; import android.widget.EditText; import com.android.settings.CustomEditTextPreference; /** * {@code EditTextPreference} that supports input validation. */ public class ValidatedEditTextPreference extends CustomEditTextPreference { public interface Validator { boolean isTextValid(String value); } private final EditTextWatcher mTextWatcher = new EditTextWatcher(); private Validator mValidator; private boolean mIsPassword; public ValidatedEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public ValidatedEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public ValidatedEditTextPreference(Context context, AttributeSet attrs) { super(context, attrs); } public ValidatedEditTextPreference(Context context) { super(context); } @Override protected void onBindDialogView(View view) { super.onBindDialogView(view); if (mValidator != null) { final EditText editText = view.findViewById(android.R.id.edit); if (editText != null) { editText.removeTextChangedListener(mTextWatcher); if (mIsPassword) { editText.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); editText.setMaxLines(1); } editText.addTextChangedListener(mTextWatcher); } } } public void setIsPassword(boolean isPassword) { mIsPassword = isPassword; } @VisibleForTesting(otherwise = VisibleForTesting.NONE) public boolean isPassword() { return mIsPassword; } public void setValidator(Validator validator) { mValidator = validator; } private class EditTextWatcher implements TextWatcher { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { final EditText editText = getEditText(); if (mValidator != null && editText != null) { final AlertDialog dialog = (AlertDialog) getDialog(); final boolean valid = mValidator.isTextValid(editText.getText().toString()); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(valid); } } } }
src/com/android/settings/wifi/WifiApEnabler.java +4 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,10 @@ import com.android.settings.datausage.DataSaverBackend; import java.util.ArrayList; /** * @deprecated in favor of WifiTetherPreferenceController and WifiTetherSettings */ @Deprecated public class WifiApEnabler { private final Context mContext; private final SwitchPreference mSwitch; Loading