diff --git a/src/se/vidstige/jadb/managers/PackageManager.java b/src/se/vidstige/jadb/managers/PackageManager.java index db1e7ba..7f238dc 100644 --- a/src/se/vidstige/jadb/managers/PackageManager.java +++ b/src/se/vidstige/jadb/managers/PackageManager.java @@ -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 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 arguments = new ArrayList(); + 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(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")); diff --git a/test/data/Tiniest_Smallest_APK_ever_v_platformBuildVersionName=_apkpure.com.apk b/test/data/Tiniest Smallest APK ever.apk similarity index 100% rename from test/data/Tiniest_Smallest_APK_ever_v_platformBuildVersionName=_apkpure.com.apk rename to test/data/Tiniest Smallest APK ever.apk diff --git a/test/se/vidstige/jadb/test/PackageMangerTests.java b/test/se/vidstige/jadb/test/PackageMangerTests.java index 9b06c30..c8ee907 100644 --- a/test/se/vidstige/jadb/test/PackageMangerTests.java +++ b/test/se/vidstige/jadb/test/PackageMangerTests.java @@ -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")); } }