Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7e447b4 authored by Arthur Hung's avatar Arthur Hung Committed by Android (Google) Code Review
Browse files

Merge "Prevent crash when unregsiter the broadcast" into tm-dev

parents c49fa4a7 33a01ec1
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -58,9 +58,6 @@ final class AppWaitingForDebuggerDialog extends BaseErrorDialog {
        getWindow().setAttributes(attrs);
    }

    public void onStop() {
    }

    @Override
    protected void closeDialog() {
        /* Do nothing */
+25 −12
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.am;

import static android.content.Context.RECEIVER_EXPORTED;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -34,6 +36,7 @@ public class BaseErrorDialog extends AlertDialog {
    private static final int DISABLE_BUTTONS = 1;

    private boolean mConsuming = true;
    private BroadcastReceiver mReceiver;

    public BaseErrorDialog(Context context) {
        super(context, com.android.internal.R.style.Theme_DeviceDefault_Dialog_AppError);
@@ -52,14 +55,33 @@ public class BaseErrorDialog extends AlertDialog {
        super.onStart();
        mHandler.sendEmptyMessage(DISABLE_BUTTONS);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(ENABLE_BUTTONS), 1000);
        if (mReceiver == null) {
            mReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
                        closeDialog();
                    }
                }
            };
            getContext().registerReceiver(mReceiver,
                new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), Context.RECEIVER_EXPORTED);
                    new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), RECEIVER_EXPORTED);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mReceiver != null) {
            try {
                getContext().unregisterReceiver(mReceiver);
            } catch (IllegalArgumentException e) {
                // Receiver not registered exception.
                android.util.Slog.e("BaseErrorDialog",
                        "unregisterReceiver threw exception: " + e.getMessage());
            }
            mReceiver = null;
        }
    }

    public boolean dispatchKeyEvent(KeyEvent event) {
@@ -107,13 +129,4 @@ public class BaseErrorDialog extends AlertDialog {
            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();
            }
        }
    };
}
+0 −3
Original line number Diff line number Diff line
@@ -38,9 +38,6 @@ final class FactoryErrorDialog extends BaseErrorDialog {
        getWindow().setAttributes(attrs);
    }

    public void onStop() {
    }

    @Override
    protected void closeDialog() {
        /* Do nothing */