mirror of
https://github.com/revanced/jadb.git
synced 2025-02-10 17:26:46 +01:00
Refactor: Cleaning up forceInstall
This commit is contained in:
parent
a1af30a81a
commit
2b71a04b4c
@ -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,21 +47,31 @@ public class PackageManager {
|
||||
if (!result.contains("Success")) throw new JadbException(getErrorMessage(operation, target, result));
|
||||
}
|
||||
|
||||
public void install(File apkFile,boolean forceInstall) 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;
|
||||
if(forceInstall){
|
||||
s= device.executeShell("pm", "install", "-r", Bash.quote(remote.getPath()));
|
||||
}else{
|
||||
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"));
|
||||
s=device.executeShell("rm", "-f", Bash.quote(remote.getPath()));
|
||||
Stream.readAll(s, Charset.forName("UTF-8"));
|
||||
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());
|
||||
|
@ -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, false);
|
||||
pm.install(miniApk);
|
||||
pm.forceInstall(miniApk);
|
||||
pm.uninstall(new Package("b.a"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user