ADB - how does it work? - java

it's clear to me that one can use ADB to run commands on connected Android device, but how does it work internally?
My assumption is that after for instance calling 'adb shell' ADB connects with some internal service running on Android device or emulator and communicates with it.
What I want to do is to connect to this service which parses ADB commands directly from device (assuming it's not connected to PC) and run ADB commands directly from device. Would it be possible?

Not as far as I know. Rooted phones can have a terminal emulator on the, but that ties directly into the phone, rather than going through the adb daemon. Depending on what you want to do, you might still be able to use the terminal emulator on a rooted phone. Check this post out: http://androidforums.com/eris-all-things-root/109607-terminal-emulators-adb-question.html

ADB is a deamon running at the native layer. It is started when the phone is started in init.rc, Androids version of init.c. ADB can take commands in Androids shell scripting language which is similar yet different to BASH.

Related

Run getevent inside an android application

I want to write an android APP which can run "getevent" command in a non-rooted device, and give out all the result when my finger draw on the device. after search, I found it need root permission, otherwise almost impossible to make it done.
It is true that in a non-rooted device, an app can not run a 'getevent'? or there is otherway around?
i found this link,
enter link description here
the author said he 'get it done', but the link he gave requires rooted device.
what can I do?
if I connect a PC to the android device with a USB line , I can use adb shell to run getevent. but this app has to be running starting from a Main() function
I failed when I change it to an android service . that means I cann't make it an auto-start up app to run 'getevent', can you help me to convert it a service, so it can auto start?
my Main() app (which works to run 'getevent')
public class Main {
public static void main(String[] args){
new ServiceThread(PORT).start(); // run getevent
while (true);
}
}
3 when done compiling the app as above question 2, how can I make it auto start and still have root permission. right now I use
adb push myapp.apk /device/path
and
adb shell app_process -Djava.class.path=myadd.apk mypack.Main
and it works. but it has to be connected to a pc.
how can i get rid of the USB line and still make it have root permission?
it baffles me quite awhile.
thank you very much.

how to specify appium to one device only

I am automating an android device, my target is to automate everything and keep physical maintenance to a minimum. I have two devices with USB debugging on but, when I turn the appium server on it starts running code on the wrong device.
Is there a way to programatically specify which device appium sends code to?
Or is there a way to disconnect a specific adb device through command prompt?
Any help would be greatly appreciated, this is the last step in finishing my project. Thank you in advance.
You can use the udid capability for that.
caps.setCapability("udid", "udidDevice");
You can find udidDevice using adb devices command on the terminal with both devices connected and get the one you are interested in.

OnePlus One not found in Android Studio on Mac

I have a strange problem while developing in Android Studio on mac and i am using OnePlus one. While debugging if a call come on my mobile adb disconnect my device and don't show it again. Help me to solve this permanently.
Only solution that i have found and which works is in following step:
Restart mac
disconnect cable from mac and OnePlus One
Kill adb server
start adb server
Revoke developer certificate and turn off developers option.
restart onePlus One
Turn on OnePlusOne and connect device with mac
Open Android Studio
Enable developer option and then enable debugging option
After I follow these steps, fingerprint dialog show and once I allow that dialog, device starts to show.
This process is time consuming. I am facing this problem on mac.
Putting the phone in airplane mode seems to have temporarily fixed the issue for me. I still need to look at the logs and figure out what is wrong, but there seems to be a bug in the latest 5.x updates for the OPO.
Are you using EasyTether? If yes, you can disable it by using the following command:
sudo kextunload /System/Library/Extensions/EasyTetherUSBEthernet.kext
If that does not work, open System Information utility and check your device manufacturer ID (Vendor ID). Copy that and paste it into your adb usb config by using
echo 0x9d17 >> ~/.android/adb_usb.ini
Then restart your macbook and mobile phone and try if it works.
There are several reasons your phone may not be getting detected properly, in my case it showed my phone in My Computers, and also asked me if I allowed my PC to debug on my phone. Yet it wasn't showing the phone in the android studio adb devices drop down menu.
All I did was, go to
Tools>Android>Enable ADB Integration
and it found my device. This is once I had installed my OPX driver that shows as a disk in My Computers and also Samsung USB driver. I'm talking about Windows here but the solution applies to Android Studio on any platform. So thought I should share.

Adb.exe (Android Debug Bridge) Can't Install .apk

Whenever I use the adb to install an Android application on either my emulator or device,
it says "Failed to install *.apk on device timeout.
I tried every solution that was offered in identical questions:
I changed the ADB connection timeout from 5000 --> 60000
I restarted ADB
I restarted the computer.
However, none of these methods seem to work. I'm running the ADB on Windows Vista 32 bit.
Is Windows Vista the problem? ADB can install apks when run on my Windows 7 computer.
The only reason I can't use Windows 7 is because its processor is too slow (the emulator runs at 2 fps)
By the way, when I used the 'adb devices' command in the command line, it seems that
the ADB recognizes my phone or emulator. For some reason, it can't install an .apk
or push or pull files.
This is something I've experienced before. It tends to occur (for me) when I'm using a generic USB cable or am not plugged in properly. There really are many things that could be wrong. For example, you may need to restart your device, you may need to try a different USB port. These kinds of thing don't have a definitive solution.

adb cannot find my device for Android debugging. Why?

I installed Windows USB Android SDK
driver for the Android Dev Phone 1
I enabled all the debugging modes and stuff on the phone.
It even says...USB debugging connected.
When I type adb devices , it shows me only my emulator , and not my phone.
It doesn't seem to recognize my Android Phone as an adb device. Why is that?
Might be faster just to restart the adb server:
adb kill-server ; adb start-server
Or what I often use:
adb kill-server ; adb devices
When you call adb devices it automatically starts up the adb server. Then gives you the list of devices it can find. Sometimes even then it doesn't find the device right away so you may need to call adb devices a few more times.
There're many reasons which can cause the problem, try:
Turn on "USB debugging mode" in Settings->Application->Development.
Reinstall device drivers.
Restart Window/Mac.
Restart device.
To complete the other answers in case other people have this problem: I also had this problem, all those solutions did not work.
I just had to... change the USB socket in which I plugged my cable.
Actually, it took some time to find that because Windows was correctly recognizing the device. But not ADB.
Mine finally recognized the device after changed USB connection mode to "Camera (PTP)"
Settings > Storage > (upper right hand corner more options) USB computer connection.
I don't know if it's because I rooted mine.
For Samsung Note 3 specifically, you will need to switch to "Media Device USB3.0" instead of just "Media Device MTP" before the device show up on adb devices.
I had same problems and tried everything, and that worked for me,
Sometimes the problem is in the drivers; try this :
http://adbdriver.com
download the adb driver and run it, it will download the driver for your phone,

Categories

Resources