OSDN Git Service

Fix bug about Wi-Fi dialog rotation
authortmfang <tmfang@google.com>
Thu, 16 Aug 2018 06:20:29 +0000 (14:20 +0800)
committertmfang <tmfang@google.com>
Fri, 17 Aug 2018 06:09:02 +0000 (14:09 +0800)
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

src/com/android/settings/wifi/WifiSettings.java

index 10111aa..877c70e 100644 (file)
@@ -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();
@@ -624,6 +624,18 @@ public class WifiSettings extends RestrictedSettingsFragment
     }
 
     @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) {
             case WIFI_DIALOG_ID: