From 8a9ccfd8d99a59bb98dd25ac0034e335d2c8fb3c Mon Sep 17 00:00:00 2001 From: Arc Wang Date: Thu, 21 Mar 2019 16:52:20 +0800 Subject: [PATCH] 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 --- res/xml/wifi_network_details_fragment.xml | 9 +++ .../details/AddDevicePreferenceController.java | 80 ++++++++++++++++++++++ .../details/WifiDetailPreferenceController.java | 8 +-- .../wifi/details/WifiNetworkDetailsFragment.java | 1 + .../wifi/dpp/WifiDppQrCodeGeneratorFragment.java | 26 +------ .../android/settings/wifi/dpp/WifiDppUtils.java | 47 ++++++++----- 6 files changed, 125 insertions(+), 46 deletions(-) create mode 100644 src/com/android/settings/wifi/details/AddDevicePreferenceController.java diff --git a/res/xml/wifi_network_details_fragment.xml b/res/xml/wifi_network_details_fragment.xml index 8979efc4b9..782a7cffed 100644 --- a/res/xml/wifi_network_details_fragment.xml +++ b/res/xml/wifi_network_details_fragment.xml @@ -71,6 +71,15 @@ android:entryValues="@array/wifi_privacy_values"/> + + + + + 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); + } + } +} diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java index cf59dbd877..5fc350bbc1 100644 --- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java @@ -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); } diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java index 66587edb54..35cc075f23 100644 --- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java +++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java @@ -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); diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java index 4e6a0d6879..d388931407 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java +++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java @@ -95,35 +95,15 @@ 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) { return inflater.inflate(R.layout.wifi_dpp_qrcode_generator_fragment, container, diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java index bf78b3f1a2..6c6444c7d9 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java +++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java @@ -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; @@ -259,18 +280,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(); -- 2.11.0