Get the exact value from android getprop - android

I wish to get specific value of properties from adb command getprop
To get specific value I use:
adb shell getprop ro.product.display_name
adb shell getprop ro.bootloader
adb shell getprop ro.serialno
adb shell getprop ro.product.model
Result example:
Galaxy Watch5
RFT4JD6GHK
RGHJKABVGTS
SM-R860
But this is not good, cos for each value, I need to do getprop each time. I wish to ask it once per device and then parse the result to get values.
Something like:
adb shell getprop
and then what I get from stdout is long list with all properties and values
...
[ro.build.version.release]: [4.2.2]
[ro.product.display_name]: [Galaxy Watch5]
[ro.bootloader]: [RFT4JD6GHK]
[ro.hardware]: [qcom]
[ro.opengles.version]: [196108]
[ro.product.brand]: [Verizon]
[ro.product.manufacturer]: [samsung]
[ro.serialno]: [RGHJKABVGTS]
[ro.product.model]: [SM-R860]
...
How to parse this big list end get same result as separate commands? I try bellow but I get the whole thing with brackets:
adb shell getprop | grep "ro.product.display_name\|ro.bootloader\|ro.serialno\|ro.product.model"
Result:
[ro.product.display_name]: [Galaxy Watch5]
[ro.bootloader]: [RFT4JD6GHK]
[ro.serialno]: [RGHJKABVGTS]
[ro.product.model]: [SM-R860]

I solve it, but I'm not sure if there is easier solution:
adb shell getprop | grep 'ro.product.display_name\|ro.bootloader\|ro.serialno\|ro.product.model' | cut -d ":" -f 2 | sed 's:^..\(.*\).$:\1:'

Using awk and defining an array with the keys you want (ro.product.display_name used as an example here), you can do
adb shell getprop | awk -F '[][:]' 'BEGIN {keys["ro.product.display_name"]++} $2 in keys {print $5}'

Related

shell alias has cache? Why?

I write a alias command for get version of android in PC using adb shell, like this:
alias av="echo v:`adb shell getprop ro.build.version.release`;
echo sdk:`adb shell getprop ro.build.version.sdk`;
echo model:`adb shell getprop ro.product.model`;
echo display:`adb shell getprop ro.build.display.id`;"
I connect one device, it right outputs :
v:4.0.4
sdk:15
model:ZTE N983
display:N983V1.0.0B06
But when I change another device. It also output last text. When i open new shell, it output rights again. Why?
Alias has a cache? How to solve it ?
Thanks.
Backticks are evaluated immediately.
Use something like
alias av="echo -n v; adb shell getprop ro.build.version.release; ..."
to make the adb commands be executed at the time of alias execution.
The final result
1 alias av="echo -n v:; adb shell getprop ro.build.version.release; echo -n sdk:;adb shell getprop ro.build.version.sdk; \
echo -n model:;adb shell getprop ro.product.model; echo -n display:;adb shell getprop ro.build.display.id";
2 alias av='echo v: adb shell getprop ro.build.version.release; echo sdk: adb shell getprop ro.build.version.sdk; echo model: adb shell getprop ro.product.model; echo display: adb shell getprop ro.build.display.id'
But The second way cannot begin a new line using \

Retrieve all folders using root (su) in ADB

How do I retrieve all folders using su in one command?
Without root I use
adb shell "ls -R / | grep /"
And when I try
adb shell su "ls -R / | grep /"
it doesn't work.
How must the syntax be to work?
Use the -c option of su to execute a command. You also need two levels of quotes --
adb shell "su -c 'ls -R / | grep /'"

"adb shell getprop persist.sys.country" returning empty string

I'm trying to get from the device (running android L) the country and the language with the following commands:
adb shell getprop persist.sys.country
adb shell getprop persist.sys.language
But both return a empty string.
When I try another getprop command, like:
adb shell getprop ro.product.model
It returns the correct value.
Anyone knows what is happening?
Found the solution:
Android has changed this prop name in the last versions. You can use now:
adb shell getprop ro.product.locale
or
adb shell getprop persist.sys.locale
There are some other useful commands related to this question:
adb shell getprop ro.csc.country_code //e.g. [Germany]
adb shell getprop ro.csc.countryiso_code //e.g. [DE]
adb shell getprop ro.csc.sales_code //e.g. [VD2]
It gives information about country and operator the Binary is dedicated to (if not modified of course).

adb: Find PID from the adb shell

