Can't see ATrace logs in logcat - android

I used the tracing mechanism for C++ described here by google. I'm checking for ATrace_isEnabled and while I'm getting true for ATrace_isEnabled, I'm unable to see any logs in the logcat.
I also went through with this answer, but to get enabled, I have to run systrace.py --app="my binary name". The setting of flags do not help
Is there something I'm missing?
I'm on Android 6.0.1

The setting of flags do not help, because in there source code, logic is such that it gets changed to 0 again. You need to specify appname wise like
adb shell "setprop debug.atrace.app_number 1"
adb shell "setprop debug.atrace.app_0 appname"
and for getting logs in logcat, use this __android_log_print(ANDROID_LOG_INFO, LOG_TAG, "ATrace_isEnabled = %s", ATrace_isEnabled1()?"true":"false");. Define LOG_TAG for this.
for more help, see this ATrace_isEnabled() return false

Related

Add native service to aosp

I am trying to add a native service written in C++ to the AOSP build.
The first thing I did was to create a native service and client to the AOSP build.
This worked as expected. I could start the service within an adb shell and call it via binder on a adb shell.
The trouble started when I wanted to start my service with init.
I added a .rc file to my build
service myp /system/bin/myp_service
class main
This did the the trick so that init tried to start it but it failed because of SELinux policies.
So I added a file_contexts to my device tree and added:
/system/bin/myp_service u:object_r:myp_exec:s0
Next I added a myp.te file and added:
type myp, domain;
type myp_exec, exec_type, file_type;
type myp_service, service_manager_type;
init_daemon_domain(myp)
net_domain(myp)
binder_use(myp)
binder_service(myp)
add_service(myp, myp_service)
binder_call(myp, binderservicedomain)
binder_call(myp, appdomain)
allow myp myp_service:service_manager add;
And finally I added a service_contexts file with:
myp u:object_r:myp_service:s0
This finally made my service successfully start at boot time.
Unfortunalty I cannot use binder against this service. When I try to connect to the service with my client the call
defaultServiceManager()->getService(String16("Demo"))
returns a null pointer.
I cannot find any hints in the dmesg.
So I assume I am still missing something for the SElinux but I have no clue what I am missing.
If I shutdown the SELinux with setenforce and restart the service then it works fine.
Can anyone give me a hint what I am missing for SELinux or where I can get more information about which policy blocked something?
You could see the denials like this:
adb logcat | grep "SELinux : avc" > /tmp/logs
Get sepolicy current file. (Can be taken from device this way adb pull sepolicy.
Using audit2allow (located in AOSP source code: external/selinux/prebuilts/bin/audit2allow or in SDK tools. Do this: cat /tmp/logs | .external/selinux/prebuilts/bin/audit2allow -p sepolicy
The audit2allow tool will tell you what permission you are missing for the logcat extracted and the current sepolicy file, watch-out because you could need to do this several times since fixing some permissions will show the next ones required.
If you have a userdebug kind of build you could get setenforce 0, logcat with it and all the denials will be in logcat even if you will be permited to do the operation desired. This will leave the audit2allow iterations required in 1.
For anyone who came across this problem, please make sure your service_contexts file is successfully merged with stock service_contexts file. If you're building your service for Android O or later, please put this file inside a folder and refer to it in your Makefile by BOARD_PLAT_PRIVATE_SEPOLICY_DIR1. And you don't need to add allow myp default_android_service:service_manager add if the build system does pick up your service_contexts.
Also, about the domain.te violation problem, you probably want to attach one of the coredomain or appdomain attribute to your domain 2 with typeattribute <your_domain> <attribute>;.
Finally, please double check the following built files to make sure you don't leave any sepolicy configurations out in the final build:
$(AOSP_ROOT)/out/target/product//obj/ETC/file_contexts.bin_intermediates/file_contexts.*
$(AOSP_ROOT)/out/target/product/potter/obj/ETC/plat_service_contexts_intermediates/service_contexts.*
$(AOSP_ROOT)/out/target/product/potter/obj/ETC/sepolicy_neverallows_intermediates/policy.conf

How to write Logs in File Android

I am using java logger for java projects.But now I want logs in Android.So how to carry out it.Alos I need to maiantain logs for warnings ,errors,informations in a file with serial logs.
Use android.util.Log and use methods like:
Log.v(), Log.d(), Log.i(), Log.w() and Log.e()
There are five levels of logs you can use in your application, for the most verbose to the least verbose :
Verbose:For extra information messages that are only compiled in a debug application, but never included in a release application.
Debug: For debug log messages that are always compiled, but stripped at runtime in a release application.
Info: For an information in the logs that will be written in debug and release.
Warning: For a warning in the logs that will be written in debug and release.
Error: For an error in the logs that will be written in debug and release.
A log message includes a tag identifying a group of messages and the message. By default the log level of all tags is Info, which means than messages that are of level Debug and Verbose should never shown unless the setprop command is used to change the log level. So, to write a verbose message to the log, you should call the isLoggable method to check if the message can be logged, and call the logging method :
if (!Log.isLoggable(logMessageTag, Log.Verbose))
Log.v("MyApplicationTag", logMessage);
And to show the Debug and Verbose log message for a specific tag, run the setprop command while your device is plugged in. If you reboot the device you will have to run the command again.
adb shell setprop log.tag.MyApplicationTag VERBOSE
Hope this solved your question.
For more reference :http://www.codelearn.org/android-tutorial/android-log
Upvote if you found it helpful.

executing static program from android init.rc

I want to start a custom program in the init process. I compiled this program statically that run fine from my booted up android stock ROM.
From the android init.rc docs I read that the exec command is what I need.
BTW all I can see in dmesg is that my program exit with code -1 (I can't return that).
init.rc snippet:
on post-fs-data
write /dev/kmsg "launching test"
exec /data/test
All I see in dmesg is this:
<4>[ 6.336816] launching test
<6>[ 6.336902] init: command 'write' r=0
<6>[ 6.337115] init: command 'exec' r=-1
Here you are the executable source code: http://pastebin.com/Hym1APWx
UPDATE
I tried to statically compile and run this program:
int main(){return 0; }
But the result is always command 'exec' r=-1. Maybe user uselen are right, maybe I cannot run executables from /data in the early-boot phase.
As christian said, it looks like exec isn't even implemented. I'm beginning to think that a lot of features documented for init.rc aren't implemented. Here's a way you can get your program to launch however.
Instead of running this as an "exec" command, set this up as a service instead.
In your init.rc, or another file included by it:
service my_service /data/test
class main
oneshot
If it's in class main, and not disabled, it should run after /data is mounted.
I had the same issue today. In my case the solution was simple: The exec function wasn't implemented yet and contained just a return -1. You should take a look at builtin.c and search for do_exec(). This code is executed when init.rc contains an exec statement.

"Run Command" file editing (i.e. " *.rc " files): Echoing to the terminal like Linux?

I am editing the Android phone file "init.tuna.rc" so that it prints to me some basic debugging checkpoint messages so I can analyze how far the phone gets in the boot process.
Does anyone know if you can simply insert the shell scripting syntax for console printing into a "run command" file (.rc)?
(I need to know this if someone can help me before I rebuild all of my code for the Android tree to test this debugging code, given the process can a while)
Will the following work? I want to insert in the following code snippet into the "init.tuna.rc" file:
# Boot debugging Checkpoint #2
echo "Check #2: Successfully wrote the file system data, including the wifi directories!"
If this does not work, what can I do to get the "rc" file to print messages to the actual terminal as it executes?
Android Boot Language is documented in a readme.txt file in the source tree under <android>/system/core/init.
No echo is mentioned, but you can try. Also remember that you should write to a file because stderr and stdout are redirected to /dev/null.
See https://github.com/aosp-mirror/platform_system_core/blob/master/init/README.md

How to enable assertions in Eclipse v3.7.2

I can't seem to get assertions working in my eclipse android project. I have followed the directions at this site
But I still can't get them to work. My code looks like:
assert(false) : "PROGRAM ERROR - invalid dialog call";
any ideas?
Dalvik VM ignores Java assertions by default. To enable that, one must change debug.assert property, e.g by invoking command in command line:
adb shell setprop debug.assert 1
Please note that you have to restart VM after that (force stop application: Settings->Apps->click on the app->Force stop).
Please also note that the setting is not persistent (assertions will be disabled again after phone reboot). However on rooted phones there's a way to make it persistent by putting /data/local.prop file containing line
debug.assert=1
What language are you expecting to use with the above?
I would try:
assertTrue("Expected true", true);
assertFalse("Expected false", true);
assertEquals("Expected equal", "same", "same");
Junit:
junit-docs/junit/framework/Assert.html

Categories

Resources