From a6861564b5258fd54cc059e0ae1cdc69b0409128 Mon Sep 17 00:00:00 2001 From: Weng Su Date: Thu, 15 Aug 2024 06:51:32 +0800 Subject: [PATCH] Avoid launching details settings after WifiEntry is forgotten - Don't launch details settings if WifiEntry isn't saved Bug: 359584817 Flag: EXEMPT bugfix Test: Manual testing atest -c NetworkProviderSettingsTest Change-Id: Iff1c37b64adef6d136d2aaa6a0a946c22af38193 --- .../settings/network/NetworkProviderSettings.java | 4 ++++ .../settings/network/NetworkProviderSettingsTest.java | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java index 0fcfcb515a1..e2406826320 100644 --- a/src/com/android/settings/network/NetworkProviderSettings.java +++ b/src/com/android/settings/network/NetworkProviderSettings.java @@ -1068,6 +1068,10 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment @VisibleForTesting void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) { final WifiEntry wifiEntry = pref.getWifiEntry(); + if (!wifiEntry.isSaved()) { + Log.w(TAG, "launchNetworkDetailsFragment: Don't launch because WifiEntry isn't saved!"); + return; + } final Context context = requireContext(); final Bundle bundle = new Bundle(); diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java index 01611788e49..59021a78cda 100644 --- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java +++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java @@ -872,6 +872,17 @@ public class NetworkProviderSettingsTest { verify(mWifiEntry, never()).getKey(); } + @Test + public void launchNetworkDetailsFragment_wifiEntryIsNotSaved_ignoreWifiEntry() { + when(mWifiEntry.isSaved()).thenReturn(false); + LongPressWifiEntryPreference preference = + mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry); + + mNetworkProviderSettings.launchNetworkDetailsFragment(preference); + + verify(mWifiEntry, never()).getKey(); + } + @Implements(PreferenceFragmentCompat.class) public static class ShadowPreferenceFragmentCompat {