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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
|
||||
/**
|
||||
* Support a QR code share button for {@code EditTextPreference} that supports input validation.
|
||||
*/
|
||||
public class WifiTetherSsidPreference extends ValidatedEditTextPreference {
|
||||
private static final String TAG = "WifiTetherSsidPreference";
|
||||
|
||||
private ImageButton mImageButton;
|
||||
private Drawable mButtonIcon;
|
||||
private View.OnClickListener mClickListener;
|
||||
private boolean mVisible;
|
||||
|
||||
public WifiTetherSsidPreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
public WifiTetherSsidPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
public WifiTetherSsidPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
public WifiTetherSsidPreference(Context context) {
|
||||
super(context);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
setWidgetLayoutResource(R.layout.wifi_button_preference_widget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
if (mImageButton == null) {
|
||||
mImageButton = (ImageButton) holder.findViewById(R.id.button_icon);
|
||||
|
||||
mImageButton.setContentDescription(
|
||||
getContext().getString(R.string.wifi_dpp_share_hotspot));
|
||||
setButtonIcon(R.drawable.ic_qrcode_24dp);
|
||||
mImageButton.setImageDrawable(mButtonIcon);
|
||||
}
|
||||
|
||||
if (mVisible) {
|
||||
mImageButton.setOnClickListener(mClickListener);
|
||||
mImageButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mImageButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setButtonOnClickListener(View.OnClickListener listener) {
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
public void setButtonVisible(boolean visible) {
|
||||
mVisible = visible;
|
||||
}
|
||||
|
||||
private void setButtonIcon(@DrawableRes int iconResId) {
|
||||
try {
|
||||
mButtonIcon = getContext().getDrawable(iconResId);
|
||||
} catch (Resources.NotFoundException exception) {
|
||||
Log.e(TAG, "Resource does not exist: " + iconResId);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isQrCodeButtonAvailable() {
|
||||
return mVisible && mClickListener != null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user