Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b410c21a authored by Salvador Martinez's avatar Salvador Martinez Committed by Android (Google) Code Review
Browse files

Merge "Make it possible to have open tether network" into pi-dev

parents 0c92430b 670a3e58
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2162,6 +2162,8 @@
    <string name="wifi_hotspot_tethering_on_subtext" product="default">Sharing this phone\u2019s internet connection via hotspot</string>
    <!-- Summary text when hotspot is on for local-only -->
    <string name="wifi_hotspot_on_local_only_subtext">App is sharing content. To share internet connection, turn hotspot off, then on</string>
    <!-- Summary text when no password is set [CHAR LIMIT=60] -->
    <string name="wifi_hotspot_no_password_subtext">No password set</string>
    <!-- Wifi hotspot settings -->
    <!-- Label for Wifi hotspot name. -->
+6 −1
Original line number Diff line number Diff line
@@ -86,9 +86,14 @@ public class ValidatedEditTextPreference extends CustomEditTextPreference {
        super.onBindViewHolder(holder);

        final TextView textView = (TextView) holder.findViewById(android.R.id.summary);
        if (textView != null && mIsSummaryPassword) {
        if (textView == null) {
            return;
        }
        if (mIsSummaryPassword) {
            textView.setInputType(
                    InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        } else {
            textView.setInputType(InputType.TYPE_CLASS_TEXT);
        }
    }

+3 −2
Original line number Diff line number Diff line
@@ -50,10 +50,11 @@ public class WifiUtils {
        return ssid.length() < SSID_ASCII_MIN_LENGTH;
    }

    public static boolean isPasswordValid(String password) {
    public static boolean isHotspotPasswordValid(String password) {
        if (TextUtils.isEmpty(password)) {
            return false;
            return true;
        }

        final int length = password.length();
        return length >= PASSWORD_MIN_LENGTH && length <= PASSWORD_MAX_LENGTH;
    }
+31 −3
Original line number Diff line number Diff line
@@ -20,11 +20,15 @@ import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import android.util.Log;

import com.android.settings.R;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.WifiUtils;

import java.util.UUID;

public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController
        implements ValidatedEditTextPreference.Validator {

@@ -49,6 +53,8 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
        if (config != null) {
            mPassword = config.preSharedKey;
            Log.d(TAG, "Updating password in Preference, " + mPassword);
        } else {
            mPassword = generateRandomPassword();
        }
        ((ValidatedEditTextPreference) mPreference).setValidator(this);
        ((ValidatedEditTextPreference) mPreference).setIsSummaryPassword(true);
@@ -67,13 +73,35 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
        return mPassword;
    }

    public int getSecuritySettingForPassword() {
        // We should return NONE when no password is set
        if (TextUtils.isEmpty(mPassword)) {
            return WifiConfiguration.KeyMgmt.NONE;
        }
        // Only other currently supported type is WPA2 so we'll try that
        return WifiConfiguration.KeyMgmt.WPA2_PSK;
    }

    @Override
    public boolean isTextValid(String value) {
        return WifiUtils.isPasswordValid(value);
        return WifiUtils.isHotspotPasswordValid(value);
    }

    private static String generateRandomPassword() {
        String randomUUID = UUID.randomUUID().toString();
        //first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
        return randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
    }

    private void updatePasswordDisplay(EditTextPreference preference) {
        preference.setText(mPassword);
        preference.setSummary(mPassword);
        ValidatedEditTextPreference pref = (ValidatedEditTextPreference) preference;
        pref.setText(mPassword);
        if (!TextUtils.isEmpty(mPassword)) {
            pref.setIsSummaryPassword(true);
            pref.setSummary(mPassword);
        } else {
            pref.setIsSummaryPassword(false);
            pref.setSummary(R.string.wifi_hotspot_no_password_subtext);
        }
    }
}
+2 −11
Original line number Diff line number Diff line
@@ -161,8 +161,8 @@ public class WifiTetherSettings extends RestrictedDashboardFragment

        config.SSID = mSSIDPreferenceController.getSSID();
        config.preSharedKey = mPasswordPreferenceController.getPassword();
        ensureWifiConfigHasPassword(config);
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
        config.allowedKeyManagement.set(
                mPasswordPreferenceController.getSecuritySettingForPassword());
        config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
        config.apBand = mApBandPreferenceController.getBandIndex();
        return config;
@@ -182,15 +182,6 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
                .updateDisplay();
    }

    @VisibleForTesting
    static void ensureWifiConfigHasPassword(WifiConfiguration config) {
        if (TextUtils.isEmpty(config.preSharedKey)) {
            String randomUUID = UUID.randomUUID().toString();
            //first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
            config.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9, 13);
        }
    }

    @VisibleForTesting
    class TetherChangeReceiver extends BroadcastReceiver {
        @Override
Loading