Make more system dialogs could receive CLOSE_SYSTEM_DIALOGS

Currently, we only dismiss AppErroDialog when received
CLOSE_SYSTEM_DIALOGS boradcast. This CL will dismiss all other error
dialogs such as anr dialog to prevent our test cases injecting input
events on such dialog.

- Ignore AppWaitingForDebuggerDialog and FactoryErrorDialog

Bug: 175797415
Test: Show ANR dialog, atest WindowInputTests
Change-Id: I7eac4bbb4a325d50005636a18c211b6e16dd0773
This commit is contained in:
arthurhung
2021-02-20 13:57:20 +08:00
parent 879a3ba6db
commit f4018d5377
6 changed files with 54 additions and 27 deletions

View File

@@ -18,10 +18,7 @@ package com.android.server.am;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
@@ -138,19 +135,6 @@ final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListen
findViewById(com.android.internal.R.id.customPanel).setVisibility(View.VISIBLE);
}
@Override
public void onStart() {
super.onStart();
getContext().registerReceiver(mReceiver,
new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
@Override
protected void onStop() {
super.onStop();
getContext().unregisterReceiver(mReceiver);
}
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
setResult(msg.what);
@@ -204,15 +188,6 @@ final class AppErrorDialog extends BaseErrorDialog implements View.OnClickListen
}
}
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
cancel();
}
}
};
static class Data {
AppErrorResult result;
int taskId;

View File

@@ -181,6 +181,11 @@ final class AppNotRespondingDialog extends BaseErrorDialog implements View.OnCli
}
};
@Override
protected void closeDialog() {
mHandler.obtainMessage(FORCE_CLOSE).sendToTarget();
}
static class Data {
final ProcessRecord proc;
final ApplicationInfo aInfo;

View File

@@ -61,6 +61,11 @@ final class AppWaitingForDebuggerDialog extends BaseErrorDialog {
public void onStop() {
}
@Override
protected void closeDialog() {
/* Do nothing */
}
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {

View File

@@ -16,16 +16,19 @@
package com.android.server.am;
import com.android.internal.R;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.Button;
import com.android.internal.R;
public class BaseErrorDialog extends AlertDialog {
private static final int ENABLE_BUTTONS = 0;
private static final int DISABLE_BUTTONS = 1;
@@ -44,10 +47,19 @@ public class BaseErrorDialog extends AlertDialog {
getWindow().setAttributes(attrs);
}
@Override
public void onStart() {
super.onStart();
mHandler.sendEmptyMessage(DISABLE_BUTTONS);
mHandler.sendMessageDelayed(mHandler.obtainMessage(ENABLE_BUTTONS), 1000);
getContext().registerReceiver(mReceiver,
new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
@Override
protected void onStop() {
super.onStop();
getContext().unregisterReceiver(mReceiver);
}
public boolean dispatchKeyEvent(KeyEvent event) {
@@ -84,4 +96,24 @@ public class BaseErrorDialog extends AlertDialog {
}
}
};
/**
* Called when received ACTION_CLOSE_SYSTEM_DIALOGS.
*/
protected void closeDialog() {
if (mCancelable) {
cancel();
} else {
dismiss();
}
}
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
closeDialog();
}
}
};
}

View File

@@ -82,6 +82,11 @@ final class StrictModeViolationDialog extends BaseErrorDialog {
DISMISS_TIMEOUT);
}
@Override
protected void closeDialog() {
mHandler.obtainMessage(ACTION_OK).sendToTarget();
}
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
synchronized (mService.mProcLock) {

View File

@@ -41,6 +41,11 @@ final class FactoryErrorDialog extends BaseErrorDialog {
public void onStop() {
}
@Override
protected void closeDialog() {
/* Do nothing */
}
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
throw new RuntimeException("Rebooting from failed factory test");