How to pull via adb the latest screenshot from an Android device? - android

Is there a method to pull via ADB the latest screenshot from my device ?
-rw-rw---- 1 root sdcard_rw 137047 2017-11-04 14:02 Screenshot_20171104-140236.png
-rw-rw---- 1 root sdcard_rw 67459 2017-11-04 14:05 Screenshot_20171104-140533.png
-rw-rw---- 1 root sdcard_rw 33939 2017-11-04 14:05 Screenshot_20171104-140557.png
-rw-rw---- 1 root sdcard_rw 329546 2017-11-06 11:12 Screenshot_20171106-111218.png
-rw-rw---- 1 root sdcard_rw 437013 2017-11-13 17:57 Screenshot_20171113-175727.png
-rw-rw---- 1 root sdcard_rw 1200088 2017-11-19 13:44 Screenshot_20171119-134405.png
-rw-rw---- 1 root sdcard_rw 146758 2017-12-12 20:19 Screenshot_20171212-201936.png
-rw-rw---- 1 root sdcard_rw 128158 2017-12-18 11:11 Screenshot_20171218-111151.png
How to pull the latest screenshot ?
-rw-rw---- 1 root sdcard_rw 128158 2017-12-18 11:11 Screenshot_20171218-111151.png
Currently i'm pulling all the files using :
adb pull /mnt/sdcard/Screenshots c:\screenshots
Then organize them by date in Windows Explorer
Edit1 I can get the latest file using :
adb shell stat -c %y /mnt/sdcard/Screenshots

ADB doesn't support flags, so you'll have to pull all the files(names), then do some logic to find the most recent file, then pull that.
It's possible using a script, more info in this related question.

I'd suggest capturing the output of the adb command that gets ya the latest file and redirecting that to an adb command that does the pulling.
Based off a somewhat related answer for saving the output of a command to a variable...
FOR /F "tokens=* USEBACKQ" %%F IN (`command`) DO (
SET var=%%F
)
... replace command with the command's output to be captured, then...
adb pull %var% c:\screenshots
... or...
adb pull /mnt/sdcard/Screenshots/%var% c:\screenshots
... should do kinda what ya want.

Related

How to verify whether I could create a file in a specific folder or not on Android by C++\C?

At my first thought, I should know how to check the permissions of a folder in the Linux system(since the kernel of Android is linux) by C or C++.
Since C++17 is not available for me, so std::filesystem could not be used. And I searched on SO, I found access may be a solution. So I wrote the code snippet below:
if (access(folder_path, W_OK | X_OK) == 0) {
SDK_LOG_ERROR("folder is not writable");
}
But it seems not work as expected, I can manually create new files in a specific folder:
C:\tools>adb root
adbd is already running as root
C:\tools>adb remount
remount succeeded
C:\tools>adb shell
promotion:/system/etc/some_folder/.../config # ls -lhd .
drwxrwxrwx 2 root root 4.0K 2022-05-31 21:14 .
promotion:/system/etc/some_folder/.../config # touch a
promotion:/system/etc/some_folder/.../config # touch b
promotion:/system/etc/some_folder/.../config # ls -lh
total 14K
-rw-rw-rw- 1 root root 0 2022-05-31 21:14 a
-rw-rw-rw- 1 root root 0 2022-05-31 21:14 b
Before running the said code snippet, I call adb root; adb remount first, and then I call whoami in the terminal, the output is root.
But when I run the aforementioned code snippet on Android, the program tells me folder is not writable". What a surprise!

How to send HDMI-CEC commands from Amlogic 905x board to the TV using sysfs

