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

Version 1.11 error with Nvidia ShieldTV 2015 (Android 9 Pie / SDK Version 28) #940

Closed
tam1m opened this issue Nov 21, 2019 · 14 comments
Closed
Labels

Comments

@tam1m
Copy link

tam1m commented Nov 21, 2019

After updating from 1.10 to 1.11 scrcpy is no longer working with my ShieldTV.

➜ scrcpy
INFO: scrcpy 1.11 <https://github.com/Genymobile/scrcpy>
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed. 5.8 MB/s (25454 bytes in 0.004s)
[server] ERROR: Exception on thread Thread[main,5,main]
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Application.createPackageContext(java.lang.String, int)' on a null object reference
at android.media.MediaCodec.isSupported(MediaCodec.java:1794)
at android.media.MediaCodec.checkAppForAutoFrc(MediaCodec.java:1831)
at android.media.MediaCodec.configureCodecParams(MediaCodec.java:1980)
at android.media.MediaCodec.<init>(MediaCodec.java:2011)
at android.media.MediaCodec.createEncoderByType(MediaCodec.java:1944)
at com.genymobile.scrcpy.ScreenEncoder.createCodec(ScreenEncoder.java:138)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:63)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:32)
at com.genymobile.scrcpy.Server.main(Server.java:146)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
INFO: Initial texture: 1920x1080
WARN: Device disconnected
@tam1m tam1m changed the title Version 1.11 error out with Nvidia ShieldTV 2015 (Android 9 Pie / SDK Version 28) Version 1.11 error with Nvidia ShieldTV 2015 (Android 9 Pie / SDK Version 28) Nov 21, 2019
@rom1v
Copy link
Collaborator

rom1v commented Nov 21, 2019

Thank you for your report.

If you try again v1.10, does it work?

@tam1m
Copy link
Author

tam1m commented Nov 21, 2019

Yes, v1.10 works perfectly fine

@rom1v
Copy link
Collaborator

rom1v commented Nov 21, 2019

Could you retry with this change, please?

diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
index c9a37f8..504e954 100644
--- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
+++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
@@ -53,7 +53,6 @@ public class ScreenEncoder implements Device.RotationListener {
 
     public void streamScreen(Device device, FileDescriptor fd) throws IOException {
         Workarounds.prepareMainLooper();
-        Workarounds.fillAppInfo();
 
         MediaFormat format = createFormat(bitRate, maxFps, iFrameInterval);
         device.setRotationListener(this);

@tam1m
Copy link
Author

tam1m commented Nov 21, 2019

That's it! It works with your patch applied.

@rom1v
Copy link
Collaborator

rom1v commented Nov 21, 2019

OK, so this conflicts with #365 (which only works with the call to fillAppInfo()). 😞

@rom1v rom1v added the bug label Nov 21, 2019
@tam1m
Copy link
Author

tam1m commented Nov 21, 2019

Would it be sensible to call it only for devices that are known to not work without it?
Something like this

if(needs_workaround_device_list.contains(Build.PRODUCT))
  Workarounds.fillAppInfo();

@rom1v
Copy link
Collaborator

rom1v commented Nov 21, 2019

If you restore Workarounds.fillAppInfo() and apply this patch instead, what is the result?

diff --git a/server/src/main/java/com/genymobile/scrcpy/Workarounds.java b/server/src/main/java/com/genymobile/scrcpy/Workarounds.java
index f45d82a..ba5cd21 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Workarounds.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Workarounds.java
@@ -1,11 +1,15 @@
 package com.genymobile.scrcpy;
 
 import android.annotation.SuppressLint;
+import android.app.Application;
+import android.app.Instrumentation;
+import android.content.Context;
 import android.content.pm.ApplicationInfo;
 import android.os.Looper;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 
 public final class Workarounds {
     private Workarounds() {
@@ -56,6 +60,14 @@ public final class Workarounds {
             Field mBoundApplicationField = activityThreadClass.getDeclaredField("mBoundApplication");
             mBoundApplicationField.setAccessible(true);
             mBoundApplicationField.set(activityThread, appBindData);
+
+            Method getSystemContextMethod = activityThreadClass.getDeclaredMethod("getSystemContext");
+            // this is not a full Android context giving access to everything
+            Context ctx = (Context) getSystemContextMethod.invoke(activityThread);
+            Application app = Instrumentation.newApplication(Application.class, ctx);
+            Field mInitialApplicationField = activityThreadClass.getDeclaredField("mInitialApplication");
+            mInitialApplicationField.setAccessible(true);
+            mInitialApplicationField.set(activityThread, app);
         } catch (Throwable throwable) {
             // this is a workaround, so failing is not an error
             Ln.w("Could not fill app info: " + throwable.getMessage());

@tam1m
Copy link
Author

tam1m commented Nov 21, 2019

Just tried and it works

rom1v added a commit that referenced this issue Nov 24, 2019
When an ApplicationInfo is set (commit
9029324), some devices (Nvidia Shield
TV) attempt to access the Application object, causing a
NullPointerException.

As a workaround, initialize an Application object.

Fixes <#940>
@rom1v
Copy link
Collaborator

rom1v commented Nov 24, 2019

Merged on dev: 2b84568

@AceHack
Copy link

AceHack commented Dec 9, 2019

Is there somewhere I can download dev builds?

@rom1v
Copy link
Collaborator

rom1v commented Dec 9, 2019

No, this will be in v1.12 (which should be released soon, hopefully).

Meanwhile, you can use v1.10.

@rom1v
Copy link
Collaborator

rom1v commented Dec 9, 2019

(v1.12 which fixes the problem is out)

@rom1v
Copy link
Collaborator

rom1v commented Apr 30, 2020

To fix #994, I changed the way the workaround is called.

Could you please take scrcpy v1.13 and replace this file:

scrcpy-server
SHA256: b64e6672eeb2b7c00c6f83673783bd8839ba65ea2ac7edcdeeca44676047328b

and confirm that it works without any error message.

Thank you.

rom1v added a commit that referenced this issue May 2, 2020
To avoid NullPointerException on some devices, workarounds have been
implemented. But these workaround produce (harmless) internal errors
causing exceptions to be printed in the console.

To avoid this problem, apply the workarounds only if it fails without
them.

Fixes #994 <#994>
Refs #365 <#365>
Refs #940 <#940>
rom1v added a commit that referenced this issue Sep 22, 2021
Workarounds.fillAppInfo() is necessary for Meizu devices even before the
first call to internalStreamScreen(), but it is harmful on other
devices (#940).

Therefore, simplify the workaround, by calling fillAppInfo() only if
Build.BRAND equals "meizu" (case insensitive).

Fixes #240 <#240> (again)
Fixes #2656 <#2656>
rom1v added a commit that referenced this issue Oct 21, 2021
Workarounds.fillAppInfo() is necessary for Meizu devices even before the
first call to internalStreamScreen(), but it is harmful on other
devices (#940).

Therefore, simplify the workaround, by calling fillAppInfo() only if
Build.BRAND equals "meizu" (case insensitive).

Fixes #240 <#240> (again)
Fixes #2656 <#2656>
rom1v added a commit that referenced this issue Jul 30, 2024
Workarounds were disabled by default, and enabled only on some device or
in specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary.

--- Cases where workarounds caused issues:
 - <#940>:
   To be tested
 - <#3805 (comment)>:
   To be tested
 - <#4015 (comment)>:
   This is not a problem anymore since commit
   b8c5853.
@rom1v
Copy link
Collaborator

rom1v commented Jul 30, 2024

Could you please test #5154 and confirm that it still works?

rom1v added a commit that referenced this issue Jul 31, 2024
Workarounds were disabled by default, and enabled only on some device or
in specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <#4015 (comment)>
[2]: <#3805 (comment)>
[3]: <#3805 (comment)>
[4]: <#940>

PR #5154 <#5154>
rom1v added a commit that referenced this issue Aug 1, 2024
Workarounds were disabled by default, and only enabled for some devices
or under specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <#4015 (comment)>
[2]: <#3805 (comment)>
[3]: <#3805 (comment)>
[4]: <#940>

PR #5154 <#5154>
FreedomBen pushed a commit to FreedomBen/scrcpy that referenced this issue Aug 2, 2024
Workarounds were disabled by default, and only enabled for some devices
or under specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <Genymobile#4015 (comment)>
[2]: <Genymobile#3805 (comment)>
[3]: <Genymobile#3805 (comment)>
[4]: <Genymobile#940>

PR Genymobile#5154 <Genymobile#5154>
Gottox pushed a commit to Gottox/scrcpy that referenced this issue Sep 29, 2024
Workarounds were disabled by default, and only enabled for some devices
or under specific conditions.

But it seems they are needed for more and more devices, so enable them
by default. They could be disabled for specific devices if necessary in
the future.

In the past, these workarounds caused a (harmless) exception to be
printed on some Xiaomi devices [1]. But this is not a problem anymore
since commit b8c5853.

They also caused problems for audio on Vivo devices [2], but it seems
this is not the case anymore [3].

They might also impact an old Nvidia Shield [4], but hopefully this is
fixed now.

[1]: <Genymobile#4015 (comment)>
[2]: <Genymobile#3805 (comment)>
[3]: <Genymobile#3805 (comment)>
[4]: <Genymobile#940>

PR Genymobile#5154 <Genymobile#5154>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants