Search code examples
androidreact-nativeandroid-permissionsmediarecorderandroid-audiorecord

Audio recording silenced upon Play Store app installation


I am using library for screen video and audio recording in my react native app. I run into an issue where also maintainer has no clue what is going on.

Library: HBRecorder Issue : HBRecorder Android related issue

During the installation of a different application from the Play Store, an issue arises where audio recording functionality becomes silenced. There could be a audio permission conflict that causes the audio to stop working.

LOG:

2023-08-29 11:53:46.811 1246-15535 QC2C2DEngine media.hwcodec I calcYSize: unsupported or RGB color format, RGBA8888(1)
2023-08-29 11:53:46.828 1246-15535 QC2C2DEngine media.hwcodec I calcYSize: unsupported or RGB color format, RGBA8888(1)
2023-08-29 11:53:46.840 1225-8088 sensors-hal [email protected] I handle_sns_std_sensor_event:231, [SSC_LIGHT] P: 43(43),als:169,green:36,ir:4,delta_avg:0,delta_max:94,stdev:0,stdev_per_4sample:1,magig_code or itime:384
2023-08-29 11:53:46.844 1246-15535 QC2C2DEngine media.hwcodec I calcYSize: unsupported or RGB color format, RGBA8888(1)

**2023-08-29 11:53:46.844 1505-7216 AppOps system_server E evalMode() Foreground Record OP returned IGNORE, uid - 10980, capability - 8
2023-08-29 11:53:46.845 1291-1751 AudioPolicyService audioserver I App op 27 missing, silencing record AttributionSourceState{pid: 15457, uid: 10980, packageName: com.hbisoft.hbrecorderexample, attributionTag: (null), token: {no toString() implemented}, renouncedPermissions: [], next: []}
**
2023-08-29 11:53:46.862 1246-15535 QC2C2DEngine media.hwcodec I calcYSize: unsupported or RGB color format, RGBA8888(1)
2023-08-29 11:53:46.868 3282-4415 ViewRootIm...orOverlay] com.android.systemui I dispatchDetachedFromWindow
2023-08-29 11:53:46.871 1505-7260 InputManager-JNI system_server W Input channel object '1e63692 ScreenDecorOverlay (client)' was disposed without first being removed with the input manager!
2023-08-29 11:53:46.873 1505-7260 WindowManager system_server I Destroying surface Surface(name=ScreenDecorOverlay$_3282)/@0x6b21ba2 called by com.android.server.wm.WindowStateAnimator.destroySurface:942 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:536 com.android.server.wm.WindowState.removeImmediately:2969 com.android.server.wm.WindowState.removeIfPossible:3227 com.android.server.wm.WindowState.removeIfPossible:3040 com.android.server.wm.WindowManagerService.removeWindow:2282 com.android.server.wm.Session.remove:236 android.view.IWindowSession$Stub.onTransact:743
2023-08-29 11:53:46.875 1505-1607 Looper system_server W Drained

Device Info:

Samsung A52s (SM-A528B) SDK version : 33 Android version: 13

AndoridManifest.xml permissions :

  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
  <uses-permission android:name="android.permission.VIBRATE"/>
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
  <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
  <uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Problem occurs with the demo of the library usage and also in implementation of the library. Goal is (if the permission it taken) that we get some kind of notification or screen recording is stopped (since video recording still runs but audio is lost) or we keep the audio somehow permission exclusive to our app.


Solution

  • Tell me if I'm wrong but you only have this bug since device Android R (API 30, android 11).

    According to the Android documentation, you must start foreground services with a foreground service type.

    To address this, make sure you have the correct permission declared in your manifest file:

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

    Don't forget to request user for RECORD_AUDIO permission.

    Then, when starting the foreground service, specify the service type:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
        startForeground(notificationId, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE)
    

    You can find a full code example here.