#84 PackageManager problems: Fixes issue 1 & 2

This commit is contained in:
Mieras Made 2018-09-04 23:08:44 +02:00
parent bad9f11441
commit b0fbb4b75f
2 changed files with 30 additions and 5 deletions

View File

@ -43,7 +43,7 @@ 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 remove(RemoteFile file) throws IOException, JadbException { private void remove(RemoteFile file) throws IOException, JadbException {
InputStream s = device.executeShell("rm", "-f", Bash.quote(file.getPath())); InputStream s = device.executeShell("rm", "-f", Bash.quote(file.getPath()));
Stream.readAll(s, StandardCharsets.UTF_8); Stream.readAll(s, StandardCharsets.UTF_8);
} }
@ -51,7 +51,7 @@ public class PackageManager {
private 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<>(); List<String> arguments = new ArrayList<>();
arguments.add("install"); arguments.add("install");
arguments.addAll(extraArguments); arguments.addAll(extraArguments);
arguments.add(remote.getPath()); arguments.add(remote.getPath());
@ -91,14 +91,16 @@ public class PackageManager {
//<editor-fold desc="InstallOption"> //<editor-fold desc="InstallOption">
public static class InstallOption { public static class InstallOption {
private final StringBuilder stringBuilder = new StringBuilder();
InstallOption(String ... varargs) { InstallOption(String ... varargs) {
String space = "";
for(String str: varargs) { for(String str: varargs) {
stringBuilder.append(str).append(" "); stringBuilder.append(space).append(str);
space = " ";
} }
} }
private final StringBuilder stringBuilder = new StringBuilder();
private String getStringRepresentation() { private String getStringRepresentation() {
return stringBuilder.toString(); return stringBuilder.toString();
} }

View File

@ -9,6 +9,7 @@ import se.vidstige.jadb.managers.Package;
import se.vidstige.jadb.managers.PackageManager; import se.vidstige.jadb.managers.PackageManager;
import se.vidstige.jadb.test.fakes.FakeAdbServer; import se.vidstige.jadb.test.fakes.FakeAdbServer;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -91,4 +92,26 @@ public class PackageManagerTest {
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@Test
public void testWithForwardLock() throws Exception {
PackageManager.InstallOption withForwardLock = PackageManager.WITH_FORWARD_LOCK;
// Letter L not number 1
String expected = "-l";
Method privateMethod = withForwardLock.getClass().getDeclaredMethod("getStringRepresentation");
privateMethod.setAccessible(true);
String actual = (String) privateMethod.invoke(withForwardLock);
assertEquals(expected, actual);
}
@Test
public void testWithInstallerPackageName() throws Exception {
PackageManager.InstallOption withInstallerPackageName = PackageManager.WITH_INSTALLER_PACKAGE_NAME("aaa bbb");
String expected = "-t aaa bbb";
Method privateMethod = withInstallerPackageName.getClass().getDeclaredMethod("getStringRepresentation");
privateMethod.setAccessible(true);
String actual = (String) privateMethod.invoke(withInstallerPackageName);
assertEquals(expected, actual);
}
} }