-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
scrcpy server does not restore Android settings in case of unexpected termination/ADB disconnection #5601
Comments
That also makes wonder, how is virtual displays handled when this happens. I hope it doesn't continue to exist and consume resources without recourse. |
Which device is it? On unexpected disconnection, cleanup should still be executed. For example, if I run I have a device (Nexus 5 with Android 6) where the cleanup process is killed before it completes, probably an Android bug. But in general, it works.
The virtual display is destroyed anyway. Currently, the content (the app launched in virtual display) is also destroyed. In future versions, it would be great to have a flag to keep the running app (moved to the main display for example). See #5563 (comment) |
Pixel 8 Pro/GrapeheneOS, but I've observed it many times on my last phone, Motorola Edge 30/LineageOS. (That's why I've left device model as N/A) Is there anything else I can provide to debug this, or is it being Android bug pretty much confirmed?
Oh, good. Yes, keeping the app running would be great. |
Can you reproduce the problem with |
I just realized, it might possibly a WONTFIX. When Android decides to roam to a different BSSID, ADB is automatically switched off... I'm guessing server cleanup doesn't have the chance to run before being killed alongside ADB. Perhaps if something like Shizuku was involved, it might be different? But Shizuku also depends on wireless ADB...
I'll try tomorrow (past midnight here). Should be easy for me to reproduce by simply kicking off device from my AP. |
Yes, it can run when adb is killed. See https://github.com/Genymobile/scrcpy/blob/master/server/src/main/java/com/genymobile/scrcpy/CleanUp.java |
I have the same issue with the "Stay Awake" option remaining activated on the phone if the USB cable is yanked. Samsung Galaxy A7 (2018), running Android 10. |
Can you reproduce with https://github.com/Genymobile/scrcpy/blob/master/doc/device.md#show-touches |
AFAIK, there are two possible problems:
I will fix the second problem soon. |
Yes, I can reproduce the behaviour consistently with both. |
It should work with: diff --git a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
index f372855bf..3df2199de 100644
--- a/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
+++ b/server/src/main/java/com/genymobile/scrcpy/CleanUp.java
@@ -108,6 +108,7 @@ public final class CleanUp {
private void run(int displayId, int restoreStayOn, boolean disableShowTouches, boolean powerOffScreen, int restoreScreenOffTimeout)
throws IOException {
String[] cmd = {
+ "setsid",
"app_process",
"/",
CleanUp.class.getName(), But I think However, this might work: diff --git server/src/main/java/com/genymobile/scrcpy/CleanUp.java server/src/main/java/com/genymobile/scrcpy/CleanUp.java
index f372855bf..f81b5c183 100644
--- server/src/main/java/com/genymobile/scrcpy/CleanUp.java
+++ server/src/main/java/com/genymobile/scrcpy/CleanUp.java
@@ -108,6 +108,8 @@ public final class CleanUp {
private void run(int displayId, int restoreStayOn, boolean disableShowTouches, boolean powerOffScreen, int restoreScreenOffTimeout)
throws IOException {
String[] cmd = {
+ "/system/bin/sh",
+ "-c",
"app_process",
"/",
CleanUp.class.getName(),
@@ -116,6 +118,7 @@ public final class CleanUp {
String.valueOf(disableShowTouches),
String.valueOf(powerOffScreen),
String.valueOf(restoreScreenOffTimeout),
+ "&",
};
ProcessBuilder builder = new ProcessBuilder(cmd); Please test this binary (to replace in 3.0.2):
|
No change, at least on my device. Yanked the cable and I still get visible touches, and stay awake remains active. |
It fixes the problem on my Nexus 5 ("show touches" must be disabled when scrcpy starts, because it restores the initial value). adb shell settings put system show_touches 0
scrcpy --show-touches
# unplug USB cable |
Oh no, sorry, it's only the
|
No dice with this one either, on my device I still get the same behaviour (of course I reset both show touches and stay awake to off before trying, like I did when I tried the other test binary). Maybe @oxwivi will have better luck with theirs. |
Maybe your device does not have |
Looks like it has both:
|
And with:
? |
Still no change. Perhaps with some devices it's just inevitable... |
I've done some experimenting on another computer, using the standard 3.0.2 scrcpy-server, running a logcat viewer on the phone. In my case, it looks like the server doesn't even recognise the USB cable being yanked, and instead it runs the cleanup process when USB is plugged back in. In the following screen recording, I start out with USB connected (as confirmed by the message in notification panel), then start I tap around and open the notification panel again, then I disconnect the USB cable, but nothing appears in the log. At around 0:28 in the video, I open the notification panel yet again to show USB is no longer connected, then tap around the screen some more and touches are still shown. At 0:53, I reconnect the cable, and only then does the cleanup process run, and touches are no longer shown. Screen_Recording_20241205-202558_Logcat.Extreme.mp4Hope this helps. |
Weird. If instead of disconnecting the USB cable you execute |
Same behaviour: nothing in logcat after doing |
Looks like a device bug, the
(or maybe the parent process does not terminate properly?) |
I can confirm this bug on a pixel 9 running latest android 15 QPR1. Not sure when it started for me, maybe after moving to A15? Also I think this problem was occurring with 2.7. I thought maybe it was a fluke after reading the /doc/device.md and I manually used adb to restore the value. But I just checked again and it's the same problem. My usecase is that i normally setup a tcpip connection via usb, and most of the time i just yank the cable to go wireless. From there on i launch a direct tcpip connection via hostname. Connecting via hostname and exiting does not seem to create this problem. I would say that this issue is large enough for me that i would avoid --stay-awake since it's caused my phone screen to stay on while charging overnight several times. Please let me know if i can provide more information to assist with diagnostics. |
Please test #5613, which solves some of the problems (but not #5601 (comment)). |
Thanks, I am now testing this. I tried to re-produce with my usecase and it seems ok but i was not necessarily able to consistently reproduce the issue before this test. I will continue testing over the weekend and report back. |
Can reproduce. Very sorry about my radio silence yesterday, I was far more busy than I expected.
Sorry, how do you specify different server bins? |
Either set the |
Still the same.
|
Some options, such as --show-touches or --stay-awake, modify Android settings and must be restored upon exit. If scrcpy terminates (e.g. due to an early error) in the middle of the clean up configuration, the device may be left in an inconsistent state (some settings might be changed but not restored). This issue can be reproduced with high probability by forcing scrcpy to fail: scrcpy --show-touches --video-encoder=fail To prevent this problem, ensure that the clean up thread is not interrupted until the clean up process is started. Refs #5601 <#5601> PR #5613 <#5613>
My situation has definitely improved, I am not able to re-produce as consistently. I did have one time where the flag did not reset, and I am not sure what I did to cause this. If I can narrow down the steps to re-produce I will present them here. |
Environment
Describe the bug
Whenever ADB disconnects (over Wi-Fi, probably because device changes frequency or roamed to different AP), server-side doesn't appear to restore settings as part of the exit cleanup. For example, when scrcpy is running with the
--stay-awake
and ADB unexpectedly terminates, the Stay awake option in Developer options remains toggled on. Any subsequent scrcpy connection takes this as a base setting and doesn't turn it off when properly exiting either. It has to be manually disabled in Developer options.What is the server-side behavior for unexpected disconnections? Is the exit cleanup only possible with ADB commands from the client-side? I'm hoping it's possible for scrcpy server to detect abrupt disconnections and execute the cleanup routine independent of the client.
The text was updated successfully, but these errors were encountered: