How to clean dumpstate/logcat with adb shell? - android

Is there anyway to clean dumpstate/logcat data with an adb shell? *#9900# is not working on my phone.
I tried adb logcat -c, but it didn't help.
I m struggling with an "Insufficient memory space" problem and cannot install any new apps. I have 5gb of those files and cannot get rid of them :P

When you are using adb logcat -c
-c : clear (flush) the entire log and exit
This a just clears the current buffer of the logcat, but the logs you are referring to aren't created by Logcat but rather by system itself. It should be located under /data/log and this have root permissions. You can delete it if your device is rooted.
If unrooted, you can try to go to settings>storage>cache to clear the cache and see if this helps. I don't know if this can help removing the files, this is a ROM bug, I don't know if there is any available solution without rooting.

Related

Apk is disappearing after moving to system parition

I'm trying to install my apk on system partition. I've rooted device and here are the steps I'm following,
adb install -d -r <apk_name>
Now apk gets installed in /data/app/<apk_name>/
Move all contents present from /data/app/<apk_name> to /system/priv-app/<apk_name>
Clear the contents within /data/app/<apk_name> and reboot the device
Post reboot not able to find my apk under adb shell pm list packages | grep <apk_name>
I'm trying to read and write value to secure setting which is asking my app to be in system partition. When I'm trying to move I'm facing this issue. I could not find something suspicious from logs while installing the apk.
Tried all possible solutions listed here (Android 5.0/Lollipop: Force rescan of /system/priv-app) but none didn't help.
Any help to debug this issue would be really helpful.

"adb pull" stuck in half way

Suddenly my "adb pull" command will stuck in the middle of the process.
I'm not sure what cause it, after install some application or driver.
Happens for Pull one files or multiple files.
Does anyone encounter the same issue before? thanks.
Example:
U:\batch>adb pull /sdcard/xxxlog/mobilelog .\xxxlog\
[ 94%] /sdcard/xxxlog/mobilelog/APLog_xxx/main_log_1__xxx: 87%
Here a screenshot from my console
for my specific answer, and provide a possible answer to who encounter similar problem.
after I reinstall the whole os, testing different adb version,
the issue still remains.
during testing adb version,
I found the issue will not happens if i use Local Disk...
where issue happens when using Network Drive..
So a possible solution, is don't use Network drive
I encountered similar problem on adb server (v 1.0.40) started on Windows 7 machine. When tried to pull files from device on other machine running Linux in same local network (I used: "adb -H pull ...") the adb was freezing occasionally.
The solution was to not use Windows for ADB server.
This problem was NOT visible, when adb server was running on Linux VM (Ubuntu 16.4/ VirtualBox). Hope that this helps.
BR,
Ziggy
Every time I encounter this, it ends up being a max path length issue. Open a shell on the device using adb and review the file names within the directories that you are pulling. If any have exceedingly long names, they will silently fail and adb will hang
The thing that really throws you for a loop is that it usually fails after giving a percentage complete which makes you think it's a faulty connection or some other issue.
I haven't found a good way to recursively list out file names in shell and test their name length prior to doing the pull in order to know that the issue is going to happen, but when I have the same issue and rename long files, it ends up working on the next attempt.
I encountered the same problem when trying to transfer a large amount of data from an Android phone to a Raspberry Pi 3B+, and the logcat output seemed to reveal that adb was silently failing due to an issue with USB buffer reads (unfortunately, I don't have the exact message with me).
After the initial failure, it was possible to get another few files individually by unplugging the phone, running adb kill-server and adb start-server, and plugging it back in between each one, but the only longer-term fix I could find was restarting the Raspberry Pi. This solution, however, is not permanent, and must be repeated occasionally.
I was not able to replicate this issue on Windows or on a traditional Ubuntu system.
I encountered this problem while copying files from My Ubuntu machine to my Pixel 7.
A workaround based on this bug report, is to run
adb shell exit
in another terminal whenever it gets stuck until all files are copied. You can also run
watch -n 30 adb shell exit
to run the command every 30 seconds so you don't have to keep watching the process. I hope this helps someone.

adb -d shell "run-as ..." not working on Android O

Has something changed that commands like the following below no longer work on Android O?
adb -d shell "run-as package.name cat /data/data/package.name/databases/foo.db" > foo.db
Running:
Build: OPP2.170420.019
Device: Nexus 6P
I have tried endless amounts of ways but even cat or cp to the /sdcard does nothing. I am guessing some permission has changed and we can no longer use run-as package.name.
The only way that I am able to get data from my non-rooted Android O device is to use a FileProvider and copy to the /sdcard.
Does anyone have success using run-as on a debug package? Anyone having the same issues as I am?
I don't know the answer to my specific question but want to share my new findings (maybe obvious to some).
After testing Android Studio 3.0 Canary 1, there is a new Device File Explorer that allows easy downloading and even syncing the latest DB!
This is such a powerful feature for anyone that needs to grab files of any sort from their devices in development. The cat command was never perfect and always screwed up the DB every once in a while.
This File Explorer + SQLPro for SQLite is gold for any Android Development that has a DB!
Will leave the question open in case someone does have a reason or solution to my original problem. Plus I would feel like a douche accepting my own answer. :)
Looks like run-as will set current directory to /data/data/packageName.
I think the following would work:
adb -d shell "run-as package.name cat databases/foo.db" > foo.db

ADB Install seems to fail (preventing me from debugging on device using Visual Studio)

I use VS2015 with Xamarin to deploy an app to my phone. After recently rooting and wiping my phone data, I'm receiving errors upon deploying. The most common issue was that the "Fast deploy" was enabled, but I already had that turned off.
I figured out that my ADB Install seems to fail (permission denied), giving me the following error:
failed to copy 'x' to '/data/local/tmp/x': Permission denied
It really starts working on my nerves, and after trying several things which I found on the internet, I ended up asking a question here.
When I go to my 'ADB Shell' (running in root mode and showing this # sign), and type 'ls -ld data data/local data/local/tmp'
it shows the following, which seems to be normal (according to things I read):
drwxrwx--x system system 2016-06-26 15:11 data
drwxr-x--x root root 2016-06-26 08:52 local
drwxrwx--x shell shell 2016-06-26 01:58 tmp
I started by recreating the 'tmp' folder, and using 'EF File Explorer' on my phone I can modify things and do everything I'd like to do. (modify rights, add folders, remove folders, recreate the folders and so on).
When I go to 'Root explorer' in EF File Explorer, I changed the '/' folder mode to 'RW', but it didn't make any change. Root explorer says it's still on "r/o" (read only) mode.
I tried the 'busybox mount -o remount, rw /system' trick and other mount-commands which did the trick for others, but still same issue with my phone.
Furthermore, I tried a "move" trick in the shell, which didn't work out either.
As a last option I even tried to do a full format/wipe, but even thát did not solve my issue.
So I'm currently back at square one, where my 'ls -ld' is still showing the same information. Copying files to the internal storage via Windows Explorer works as it should.
Hopefully I'm doing something stupid and is there a fix for this issue. Thanks in advance for your help.

Where does Android store shutdown logs?

I know that the boot up log can be obtained by pulling out contents of kmsg or dmesg through ADB.
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /var folder in Android (place where most desktop linux distros generally store their shutdown logs).
So how can I obtain the shutdown logs in Android?
Look in some locations such as these:
/proc/last_kmsg
/data/tombstones/
/data/dontpanic/
/data/system/dropbox/
(This list isn't strictly kernel logs, including framework and application logs too, which are also sometimes of interest)
One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\Logs.txt on the host PC and then switch off the device. You will get the logs till the USB communication between the host and the device snaps! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases!
TL;DR:
Run command through adb that copies logcat and proc/kmsg to a file and keep it running even when adb disconnects with nohup, disown or setsid. Probably needs busybox, needs root and adb root, too.
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt (somehow only works without setsid)
Or add normal copy commands to some startup script.
/TL;DR
You can constantly copy proc/kmsg and logcat to a file on your android device or a microSD card to get the logs even after adb disconnects.
You need root access and adb root access for this to work. For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app.
After using adb shell to get your android shell, type su to get superuser access.
Then you not only need to put an ampersand (&) after the command but also make sure that the command keeps running after adb disconnects. That is done by nohup, disown or setsid (see here for usage).
If it doesn't work because you don't have these commands, you need to install busybox.
See my question here.
See here for how to get logcat and kernel logs and print it to some file or merge it.
See developer.android.com/tools/help/logcat.html for parameters for the logcat command.
In the end you could have a command like setsid cat proc/kmsg > /sdcard/kmsg.txt & for the kernel messages.
For logcat you could have one of the following commands: logcat -v long -f /sdcard/logcat.txt or logcat -v long > /sdcard/logcat.txt
I don't know why, but sometimes it didn't work with setsid and just didn't copy continuously but stopped shortly after executing the command. In these situations, it also showed up when entering jobs, which it didn't otherwise. Then it just worked without setsid, it stayed alive after disconnecting and reconnecting. I guess you must just try when the file does keep getting larger. If someone figured out why it is behaving like it is... let me know and I'll edit the answer.
Probably adding the commands to a startup script could be a solution for some, too.
Hope this helps.
fightcookie
Newer phones do NOT use any of these locations so if you're reading this article then as of now
The kernel crash logs are now in /sys/fs/pstore instead of /proc/last_kmsg
I was looking for the same thing, and finally, I found the answer!
In android 8 all logs are located in \data\log\android_logs\... including apps and kernel logs. Kernel logs are called kmsgcat-log_timestamp_.gz
edit: Although this is a very old thread, I think the answer might be helpful.

Categories

Resources