Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio capture does not work on OnePlus 6T (Android 11) *not on the main user* #4153

Closed
2 tasks done
axxapy opened this issue Jul 9, 2023 · 4 comments
Closed
2 tasks done

Comments

@axxapy
Copy link

axxapy commented Jul 9, 2023

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Linux (arch btw)
  • scrcpy version: 2.1
  • installation method: aur package
  • device model: OnePlus 6T
  • Android version: 11

Describe the bug
Audio capture fails with following error

WARN: Demuxer 'audio': stream explicitly disabled by the device

Looks similar to #4015 as startRecording method also seem to be modified:

    public void startRecording() throws IllegalStateException {
        if (OpFeatures.isSupport(11)) {
            try {
                Context context = ActivityThread.currentApplication().getApplicationContext();
                String pkgName = context.getApplicationContext().getApplicationInfo().packageName;
                boolean rejectPerm = PermissionInjector.rejectPerm(context, Manifest.permission.RECORD_AUDIO);
                this.mIsPermRejected = rejectPerm;
                if (rejectPerm && !PermissionInjector.isSpecialHandleForRecordAudio(pkgName)) {
                    throw new IllegalStateException("permission denied");
                }
            } catch (NullPointerException e) {
                Log.e(TAG, "request permission RECORD_AUDIO fail");
                e.printStackTrace();
            }
        }
        SeempLog.record(70);
        if (this.mState != 1) {
            throw new IllegalStateException("startRecording() called on an uninitialized AudioRecord.");
        }
        synchronized (this.mRecordingStateLock) {
            if (native_start(0, 0) == 0) {
                handleFullVolumeRec(true);
                this.mRecordingState = 3;
                OpMediaInjector.noteStartAudio(Process.myUid(), Process.myPid());
            }
        }
    }

My framework.jar: framework.jar.zip

scrcpy -Vverbose output:

 scrcpy -Vverbose
scrcpy 2.1 <https://github.com/Genymobile/scrcpy>
DEBUG: ADB device found:
DEBUG:     -->   (usb)  6afg341a                        device  ONEPLUS_A6013
DEBUG: Device serial: 6afg341a
DEBUG: Using server: /usr/share/scrcpy/scrcpy-server
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 508.8 MB/s (56955 bytes in 0.000s)
[server] INFO: Device: [OnePlus] OnePlus ONEPLUS A6013 (Android 11)
DEBUG: Server connected
DEBUG: Starting controller thread
DEBUG: Starting receiver thread
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 23.1.2
INFO: Trilinear filtering enabled
DEBUG: Using icon: /usr/share/icons/hicolor/256x256/apps/scrcpy.png
DEBUG: Demuxer 'video': starting thread
DEBUG: Demuxer 'audio': starting thread
[server] DEBUG: Using video encoder: 'OMX.qcom.video.encoder.avc'
INFO: Texture: 1080x2336
[server] DEBUG: Using audio encoder: 'c2.android.opus.encoder'
[server] DEBUG: Failed to start audio capture, retrying...
[server] DEBUG: Failed to start audio capture, retrying...
[server] ERROR: Failed to start audio capture
[server] ERROR: On Android 11, audio capture must be started in the foreground, make sure that the device is unlocked when starting scrcpy.
WARN: Demuxer 'audio': stream explicitly disabled by the device
[server] DEBUG: Audio encoder stopped
VERBOSE: input: key down code=59 repeat=0 meta=200041

@axxapy axxapy changed the title Audio capture does not work on OnePlus 6T (Android 11) Audio capture does not work on OnePlus 6T (Android 11) *not on the main user* Jul 9, 2023
@axxapy
Copy link
Author

axxapy commented Jul 9, 2023

Update

Checked logcat and it seems that audio recording is not allowed only for non-main user.

If I switch to the main user, audio works fine

AudioPolicyIntefaceImpl: getInputForAttr permission denied: recording not allowed for uid 2000 pid 4206

full log:

