Support to share Wi-Fi hotspot via QR code

1. QR code scanner (Wi-Fi Easy Connect) does not support sharing Wi-Fi hotspot
   at current stage
2. Wi-Fi hotspot QR code button only shows when Wi-Fi hotspot is enabled
3. The QR code has the security string "WPA" for hotspot's WPA2_PSK

Bug: 123151660
Test: atest WifiTetherSSIDPreferenceControllerTest
            WifiQrCodeTest WifiDppConfiguratorActivityTest
            WifiDppEnrolleeActivityTest
            WifiDppQrCodeGeneratorFragmentTest
            WifiDppQrCodeScannerFragmentTest
            WifiNetworkListFragmentTest
            WifiDppChooseSavedWifiNetworkFragmentTest

Change-Id: I2e89450180b82cc841ee3b15be52bfc6f9f6164d
This commit is contained in:
Arc Wang
2019-03-04 17:20:41 +08:00
parent 131eeac4aa
commit b249fb7d13
13 changed files with 361 additions and 102 deletions

View File

@@ -17,13 +17,18 @@
package com.android.settings.wifi.tether;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiConfiguration;
import android.util.Log;
import android.view.View;
import androidx.annotation.VisibleForTesting;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.dpp.WifiDppUtils;
public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreferenceController
implements ValidatedEditTextPreference.Validator {
@@ -56,6 +61,23 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
mSSID = DEFAULT_SSID;
}
((ValidatedEditTextPreference) mPreference).setValidator(this);
if (mWifiManager.isWifiApEnabled() && config != null) {
final Intent intent = WifiDppUtils.getHotspotConfiguratorIntentOrNull(mContext,
mWifiManager, config);
if (intent == null) {
Log.e(TAG, "Invalid security to share hotspot");
((WifiTetherSsidPreference) mPreference).setButtonVisible(false);
} else {
((WifiTetherSsidPreference) mPreference).setButtonOnClickListener(
view -> shareHotspotNetwork(intent));
((WifiTetherSsidPreference) mPreference).setButtonVisible(true);
}
} else {
((WifiTetherSsidPreference) mPreference).setButtonVisible(false);
}
updateSsidDisplay((EditTextPreference) mPreference);
}
@@ -80,4 +102,19 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
preference.setText(mSSID);
preference.setSummary(mSSID);
}
private void shareHotspotNetwork(Intent intent) {
final String title = mContext.getString(
R.string.lockpassword_confirm_your_pattern_header);
final String description = String.format(
mContext.getString(R.string.wifi_sharing_message), mSSID);
WifiDppUtils.showLockScreen(mContext, title, description,
() -> mContext.startActivity(intent));
}
@VisibleForTesting
boolean isQrCodeButtonAvailable() {
return ((WifiTetherSsidPreference) mPreference).isQrCodeButtonAvailable();
}
}