mirror of
https://github.com/revanced/jadb.git
synced 2025-02-15 03:26:53 +01:00
vidstige/jadb#17 adding options for pm install command
This commit is contained in:
parent
6afe96b0e0
commit
983dedf706
@ -52,10 +52,10 @@ public class PackageManager {
|
|||||||
Stream.readAll(s, Charset.forName("UTF-8"));
|
Stream.readAll(s, Charset.forName("UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void install(File apkFile, List<String> extraArguments) throws IOException, JadbException {
|
private void install(File apkFile, List<String> extraArguments) throws IOException, JadbException {
|
||||||
RemoteFile remote = new RemoteFile("/sdcard/tmp/" + apkFile.getName());
|
RemoteFile remote = new RemoteFile("/sdcard/tmp/" + apkFile.getName());
|
||||||
device.push(apkFile, remote);
|
device.push(apkFile, remote);
|
||||||
ArrayList<String> arguments = new ArrayList<String>();
|
ArrayList<String> arguments = new ArrayList<>();
|
||||||
arguments.add("install");
|
arguments.add("install");
|
||||||
arguments.addAll(extraArguments);
|
arguments.addAll(extraArguments);
|
||||||
arguments.add(remote.getPath());
|
arguments.add(remote.getPath());
|
||||||
@ -69,8 +69,17 @@ public class PackageManager {
|
|||||||
install(apkFile, new ArrayList<String>(0));
|
install(apkFile, new ArrayList<String>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void installWithOptions(File apkFile, List<? extends InstallOptions> options) throws IOException, JadbException {
|
||||||
|
List<String> optionsAsStr = new ArrayList<>(options.size());
|
||||||
|
|
||||||
|
for(InstallOptions installOptions: options) {
|
||||||
|
optionsAsStr.add(installOptions.getStringRepresentation());
|
||||||
|
}
|
||||||
|
install(apkFile, optionsAsStr);
|
||||||
|
}
|
||||||
|
|
||||||
public void forceInstall(File apkFile) throws IOException, JadbException {
|
public void forceInstall(File apkFile) throws IOException, JadbException {
|
||||||
install(apkFile, Collections.singletonList("-r"));
|
installWithOptions(apkFile, Collections.singletonList(new REINSTALL_KEEPING_DATA()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uninstall(Package name) throws IOException, JadbException {
|
public void uninstall(Package name) throws IOException, JadbException {
|
||||||
@ -82,4 +91,78 @@ public class PackageManager {
|
|||||||
public void launch(Package name) throws IOException, JadbException {
|
public void launch(Package name) throws IOException, JadbException {
|
||||||
InputStream s = device.executeShell("monkey", "-p", name.toString(), "-c", "android.intent.category.LAUNCHER", "1");
|
InputStream s = device.executeShell("monkey", "-p", name.toString(), "-c", "android.intent.category.LAUNCHER", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//<editor-fold desc="InstallOptions">
|
||||||
|
public static abstract class InstallOptions {
|
||||||
|
InstallOptions(String ... varargs) {
|
||||||
|
for(String str: varargs) {
|
||||||
|
stringBuilder.append(str).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
private String getStringRepresentation() {
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class WITH_FORWARD_LOCK extends InstallOptions {
|
||||||
|
public WITH_FORWARD_LOCK() {
|
||||||
|
super("-l");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class REINSTALL_KEEPING_DATA extends InstallOptions {
|
||||||
|
public REINSTALL_KEEPING_DATA() {
|
||||||
|
super("-r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class ALLOW_TEST_APK extends InstallOptions {
|
||||||
|
public ALLOW_TEST_APK() {
|
||||||
|
super("-t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class WITH_INSTALLER_PACKAGE_NAME extends InstallOptions {
|
||||||
|
public WITH_INSTALLER_PACKAGE_NAME(String name) {
|
||||||
|
super("-t", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class ON_SHARED_MASS_STORAGE extends InstallOptions {
|
||||||
|
public ON_SHARED_MASS_STORAGE(String name) {
|
||||||
|
super("-s", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class ON_INTERNAL_SYSTEM_MEMORY extends InstallOptions {
|
||||||
|
public ON_INTERNAL_SYSTEM_MEMORY(String name) {
|
||||||
|
super("-f", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class ALLOW_VERSION_DOWNGRADE extends InstallOptions {
|
||||||
|
public ALLOW_VERSION_DOWNGRADE() {
|
||||||
|
super("-d");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This option is sSupported only from Android 6.X+
|
||||||
|
*/
|
||||||
|
public static final class GRANT_ALL_PERMISSIONS extends InstallOptions {
|
||||||
|
public GRANT_ALL_PERMISSIONS() {
|
||||||
|
super("-g");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class CUSTOM_PARAMETER extends InstallOptions {
|
||||||
|
public CUSTOM_PARAMETER(String ... varargs) {
|
||||||
|
super(varargs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,9 @@ import se.vidstige.jadb.managers.PackageManager;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PackageMangerTests {
|
public class PackageMangerTests {
|
||||||
@ -51,4 +54,12 @@ public class PackageMangerTests {
|
|||||||
pm.forceInstall(miniApk);
|
pm.forceInstall(miniApk);
|
||||||
pm.uninstall(new Package("b.a"));
|
pm.uninstall(new Package("b.a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallWithOptionsUninstallCycle() throws Exception {
|
||||||
|
pm.install(miniApk);
|
||||||
|
pm.installWithOptions(miniApk, Arrays.asList(new PackageManager.REINSTALL_KEEPING_DATA(), new PackageManager.ALLOW_VERSION_DOWNGRADE()));
|
||||||
|
pm.uninstall(new Package("b.a"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user