07-09 08:43:12.115  4206  4255 I AudioRecord: set(): inputSource 8, sampleRate 48000, format 0x1, channelMask 0xc, frameCount 15360, notificationFrames 0, sessionId 0, transferType 0, flags 0, opPackageName com.android.shell uid -1, pid -1
07-09 08:43:12.119  1150 31382 E ServiceUtilities: Request denied by app op: 27
07-09 08:43:12.119  1150 31382 E AudioPolicyIntefaceImpl: getInputForAttr permission denied: recording not allowed for uid 2000 pid 4206
07-09 08:43:12.119  1150 31382 E AudioFlinger: createRecord() getInputForAttr return error -1
07-09 08:43:12.119  4206  4255 E IAudioFlinger: createRecord returned error -1
07-09 08:43:12.119  4206  4255 E AudioRecord: createRecord_l(0): AudioFlinger could not create record track, status: -1
07-09 08:43:12.119  4206  4255 E AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
07-09 08:43:12.119  4206  4255 E android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
07-09 08:43:12.146   601   601 I hwservicemanager: getTransport: Cannot find entry [email protected]::IMapper/default in either framework or device manifest.
07-09 08:43:12.146  4838  4329 I Gralloc4: mapper 4.x is not supported
07-09 08:43:12.146   601   601 I hwservicemanager: getTransport: Cannot find entry [email protected]::IMapper/default in either framework or device manifest.
07-09 08:43:12.147  4838  4329 W Gralloc3: mapper 3.x is not supported
07-09 08:43:12.207   600   600 E SELinux : avc:  denied  { find } for pid=9297 uid=1010394 name=tethering scontext=u:r:permissioncontroller_app:s0:c138,c257,c522,c768 tcontext=u:object_r:tethering_service:s0 tclass=service_manager permissive=0
07-09 08:43:12.207   600   600 E SELinux : avc:  denied  { find } for pid=4638 uid=10495 name=tethering scontext=u:r:vendor_systemhelper_app:s0:c512,c768 tcontext=u:object_r:tethering_service:s0 tclass=service_manager permissive=0
07-09 08:43:12.220  4206  4255 I AudioRecord: set(): inputSource 8, sampleRate 48000, format 0x1, channelMask 0xc, frameCount 15360, notificationFrames 0, sessionId 0, transferType 0, flags 0, opPackageName com.android.shell uid -1, pid -1
07-09 08:43:12.222  1150 31382 E ServiceUtilities: Request denied by app op: 27
07-09 08:43:12.222  1150 31382 E AudioPolicyIntefaceImpl: getInputForAttr permission denied: recording not allowed for uid 2000 pid 4206
07-09 08:43:12.222  1150 31382 E AudioFlinger: createRecord() getInputForAttr return error -1
07-09 08:43:12.222  4206  4255 E IAudioFlinger: createRecord returned error -1
07-09 08:43:12.222  4206  4255 E AudioRecord: createRecord_l(0): AudioFlinger could not create record track, status: -1
07-09 08:43:12.222  4206  4255 E AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
07-09 08:43:12.222  4206  4255 E android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
07-09 08:43:12.222  4206  4255 E scrcpy  : Failed to start audio capture
07-09 08:43:12.223  4206  4255 E scrcpy  : On Android 11, audio capture must be started in the foreground, make sure that the device is unlocked when starting scrcpy.

@yume-chan
Copy link
Contributor

Did you see a "Heap Dump" popup on your device screen when starting Scrcpy?

Please try running adb shell "am start com.android.shell/.HeapDumpActivity" before starting Scrcpy. See #3796, #4147

Looks similar to #4015 as startRecording method also seem to be modified:

Now it throws in new AudioRecrod(), it hasn't got to audioRecord.startRecording()

@axxapy
Copy link
Author

axxapy commented Jul 15, 2023

Unfortunately calling and keeping HeapDumpActivity does not help in my case.
But If I switch to main user, start scrcpy and then switch to second user, audio streaming works just fine

@yume-chan
Copy link
Contributor

yume-chan commented Aug 31, 2023

But If I switch to main user, start scrcpy and then switch to second user, audio streaming works just fine

That means startRecording() works alright.


This doesn't work because Scrcpy is running with uid 2000, but the Heap Dump dialog belongs to uid 1002000 (if current Android user ID is 10), so Android still don't think Scrcpy is in foreground.

I found no method to run Scrcpy in current active Android user (because it's started by ADB, which has uid 2000), or make uid 2000 become foreground (Starting an activity for another Android user does nothing, there is no API to forcefully mark an uid as foreground). I don't think it's solvable.

@axxapy axxapy closed this as completed Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants