mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Merge remote-tracking branch 'upstream/master' into IMP-1-Maven-support
This commit is contained in:
commit
62480e3fe8
@ -8,6 +8,7 @@ import se.vidstige.jadb.Stream;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,15 +47,32 @@ public class PackageManager {
|
|||||||
if (!result.contains("Success")) throw new JadbException(getErrorMessage(operation, target, result));
|
if (!result.contains("Success")) throw new JadbException(getErrorMessage(operation, target, result));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void install(File apkFile) throws IOException, JadbException {
|
public void remove(RemoteFile file) throws IOException, JadbException {
|
||||||
|
InputStream s = device.executeShell("rm", "-f", Bash.quote(file.getPath()));
|
||||||
|
Stream.readAll(s, Charset.forName("UTF-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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);
|
||||||
InputStream s = device.executeShell("pm", "install", Bash.quote(remote.getPath()));
|
ArrayList<String> arguments = new ArrayList<String>();
|
||||||
|
arguments.add("install");
|
||||||
|
arguments.addAll(extraArguments);
|
||||||
|
arguments.add(remote.getPath());
|
||||||
|
InputStream s = device.executeShell("pm", arguments.toArray(new String[arguments.size()]));
|
||||||
String result = Stream.readAll(s, Charset.forName("UTF-8"));
|
String result = Stream.readAll(s, Charset.forName("UTF-8"));
|
||||||
// TODO: Remove remote file
|
remove(remote);
|
||||||
verifyOperation("install", apkFile.getName(), result);
|
verifyOperation("install", apkFile.getName(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void install(File apkFile) throws IOException, JadbException {
|
||||||
|
install(apkFile, new ArrayList<String>(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forceInstall(File apkFile) throws IOException, JadbException {
|
||||||
|
install(apkFile, Collections.singletonList("-r"));
|
||||||
|
}
|
||||||
|
|
||||||
public void uninstall(Package name) throws IOException, JadbException {
|
public void uninstall(Package name) throws IOException, JadbException {
|
||||||
InputStream s = device.executeShell("pm", "uninstall", name.toString());
|
InputStream s = device.executeShell("pm", "uninstall", name.toString());
|
||||||
String result = Stream.readAll(s, Charset.forName("UTF-8"));
|
String result = Stream.readAll(s, Charset.forName("UTF-8"));
|
||||||
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||||||
public class PackageMangerTests {
|
public class PackageMangerTests {
|
||||||
private static JadbConnection jadb;
|
private static JadbConnection jadb;
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
|
private final File miniApk = new File("test/data/Tiniest Smallest APK ever.apk");
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void connect() throws IOException {
|
public static void connect() throws IOException {
|
||||||
@ -46,8 +47,8 @@ public class PackageMangerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInstallUninstallCycle() throws Exception {
|
public void testInstallUninstallCycle() throws Exception {
|
||||||
File f = new File("test/data/Tiniest_Smallest_APK_ever_v_platformBuildVersionName=_apkpure.com.apk");
|
pm.install(miniApk);
|
||||||
pm.install(f);
|
pm.forceInstall(miniApk);
|
||||||
pm.uninstall(new Package("b.a"));
|
pm.uninstall(new Package("b.a"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user