How "adb reboot bootloader" works internally? - android

I am seeing an issue with my android images where the command adb reboot bootloader simply reboots back the android, instead of going to bootloader mode.
In order to fix the issue, I did some study and find that there are acually two things, adb and adbd and the host and target devices communicate using the TCP protocol over sockets.
So, the interesting thing is commands like adb shell and adb devices are working but not the reboot bootloader. I want to understand what the adbd on receiving the reboot bootloader. Does it change the boor order, sets some flag, changes EFI vars....?
Can you please point to some good links or understanding you can share?
PS : I am working on embedded device environ, similar to raspberry pi...

This is how adb reboot bootloader works on a standard Android device connected via USB (the only transport supported by the standard Android bootloader in the fastboot mode):
adb client sends the reboot bootloader command to the adb server (over TCP)
adb server forwards the reboot bootloader command to the adbd on the device (over USB)
adbd sets the sys.powerctl property to reboot,bootloader
sys.powerctl change triggers the init.rc rule which runs powerctl init's built-in
which does _NR_reboot syscall
which sets the reboot to bootloader flag and reboots the device
On the next power up the bootloader would see the flag and go to the fastboot mode. But only if USB is connected.

Related

Pair computer and phone with USB cable once, and then always use ADB over WiFi, even after reboot

I'm using scrcpy to mirror the phone screen to computer, which uses adb.
I've followed the steps and it works:
# connect via USB
adb devices
adb tcpip 5555
# now unplug USB, and the following will work over WiFi
adb connect 192.168.1.14:5555
scrcpy
But when you reboot the phone or computer, doing adb connect 192.168.1.14:5555 and scrcpy doesn't work anymore (NB: the phone IP hasn't changed, it's fixed).
Reading the answers from Run/install/debug Android applications over Wi-Fi?, I see 3 options:
plug the USB cable each time before doing a wireless connection, but this is annoying, and somehow reduces the interest of wireless...
Use "ADB over network" (main answer's screenshot), but as noted by many people in comments: "i do not have the "ADB over network" option in debugging option"; so this option doesn't work for me
other techniques that need root (not possible for me)
Question: how to pair the phone and computer with a USB cable only once, and then be able to use adb between them without having to use a USB connection first, after each reboot?
Note: I don't use Android Studio, but only scrcpy.
It's not possible without root the phone. If your phone has rooted. You can use this app. https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=en. With this app you can easily debugs android apps with only wifi. Don't want USB cable even only first time.
Based on all the information I have the next conclusion. Just for reference, how a low-level setup with changing add routes works inside, described here. It comes up, there is a pretty straight thing inside changing navigation with adb tcpip <port>.
The first thing we need to do, it's setup system property with tcp port with name setprop service.adb.tcp.port (and values with a port number) By default, there is not such property.
And then just restart adb with few commands. stop adbd and start adbd on a device in order to debug bridge listen new port. What is the trick here, that you don't have access to this service and stop/start it without root. But it could be easily done, via Developer setting with stop/start debugging.
This few simple action hidden inside adb tcpip <port>. And the problem, that you cannot change system properties (point 1). That is why all application requires root access, it's just to change the single option. That is why, we need to connect with USB to debug bridge, which can change properties with his sepolicy.
So answering your question. I don't understand either, what is the problem or enabling this small setup in Developer options. But right now, it's possible to do so on some Roms, or devices with root access.

Remotely turning on display and opening Apps

I have a tablet connected to my home automation system. I would like my tablet to open an app when specific conditions are met.
My idea was to install some sort of SSH server on the tablet. When my server wants the tablet to open the App, it logins into the tablet and executes a command turn on the display and open the App.
In theory this works but I haven't been able to find any documentation on the web on how to do this.
I've got as far as installing SSHDroid however when the tablet locks, the SSH disconnects. I'm also unable to find any commands which turn on the display and open apps.
From a computer, if you have USB access already (no root required), check this answer more details.
Connect your tablet with computer(has adb installed) and run
adb tcpip 5555
Then you can control your tablet over wifi by run
adb connect 192.168.0.101:5555 // you can use port forward in you gateway to enable you connect over internet.
Now after connected with tablet you are able to use adb shell commands.
Turn Screen On
adb shell input keyevent KEYCODE_POWER
Start an Application
adb shell am start -n com.package.name/com.package.name.ActivityName

How to disable battery charging during ADB connection?

Problem description:
Each time wen I connect USB cable between PC and my mobile phone the battery automatically is charged. I want to use ADB protocol but I don't want to charge my battery during ADB connection. Is it possible to to turn off this charging? And ofcourse how can I do this?
Environment:
Mobile phone with Android os 4 and higher
I need only mention that my referential device working on android 5 so there is no /sys/class/power_supply/battery/force_usb_charging file
BEWARE: adb shell dumpsys battery unplug only MOCKS the battery status. I checked with a current indicator on my usb cable and this does not change the amount of flowing current at all so the battery is still charging.
It only changes what applications think about the state, so for example google play would not start updating if you have configured that it can only update when charging...
Changing the value of a file like /sys/devices/battery.XX/power_supply/battery/hv_charger_set to 0 does really work but its a different file for every device. For example, for my yotaphone 2 with a snapdragon 805 there is a file: /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
So you could make a script that you can use in tasker(if you have root):
echo $1 > /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
if you write that to an executable file /data/setcharging.sh then you could call the script like /data/setcharging.sh 0 to disable or
/data/setcharging.sh 1 to enable.
This works, I checked with my current metering usb cable, but it does not show that it works in the battery status icon. So you could use a combination of this and adb shell dumpsys battery unplug / reset to make it look better, but the problem is that then apps like tasker don't know whether you have ac power or not, so you can not put triggers for that when you've set it to unplugged...
One more thing, I also tested what it does in recovery (twrp) and during boot. And it turns out that during boot and in recovery, the charging just works. So its not like your device will end up dead if you forget to turn on charging again. You can always charge it in recovery mode and then boot up and change the value again (or change it while in recovery if your recovery gives access to adb).
Lastly, there are apps on the play store that are made exactly for this, but I would recommend getting such a current indicating usb-cable and checking if they really do what they say and are not just mocking.
You can make the system think it is not loading th battery using
adb shell dumpsys battery unplug
Refer to this good article :
https://stanfy.com/blog/android-shell-part-1-mocking-battery-status/
Try this for rooted device:
To enable battery Charging:
adb shell dumpsys battery set ac 1
adb shell dumpsys battery set usb 1
adb shell dumpsys battery set wireless 1
To disable battery Charging:
adb shell dumpsys battery set ac 0
adb shell dumpsys battery set usb 0
adb shell dumpsys battery set wireless 0
Probably it can be done via (root privileges):
/sys/devices/battery.XX/power_supply/battery/hv_charger_set
0 - Disable USB Charging
1 - Enable USB Charging
if android os version is more than 6 use unplug and reset to revert back.
adb shell dumpsys battery unplug
adb shell dumpsys battery reset
Copied from perfetto.dev
On rooted phones the power management IC driver allows to disconnect the USB charging while keeping the USB data link active. This feature is SoC-specific, is undocumented and not exposed through any HAL. For instance on a Pixel 2 this can be achieved running, as root: echo 1 > /sys/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-02/800f000.qcom,spmi:qcom,pmi8998#2:qcom,qpnp-smb2/power_supply/battery/input_suspend. Note that in most devices the kernel USB driver holds a wakelock to keep the USB data link active, so the device will never fully suspend even when turning the screen off.

Galaxy Nexus execute AT commands?

Would it be possible to send AT commands to the Galaxy Nexus using Hyperterminal or an other program?
If so, is there also a way to directly execute the commands on the phone?
I haven't send AT commands to the Galaxy Nexus, but it is possible with other mobile phones. They act like Plug and Pr/lay devices when you connect them to a Windows computer.
Plug the phone in, then check Windows Device Manager to see if there's a modem port for the phone.
If you can see the phone as a modem, then that's the port to which you can send AT commands via Hyperterminal.
I'm not aware of any phones that let you enter AT commands into the phone via its keypad (that's what you mean, isn't it?). The interface just isn't there.
If the phone shows up on the computer as a Windows Mobile Broadband device, you could also use Mobile Broadband API - documentation here. You would have to write some code for that.
It depends on the driver support whether this is possible or not.
It's possible on Linux (haven't tried on Win), but you'll need root on your GNex:
Connect rooted GNex to Linux PC with USB cable (debug mode and superuser access over adb must be enabled)
Go into adb shell and change to root with su command:
adb shell
su
as root execute the following:
echo MODEM > /sys/devices/tuna_otg/usb_sel
This would drop you out of the adb shell and you should now have 7 new pseudo-tty devices in /dev named ttyACM[0-6]. You should now be able to use /dev/ttyACM0 to send AT commands to you GNex.
Personally, I use atinout to send the AT commands.

