I want to implement __android_log_write() functionality using write() or some api available in libc(actually ulibc). The reason being that i cannot use any libraries associated with android as that would increase the memory required. I have very limited amount of memory as my code is running in separate memory region reserved during boot up. Main goal is to attach my debugging logs to logcat.
I am looking something similar to this:
write(1,"sandy",6);
The abovce code i can directly write to stdout. Similarly, i want to use write() or something else and write to logcat. What is the clean way to do it.
Hope i am clear. Thanks.
Got the answer. We need to open /dev/radio and write into them.
Thanks
Related
my problem isn't really that hard probably. I just want to save the log from logcat in android studio using Kotlin. Basically, I just need to save all of the text from the logcat in a readable manner as a text file whenever the application closes.
It needs to work with API versions of 28 and up to version 31.
Thank you very much ahead of time.
I don't think you're supposed to
READ_LOGS
Added in API level 1
public static final String READ_LOGS
Allows an application to read the low-level system log files.
Not for use by third-party applications, because Log entries can contain the user's private information.
There are some solutions here using Runtime#exec to run a logcat command - but honestly, if you just want to save your own app's logs, you're probably best using a library like Timber and creating a Tree that also writes out each line as well as calling Log.
(You could just create your own wrapper functions, but that requires you to remember to call them - Timber does a lot of the work for you, it's convenient!)
That won't catch other logged stuff generated by your app though, like library logs and system info.
first off: I know that this worky only on rooted devices and i know that it is not recommended - but I still want and need to do it.
I am writing an app which performs OCR on an other app, parses its on-screen output and gives the user feedback on the apps progress (therefor using getRootView is out of the question).
This can not be done in an other way, I need to have screenshots of the app at least 3 to 4 times per second.
Other ways that I tried:
/system/bin/screencap - too slow, takes >2 sec per shot on a Galaxy S5.
using obscure C Code to access the internal API of the SurfaceComposer (bloated, did not compile)
What I want: Have a way to read bytes from the framebuffer without having to write it to a file each time.
Currently I have the problem that my app does not have the right permissions. I added the READ_FRAME_BUFFER permission, but I still get a ERRNO 13 (Permission denied) when reading /dev/graphics/fb0, as the app itself is not started with root permissions.
I know I can start a shell or something similar with su, but that is not convenient - I would prefer a way to start a Service or my native Code with the right permissions.
I read about System Services but could not find any "easy" introductions. My experience in C/C++/Java is more than enough, but the Android API's jungle is newfound land to me.
The information from TI-Wiki - Writing System Services seems to implie that a rebuild of the Android System is necessary to integrate a System Service. That would be out of the question. Is that correct?
In an ideal world I would have:
Bitmap Service.getCurrentFrame() {
read one frame from /dev/graphics/fb0
create Java Bitmap
return Bitmap
}
This could be either native or Java code.
But how to gain the privileges?
Any ideas?
Additionally, I read that using the framebuffer is not recommended since it is about to be removed in future releases (sorry, lost source link).
What other fast ways are there to get the current screen content?
Use DDMS lib /dev/graphics/fb0 to get bitmap. No special permission needed.
How can I get the trace of dalvik bytecode that is being executed while the device is running an app (like logcat does)?
There is no existing tool to do what you want, but it might be possible to implement such a tool without too much work.
The general idea is that you want to connect to dalvik's vm as a debugger, using the jdwp protocol, and single step the virtual machine, inspecting the state between each step and printing out the instruction. You should be able to get the... instruction index. Or maybe the instruction offset, via JDWP.
Additionally, you will need to read the dex file, and look up the exact instruction being executed, based on the instruction index/offset you get from JDWP.
You should be able to use AndBug to implement the first part of the above solution, and then use dexlib to access the dex file, in order to get the instruction.
You might want to check out traceview
It is realy too slow to trace the method not to speak the byte code,when you want to know what the app is doing the best way is to trace method first,then trace the byte code in it.
sorry if it's a silly question. Do comments in the java or xml file effect the memory usage of the android application? has anyone tried to monitor the memory usage of his/her application with and without the comments?
No, comments do not use any memory.
It's important to understand that, in programming in C, Java, etc. what you're writing is source code which, before being run on the computer (or, specifically, your Android device) is compiled into a machine code format. The processor does not run your source code as you see it. The source code you write typically contains lots of stuff like comments (which do NOT have any effect on the actual code) or perhaps things like compiler directives (which may control how the compiler compiles sections of your code).
(I realise it's more correct to use the term byte code in the case of Java, but trying to keep the answer simple here.)
An exception to this however would be if you're talking about the case where you insert a file (e.g. XML file) as a raw resource within your Android application. But, I think this topic is an advanced one for you to learn about later.
Comments in your code are compiled out and have no effect whatsoever on memory usage in an application.
I'm working on an archiving mechanism of my application's log files and would like some advice.
What I want to do: When receiving a LogEntry, the LogListenerService will save it in a buffer and at some point it will print all the log entries in a file. When the file reaches a certain size an archiving service is called that will zip the contents of the log files and clean it.
I've implemented most of the functionality but have some questions:
How do I go about defining the ideal size of the buffer?
How do I make sure the log file size is kept under a given "maximum size"?
Thanks
Answering my own question.. :)
Depends on the application but the maximum memory an application can use is 16MB.
Simply by adding a check before writing to the file (I was hoping for a cleverer way)
Have you considered e.g. DroidDrop instead of rolling your own? (Caveat: haven't tested it myself yet.)