summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-11-15 07:57:20 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-11-15 07:57:20 +0000
commitf900cb78021c9169c4212a3f2debc496f9abf68e (patch)
treeb7cfd8c342281ffe7d7e40e8ab5751832420117e
parentdf834d67ed293a54c5ee706f0ea62ca3d81003b8 (diff)
parentbcf05137fdc08410d11e8914aadcae3ee528442c (diff)
Merge "Fix flaky onReceiveTimeoutIntent_finishesActivity" into main
-rw-r--r--android/app/src/com/android/bluetooth/pbap/BluetoothPbapActivity.java10
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapActivityTest.java21
2 files changed, 25 insertions, 6 deletions
diff --git a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapActivity.java b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapActivity.java
index e8cbe3fd51..6e3f253731 100644
--- a/android/app/src/com/android/bluetooth/pbap/BluetoothPbapActivity.java
+++ b/android/app/src/com/android/bluetooth/pbap/BluetoothPbapActivity.java
@@ -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
diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapActivityTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapActivityTest.java
index be0d8dedd0..ce3f02f63c 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapActivityTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/pbap/BluetoothPbapActivityTest.java
@@ -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