Android Host Mode USB debugging

I am developing an application where my android phone connects to a USB accessory. However, when the accessory is connected is there any easy way to debug the application?
Can we use a micro usb hub or similar device?
When debugging applications that use USB accessory or host features, you most likely will have USB hardware connected to your Android-powered device. This will prevent you from having an adb connection to the Android-powered device via USB. You can still access adb over a network connection. To enable adb over a network connection:
Connect the Android-powered device via USB to your computer.
From your SDK platform-tools/ directory, enter adb tcpip 5555 at the command prompt.
Enter adb connect <device-ip-address>:5555 You should now be connected to the Android- powered device and can issue the usual adb commands like adb logcat.
To set your device to listen on USB, enter adb usb.
source: Android developer site
You could write an app that reads the logcat output on the phone and displays it on the screen and/or saves it to a file which you can pull with adb afterwards.
The app must be given READ_LOGS permission, which you can do with adb shell pm grant com.package.appname android.permission.READ_LOGS (at least on a rooted phone).
Another alternative might be to log over WiFi. adb has an option to connect over TCP/IP, but this is not something I've tried so I don't know how difficult it is to set up or how well it works.
Unless your logs are really verbose it's sometimes enough to run through your USB accessory use-case and then unplug the accessory and connect the phone to your computer to catch the logcat output. The logs are buffered up to a certain amount, so you can get a reasonable amount of logs using this method.
You could run an Android image in Virtualbox. This would allow you to connect your USB device to the virtual device, and debug over the bridged network connection.
I haven't figured out how to convert the SDK .img OS images to VDIs for use in Virtualbox, but there are plenty of canned VDIs out there.

Categories

Resources