-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a clean up process on the device
In order to clean up on close, use a separate process which is not killed when the device is disconnected (even if the main process itself is killed).
- Loading branch information
Showing
2 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.genymobile.scrcpy; | ||
|
||
import com.genymobile.scrcpy.wrappers.ContentProvider; | ||
import com.genymobile.scrcpy.wrappers.ServiceManager; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Handle the cleanup of scrcpy, even if the main process is killed. | ||
* <p> | ||
* This is useful to restore some state when scrcpy is closed, even on device disconnection (which kills the scrcpy process). | ||
*/ | ||
public final class CleanUp { | ||
|
||
public static final String SERVER_PATH = "/data/local/tmp/scrcpy-server.jar"; | ||
|
||
private CleanUp() { | ||
// not instantiable | ||
} | ||
|
||
public static void configure() throws IOException { | ||
// TODO | ||
boolean needProcess = false; | ||
if (needProcess) { | ||
startProcess(); | ||
} else { | ||
// There is no additional clean up to do when scrcpy dies | ||
unlinkSelf(); | ||
} | ||
} | ||
|
||
private static void startProcess() throws IOException { | ||
String[] cmd = {"app_process", "/", CleanUp.class.getName()}; | ||
|
||
ProcessBuilder builder = new ProcessBuilder(cmd); | ||
builder.environment().put("CLASSPATH", SERVER_PATH); | ||
builder.start(); | ||
} | ||
|
||
private static void unlinkSelf() { | ||
try { | ||
new File(SERVER_PATH).delete(); | ||
} catch (Exception e) { | ||
Ln.e("Could not unlink server", e); | ||
} | ||
} | ||
|
||
public static void main(String... args) { | ||
unlinkSelf(); | ||
|
||
try { | ||
// Wait for the server to die | ||
System.in.read(); | ||
} catch (IOException e) { | ||
// Expected when the server is dead | ||
} | ||
|
||
Ln.i("Cleaning up"); | ||
// TODO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters