Can we override adb environment variables from terminal? - android

ADB has following environment variables in their docs.
What is the purpose of providing them in docs. Can we override their default values from terminal ? If so how?
environment variables:
$ADB_TRACE
comma-separated list of debug info to log:
all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
$ADB_VENDOR_KEYS colon-separated list of keys (files or directories)
$ANDROID_SERIAL serial number to connect to (see -s)
$ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
$ADB_LOCAL_TRANSPORT_MAX_PORT max emulator scan port (default 5585, 16 emus)
$ADB_MDNS_AUTO_CONNECT comma-separated list of mdns services to allow auto-connect (default adb-tls-connect)
I am trying to set as shown in docs
I have tried the same on windows PowerShell and macOS terminal without any effect.
for widows powershell I tried
set ANDROID_VERBOSE=radio;adb logcat
for macos terminal I tried
export ANDROID_VERBOSE=radio;adb logcat
But I don't find any difference in output

The purpose of listing them in the documentation is simply to tell people who need to use them that they exist. I don't know Powershell, but the correct macOS syntax is:
export ANDROID_VERBOSE=radio
adb logcat
or:
ANDROID_VERBOSE=radio adb logcat
You can use either, according to your taste.

Related

adb devices is not recognised as a known command

I am trying to set-up a command in Android studio that would allow me to see the current active devices like in this tutorial (1:39:41):
I have opened the environment settings and created the variable adb devices like it was explained in the tutorial
However, when I run it in Android Studio Terminal, the command is not recognised:
What did I do wrong?
The problem is with your naming. Try remove the white space and it will work.
Cause you type adb with argument devices.
Try change your variable to adb
then type
$ adb devices
and it will work

Android ADB LogCat: ANDROID_PRINTF_LOG environment variable not working

When I execute adb logcat --help, the Logcat usage details are printed. Near the bottom, it describes two environment variables:
"If not specified on the commandline, filterspec is set from
ANDROID_LOG_TAGS. If no filterspec is found, filter defaults to '*:I'
If not specified with -v, format is set from ANDROID_PRINTF_LOG or
defaults to 'brief'"
On my Windows 7 machine, when I add ANDROID_LOG_TAGS to my environment variables with a value of "Foo:* *:S", for example, then it works! Calling adb logcat without tag filters will default to my custom values. Great!
However, when I add ANDROID_PRINTF_LOG, with any valid setting (I prefer "time"), this will NOT have an affect on the logcat output. adb logcat still outputs in "brief" format.
Is there some mistake I am making, or something I can do to get to work??
I would really like to get this working because I use "-v time" a lot.
My ADB version is 1.0.31.
Thanks in advance.
Android pages themselves didn't mention this variable:
http://developer.android.com/tools/help/logcat.html
http://developer.android.com/tools/debugging/debugging-log.html#outputFormat
ANDROID_PRINTF_LOG and ANDROID_LOG_TAGS are processed by the logcat binary running on the device side. It means that in order to affect the output format the variables need to be set inside of the device's shell environment. And you are setting them in your PC's shell environment. The reason why ANDROID_LOG_TAGS still works when set on the PC side is the following:
When you run the adb logcat the actual command being executed is this:
adb shell export ANDROID_LOG_TAGS=\"%ANDROID_LOG_TAGS%\"; exec logcat
i.e. your local ANDROID_LOG_TAGS value is being copied into the device's environment before every logcat call. Not sure if not copying the ANDROID_PRINTF_LOG as well qualifies as a bug though. adb -h lists all the variables supported on the PC side and ANDROID_PRINTF_LOG is not among them.

What is "adb.bash" used for?

in the script ./build/envsetup.sh
in the function addcompletions() it finally run the command . /sdk/bash_completion/adb.bash
What is this command here for?
And what is the script "adb.bash" used for?
The file sets up integration between the bash shell and adb. Specifically, it sets up command line completion, so you can type "adb " and press tab, and get a list of adb commands you can use. Briefly skimming it, it seems like it might also support remote file listing by pressing tab twice in contexts where that is appropriate (e.g. after 'adb pull').