I want to send raw HDMI-CEC commands (adb shell) from an Amlogic 905x ARM board (Android 6) to test the functionality. The board is rooted (tested, 'adb root' works) and connected to a TV with CEC capabilities (enabled, tested with video game console too).
First of all I want to clarify if the core functionality is built in, so I guess that if the right CEC command is sent to the right channel, I should notice a change of any kind to the TV set.
I want to test it at a lower abstraction level (sysfs i guess is ok and http://www.cec-o-matic.com/ is pretty straightforward on how to build the command strings) to avoid the complexity of a system library as of this step.
I noticed that some guys had positive results on turning the TV on, by using:
#echo 0x40 0x04 > /sys/class/cec/cmd
It didn't work on my end.
I think that I might have a different class file allocated for this purpose and I found '/sys/class/amhdmitx/amhdmitx0' which has a lot of endpoints/files that offers IO capabilities.
I got back from the device the details of the TV set connected to (EDID - Extended Display Identification Data), by using:
#cat /sys/class/amhdmitx/amhdmitx0/edid
That means there has to be a way to send commands to the TV too, like turning the TV on/off, changing source ...
Tried by sending to debug file because there is no cmd file available like in '/sys/class/cec/cmd':
#echo 0x40 0x04 > /sys/class/amhdmitx/amhdmitx0/debug
Does anyone know how can I do this, to test the sending procedure (device)-->(TV)?
Why there is no activity on the TV when using '/sys/class/cec/cmd'?
Which is the right file to use to send hex data to the TV?
The result of
cat /system/build.prop |grep hdmi && ls -l /dev/cec && ls -laht /sys/class/cec/ && settings list global |grep hdmi && echo 0x40 0x04 > /sys/class/cec/cmd && sleep 0.1 && cat /sys/class/cec/dump_reg && sleep 1 && cat /sys/class/cec/dump_reg
is
ro.sys.hdmiin.enable=true
mbx.hdmiin.switchfull=false
mbx.hdmiin.videolayer=false
ubootenv.var.hdmimode=
ro.hdmi.device_type=4
persist.sys.hdmi.keep_awake=false
crw-rw-rw- root root 222, 0 2014-12-31 16:00 cec
-r--r--r-- root root 4096 2018-05-08 08:47 arc_port
lrwxrwxrwx root root 2018-05-08 08:47 cec -> ../../devices/aocec/cec
--w------- root root 4096 2018-05-08 08:47 cmd
-rw-rw-r-- root root 4096 2018-05-08 08:47 dbg_en
-rw-rw-r-- root root 4096 2018-05-08 08:47 device_type
-r--r--r-- root root 4096 2018-05-08 08:47 dump_reg
-rw-rw-r-- root root 4096 2018-05-08 08:47 fun_cfg
-rw-rw-r-- root root 4096 2018-05-08 08:47 menu_language
-r--r--r-- root root 4096 2018-05-08 08:47 osd_name
-rw-rw-r-- root root 4096 2018-05-08 08:47 physical_addr
-r--r--r-- root root 4096 2018-05-08 08:47 port_num
-r--r--r-- root root 4096 2018-05-08 08:47 port_seq
-r--r--r-- root root 4096 2018-05-08 08:47 port_status
-rw-rw-r-- root root 4096 2018-05-08 08:47 vendor_id
-r--r--r-- root root 4096 2018-05-08 08:47 wake_up
Are you simply missing how to write to file? It is
echo "0x40 0x04" > /sys/class/cec/cmd
That works for me on s905x3 unit.

Managing files in Android terminal

Using a terminal emulator in my android phone I accidentally copied /proc directory into another user directory. Now I want to delete the copy but I don't have the permissions to do so. I tried to change ownership and permissions to 777 but with no success. I am using Oneplus 2 and termux application. Any suggestions?
Edit:
The original /proc directory :
dr-xr-xr-x 459 root root 0 Jan 1 1970 proc/
it was copied to /.../line/proc:
Line:
drwxrwxrwx 4 u0_a45 u0_a45 4096 Oct 17 12:23 line/
Line/proc:
dr-xr-xr-x 52 u0_a45 u0_a45 4096 Jan 1 1970
proc/
The new proc directories are not removable:
rm -rf line/proc
rm: can't remove 'line/proc/12159/task/12247': Permission denied
...

File not found in /data/media/0, but found in /storage/emulated/0

I use the smartphone emulator in Android Studio for a Nexus 4, API 23.
I took a picture through its camera, and I can check that the file is present at this different paths through the Android Device Monitor:
/data/media/0/DCIM/Camera/IMG_20160408_143726.jpg (rw-rw-r)
/storage/emulated/0/DCIM/Camera/IMG_20160408_143726.jpg (rw-rw)
Nevertheless, in my Activity I got different behaviors when I try to read the file:
new File("/data/media/0/DCIM/Camera/IMG_20160408_143726.jpg");
// isFile at false, canRead at false, length at 0
new File("/storage/emulated/0/DCIM/Camera/IMG_20160408_143726.jpg");
// isFile at true, canRead at true, length with a real value
Why is it so?
it depends on contructor, use this method to get the sdcard path instead, that will find the correct path for all devices
new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/IMG_20160408_143726.jpg")
You probably would like to grant your app root permission so as to let it work properly. Take a look at this example:
u0_a1#android:/ $ toolbox ls -l /storage/emulated/0/UPDATE*
-rw-rw---- root sdcard_r 4997896 2016-09-08 20:08 UPDATE-SuperSU-v2.78.zip
u0_a1#android:/ $ toolbox ls -l /data/media/0/UPDATE*
/data/media/0/*: Permission denied
1|u0_a1#android:/ $ su
root#android:/ # toolbox ls -l /data/media/0/UPDATE*
-rw-rw-r-- media_rw media_rw 4997896 2016-09-08 20:08 UPDATE-SuperSU-v2.78.zip

Using ADB : How to get file modification date command

I have following command to get file date with time
adb shell ls -l /sdcard/sample.txt
Result of this command :
-rwxrwxr-x system sdcard_rw 676 2013-09-24 11:23 sample.txt
Now, I want 2013-09-24 11:23 time with seconds as well. like 2013-09-24 11:23:11
How I will get file modification date including seconds.
Thanks.. :)
If you have a stat command:
stat -c %y /sdcard/sample.txt
Seconds since Epoch
stat -c %Y /sdcard/sample.txt
By tweaking the code posted, I was able to get it worked using this command :
adb -d shell ls -l time-style="+%Y-%m-%d %H:%M:%S" path_to_file_in_device
The output is :
-rw-rw-r-- root sdcard_rw 22357385 2013-09-25 22:42 launcher.apk
ls -l --time-style="+%Y-%m-%d %H:%M:%S" /sdcard/sample.txt

Categories

Resources