Firebase emulator tests fails when recording audio

Issue

Audio recording is working perfectly fine on physical devices, however, 15-20%(1 out of 5) firebase emulator tests fail. The only information we know is this is a native crash. Can someone enlighten me?

  • We have permissions, don’t worry about them

We use something like this to press and hold the record button and release it after 5 seconds

onView(withId(R.id.sound_button)).perform(pressAndHold());
waitforSec(5);
onView(withId(R.id.sound_button)).perform(release());


static class PressAndHoldAction implements ViewAction {
            @Override
            public Matcher<View> getConstraints() {
                return isDisplayingAtLeast(90); // Like GeneralClickAction
            }

            @Override
            public String getDescription() {
                return "Press and hold action";
            }

            @Override
            public void perform(final UiController uiController, final View view) {
                if (sMotionEventDownHeldView ! null) {
                    throw new AssertionError("Only one view can be held at a time");
                }

                float[] precision  Press.FINGER.describePrecision();
                float[] coords  GeneralLocation.CENTER.calculateCoordinates(view);
                sMotionEventDownHeldView  MotionEvents.sendDown(uiController, coords, precision).down;
                // save view information and make sure release() is on same view
            }
        }

And release the button with this

static class ReleaseAction implements ViewAction {
            @Override
            public Matcher<View> getConstraints() {
                return isDisplayingAtLeast(90);  // Like GeneralClickAction
            }

            @Override
            public String getDescription() {
                return "Release action";
            }

            @Override
            public void perform(final UiController uiController, final View view) {
                if (sMotionEventDownHeldView  null) {
                    throw new AssertionError("Before calling release(), you must call pressAndHold() on a view");
                }

                float[] coords  GeneralLocation.CENTER.calculateCoordinates(view);
                MotionEvents.sendUp(uiController, sMotionEventDownHeldView, coords);
                sMotionEventDownHeldView  null;
            }
        }

Firebase Log

Native crash
Native crash of /system/bin/mediaserver

Build fingerprint: 'generic/gce_x86_phone/gce_x86:8.1.0/OGM1.181114.001/5131284:userdebug/test-keys'
Revision: '0'
ABI: 'x86'
pid: 1542, tid: 17551, name: AudioRecord  >>> /system/bin/mediaserver <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
    eax 00000000  ebx 00000606  ecx 0000448f  edx 00000006
    esi 0000001e  edi 00000606
    xcs 00000023  xds 0000002b  xes 0000002b  xfs 00000003  xss 0000002b
    eip ef7e7d10  ebp 00006472  esp e8e055d8  flags 00000296
backtrace:
    #00 pc 00000d10  [vdso:ef7e7000] (__kernel_vsyscall+16)
    #01 pc 0001edf8  /system/lib/libc.so (syscall+40)
    #02 pc 0001f013  /system/lib/libc.so (abort+115)
    #03 pc 000ddf33  /system/lib/libstagefright.so (android::AudioSource::dataCallback(android::AudioRecord::Buffer const&)+2339)
    #04 pc 000dd5a4  /system/lib/libstagefright.so (_ZN7androidL27AudioRecordCallbackFunctionEiPvS0_.cfi+84)
    #05 pc 00031a50  /system/lib/libaudioclient.so (android::AudioRecord::processAudioBuffer()+1312)
    #06 pc 00032656  /system/lib/libaudioclient.so (android::AudioRecord::AudioRecordThread::threadLoop()+214)
    #07 pc 000103be  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+222)
    #08 pc 0000fd86  /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+246)
    #09 pc 000713e5  /system/lib/libc.so (__pthread_start(void*)+53)
    #10 pc 0002057b  /system/lib/libc.so (__start_thread+75)
    #11 pc 0001ec16  /system/lib/libc.so (__bionic_clone+70)


androidx.test.espresso.AppNotIdleException: Looped for 2219 iterations over 60 SECONDS. The following Idle Conditions failed .

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1538)
at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:88)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:51)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:173)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:114)
at com.package_name.utils.TestMethods.sendAudioMessage(TestMethods.java:643)
at com.package_name.firebase.LoginMessageTest.mainTest(LoginMessageTest.java:81)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075)

TestMethods.java — Line: 643

onView(withId(R.id.sound_button)).perform(release());

Solution

Finally figured it out, after 5 painful days!

The problem is Audio Sampling Rate and Encoding Bit Rate.

When initializing MediaRecorder object (before start)

Emulator

audioRecorder.setAudioSamplingRate(8000);
audioRecorder.setAudioEncodingBitRate(32000);

Device

audioRecorder.setAudioSamplingRate(44100);
audioRecorder.setAudioEncodingBitRate(96000);

Answered By – Deniz

Leave a Comment