Loading res/xml/wifi_network_details_fragment.xml +9 −0 Original line number Diff line number Diff line Loading @@ -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" Loading src/com/android/settings/wifi/details/AddDevicePreferenceController.java 0 → 100644 +80 −0 Original line number Diff line number Diff line /* * 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); } } } src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); } Loading src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -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); Loading src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java +3 −23 Original line number Diff line number Diff line Loading @@ -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); 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) { Loading Loading
res/xml/wifi_network_details_fragment.xml +9 −0 Original line number Diff line number Diff line Loading @@ -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" Loading
src/com/android/settings/wifi/details/AddDevicePreferenceController.java 0 → 100644 +80 −0 Original line number Diff line number Diff line /* * 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); } } }
src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +4 −4 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); } Loading
src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
src/com/android/settings/wifi/dpp/WifiDppQrCodeGeneratorFragment.java +3 −23 Original line number Diff line number Diff line Loading @@ -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); 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) { Loading