From b53cdf09ddd04b098b949cec4f6bce661f8587cd Mon Sep 17 00:00:00 2001 From: tmfang Date: Thu, 16 Aug 2018 14:20:29 +0800 Subject: [PATCH 1/2] Fix bug about Wi-Fi dialog rotation When user clicks a Wi-Fi access point in WifiSettings, screen pops up a Wi-Fi point dialog. And then user rotates the screen, Wi-Fi access dialog changes to "Add network" full screen dialog. In old code, we check whether dialog is showing by dialog.isShowing() in onSaveInstanceState. For now, this design is not appropriate. Since isShowing() won't return true anymore when fragment calls onSaveInstanceState. So, we check dialog object whether is null or not now. If dialog is null, it means that there is no dialog was shown, before user rotates the screen. Change-Id: I7dc26369c005f576fe679abc70327f6a02620935 Fixes: 112624846 Test: manual test, robo test --- .../android/settings/wifi/WifiSettings.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 10111aa7204..877c70e909b 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -24,6 +24,7 @@ import android.app.Activity; import android.app.Dialog; import android.content.ContentResolver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.net.ConnectivityManager; @@ -87,7 +88,7 @@ import java.util.List; @SearchIndexable public class WifiSettings extends RestrictedSettingsFragment implements Indexable, WifiTracker.WifiListener, AccessPointListener, - WifiDialog.WifiDialogListener { + WifiDialog.WifiDialogListener, DialogInterface.OnDismissListener { private static final String TAG = "WifiSettings"; @@ -432,9 +433,8 @@ public class WifiSettings extends RestrictedSettingsFragment @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - - // If the dialog is showing, save its state. - if (mDialog != null && mDialog.isShowing()) { + // If dialog has been shown, save its state. + if (mDialog != null) { outState.putInt(SAVE_DIALOG_MODE, mDialogMode); if (mDlgAccessPoint != null) { mAccessPointSavedState = new Bundle(); @@ -623,6 +623,18 @@ public class WifiSettings extends RestrictedSettingsFragment return super.onCreateDialog(dialogId); } + @Override + public void onDialogShowing() { + super.onDialogShowing(); + setOnDismissListener(this); + } + + @Override + public void onDismiss(DialogInterface dialog) { + // We don't keep any dialog object when dialog was dismissed. + mDialog = null; + } + @Override public int getDialogMetricsCategory(int dialogId) { switch (dialogId) { From 5f7c991162190b9a038b2126d5bf4148595494dc Mon Sep 17 00:00:00 2001 From: tmfang Date: Fri, 17 Aug 2018 15:16:12 +0800 Subject: [PATCH 2/2] Fix crash on "Set up Wi-Fi NFC tag" dialog When user launches "Set up Wi-Fi NFC tag" dialog and then tries to rotate screen, device will crash. Because isShowing() of dialog won't return true anymore when fragment calls onSaveIntance(), we can't save status of dialog successfully. And then, when fragment called onCreateDialog() again, it can't get any dialog object. So, we only check dialog whether is null or not. If dialog is null, it means that there is no dialog was shown before user rotates the screen. Fixes: 112741721 Test: NFC tag wifi test, robo test Change-Id: Idb448ea32c4215d8380c69bfd896cc91d8c1f8d1 --- src/com/android/settings/wifi/WifiSettings.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 877c70e909b..9e2fac32646 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -443,7 +443,7 @@ public class WifiSettings extends RestrictedSettingsFragment } } - if (mWifiToNfcDialog != null && mWifiToNfcDialog.isShowing()) { + if (mWifiToNfcDialog != null) { Bundle savedState = new Bundle(); mWifiToNfcDialog.saveState(savedState); outState.putBundle(SAVED_WIFI_NFC_DIALOG_STATE, savedState); @@ -617,7 +617,6 @@ public class WifiSettings extends RestrictedSettingsFragment mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(getActivity(), mWifiNfcDialogSavedState); } - return mWifiToNfcDialog; } return super.onCreateDialog(dialogId); @@ -633,6 +632,7 @@ public class WifiSettings extends RestrictedSettingsFragment public void onDismiss(DialogInterface dialog) { // We don't keep any dialog object when dialog was dismissed. mDialog = null; + mWifiToNfcDialog = null; } @Override