Add a different Wi-Fi Easy Connect entry point
To separate it further from Wi-Fi sharing as it was causing some confusion. Bug: 129031195 Test: manual test Change-Id: Ia55e3ed91e92c3ec36ae6a9401897c5c960762da
This commit is contained in:
@@ -71,6 +71,15 @@
|
||||
android:entryValues="@array/wifi_privacy_values"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Add device Category -->
|
||||
<PreferenceCategory
|
||||
android:key="add_device_category" >
|
||||
<Preference
|
||||
android:key="add_device_to_network"
|
||||
android:title="@string/wifi_dpp_add_device"
|
||||
android:summary="@string/wifi_dpp_connect_network_using_qr_code"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Network Details -->
|
||||
<PreferenceCategory
|
||||
android:key="ip_details_category"
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.details;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
/**
|
||||
* {@link AbstractPreferenceController} that launches Wi-Fi Easy Connect configurator flow
|
||||
*/
|
||||
public class AddDevicePreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "AddDevicePreferenceController";
|
||||
|
||||
private static final String KEY_ADD_DEVICE_CATEGORY = "add_device_category";
|
||||
private static final String KEY_ADD_DEVICE = "add_device_to_network";
|
||||
|
||||
private AccessPoint mAccessPoint;
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
public AddDevicePreferenceController(Context context, AccessPoint accessPoint) {
|
||||
super(context, KEY_ADD_DEVICE_CATEGORY);
|
||||
|
||||
mAccessPoint = accessPoint;
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (WifiDppUtils.isSupportConfiguratorQrCodeScanner(mContext, mAccessPoint)) {
|
||||
return AVAILABLE;
|
||||
} else {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (KEY_ADD_DEVICE.equals(preference.getKey())) {
|
||||
WifiDppUtils.showLockScreen(mContext, () -> launchWifiDppConfiguratorQrCodeScanner());
|
||||
return true; /* click is handled */
|
||||
}
|
||||
|
||||
return false; /* click is not handled */
|
||||
}
|
||||
|
||||
private void launchWifiDppConfiguratorQrCodeScanner() {
|
||||
final Intent intent = WifiDppUtils.getConfiguratorQrCodeScannerIntentOrNull(mContext,
|
||||
mWifiManager, mAccessPoint);
|
||||
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "Launch Wi-Fi QR code scanner with a wrong Wi-Fi network!");
|
||||
} else {
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
@@ -342,7 +342,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
||||
.setButton3Text(R.string.share)
|
||||
.setButton3Icon(R.drawable.ic_qrcode_24dp)
|
||||
.setButton3OnClickListener(view -> shareNetwork())
|
||||
.setButton3Visible(WifiDppUtils.isSuportConfigurator(mContext, mAccessPoint));
|
||||
.setButton3Visible(WifiDppUtils.isSupportConfiguratorQrCodeGenerator(mAccessPoint));
|
||||
|
||||
mSignalStrengthPref = screen.findPreference(KEY_SIGNAL_STRENGTH_PREF);
|
||||
mTxLinkSpeedPref = screen.findPreference(KEY_TX_LINK_SPEED);
|
||||
@@ -757,11 +757,11 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
||||
* Show QR code to share the network represented by this preference.
|
||||
*/
|
||||
public void launchWifiDppConfiguratorActivity() {
|
||||
final Intent intent = WifiDppUtils.getConfiguratorIntentOrNull(mContext, mWifiManager,
|
||||
mAccessPoint);
|
||||
final Intent intent = WifiDppUtils.getConfiguratorQrCodeGeneratorIntentOrNull(mContext,
|
||||
mWifiManager, mAccessPoint);
|
||||
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "Launch Wi-Fi DPP configurator with a wrong Wi-Fi network!");
|
||||
Log.e(TAG, "Launch Wi-Fi DPP QR code generator with a wrong Wi-Fi network!");
|
||||
} else {
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
@@ -134,6 +134,7 @@ public class WifiNetworkDetailsFragment extends DashboardFragment {
|
||||
mMetricsFeatureProvider);
|
||||
|
||||
controllers.add(mWifiDetailPreferenceController);
|
||||
controllers.add(new AddDevicePreferenceController(context, mAccessPoint));
|
||||
controllers.add(new WifiMeteredPreferenceController(context, mAccessPoint.getConfig()));
|
||||
WifiPrivacyPreferenceController privacyController = new WifiPrivacyPreferenceController(
|
||||
context);
|
||||
|
@@ -95,34 +95,14 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
final WifiNetworkConfig wifiNetworkConfig = getWifiNetworkConfigFromHostActivity();
|
||||
MenuItem menuItem;
|
||||
if (!wifiNetworkConfig.isHotspot() &&
|
||||
wifiNetworkConfig.isSupportWifiDpp(getActivity())) {
|
||||
menuItem = menu.add(0, Menu.FIRST, 0, R.string.next_label);
|
||||
menuItem.setIcon(R.drawable.ic_scan_24dp);
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
} else {
|
||||
menuItem = menu.findItem(Menu.FIRST);
|
||||
if (menuItem != null) {
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
}
|
||||
final MenuItem menuItem = menu.findItem(Menu.FIRST);
|
||||
if (menuItem != null) {
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
}
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case Menu.FIRST:
|
||||
mListener.onQrCodeGeneratorFragmentAddButtonClicked();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@@ -165,9 +165,8 @@ public class WifiDppUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an intent to launch QR code generator or scanner according to the Wi-Fi network
|
||||
* security. It may return null if the security is not supported by QR code generator nor
|
||||
* scanner.
|
||||
* Returns an intent to launch QR code generator. It may return null if the security is not
|
||||
* supported by QR code generator.
|
||||
*
|
||||
* Do not use this method for Wi-Fi hotspot network, use
|
||||
* {@code getHotspotConfiguratorIntentOrNull} instead.
|
||||
@@ -177,12 +176,34 @@ public class WifiDppUtils {
|
||||
* @param accessPoint An instance of {@link AccessPoint}
|
||||
* @return Intent for launching QR code generator
|
||||
*/
|
||||
public static Intent getConfiguratorIntentOrNull(Context context,
|
||||
public static Intent getConfiguratorQrCodeGeneratorIntentOrNull(Context context,
|
||||
WifiManager wifiManager, AccessPoint accessPoint) {
|
||||
final Intent intent = new Intent(context, WifiDppConfiguratorActivity.class);
|
||||
if (isSupportConfiguratorQrCodeGenerator(accessPoint)) {
|
||||
intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
} else if (isSupportConfiguratorQrCodeScanner(context, accessPoint)) {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
final WifiConfiguration wifiConfiguration = accessPoint.getConfig();
|
||||
setConfiguratorIntentExtra(intent, wifiManager, wifiConfiguration);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an intent to launch QR code scanner. It may return null if the security is not
|
||||
* supported by QR code scanner.
|
||||
*
|
||||
* @param context The context to use for the content resolver
|
||||
* @param wifiManager An instance of {@link WifiManager}
|
||||
* @param accessPoint An instance of {@link AccessPoint}
|
||||
* @return Intent for launching QR code scanner
|
||||
*/
|
||||
public static Intent getConfiguratorQrCodeScannerIntentOrNull(Context context,
|
||||
WifiManager wifiManager, AccessPoint accessPoint) {
|
||||
final Intent intent = new Intent(context, WifiDppConfiguratorActivity.class);
|
||||
if (isSupportConfiguratorQrCodeScanner(context, accessPoint)) {
|
||||
intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
} else {
|
||||
return null;
|
||||
@@ -258,18 +279,6 @@ public class WifiDppUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Android Q supports Wi-Fi configurator by:
|
||||
*
|
||||
* 1. QR code generator of ZXing's Wi-Fi network config format.
|
||||
* and
|
||||
* 2. QR code scanner of Wi-Fi DPP QR code format.
|
||||
*/
|
||||
public static boolean isSuportConfigurator(Context context, AccessPoint accessPoint) {
|
||||
return isSupportConfiguratorQrCodeScanner(context, accessPoint) ||
|
||||
isSupportConfiguratorQrCodeGenerator(accessPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows authentication screen to confirm credentials (pin, pattern or password) for the current
|
||||
* user of the device.
|
||||
@@ -314,7 +323,7 @@ public class WifiDppUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSupportConfiguratorQrCodeScanner(Context context,
|
||||
public static boolean isSupportConfiguratorQrCodeScanner(Context context,
|
||||
AccessPoint accessPoint) {
|
||||
if (!isWifiDppEnabled(context)) {
|
||||
return false;
|
||||
@@ -329,7 +338,7 @@ public class WifiDppUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSupportConfiguratorQrCodeGenerator(AccessPoint accessPoint) {
|
||||
public static boolean isSupportConfiguratorQrCodeGenerator(AccessPoint accessPoint) {
|
||||
// QR code generator produces QR code with ZXing's Wi-Fi network config format,
|
||||
// it supports PSK and WEP and non security
|
||||
final int security = accessPoint.getSecurity();
|
||||
|
Reference in New Issue
Block a user