Add option to force-stop app before starting
The previous commit introduced: scrcpy --start-app=name By adding a '+' prefix, the app is stopped beforehand: scrcpy --start-app=+name This may be useful to start a fresh app on a new virtual display: scrcpy --new-display --start-app=+org.mozilla.firefox PR #5370 <https://github.com/Genymobile/scrcpy/pull/5370>
This commit is contained in:
parent
13ce277e1f
commit
dd20efa41c
@ -498,6 +498,10 @@ Default is "lalt,lsuper" (left-Alt or left-Super).
|
|||||||
.BI "\-\-start\-app " name
|
.BI "\-\-start\-app " name
|
||||||
Start an Android app, by its exact package name.
|
Start an Android app, by its exact package name.
|
||||||
|
|
||||||
|
Add a '+' prefix to force-stop before starting the app:
|
||||||
|
|
||||||
|
scrcpy --new-display --start-app=+org.mozilla.firefox
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B \-t, \-\-show\-touches
|
.B \-t, \-\-show\-touches
|
||||||
Enable "show touches" on start, restore the initial value on exit.
|
Enable "show touches" on start, restore the initial value on exit.
|
||||||
|
@ -811,7 +811,9 @@ static const struct sc_option options[] = {
|
|||||||
.longopt_id = OPT_START_APP,
|
.longopt_id = OPT_START_APP,
|
||||||
.longopt = "start-app",
|
.longopt = "start-app",
|
||||||
.argdesc = "name",
|
.argdesc = "name",
|
||||||
.text = "Start an Android app, by its exact package name.",
|
.text = "Start an Android app, by its exact package name.\n"
|
||||||
|
"Add a '+' prefix to force-stop before starting the app:\n"
|
||||||
|
" scrcpy --new-display --start-app=+org.mozilla.firefox",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.shortopt = 't',
|
.shortopt = 't',
|
||||||
|
@ -594,6 +594,11 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startApp(String name) {
|
private void startApp(String name) {
|
||||||
|
boolean forceStopBeforeStart = name.startsWith("+");
|
||||||
|
if (forceStopBeforeStart) {
|
||||||
|
name = name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
DeviceApp app = Device.findByPackageName(name);
|
DeviceApp app = Device.findByPackageName(name);
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
Ln.w("No app found for package \"" + name + "\"");
|
Ln.w("No app found for package \"" + name + "\"");
|
||||||
@ -607,7 +612,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ln.i("Starting app \"" + app.getName() + "\" [" + app.getPackageName() + "] on display " + startAppDisplayId + "...");
|
Ln.i("Starting app \"" + app.getName() + "\" [" + app.getPackageName() + "] on display " + startAppDisplayId + "...");
|
||||||
Device.startApp(app.getPackageName(), startAppDisplayId);
|
Device.startApp(app.getPackageName(), startAppDisplayId, forceStopBeforeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStartAppDisplayId() {
|
private int getStartAppDisplayId() {
|
||||||
|
@ -264,7 +264,7 @@ public final class Device {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startApp(String packageName, int displayId) {
|
public static void startApp(String packageName, int displayId, boolean forceStop) {
|
||||||
PackageManager pm = FakeContext.get().getPackageManager();
|
PackageManager pm = FakeContext.get().getPackageManager();
|
||||||
|
|
||||||
Intent launchIntent = getLaunchIntent(pm, packageName);
|
Intent launchIntent = getLaunchIntent(pm, packageName);
|
||||||
@ -283,6 +283,9 @@ public final class Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ActivityManager am = ServiceManager.getActivityManager();
|
ActivityManager am = ServiceManager.getActivityManager();
|
||||||
|
if (forceStop) {
|
||||||
|
am.forceStopPackage(packageName);
|
||||||
|
}
|
||||||
am.startActivity(launchIntent, options);
|
am.startActivity(launchIntent, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user