Sending AT Commands Via ADB Android

I have a task at work to investigate if it is possible to send AT commands to an android device via ADB shell. So far,I have tried to echo out the AT commands but it passes them as normal strings.
Any help please anyone.
Please try this:
echo -e "AT+CFUN=?\r\n" > /dev/ttyUSB0
On your phone, the serial line must not necessarily be called ttyUSB0. If this is not working or not available, check out the other entries of the /dev/ directory.
So it could also be /dev/ttyGS0 or /dev/SMD0 (as found out by #Sani).
For further information, please check out this Guide
NOTE:
There might also be phones, that do not respond to AT commands on any of their serial (tty) devices.
I just tried my own procedure on a Samsung Galaxy S4 and did not have any success.
Echo them where? In Android you talk to the rild (Radio Interface Layer) daemon, which in turns talks to a proprietary library, which sends commands to the actual hardware. Check rild source code for details. You could probably write a command line program that talks to the rild and execute it via adb shell, if that fits your needs.
In order to find out which port to use :
You can check
# cat /proc/tty/drivers
Use logcat -b radio | grep dev to see wich tty the radio is using.
Yes you can run AT commands from adb shell too...
prerequsite :-
1. rooted android phone
2. you are aware of the port that RIL use for i/o operation.
3. to check which port is being used by RIl use `getprop rild.libargs`
To run AT command from ADB use:
echo -c "AT\r\n" > /dev/smd11
PS: smd11 is port used by RIL.This varies from device to device.
ALso to run AT commands from android application check this tutorial
http://tech-papers.org/executing-at-commands-android-application/
Kind of a combination of the above. We got it working with 2 terminals on a Pixel 4 XL.
On one we did:
cat /dev/smd7
in the other:
echo "AT\r" > /dev/smd7
The output shows up in the first terminal
Notes:
Have to be root!
None of the discovery mechanisms worked for us, so we blindly called into smdX until we got a response from "AT\r".
echo automatically adds a \n, so adding it is redundant.

Getting Android SDK version of a device from command line

I'm planning to build an automated system for deploying an Android build to various devices, in order to make development for multiple platforms a bit more comfortable. Is there a way to get the sdk version of a connected device through android shell or adb?
There will be a computer to which several test devices is connected, and I was planning to write a script which will fetch the correct build for each of those from a build-server, install the different apks on their respective devices, launch them and collect log info, to be made available through some other program whose specifications are beside the point.
The point is that I need to know the sdk version each device is running to install the correct apk, and I was hoping I could get this through adb, but I can't seem to find a way to access it short of building a tiny app, compatible with all versions, whose sole purpose would be to output android.os.Build.VERSION.SDK or similar somewhere my script could read it.
you can use this command:
adb shell grep ro.build.version.sdk= system/build.prop
It will output something like this:
ro.build.version.sdk=10
adb shell getprop ro.build.version.sdk
Note #Tim: this works even on phones without grep support on all host OS :-). (i.e. on old phones where toolbox does not support grep you you need to have busybox on your phone).
I also discovered a way to get the exact version of Android e.g. 4.2.2 based on the following web article http://xayon.net/looking-for-android-version-with-adb/ You need to be using a unix-like operating system - Linux and Mac OSX are fine, and windows users can use cygwin or equivalent.
At a command line:
echo version=$(adb shell getprop |awk -F":" '/build.version.release/ { print $2 }')|tr -d '[]'
Here is the result for my Nexus 4:
version= 4.2.2
I think you can by accessing the device with adb shell - change directories to position you at system and do a cat of build.prop. Here you will find for instance, ro.build.description=google_sdk-eng 2.2, ro.build.version.release=2.2 etc

Categories

Resources