-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Create AudioRecord using reflection as a fallback #3862
Conversation
Thank you for your work 👍
Sure, but I want to avoid adding dependencies for only minor convenience gains. This adds complexity at other places (e.g. when the project is not built with
Adding the following annotation seems sufficient: @SuppressLint("SoonBlockedPrivateApi")
public class AudioRecordWrapper {
Thank you for taking care of all the difference for each version! That's a lot of painful work :) IMO, we should minimize the duplicated code from AOSP, this is just a workaround with known values. For example, in the implementation of I think we don't even need a reimplementation of This should probably remove the need of most of Also, I noticed that this fallback code is executed on Android 11 when the screen is locked (even on non Vivo devices), IMO it should not (and it interacts with the retrying mechanism introduced by 02f4ff7). I don't know how we should detect that a failure is due to screen lock or because the |
e873a4d
to
b3ca4d9
Compare
I removed some checks, but I don't want to deviate it from AOSP too much, so others can read it more easily.
Not sure how to do this. What's the |
Some devices (Vivo phones) fail to create an AudioRecord from an AudioRecord.Builder (which throw a NullPointerException). In that case, create an AudioRecord instance directly by reflection. The AOSP version of AudioRecord constructor code can be found at: - Android 11 (R): <https://cs.android.com/android/platform/superproject/+/android-11.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=335;drc=64ed2ec38a511bbbd048985fe413268335e072f8> - Android 12 (S): <https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=388;drc=2eebf929650e0d320a21f0d13677a27d7ab278e9> - Android 13 (T, functionally identical to Android 12): <https://cs.android.com/android/platform/superproject/+/android-13.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=382;drc=ed242da52f975a1dd18671afb346b18853d729f2> - Android 14 (U): Not released, but expected to change PR #3862 <#3862> Fixes #3805 <#3805> Signed-off-by: Romain Vimont <[email protected]>
Thank you @yume-chan for your latest version 👍 I move your code to Here is a binary:
cc @A-viral-dev (#3805) EDIT: I also moved the URLs pointing to AOSP AudioRecord implementation from code comments to the commit message. I could invent a reason, but the real one is that I did not manage to silent the linter errors about the lines greater than 150 chars due to the long URLs 😄 |
I tried this and got this error:
|
@rahaaatul Your stacktrace (line numbers) does not match the binary I posted, but matches v2.0, so you're probably not using the binary posted in the previous command. How did you run it? |
Oh shoot! My bad! I forgot that I added the released version in the PATH. So after I downloaded your new binary, I extracted and opened the terminal and ran scrcpy there. Most likely it ran the other one in the PATH. Sorry to bother you like that, I will try again. Please accept my apology. |
Okay, just tested it works fine. But the screen must be on first. |
Android 11? |
Yes |
I think those are good simplifications. One thing I noticed is that the |
Some devices (Vivo phones) fail to create an AudioRecord from an AudioRecord.Builder (which throw a NullPointerException). In that case, create an AudioRecord instance directly by reflection. The AOSP version of AudioRecord constructor code can be found at: - Android 11 (R): <https://cs.android.com/android/platform/superproject/+/android-11.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=335;drc=64ed2ec38a511bbbd048985fe413268335e072f8> - Android 12 (S): <https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=388;drc=2eebf929650e0d320a21f0d13677a27d7ab278e9> - Android 13 (T, functionally identical to Android 12): <https://cs.android.com/android/platform/superproject/+/android-13.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=382;drc=ed242da52f975a1dd18671afb346b18853d729f2> - Android 14 (U): Not released, but expected to change PR #3862 <#3862> Fixes #3805 <#3805> Signed-off-by: Romain Vimont <[email protected]>
Indeed, it is better to set it to the correct value (even if it works without). I updated the branch. |
Some devices (Vivo phones) fail to create an AudioRecord from an AudioRecord.Builder (which throws a NullPointerException). In that case, create an AudioRecord instance directly by reflection. The AOSP version of AudioRecord constructor code can be found at: - Android 11 (R): <https://cs.android.com/android/platform/superproject/+/android-11.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=335;drc=64ed2ec38a511bbbd048985fe413268335e072f8> - Android 12 (S): <https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=388;drc=2eebf929650e0d320a21f0d13677a27d7ab278e9> - Android 13 (T, functionally identical to Android 12): <https://cs.android.com/android/platform/superproject/+/android-13.0.0_r1:frameworks/base/media/java/android/media/AudioRecord.java;l=382;drc=ed242da52f975a1dd18671afb346b18853d729f2> - Android 14 (U): Not released, but expected to change PR #3862 <#3862> Fixes #3805 <#3805> Signed-off-by: Romain Vimont <[email protected]>
Merged into |
On my device, this doesn't seem to be a scrcpy bug,i dont't know. because I turned off selinux permissions, which is permissive. When I set "setenforce 1" in the shell again, it worked fine |
Fixes #3805
It duplicated all code from
AudioRecord
's constructor andAudioRecord.Builder.build()
for both Android 11 and Android 12.Android 13 uses
AudioAttributes.Builder.replaceTags()
instead ofAudioAttributes.Builder.addTag()
. The former may copy more fields from the sourceattributes
, but not using it (in this PR) doesn't seem to matter.It uses native reflections, but the code is much harder to read with that. Most methods/fields are only used once so performance shouldn't change even if joor was used. Jar package size grows from 52KB to 57KB (previous one using joor was 61KB).
The linter doesn't like it using private APIs, so alint-baseline.xml
file was created according to the docs. To update it, simply delete it and rebuild the project. Doesn't know why it can still access those APIs even if they are blocked, maybe Android Shell process doesn't have that restriction. Using joor won't cause those linting errors (and don't need thelint-baseline.xml
file) maybe because the linter can't recognize the usage.Tested (by using this
build()
method forcefully) on Android 11 and Android 13 emulator.Expected to break in Android 14 since the addition of
deviceId
parameter.