mirror of
https://github.com/revanced/jadb.git
synced 2024-06-10 07:07:49 +02:00
Merge remote-tracking branch 'upstream/master' into develop
This commit is contained in:
commit
ee20300b30
28
CONTRIBUTING.md
Normal file
28
CONTRIBUTING.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Contributing #
|
||||
## Why contributing? ##
|
||||
The original author and all users of this library are very greatful for your contribution
|
||||
to this Open Source Project. Also most employers value people active in the Open Source
|
||||
community.
|
||||
|
||||
## The Checklist ##
|
||||
If you want to help out and contribute to this Open Source Project, please keep reading.
|
||||
|
||||
My thought with `jadb` was to make it very light weight and easy to use as a developer.
|
||||
This means as little boilerplate code, (mostly) self-documenting public interface, and
|
||||
overall clean code.
|
||||
|
||||
Before submitting a pull request, please go through the below checklist to verify
|
||||
your proposed change meets, or exceeds, the quality of the jadb source code.
|
||||
|
||||
* Builds - Make sure the code builds by issuing `ant build`.
|
||||
* Works - Make sure all the test runs and passes.
|
||||
* Works - Double check any features you might have changed, and of course any _new_ code
|
||||
by testing manually.
|
||||
* Formatting - Keep the formatting _consistent_. Nothing
|
||||
fancy, pretty standard java stuff, check other source files
|
||||
for reference.
|
||||
* Readability - Is your code easy to read? This usually means shorter code, but don't go
|
||||
full terse.
|
||||
* Newline at end of file - This makes `cat`-ing files, etc easier.
|
||||
|
||||
Happy coding! I, the original author, and all users are greatful for your contribution. :-)
|
22
README.md
22
README.md
|
@ -13,7 +13,7 @@ This projects aims at providing an up to date implementation of the ADB protocol
|
|||
Usage cannot be simpler. Just create a `JadbConnection` and off you go.
|
||||
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
List<JadbDevice> devices = jadb.getDevices();
|
||||
List<JadbDevice> devices = jadb.getDevices();
|
||||
|
||||
Make sure the adb server is running. You can start it by running `adb` once from the command line.
|
||||
|
||||
|
@ -39,8 +39,8 @@ A list of the available commands that a ADB Server may accept can be found here:
|
|||
|
||||
Since version v1.1 Jadb support [maven](https://maven.apache.org/) as a build system. Although this project is not presented in official apache maven
|
||||
repositories this library can be used as dependencies in your maven/gradle project with the help of [jitpack](https://jitpack.io).
|
||||
[Оitpack](https://jitpack.io) is a system which parse github public repositories and make artifacts from them.
|
||||
You will just only need to add [jitpack](https://jitpack.io) as a repository to let maven/gradle to search for artifacts in it
|
||||
[Jitpack](https://jitpack.io) is a system which parses github public repositories and make artifacts from them.
|
||||
You only need to add [jitpack](https://jitpack.io) as a repository to let maven/gradle to search for artifacts in it, like so
|
||||
|
||||
```
|
||||
<repositories>
|
||||
|
@ -52,7 +52,7 @@ You will just only need to add [jitpack](https://jitpack.io) as a repository to
|
|||
```
|
||||
|
||||
After that you will need to add actual dependency. [Jitpack](https://jitpack.io) takes groupId, artifactId and version id from repository name,
|
||||
project name and **tag** ignoring actual values from pom.xml. So you need to write:
|
||||
project name and tag ignoring actual values from pom.xml. So you need to write:
|
||||
|
||||
```
|
||||
<dependency>
|
||||
|
@ -62,5 +62,15 @@ project name and **tag** ignoring actual values from pom.xml. So you need to wri
|
|||
</dependency>
|
||||
```
|
||||
|
||||
## Author ##
|
||||
Samuel Carlsson <samuel.carlsson@gmai.com>
|
||||
## Contributing ##
|
||||
This project would not be where it is, if it where not for the helpful [contributors](https://github.com/vidstige/jadb/graphs/contributors)
|
||||
supporting jadb with pull requests, issue reports, and great ideas. If _you_ would like to
|
||||
contribute, please read through [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
|
||||
## Authors ##
|
||||
Samuel Carlsson <samuel.carlsson@gmai.com>
|
||||
|
||||
See [contributors](https://github.com/vidstige/jadb/graphs/contributors) for a full list.
|
||||
|
||||
## License ##
|
||||
This project is released under the Apache License Version 2.0, see [LICENSE.md](LICENSE.md) for more information.
|
||||
|
|
|
@ -52,10 +52,10 @@ public class PackageManager {
|
|||
Stream.readAll(s, Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
public 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());
|
||||
device.push(apkFile, remote);
|
||||
ArrayList<String> arguments = new ArrayList<String>();
|
||||
ArrayList<String> arguments = new ArrayList<>();
|
||||
arguments.add("install");
|
||||
arguments.addAll(extraArguments);
|
||||
arguments.add(remote.getPath());
|
||||
|
@ -69,8 +69,17 @@ public class PackageManager {
|
|||
install(apkFile, new ArrayList<String>(0));
|
||||
}
|
||||
|
||||
public void installWithOptions(File apkFile, List<? extends InstallOptions> options) throws IOException, JadbException {
|
||||
List<String> optionsAsStr = new ArrayList<>(options.size());
|
||||
|
||||
for(InstallOptions installOptions: options) {
|
||||
optionsAsStr.add(installOptions.getStringRepresentation());
|
||||
}
|
||||
install(apkFile, optionsAsStr);
|
||||
}
|
||||
|
||||
public void forceInstall(File apkFile) throws IOException, JadbException {
|
||||
install(apkFile, Collections.singletonList("-r"));
|
||||
installWithOptions(apkFile, Collections.singletonList(new REINSTALL_KEEPING_DATA()));
|
||||
}
|
||||
|
||||
public void uninstall(Package name) throws IOException, JadbException {
|
||||
|
@ -82,4 +91,78 @@ public class PackageManager {
|
|||
public void launch(Package name) throws IOException, JadbException {
|
||||
InputStream s = device.executeShell("monkey", "-p", name.toString(), "-c", "android.intent.category.LAUNCHER", "1");
|
||||
}
|
||||
|
||||
//<editor-fold desc="InstallOptions">
|
||||
public static abstract class InstallOptions {
|
||||
InstallOptions(String ... varargs) {
|
||||
for(String str: varargs) {
|
||||
stringBuilder.append(str).append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
private final StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
private String getStringRepresentation() {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class WITH_FORWARD_LOCK extends InstallOptions {
|
||||
public WITH_FORWARD_LOCK() {
|
||||
super("-l");
|
||||
}
|
||||
}
|
||||
|
||||
public static class REINSTALL_KEEPING_DATA extends InstallOptions {
|
||||
public REINSTALL_KEEPING_DATA() {
|
||||
super("-r");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ALLOW_TEST_APK extends InstallOptions {
|
||||
public ALLOW_TEST_APK() {
|
||||
super("-t");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class WITH_INSTALLER_PACKAGE_NAME extends InstallOptions {
|
||||
public WITH_INSTALLER_PACKAGE_NAME(String name) {
|
||||
super("-t", name);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ON_SHARED_MASS_STORAGE extends InstallOptions {
|
||||
public ON_SHARED_MASS_STORAGE(String name) {
|
||||
super("-s", name);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ON_INTERNAL_SYSTEM_MEMORY extends InstallOptions {
|
||||
public ON_INTERNAL_SYSTEM_MEMORY(String name) {
|
||||
super("-f", name);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ALLOW_VERSION_DOWNGRADE extends InstallOptions {
|
||||
public ALLOW_VERSION_DOWNGRADE() {
|
||||
super("-d");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This option is sSupported only from Android 6.X+
|
||||
*/
|
||||
public static final class GRANT_ALL_PERMISSIONS extends InstallOptions {
|
||||
public GRANT_ALL_PERMISSIONS() {
|
||||
super("-g");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CUSTOM_PARAMETER extends InstallOptions {
|
||||
public CUSTOM_PARAMETER(String ... varargs) {
|
||||
super(varargs);
|
||||
}
|
||||
}
|
||||
//</editor-fold>
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import se.vidstige.jadb.managers.PackageManager;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PackageMangerTests {
|
||||
|
@ -51,4 +52,12 @@ public class PackageMangerTests {
|
|||
pm.forceInstall(miniApk);
|
||||
pm.uninstall(new Package("b.a"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInstallWithOptionsUninstallCycle() throws Exception {
|
||||
pm.install(miniApk);
|
||||
pm.installWithOptions(miniApk, Arrays.asList(new PackageManager.REINSTALL_KEEPING_DATA(), new PackageManager.ALLOW_VERSION_DOWNGRADE()));
|
||||
pm.uninstall(new Package("b.a"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user