Merge remote-tracking branch 'upstream/master' into IMP-1-Maven-support

This commit is contained in:
Arthur 2016-05-24 17:24:37 +03:00
commit 62480e3fe8
3 changed files with 24 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import se.vidstige.jadb.Stream;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -46,15 +47,32 @@ public class PackageManager {
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());
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"));
// TODO: Remove remote file
remove(remote);
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 {
InputStream s = device.executeShell("pm", "uninstall", name.toString());
String result = Stream.readAll(s, Charset.forName("UTF-8"));

View File

@ -14,6 +14,7 @@ import java.util.List;
public class PackageMangerTests {
private static JadbConnection jadb;
private PackageManager pm;
private final File miniApk = new File("test/data/Tiniest Smallest APK ever.apk");
@BeforeClass
public static void connect() throws IOException {
@ -46,8 +47,8 @@ public class PackageMangerTests {
@Test
public void testInstallUninstallCycle() throws Exception {
File f = new File("test/data/Tiniest_Smallest_APK_ever_v_platformBuildVersionName=_apkpure.com.apk");
pm.install(f);
pm.install(miniApk);
pm.forceInstall(miniApk);
pm.uninstall(new Package("b.a"));
}
}