From 1a716842e8cd95b4fc5ada2b284c576a3fb27d1d Mon Sep 17 00:00:00 2001 From: Quang Luong Date: Fri, 15 Jul 2022 03:22:27 +0000 Subject: Do not kill WifiDialog process if there are activities remaining There may be edge cases where WifiDialogActivity finishes and a new dialog is requested immediately. In this case, the new dialog request starts a new WifiDialogActivity since the first one is finishing. However, once the first activity calls onDestroy(), we end up killing the entire Process which kills the second activity. Instead, we should check if there are any other activity instances before calling killing the process. Bug: 236803960 Test: Enable iface conflict dialog, turn on STA + AP, go to P2P settings and reject the dialog. Verify the second dialog pops up immediately and the process is not killed. Verify accepting the second dialog kills the process. Change-Id: I19ffebdc1b7285b67dd0b4ca825dd27fac945e2b --- .../com/android/wifi/dialog/WifiDialogActivity.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'WifiDialog/src') diff --git a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java index 49824da5fa..734fbd9522 100644 --- a/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java +++ b/WifiDialog/src/com/android/wifi/dialog/WifiDialogActivity.java @@ -65,6 +65,8 @@ import java.util.Set; * Main Activity of the WifiDialog application. All dialogs should be created and managed from here. */ public class WifiDialogActivity extends Activity { + private static int sNumActiveInstances = 0; + private static final String TAG = "WifiDialog"; private static final String KEY_DIALOG_INTENTS = "KEY_DIALOG_INTENTS"; @@ -194,6 +196,10 @@ public class WifiDialogActivity extends Activity { @Override protected void onStart() { super.onStart(); + sNumActiveInstances++; + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "onStart() incrementing sActiveInstances to " + sNumActiveInstances); + } registerReceiver( mCloseSystemDialogsReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); ArraySet invalidDialogIds = new ArraySet<>(); @@ -237,6 +243,10 @@ public class WifiDialogActivity extends Activity { @Override protected void onStop() { super.onStop(); + sNumActiveInstances--; + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "onStop() decrementing sActiveInstances to " + sNumActiveInstances); + } unregisterReceiver(mCloseSystemDialogsReceiver); if (isChangingConfigurations()) { @@ -296,7 +306,15 @@ public class WifiDialogActivity extends Activity { protected void onDestroy() { super.onDestroy(); if (isFinishing()) { - // Kill the process now instead of waiting indefinitely for ActivityManager to kill it. + if (sNumActiveInstances > 0) { + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "Finished with sNumActiveInstances: " + sNumActiveInstances); + } + return; + } + if (mIsVerboseLoggingEnabled) { + Log.v(TAG, "Finished with no active instances left. Killing process."); + } Process.killProcess(android.os.Process.myPid()); } } -- cgit v1.2.3-59-g8ed1b