I am trying to get the PID of the process INSIDE adb shell. So, I am doing adb shell which gets me to the android shell. Now, if I were to get the PID using a regular shell I would use
adb shell ps | grep android.process.acore | sed 's/\s\s*/ /g' | cut -d ' ' -f 2
OR
adb shell ps | grep android.process.acore | awk '{ print $2 }'
I get the PID (a numeric number - 2nd field of the ps | grep android.process.acore) output.
However, if I run the above commands inside android shell(after doing adb shell), I get /system/bin/sh: sed: not found and /system/bin/sh: awk: not found errors respectively. Which means, these commands are not available inside adb shell. However, grep works.
The output of the ps | grep android.process.acore inside adb shell is:
XXX_x21 11826 441 502296 39028 ffffffff 4010ff6c S android.process.acore
I am looking for the number 11826.
How can I extract it inside adb shell?
Also, please help if there is a direct way to get the PID inside the adb shell.
Regards,
Rumit
Android versions starting with 6.0 already include pidof utility:
usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...
Print the PIDs of all processes with the given names.
-s single shot, only return one pid.
-o omit PID(s)
Not sure if you can get the PID directly however you can try the following
set `ps |grep android.process.acore`
echo $2
This has the affect of setting the output of the ps command into variables $1, $2, $3 etc. The PID value is in $2
I tried this one and it seems to work:
adb shell "set "ps | grep android.process.media"; kill -9 $2"
adb shell pidof [package name]
or
adb shell pidof -s [package name]
-s option is for single shot, returning only one pid.
I tried this one and it seems to work:
adb shell
ps -A | grep "android.process.acore"

Android ADB commands to get the device properties

I am trying to get the device properties from ADB commands. I can how ever get those values by running sample android application. How ever I wish to get using adb shell command itself to make my life easier. Here is the way I will get through sample application but I want corresponding adb commands for
device manufacturer
device hardware
device model
Os version(integer value)
Kernel version
* Please note my device is not rooted and I have no idea of rooting the device to get these values :-) *
## Code snippet
import android.os.Build;
manufacturer = Build.MANUFACTURER;
hardware = Build.HARDWARE;
model = Build.MODEL;
oSVersion = Build.VERSION.SDK_INT;
kernelVersion = System.getProperty("os.version");
However I can able to get the os version. But then I want SDK version in integer. I want 18 in place of 4.2.2
C:\>adb shell getprop ro.build.version.release
4.2.2
adb shell getprop ro.build.version.sdk
If you want to see the whole list of parameters just type:
adb shell getprop
From Linux Terminal:
adb shell getprop | grep "model\|version.sdk\|manufacturer\|hardware\|platform\|revision\|serialno\|product.name\|brand"
From Windows PowerShell:
adb shell
getprop | grep -e 'model' -e 'version.sdk' -e 'manufacturer' -e 'hardware' -e 'platform' -e 'revision' -e 'serialno' -e 'product.name' -e 'brand'
Sample output for Samsung:
[gsm.version.baseband]: [G900VVRU2BOE1]
[gsm.version.ril-impl]: [Samsung RIL v3.0]
[net.knoxscep.version]: [2.0.1]
[net.knoxsso.version]: [2.1.1]
[net.knoxvpn.version]: [2.2.0]
[persist.service.bdroid.version]: [4.1]
[ro.board.platform]: [msm8974]
[ro.boot.hardware]: [qcom]
[ro.boot.serialno]: [xxxxxx]
[ro.build.version.all_codenames]: [REL]
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [G900VVRU2BOE1]
[ro.build.version.release]: [5.0]
[ro.build.version.sdk]: [21]
[ro.build.version.sdl]: [2101]
[ro.com.google.gmsversion]: [5.0_r2]
[ro.config.timaversion]: [3.0]
[ro.hardware]: [qcom]
[ro.opengles.version]: [196108]
[ro.product.brand]: [Verizon]
[ro.product.manufacturer]: [samsung]
[ro.product.model]: [SM-G900V]
[ro.product.name]: [kltevzw]
[ro.revision]: [14]
[ro.serialno]: [e5ce97c7]
You should use adb shell getprop command and grep specific info about your current device, For additional information you can read documentation:
Android Debug Bridge documentation
I added some examples below:
language - adb shell getprop | grep language
[persist.sys.language]: [en]
[ro.product.locale.language]: [en]
boot complete ( device ready after reset) - adb shell getprop | grep boot_completed
[sys.boot_completed]: [1]
device model - adb shell getprop | grep model
[ro.product.model]: [Nexus 4]
sdk version - adb shell getprop | grep sdk
[ro.build.version.sdk]: [22]
time zone - adb shell getprop | grep timezone
[persist.sys.timezone]: [Asia/China]
serial number - adb shell getprop | grep serialno
[ro.boot.serialno]: [1234567]
For Power-Shell
./adb shell getprop | Select-String -Pattern '(model)|(version.sdk)|(manufacturer)|(platform)|(serialno)|(product.name)|(brand)'
For Linux (burrowing answer from #0x8BADF00D)
adb shell getprop | grep "model\|version.sdk\|manufacturer\|hardware\|platform\|revision\|serialno\|product.name\|brand"
For single string find in power shell
./adb shell getprop | Select-String -Pattern 'model'
or
./adb shell getprop | Select-String -Pattern '(model)'
For multiple
./adb shell getprop | Select-String -Pattern '(a|b|c|d)'

Categories

Resources