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

Commit bcf05137 authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Fix flaky onReceiveTimeoutIntent_finishesActivity

Bug: 309032407
Test: atest BluetoothPbapActivityTest --rerun-until-failure 50
Change-Id: I557f2e15d7669d2ef44f43e129e88ff7d4e54655
parent ee79690a
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.bluetooth.BluetoothMethodProxy;
import com.android.bluetooth.R;
import com.android.internal.annotations.VisibleForTesting;

@@ -87,9 +88,9 @@ public class BluetoothPbapActivity extends AlertActivity

    private boolean mTimeout = false;

    private static final int DISMISS_TIMEOUT_DIALOG = 0;
    @VisibleForTesting static final int DISMISS_TIMEOUT_DIALOG = 0;

    private static final int DISMISS_TIMEOUT_DIALOG_VALUE = 2000;
    @VisibleForTesting static final long DISMISS_TIMEOUT_DIALOG_DELAY_MS = 2_000;

    private BluetoothDevice mDevice;

@@ -218,8 +219,9 @@ public class BluetoothPbapActivity extends AlertActivity
            changeButtonVisibility(DialogInterface.BUTTON_NEGATIVE, View.GONE);
        }

        mTimeoutHandler.sendMessageDelayed(mTimeoutHandler.obtainMessage(DISMISS_TIMEOUT_DIALOG),
                DISMISS_TIMEOUT_DIALOG_VALUE);
        BluetoothMethodProxy.getInstance()
                .handlerSendMessageDelayed(
                        mTimeoutHandler, DISMISS_TIMEOUT_DIALOG, DISMISS_TIMEOUT_DIALOG_DELAY_MS);
    }

    @Override
+19 −2
Original line number Diff line number Diff line
@@ -24,9 +24,16 @@ import static android.content.pm.PackageManager.DONT_KILL_APP;
import static androidx.lifecycle.Lifecycle.State;
import static androidx.lifecycle.Lifecycle.State.DESTROYED;

import static com.android.bluetooth.pbap.BluetoothPbapActivity.DISMISS_TIMEOUT_DIALOG;
import static com.android.bluetooth.pbap.BluetoothPbapActivity.DISMISS_TIMEOUT_DIALOG_DELAY_MS;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -38,6 +45,8 @@ import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.BluetoothMethodProxy;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -54,8 +63,13 @@ public class BluetoothPbapActivityTest {

    ActivityScenario<BluetoothPbapActivity> mActivityScenario;

    BluetoothMethodProxy mMethodProxy;

    @Before
    public void setUp() {
        mMethodProxy = spy(BluetoothMethodProxy.getInstance());
        BluetoothMethodProxy.setInstanceForTesting(mMethodProxy);

        mIntent = new Intent();
        mIntent.setClass(mTargetContext, BluetoothPbapActivity.class);
        mIntent.setAction(BluetoothPbapService.AUTH_CHALL_ACTION);
@@ -72,6 +86,7 @@ public class BluetoothPbapActivityTest {
            mActivityScenario.close();
        }
        enableActivity(false);
        BluetoothMethodProxy.setInstanceForTesting(null);
    }

    @Test
@@ -121,14 +136,16 @@ public class BluetoothPbapActivityTest {
    }

    @Test
    public void onReceiveTimeoutIntent_finishesActivity() throws Exception {
    public void onReceiveTimeoutIntent_sendsDismissDialogMessage() throws Exception {
        Intent intent = new Intent(BluetoothPbapService.USER_CONFIRM_TIMEOUT_ACTION);

        mActivityScenario.onActivity(activity -> {
            activity.mReceiver.onReceive(activity, intent);
        });

        assertActivityState(DESTROYED);
        verify(mMethodProxy)
                .handlerSendMessageDelayed(
                        any(), eq(DISMISS_TIMEOUT_DIALOG), eq(DISMISS_TIMEOUT_DIALOG_DELAY_MS));
    }

    @Test