tananaev / adblib Goto Github PK
View Code? Open in Web Editor NEWJava ADB library
License: BSD 3-Clause "New" or "Revised" License
Java ADB library
License: BSD 3-Clause "New" or "Revised" License
I am using your adblib, thank you very much for being open source.
I met a question and wanted to ask for your help. I use your project on Android, the code as same as your demo, the interface is AdbCrypto.loadAdbKeyPair.However,when I re-open my application, it need to re-prompt to allow USB debugging, but the computer's RSA key as same as last RSA.
Android 11 introduces wireless debugging which greatly simplifies the process of using ADB. However, before making the ADB connection, it needs an additional pairing, meaning it needs extra work to make the pairing first.
I've seen this on two devices at least, occurs at AdbProtocol.java#L323:
java.lang.OutOfMemoryError: Failed to allocate a 1598575456 byte allocation with 7544583 free bytes and 248MB until OOM, target footprint 15089167, growth limit 268435456
at com.cgutman.adblib.AdbProtocol$AdbMessage.parseAdbMessage (AdbProtocol.java:276)
Hi,
Firstly, thanks for making this library available through Gradle.
I'm using this library in a new project and would like to add a number of enhancements to the library. But before I do the coding and pull requests, I want to run them by you to make sure we're on the same page.
Enhancements I want to make are:
AdbConnection.openStreams
is a regular HashMap
but has a race condition when read from the connection thread and updated from main thread at the same time. I'm thinking of changing it to a ConcurrentHashMap
or possibly adding some locks in the code that accesses it.AdbConnection.connect()
since this method will never return in the following situations:
0x01000000
AdbConnection.connect()
to throw an AdbAuthenticationFailedException
if we receive a second AUTH
message after we've already sent our signature. This way we get instant feedback about whether we are "always allowed" from a previous auth attempt, and this is exactly how the adb
command line tool handles the situation. (The adb
tool assumes authentication failed in this situation, but then if the user accepts the auth popup and the adb
tool receives a subsequent CNXN
, then it changes its mind and decides the connection was ok after all.) Or the other option is, instead of throwing an exception, to at least provide status updates about the current state (eg connecting vs authenticating vs connected) so our app can respond to them in real-time.0x01000000
to 0x01000001
. The main benefit of this is, when the target device gets an auth popup, then when the user presses the "OK" button, then we receive a CNXN
message and the connection establishes. Whereas if we're on the old version, then we never receive a CNXN
message when the user presses "OK", so connection attempts always fail unless the user has previously checked the "always allow" box on the auth popup.This is based on testing against an NVIDIA Shield TV Pro 2019 and Google Pixel 3 XL. Maybe older Android devices that run the older 0x01000000
protocol version have less issues?
Can you let me know what you think of these ideas? And do you need unit tests or any other specific checks and balances before I raise the pull request?
Lastly, how long would the review and release process take before the changes are live and ready to pull into an app through Gradle?
Thanks!
hang for shell:dumpsys window windows
I know it's possible as the original app developer has a Ctrl+C send option in his adb app built in, but I was wondering how to send such a command for myself using this library. I can't seem to find out how.
It would be great to add Kotlin support.
Adding apply plugin: "kotlin"
to build.gradle should be enough.
Creating a Flutter plugin package is not as easy but would also be very useful.
https://docs.flutter.dev/development/packages-and-plugins/developing-packages
Hi
there is a delay every time I send a command and until i see the reaction on the device.
is there a way to solve it?
thanks
Can the "pull" instruction be used? What is the example code like
A usage guide would be really helpful here! I've been trying to understand the sort of commands I can send across, and am struggling.
Say I need to call a binary in a remote adb device. How would I do so?
Essentially all I want to do is call the following ->
Thanks for this library.
I'm doubt about what is destination at AdbConnection$open(String destination)
, the code:
/**
* Opens an AdbStream object corresponding to the specified destination.
* This routine will block until the connection completes.
*
* @param destination The destination to open on the target
* @return AdbStream object corresponding to the specified destination
* @throws UnsupportedEncodingException If the destination cannot be encoded to UTF-8
* @throws IOException If the stream fails while sending the packet
* @throws InterruptedException If we are unable to wait for the connection to finish
*/
public AdbStream open(String destination) throws UnsupportedEncodingException, IOException, InterruptedException {
}
i don't clearly that how many the specified destination
; I want to execute adb forward tcp:$port localabstract: $remotePort
, what should I set destination ? why ?
Hello, i'm using your adblib and i'm trying using local command (push, pull or install for example) but I've only found examples that use "adbConnection.open("shell:")"
It's possible using this library to use local command ?
I am looking forward to your response.
Hi @cgutman, @tananaev, @sampalmer, @ckesc
I would like to run a command "adb root" and not passing through adb shell (which works):
using adb shell: getprop ro.build.version.incremental
it is working:
String getpropCommand = "getprop ro.build.version.incremental";
AdbStream streamGetpropCommand = connection.open("shell:" + getpropCommand);
while (!streamGetpropCommand .isClosed()) {
try {
String result = new String(streamGetpropCommand.read(), StandardCharsets.US_ASCII);
// Print each thing we read from the shell stream
System.out.println("-->step1: getprop result: " + result);
if (!result.isEmpty()) {
streamGetpropCommand.close();
}
} catch (InterruptedException | IOException e) {
e.printStackTrace();
return;
}
}
and when using adb root
does not work:
String rootCommand = "adb root";
AdbStream streamRootCommand = connection.open(rootCommand);
while (!streamRootCommand.isClosed()) {
try {
String result = new String(streamRootCommand.read(), StandardCharsets.US_ASCII);
// Print each thing we read from the shell stream
System.out.println("--> step2: adb root result: " + result);
if (!result.isEmpty()) {
streamRootCommand.close();
}
} catch (InterruptedException | IOException e) {
e.printStackTrace();
return;
}
}
Hi,
Just wondering if you have any plans to release a new version with the latest changes?
Thanks
Hi @cgutman, @tananaev, @ckesc, @sampalmer
I would like to run a command "adb root" and not passing through adb shell (which works):
using adb shell: getprop ro.build.version.incremental
it is working:
String getpropCommand = "getprop ro.build.version.incremental";
AdbStream streamGetpropCommand = connection.open("shell:" + getpropCommand);
while (!streamGetpropCommand .isClosed()) {
try {
String result = new String(streamGetpropCommand.read(), StandardCharsets.US_ASCII);
// Print each thing we read from the shell stream
System.out.println("-->step1: getprop result: " + result);
if (!result.isEmpty()) {
streamGetpropCommand.close();
}
} catch (InterruptedException | IOException e) {
e.printStackTrace();
return;
}
}
and when using adb root
does not work:
String rootCommand = "adb root";
AdbStream streamRootCommand = connection.open(rootCommand);
while (!streamRootCommand.isClosed()) {
try {
String result = new String(streamRootCommand.read(), StandardCharsets.US_ASCII);
// Print each thing we read from the shell stream
System.out.println("--> step2: adb root result: " + result);
if (!result.isEmpty()) {
streamRootCommand.close();
}
} catch (InterruptedException | IOException e) {
e.printStackTrace();
return;
}
}
there are example code in order to get os version of device as belows: use cmd: getprop ro.build.version.release
AdbStream stream = adb.open("shell:");
stream.write("getprop ro.build.version.release" +'\n');
when stream read
String bufStr = new String(stream.read(), StandardCharsets.UTF_8);
//...
the output of bufStr contains some special character: like ^@, / $...
does any wrong when I use adblib?
I need to use this function to implement the bugreport function, and if there are multiple connects, there will be a problem that the second connect cannot be executed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.