Android How-tos
From OMAPpedia
[edit] Android Configuration Options
[edit] Audio
BOARD_USES_GENERIC_AUDIO := true
this define allows a dummy audio device to be built for initial testing. to use this option comment out other audio defines such as alsa:
BOARD_USES_GENERIC_AUDIO := true #BOARD_USES_ALSA_AUDIO := true #BUILD_WITH_ALSA_UTILS := true
[edit] Camera
USE_CAMERA_STUB := true
this define allows a dummy camera device to be built for initial testing.
[edit] OMAP
OMAP_ENHANCEMENT := true
this define enables a wide range of android enhancements targeted towards the usage of OMAP3 and OMAP4 platforms.
[edit] Root File System
[edit] Vendor Files
new with gingerbread, a vendor directory is now supported. the vendor directory is expected to be in the root directory. if your vendor directory is in another part of the file system, include a link to the correct directory:
ln -s /vendor /system/vendor
[edit] JAR Files
make sure that the /data and /cache directories are mounted read/write or you will get errors reporting that some of the jar files needed for the JNI are not found.
[edit] GFX Suppport
[edit] Verify Lib GFX Version
cd /system/vendor/lib/egl ls -al lrwxrwxrwx 1 danders danders 40 2011-05-10 10:45 libEGL_POWERVR_SGX540_120.so -> libEGL_POWERVR_SGX540_120.so.1.1.17.4403 -rw-r--r-- 1 danders danders 20192 2011-05-10 10:45 libEGL_POWERVR_SGX540_120.so.1.1.17.4403 lrwxrwxrwx 1 danders danders 46 2011-05-10 10:45 libGLESv1_CM_POWERVR_SGX540_120.so -> libGLESv1_CM_POWERVR_SGX540_120.so.1.1.17.4403 -rw-r--r-- 1 danders danders 3331116 2011-05-10 10:45 libGLESv1_CM_POWERVR_SGX540_120.so.1.1.17.4403 lrwxrwxrwx 1 danders danders 43 2011-05-10 10:45 libGLESv2_POWERVR_SGX540_120.so -> libGLESv2_POWERVR_SGX540_120.so.1.1.17.4403 -rw-r--r-- 1 danders danders 2955632 2011-05-10 10:45 libGLESv2_POWERVR_SGX540_120.so.1.1.17.4403
each GFX library file with have an extension with the library version number. in this example the version is 4403
Another way to tell the DDK version of the user mode binaries is to run "strings" on the libIMGegl.so binary
strings /system/vendor/lib/libIMGegl.so | fgrep build 1.4 build 1.8.18.468
This DDK is version 1.8.18.468, or sometimes shorthanded to as 468. Note that all version numbers are significant, and as such 1.1.17.468 is not the same as 1.8.18.468.
[edit] Verify Kernel GFX Version
cat drivers/gpu/pvr/pvrversion.h | grep -e PVRVERSION #ifndef _PVRVERSION_H_ #define _PVRVERSION_H_ #define PVRVERSION_MAJ 1 #define PVRVERSION_MIN 7 #define PVRVERSION_BRANCH 17 #define PVRVERSION_BUILD 4403 #define PVRVERSION_STRING "1.7.17.4403" #define PVRVERSION_FILE "eurasiacon.pj"
to check the version of GFX inside the kernel source, look at the drivers/gpu/pvr/pvrversion.h file.
cat /proc/pvr/version Version 1.7.17.4403 (release) omap_sgx_android System Version String: SGX revision = 1.2.0
to check the version of GFX from a running linux kernel, cat the /proc/pvr/version file.
this version information needs to match that of the GFX libraries on the android root file system.
[edit] Memory Allocation
Android defaults to using two framebuffers for page flipping. in order to support this memory for the video subsystem needs to be allocate properly as part of the boot arguments:
vram=32M omapfb.vram=0:16M
these boot args allocate 32M for the video subsystem and then sets the display 0 to use 16M (half) for the primary portion of the display.
For large screens (i.e. 1920x1200), it is necessary to double the amount of video memory:
vram=64M omapfb.vram=0:32M
If you have failed to allocate the memory properly you may receive one or more of the following errors:
I/SurfaceFlinger( 1198): SurfaceFlinger is starting I/SurfaceFlinger( 1198): SurfaceFlinger's main thread ready to run. Initializing graphics H/W... E/SurfaceFlinger( 1198): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake E/FramebufferNativeWindow( 1198): couldn't open framebuffer HAL (Bad address)
or
I/SurfaceFlinger( 1198): SurfaceFlinger is starting I/SurfaceFlinger( 1198): SurfaceFlinger's main thread ready to run. Initializing graphics H/W... E/SurfaceFlinger( 1198): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake E/FramebufferNativeWindow( 1198): couldn't open framebuffer HAL (No such device)
Note: The above error messages could also be due to a mismatch in kernel/library versions of GFX drivers. Make sure they have the same version number. Refer to: http://omapedia.org/wiki/Android_How-tos#Verify_Kernel_GFX_Version
[edit] Run Android Application from Command Line
Sometimes, we want to launch an UI app from command line. This can be accomplished using the ‘am’ command. The ‘am’ command syntax is as follows:
am start [-a] [-d ] [-t ] [-c [-c ] ...] [-e [-e ...] [-n ] [-D] [ ]
Examples:
To play video:
am start -n com.android.gallery/com.android.camera.MovieView -d /sdcard/AV_000574_nieve_H263_CIF_384kbps_30fps_AAC_128kbps_48khz.mp4
To play music:
am start -n com.android.music/com.android.music.MediaPlaybackActivity -d {file_uri}
For more info, refer to http://learnandroid.blogspot.com/2008/01/run-android-application-from-command.html
[edit] Work Flow: Code Changes
- Setup your environment from the root of your Android folder:
$ source build/envsetup.sh $ setpaths
- Make changes to your source code
- Build your module
- From folder with your source code changes (builds only your specific component):
$ mm
- OR if there is some weird Android.mk dependencies (i.e OMX):
$ mmm
- OR from any folder you can build from the root:
$ m
- From folder with your source code changes (builds only your specific component):
- Sync environment to target
- If you are using binaries built from your environment: From your Blaze terminal (TeraTerm/Minicom/Cutecom) prompt (if eMMC filesystem)
$ adb remount
From your Linux box prompt
$ adb kill-server $ adb sync
- If you are using pre-built binaries and only building specific component (might be other methods, but this is the way I do it): From your Blaze terminal (TeraTerm/Minicom/Cutecom) prompt (if eMMC filesystem)
$ adb remount
From your Linux box prompt
$ adb kill-server $ find $ANDROID_PRODUCT_OUT/system/lib -maxdepth 1 -name *.so -mmin -10 -exec adb push {} /system/lib \;
You will want to change the find parameters appropriately for your changes
- If you are using binaries built from your environment: From your Blaze terminal (TeraTerm/Minicom/Cutecom) prompt (if eMMC filesystem)
- Test and Repeat
[edit] Android Scripting Environment
You can write python scripts on computer and run them on the target. This is possible using adb's port forwarding. First, start an ASE interactive terminal in Python. Take note of the AP_PORT variable at the top of the terminal. Next, set up adb port forwarding and set the AP_PORT environment variable locally.
example: $ python2.6 Python 2.6 Type "help", "copyright", "credits" or "license" for more information. >>> import android NB: The ASE android.py module should be on your sys.path. >>> droid = android.Android() >>> droid.makeToast("Hello from my computer!")
More info and examples using image gallery and web browsing: http://opbuwiki.dal.design.ti.com/index.php/Installing_and_Using_ASE
[edit] Debugging Segmentation Faults
Normally we get the backtrace for the seg fault prints in the device console. For analyzing it using the PC value and tracing them to code, kindly refer to my new post in Omappedia: https://omappedia.com/wiki/Android_Debugging#Debugging_segmentation_fault
In some cases we might get Server died message or binder failure as below:
W/AudioSystem( 1000): AudioFlinger server died! W/MediaPlayer( 1000): MediaPlayer server died! W/AudioSystem( 1000): AudioPolicyService server died! I/ServiceManager( 937): service 'media.audio_flinger' died I/ServiceManager( 937): service 'media.player' died I/ServiceManager( 937): service 'media.camera' died I/ServiceManager( 937): service 'media.audio_policy' died W/MediaMetadataRetriever( 1140): MediaMetadataRetriever server died!
It is possible that such scenarios are also caused by seg faults but they are not printed and we would be left clueless.
Inorder to confirm that are no seg faults we can enable additional user space fault prints for debugging purpose.
In the kernel: arch/arm/mm/fault.c file, Within function __do_user_fault () we can enable the CONFIG_DEBUG_USER or just comment the macro and user debug condition so that back trace is printed in case of any fault.
The steps mentioned in the Wiki link above can be used to analyze the seg fault trace
[edit] Open Source Means Participation
No opensource project can be successful without people participating in it. Since many people on the Android team are a little new to opensource and to Linux, I thought I would start my first tip with some advice: participate.
To that end, you must be a learner and a do-er. The best tip I can give regarding this is to start using Internet Relay Chat (IRC). You can listen in and learn from people, you can ask your own questions and learn directly, and when ready you can answer others questions and influence the community in a positive way.
For starters:
- Join Freenode.net server. You can get a nice GUI app for any OS these days - on Ubuntu Linux, I like XChat.
- Create (AND REGISTER) a nick-name with the freenode NickServ.
- Join the #linux-omap channel at minimum.
- Browse the channel list and pick topics that are relevant to you. As an audio aficionado , I constantly listen/learn and participate on #alsa and #alsa-soc channels. You can certainly find channels for your domain as well. I know there are channels speficif to V4L, DSS, BlueZ, etc. You can also learn alot on the #ubuntu-arm channel. I have noticed a recent increase in TI presence here since our L23 GL efforts have started making Ubuntu releases for OMAP...
- Explore, don't be shy. Ask a question if you have one; challenge some one else's answer if you don't agree 100%. After all, in opensource, the goal is always to be better.
[edit] GIT: Temporarily setting aside work in progress
While you are in the middle of working on something complicated, you find an unrelated but obvious and trivial bug. You would like to fix it before continuing. You can use 'git stash' to save the current state of your work, and after fixing the bug (or, optionally after doing so on a different branch and then coming back), unstash the work-in-progress changes.
$ git stash save "work in progress for foo feature" This command will save your changes away to the stash.
And reset your working tree and the index to match the tip of your current branch. Then you can make your fix as usual. ... edit and test ...
$ git commit -a -s After that,
You can go back to what you were working on with git stash pop:
$ git stash pop
You can also stash several things at the same time just by giving a different name for the stashed item. Like, git stash save "item1" ...do some more modifications... git stash save "item2" Both item1 and item2 will be present in the stash and can be fetched at a later point.
You can view all items in the stash by typing git stash list Suppose you want to fetch item1 back again, you can do that by typing
$ git stash apply stash@{1}
For more details try
$ git stash –help
If you don't want to think of a fancy name for the work you are saving you can just run,
$ git stash
This doesn't require you to use "git add" to select which files to save, as it saves all files with changes made to them. Also this will autogenerate a name including the branch you are on and the latest commit id. E.g:
stash@{1}: WIP on p-android-omap-2.6.35-dpllcascade-jonathan: ef4d2b9 OMAP4: OPP25 for ABE
Also know that when get stash is run it will wipe out all changes in your working dir that are not in the staging area (i.e, git add ...). So if you have three files with changes named f1, f2 & f3 and you run the following,
git add f1 f2 git stash save "saving f1 and f2 for later work"
Then the changes made to f3 will not be saved, and will be wiped out. This is dangerous because you might think that the changes to f3 will remain in your working directory, but unsaved. Instead they'll be gone forever :-(
[edit] Color coding logcat output for easier debugging
You can pipe your adb logcat output through the attached Python script to get started, or you can run the script directly to invoke adb:
$ adb logcat | ~/coloredlogcat.py$ ~/coloredlogcat.py
The ouput will be colored to point out various sections in the log Reference: http://jsharkey.org/blog/2009/04/22/modifying-the-android-logcat-stream-for-full-color-debugging/
[edit] Making Ctrl+C work in Android console
If you have ever faced an issue, that the console hangs, and "Ctrl+C" doesnt work, you can add the following to variable to your bootcmd (make sure that you set the right ttyS port for your platform) androidboot.console=ttyS3
[edit] Getting su work from serial console
In some cases running su to get superuser privileges will not work from the serial console. You may get a permission denied error.
shell@android:/ $ su su: permission denied
To fix this, get to superuser mode from adb shell. (You may have to run adb root first.) Then change the permissions on the su binary:
chmod 6755 /system/xbin/su
[edit] Disabling screen lock forever
Screen lock can be disabled for development, prolonged tests by
#sqlite3 /data/data/com.android.providers.settings/databases/settings.db #sqlite> update system set value="-1" where name="screen_off_timeout"; #sqlite> .quit
..or via UI,
Settings->Applications->Developers -> Stay Awake
This will avoid android to lock the screen, but still system wide suspend might happen
Hence System wide suspend can be prevented by helding wakelock.
echo test > /sys/power/wake_lock
[edit] Booting with Unlocked Screen
To always boot with unlocked screen make the following change to frameworks/base/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
diff --git a/phone/com/android/internal/policy/impl/KeyguardViewMediator.java b/phone/com/android/internal/policy/impl/KeyguardViewMediator.java index c255041..c602c1b 100644 --- a/phone/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/phone/com/android/internal/policy/impl/KeyguardViewMediator.java @@ -553,7 +553,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback, } if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); - showLocked(); + //showLocked(); } }
[edit] Auto-add reviewers to your patches
If you submit a large number of patches, or even if you just feel burdened by the extra steps required to add reviewers to yourpatches in Gerrit, this tip is for you...
No longer will you need to open your browser and manually type names for each patch.
You can set up your git config to automatically add certain reviewers to each patch (i.e. maintainer, team-lead).
For example, I auto-add a team member to each patch I send to kernel by adding these to my .git/config.
[remote "for-k32"] url = oz:kernel/omap receivepack = git receive-pack --reviewer= push = HEAD:refs/for/p-android-omap-2.6.32
Note: oz is an alias for omapzoom review site in my ~/.ssh/config
Then you can simply use
# git push for-k32
to upload changes. As the linked site mentions, you can specify multiple reviewers this way. You can also specify multiple aliases for your remote/upstream and specify different reviewers for each.
You could also choose to put this in your global .gitconfig, though I prefer to use this in each specific git tree .git/config.
More info here: http://gerrit.googlecode.com/svn/documentation/2.0/user-upload.html
[edit] To Clean Build a Subdirectory (mm -B)
Top up tips on cleaning build.
- To clean all modules under a sub directory (reverse of mm).
mm -B
eg:
$MYDROID/hardware/ti/omap3/liboverlay> mm -B
Real handy when you update just a .mk file, but not a header/source file, in which case a incremental build wont build the changes as intended. Works well with single liibarary, and so should multiple libraries (yet to confirm sanity of multiple libraries)
- To clean one or multiple library
make clean-
eg:
$make clean-libOMX_CoreOsal (cleans libOMX_CoreOsal.so) $make clean-libOMX_Core clean-libOMX_CoreOsal (cleans libOMX_Core.so, libOMX_CoreOsal.so)
[edit] Use "repo" to Push Patches
repo can manage the branches where the patches will be submitted. This is dependent of the manifest and as long as it is aiming to the correct project branch then your patch will be submitted always to the correct branch.
So replace the following command
$ git checkout -b mybranch
for
$ cd ${Some Project} $ repo start mybranch .
don't forget the dot at the end.
Then work as usual, commit your change and then push your patch to gerrit.
Replace
$ git push ssh://$:29418/ mybranch:refs/for/somebranch
$ cd ${Some Project} $ repo upload .
Don't forget the dot at the end
If there are multiple branches on your project repo will instruct you to choose the correct one
[edit] Create and Insert a Unique Change-Id Line During git commit
Gerrit Code Review provides a standard commit-msg hook which can be installed in the local Git repository to automatically create and insert a unique Change-Id line during "git commit". To install the hook, copy it from Gerrit's SSH daemon:
# cd/ # scp -p -P 29418 @review.omapzoom.org:hooks/commit-msg .git/hooks/
With the Change-Id in place any patch can be identified across all drafts of it. With this information a new version of the patch/Change can be associated to its original review, even across cherry-picks and rebases
[edit] Git Usage Tips
TIP#1: Generating and applying .patch files with GIT If you ever wanted to send someone a .patch file from git, use the below command that generates patch files for every commit starting from commit id1 to commit id2
git format-patch...
...and to apply a patch created using the above command to your git log
git am <.patch file name>
TIP#2: Finding out if you are on the right tag You want to absolutely make sure your current commit is pointing to the official release tag, then you can use the following git command. This prints out the tag corresponding the latest commit on your branch
git describe --exact-match HEAD
[edit] Recovering Lost Commits
So, you just did a git reset --hard HEAD^ and threw out your last commit. Well, it turns out you really did need those changes. You’ll never be able to implement that algorithm that perfectly twice, so you need it back. Don’t fear, git reflog should help you recover your lost commit. Type the following commands
git reflog
This will spit out the history of the commands executed so far:
2e5a0e8 HEAD@{0}: 2e5a0e89f2eff1146eedfb93a19ab76aff154c65: updating HEAD 8431bc0 HEAD@{1}: commit: OMAP4 CameraHAL: VSTAB updates 2e5a0e8 HEAD@{2}: commit: OMAP4 Camera HAL: Support for sensor selection inside CameraAdapter 6f20714 HEAD@{3}: HEAD^: updating HEAD 0ce00d9 HEAD@{4}: commit: OMAP4 Camera HAL: Support for sensor selection inside CameraAdapter 6f20714 HEAD@{5}: commit: OMAP4 CameraHAL: Adding prints to dump the 3A parameters in OMXCameraAdapter. 0819baf HEAD@{6}: checkout: moving from 0819bafb16173174de22a0a002f6fb9a00f88854 to patch 0819baf HEAD@{7}: checkout: moving from ac629516642b934c6fdb82bff7777109f06df13b to 0819bafb16173174de22a0a002f6fb9a00f88854
The commit in bold is the one you thought you lost, you can then recover that commit by executing
git merge 8431bc0
[edit] Measure Yourself Against Your Team
Measure yourself against your team Have you ever wondered how many patches you have contributed to a project?. Well, git has a nice way to do it
git shortlog -s -n
This prints the number of commits against the author's name. Try it for yourself and see.
[edit] Speed Up Repo Sync
Whenever you do repo sync for the first time on a project, you should back-up the .repo/projects folder.
Assuming that the projects folder is backed up in ~/mydroid_latest, you can use the following commands
The steps I follow are:
repo init -u git://git.omapzoom.org/platform/omapmanifest.git -b gingerbread cp -r ~/mydroid_latest/projects .repo/
Doing this will avoid the ~6 Gb download that repo sync does.
Once the copying is finished, you can do
repo sync
and it will only download the new code that was added to the repo using the manifest file, that was used to init the repo
[edit] Android Debug Commands
Some handy debug tools...
LOGCAT No tips required though. A hint is: we can filter logcat messages using LOG_TAG field and flags V/D/I/W/E/F/S (corresponds from LOGV verbose to LOGE error, silent)
logcat TIOverlay:V OMXCodec:D *:S prints TIOverlay’s all logs, OMXCodec’s only LOGE/LOGD/LOGI logs, but suppresses rest.
DUMPSYS Dumps state of whole system
dumpsys meminfo Displays breakup of memory usage by a process dumpsys meminfo Displays breakup of memory usage of all process dumpsys Displays whole system status
DUMPSTATE Same as dumpsys, prints extra system debug information starting from bootargs, /proc/meminfo, etc...
BUGREPORT Supposed to save logcat, dumpsys, dumpstate data to file. But just prints as trace today in éclair/froyo
Source of these utilities can be found at native app section ./frameworks/base/cmds/
More Info: http://developer.android.com/guide/developing/tools/adb.html
[edit] Kernel Traces - On the Go
To get a snapshot of kernel trace buffer
dmesg
To enable complete kernel traces
echo 8 > /proc/sys/kernel/printk
To disable complete kernel traces
echo 0 > /proc/sys/kernel/printk
[edit] Repo Commands and Their Equivalent git Commands
Occasionally the repo commands fail. Whenever such a problem occurs try using git equivalent commands:
1. repo start local_branch_name . -> GIT: git checkout -b local_branch_name 2. repo upload local_branch_name -> GIT: git push ssh://:29418/platform/git_name :refs/for/remote_branch_name (froyo, p-froyo etc) 3. repo upload --replace (to replace a patch) -> GIT: git push ssh://:29418/platform/git_name :refs/changes/patch_id
[edit] Finding Your Kernel Version
Here is a quick way to find the kernel version you are using. At the command prompt type:
cat /proc/version
The output from this will look something like the below:
Linux version 2.6.35.7-00081-g16bf9a3 (x0066741@autumn) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-202) ) #1 SMP PREEMPT Mon Apr 18 03: 09:42 CDT 2011
In this example 16bf9a3 is the commit ID this Kernel is based on.
[edit] Find What Changed in a subdir of a git Tree
Have you ever needed to find what was recently changed on a specific module or functional block of code? In many git trees like the kernel tree, there are many times where knowing the patches that were made on a specific subdir can help you know what a test suddenly fails, or why something is not working as expected. Try this:
git log -my-sub-tree-
For example, to see recent changes in the omap specific audio driver you could use
git log sound/soc/omap
This can be especially nice if you know the last working version and there are not many changes to look at... in this case, you can specify a time in history to begin your log:
git log some-SHA my-sub-tree
Or, back to the audio example to see what changed since commit=c0ff3e you can use
git log c0ff3e.. sound/soc/omap
Happy git-logging!! More info found at man git-log
[edit] Compiling latest Android SDK version
When using Android SDK + Eclipse to develop or debug an application downloaded a Android image can be a pre-release version, to compile the current version follow next procedure;
These instruction can be found in
$MYDROID/development/docs/howto_build_SDK.txt
or for Icecream Sandwich
$MYDROID/sdk/docs/howto_build_SDK.txt
Following the procedure Download code at http://omapedia.org/wiki/Android_Getting_Started#Accessing_Source_Code or using a release notes for specific target, then compile it with next steps. -Depending on the version of Android you are compiling select one option, check for what device you are compiling, the folder's location can change, this instruction comes in Accessing_Source_Code in Android compilation instructions.
check you are located in $MYDROID directory
in Froyo, GingerBread, HoneyComb
cp device/ti/blaze/buildspec.mk.default ./buildspec.mk
in Icecream Sandwich
lunch blaze_tablet-userdebug # (for Blaze Tablet)
or
lunch full_blaze-userdebug # (for Blaze)
or run command "lunch" alone for a list of options.
then run next commands from $MYDROID
source build/envsetup.sh setpaths make sdk
This will create out/host/darwin-x86/sdk/android-sdk_eng._linux-x86.zip output file, or one named according to the selected version. Follow installation steps from http://developer.android.com/sdk/index.html in order to install just compiled package in your environment;
The instructions to build "ADT plug-in" can be found in this document too. This are build instructions in mentions about using Eclipse specific RCP/Plug-in use the one indicated in the file;
Depending on Android version that you use, the script location ADT plugin can change:
$MYDROID/development/tools/eclipse/scripts/build_server.sh ~/mysdk $USER
or for Icecream Sandwich
$MYDROID/sdk/eclipse/scripts/build_server.sh
Read howto_build_SDK.txt file and follow compilation instructions.
Notes: Try to do a backup copy of Android SDK that just compiled before compiling "ADT plug-in", previously generated files are erased.
[edit] Faster Git Clones
Any git tree clone can be made much faster using the "--reference" option in clone command.
Eg: Fast Kernel clone when you already had an old kernel clone in kernel-old/ folder.
git clone git://git.omapzoom.org/kernel/omap.git --reference kernel-old/
[edit] Run-time Debug (and module) Parameter Access
Did you know that you can access kernel module parameters at run-time via sysfs under /sys/module//parameters/?
Many parameters are read-write, allowing you to change it during runtime. Here are a few parameters to try:
/sys/module/omap_vout_mod/parameters/debug (0=off, 1=on) – OMAP V4L2 debugging /sys/module/omapfb/parameters/debug (0=off, 1=on) – FB debugging /sys/module/videobuf_core/parameters/debug (0=off, 1=on, 2=more) – V4L2 buffer handling debugging /sys/module/binder/parameters/debug_mask – Binder debug levels:
BINDER_DEBUG_USER_ERROR = 1U << 0, BINDER_DEBUG_FAILED_TRANSACTION = 1U << 1, BINDER_DEBUG_DEAD_TRANSACTION = 1U << 2, BINDER_DEBUG_OPEN_CLOSE = 1U << 3, BINDER_DEBUG_DEAD_BINDER = 1U << 4, BINDER_DEBUG_DEATH_NOTIFICATION = 1U << 5, BINDER_DEBUG_READ_WRITE = 1U << 6, BINDER_DEBUG_USER_REFS = 1U << 7, BINDER_DEBUG_THREADS = 1U << 8, BINDER_DEBUG_TRANSACTION = 1U << 9, BINDER_DEBUG_TRANSACTION_COMPLETE = 1U << 10, BINDER_DEBUG_FREE_BUFFER = 1U << 11, BINDER_DEBUG_INTERNAL_REFS = 1U << 12, BINDER_DEBUG_BUFFER_ALLOC = 1U << 13, BINDER_DEBUG_PRIORITY_CAP = 1U << 14, BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 15,
You can set the parameter by writing into the file, e.g. “echo value > file”. Read with “cat file”.
[edit] gedit-plugins to make gedit easier to use.
For Ubuntu\GNOME distribution gedit provides a set of useful plugins
You can use either synaptic or apt-get to install the package gedit-plugins;
Set of plugins for gedit gedit-plugins contain a set of plugins for gedit, GNOME's text editor.
The following plugins are included:
- Smart Spaces: Forget you're not using tabulations.
- Embedded Terminal: Embed a terminal in the bottom pane.
- Show/Hide Tabbar: Add a menu entry to show/hide the tabbar.
- Join/Split Lines: Join several lines or split long ones
- Color Picker: Pick a color from a dialog and insert its hexadecimal representation.
- Draw Spaces: Draw Spaces and Tabs
- Session Saver: Save and restore your working sessions
- Code comment: Comment out or uncomment a selected block of code.
- Bracket Completion: Automatically adds closing brackets.
- Character Map: Insert special characters just by clicking on them.
Then just go to menu\edit\preferences\plugin to select which one to use.
[edit] repo forall: One Shell Command for All the Projects
"Repo forall" is a very useful tool to run a command in each project of your repository or in a particularly list of projects.
For example if I want to create a branch in all the projects:
[MYDROID]$ repo forall -c "repo start my-branch ."
Or if you prefer to create a branch is some specific projects (i.e. build and bionic):
[MYDROID]$ repo forall build bionic -c "repo start my-branch ."
What about a "git reset" in all projects:
[MYDROID]$ repo forall -c "git reset --hard HEAD"
USAGE: repo forall [project-list ] -c command [arg. ..]
[edit] The Power of Rebasing a Commit
Rebasing a commit is very powerful. It allows you to perform actions on a commit
- Change the wording on a commit
- Squash changes from one commit to another
- Remove commits
- Update your branch to the latest version for submission.
First what does squash mean? Squash means that you merge the changes from one commit to another commit.
The command to rebase is
git rebase -i HEAD~X
Where X is the number of commits that need to be rebased. In most cases it is all of the commits that you have committed on a single branch. Failure to include all of the branches may result in the missing commits to be removed from your branch.
Once you are in the interactive rebase screen you have multiple options
- reword
- squash
- edit
- pick
- fixup
For this tip we will talk about pick and squash. To use this properly you need to place the commit with the recent changes directly under the commit that you want your new changes to be merged into.
Below is an example: I committed two changes to the same branch. Once both changes were committed I typed
git rebase -i HEAD~2
Then git presented me with this screen:
pick 626d57f This is my original commit pick daef8c4 This is a change on the first commit # Rebase a430036..daef8c4 onto a430036 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
In order to squash the second commit into the first I change the second line so that the entry looks like this
pick 626d57f This is my original commit squash daef8c4 This is a change on the first commit
Then I saved the file. If the merge does not go through successfully you will need to resolve any conflicts. Otherwise git will present you with this screen:
# This is a combination of 2 commits. # The first commit's message is:
This is my original commit
Change-Id: Icf1644927afd03c208d6295430d7192893182017 Signed-off-by: Dan Murphy # This is the 2nd commit message: This is a change on the first commit Change-Id: I7f23258a35d7ec1dc6bfa7bb9ea102d9388e836a Signed-off-by: Dan Murphy
Now here is where you have a choice as anything you leave in here will show up in the git log. So I usually comment out the second commits message like so.
# This is a combination of 2 commits. # The first commit's message is: This is my original commit Change-Id: Icf1644927afd03c208d6295430d7192893182017 Signed-off-by: Dan Murphy # This is the 2nd commit message: #This is a change on the first commit #Change-Id: I7f23258a35d7ec1dc6bfa7bb9ea102d9388e836a #Signed-off-by: Dan Murphy
Once you have made these changes (if you choose to do so) then you just have to save the file.
So you have successfully squashed two commits. Now you can re-push these changes to Gerrit and the change should show up as another patchset. There is no limit to the number of rebases you can do on a single commit. You can rebase every change you made in one single rebase activity.
Now if you have commits between your last change and the change you want to squash then you merely need to move the changes directly under the commit that it should be merged into. See below for an example.
Changes: pick 626d57f This is my original commit pick 12345df This is an unrelated change that will not squash pick daef8c4 This is a change on the first commit
Move the commit and then change pick to squash: (NOTE: DO NOT DELETE ANY COMMITS HERE OR THEY WILL BE LOST!!!!)
pick 626d57f This is my original commit squash daef8c4 This is a change on the first commit pick 12345df This is an unrelated change that will not squash
Then continue as you did before. With the commit message and a repush.
For more information you can type:
git rebase --help
At the command line
[edit] git gc /prune: Reduce Disk Space and Increase Performance
A git project contains an object database which gives a lot of power to git in self. This database contains 3 basic elements: trees, commits and blobs With the time this database increases and many of the objects become unnecessary due to many regular operation like rebase, amend, delete, etc "git gc" will run some housekeeping tasks within the current repository, such as compressing file revisions and removing unreachable object By adding the "--prune" option, "git gc" will packs objects and also deletes loose object The result is a more efficient disk space usage which also increases the performance of your repository.
Usage:
[MYDROID]$ repo forall "git gc --prune"
or if you are interested only in deleting all unreachable objects from the object database then you can use:
[MYDROID]$ repo forall "repo prune ."
or
[MYDROID]$ repo prune
[edit] ADB Usage
The Android Debug Bridge, aka ADB, is used to interface with Android devices over USB or TCP connection.
ADB can be used to:
- Access the command line of a device
- Reboot the device to the operating system or to the bootloader
- Access the logcat logs in the device.
- Push or pull libraries to/from the device
- Install or unintstall apks (Android applications).
- Obtain Android bugreports.
Below is the list of commands for each scenario above.
- adb shell - Will log you into the device and allow you to access the devices command line
- adb reboot - Will reboot the device to the OS. abd reboot bootloader - Will reboot the device into the boot loader
- adb logcat - Will log into the device and print the logcat output to the terminal window used. The output can be redirected to a file on the host if the host supports redirection.
- adb push - This command will push the a library from the source directory (generally the out directory of the build) to the destination (generally the location in the device that the library will be loaded)
adb pull - This command will pull the library from the device and copy it to the host location specified. - adb install - This will install an application into the device. This command will fail if the application already exists or if the Android SDK is not supported by the application.
adb uninstall - This will uninstall the application only not the support or data stored for the application. - adb bugreport - This command will print to terminal window that the command was typed. The output can be redirected to a file on the host if the host supports redirection.
For more information use: adb help- At the command line
[edit] ADB over ethernet
- Enable the network port. netcfg eth0 up;netcfg eth0 dhcp if needed. DHCP is enabled by default on target so no need to reserve static IP (ifconfig eth0 will display the IP address acquired).
- start adbd on target: setprop service.adb.tcp.port 5555; stop adbd; start adbd
- Connect to the adb daemon running on target.
sudo adb root sudo adb connectsudo adb devices (this should display the connected device) sudo adb remount sudo adb sudo adb reboot (this hangs forever we have to explicitly do CTRL C)
[edit] Verbose Logs
All verbose LOGV logs will appear only if macro LOG_NDEBUG is enabled with value 0 during compilation (“#define LOG_NDEBUG 0”)
For debugging purpse, we can enable LOGV like,
- for a single file, enable below macro in top of the file
#define LOG_NDEBUG 0
- for a library, add below flag to Android.mk and clean build
LOCAL_CFLAGS += -DLOG_NDEBUG=0
- for multiple files across android setup,
- build whole android
- add below macro to $MYDROID/device/ti//BoardConfig.mk,
COMMON_GLOBAL_CFLAGS += -DLOG_NDEBUG=0
- touch just required files, or clean build desired modules.
- Do incremental build. (caution: global flag is visible to all files, make sure only minimal files are rebuilt)
[edit] Prelinking in Android
Ever wondered how stagefright library (say) is loaded at same address irrespective of different processes?
cat /proc/1410/maps (system server) cat /proc/1357/maps (mediaserver) . . . a2f00000-a2faf000 r-xp 00000000 b3:12 22907 /system/lib/libstagefright.so (code-section) a2faf000-a2fb3000 rwxp 000af000 b3:12 22907 /system/lib/libstagefright.so (data-section) . . . prelink-linux-arm.map provides predefined load addresses of registered libraries, so loading of libraries can be faster aiding faster boot, and making applications start faster, in a system like android with large number of libraries. #MYDROID/build/core/prelink-linux-arm.map # stagefright libraries libstagefright_amrnb_common.so 0xA3700000 # [~1M] libstagefright_avc_common.so 0xA3600000 # [~1M] libstagefright_color_conversion.so 0xA3500000 # [
[edit] Clearing Airplane Mode
On our platforms (zoom/blaze) we have issue with Airplane mode. If you have accidentally enabled it, it's not possible to disable it.
Follow the procedure below to clear the setting...
//Launch sqlite3
sqlite3 /data/data/*/*/settings.db
//After launching it, execute following command
> delete from system where name='airplane_mode_on';
Now restart the board
[edit] Switching Java Versions
After moving to Java 6 for Gingerbreads, you will have switch between Java versions for building Froyo and Gingerbread on the same machine.
Here are the instructions for doing that:
Step 1: Install Java 5
This method adds the Jaunty repositories and installs Java5 as the default java setting in the system. Open the sources file (/etc/apt/sources.list) for editing, as root
sudo gedit /etc/apt/sources.list
and add:
deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse
save the file and close gedit. Next sync your sources by running
sudo apt-get update
and install
sudo apt-get install sun-java5-jdk
Step 2: Update your ~/.bashrc file with following aliases
alias j5='sudo update-alternatives --config java && sudo update-alternatives --config javac' alias j6='sudo update-java-alternatives -s java-6-sun'
Step 3: Close and re-open your terminal for these aliases to be effective
Step 4: Before starting FROYO build type j5 on your terminal and Before starting GINGERBREAD build type j6
[edit] Android Screen Capture
There is a nice way to capture screen shots of Android device using android SDK tool (ddms.bat)
The video below explains how to use it...
(Works on blaze)
[edit] Building Gingerbread from 32-bit Ubuntu
- In build/core/main.mk
change ifneq (64,$(findstring 64,$(build_arch))) to ifneq (i686,$(findstring i686,$(build_arch)))
- In the following files
external/clearsilver/cgi/Android.mk external/clearsilver/java-jni/Android.mk external/clearsilver/util/Android.mk external/clearsilver/cs/Android.mk
change
LOCAL_CFLAGS += -m64 LOCAL_LDFLAGS += -m64 to LOCAL_CFLAGS += -m32 LOCAL_LDFLAGS += -m32
- Install following packages (in addition to packages you must have installed for Froyo Build.)
sudo apt-get install lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6
- Install Java 1.6
sudo apt-get install sun-java6-jdk
If you receive the next error: E: Package 'sun-java6-jdk' has no installation candidate, try the following
sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
NOTE: replace maverick with your current distro name
sudo apt-get update sudo apt-get install sun-java6-jdk
NOTE: If you still want to have the ability to make Froyo builds you will need to switch to Java 1.5. Use the following to switch Java versions:
To switch to Java 1.5 (needed for Froyo builds):
sudo update-java-alternatives -s java-1.5.0-sun
To switch to Java 1.6 (needed for Gingerbread builds):
sudo update-java-alternatives -s java-6-sun
If building from a 64-bit machine these additional libraries are needed:
sudo apt-get install lib32z1-dev lib32ncurses5-dev sudo apt-get install g++-multilib sudo apt-get install flex sudo apt-get install gperf
[edit] eMMC boot: Quickly Flash Incremental Kernel
While repeatedly testing small changes on top of a kernel, below might be handy.
Have a folder ready with ramdisc,umulti.sh (and preferably all emmc binaries).,
Have an alias to automate all the steps involved in building a kernel.
alias kinc='cd /data/build/kernel_l27x/omap;make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- -j4 uImage;cp arch/arm/boot/zImage /data/data/emmc/zImage;cd /data/data/emmc; ./umulti.sh; ls -l;sudo ./fastboot flash boot boot.img'
kinc
[edit] eMMC boot: Steps to Update init.rc Changes
cd $MYDROID out/host/linux-x86/bin/acp -fpt system/core/rootdir/init.rc out/target/product/blaze/root/init.rc out/host/linux-x86/bin/acp -fpt system/core/rootdir/init.omap4430.rc out/target/product/blaze/root/init.omap4430.rc out/host/linux-x86/bin/mkbootfs out/target/product/blaze/root | out/host/linux-x86/bin/minigzip > out/target/product/blaze/ramdisk.img cp out/target/product/blaze/ramdisk.img /data/data/emmc/ramdisk.img cd /data/data/emmc/ ./umulti.sh ls -l sudo ./fastboot flash boot boot.img
[edit] Parallelize Repo Sync
You can parallelize a repo sync by using the -j option. For example,
repo sync -j 4
will fetch up to 4 projects at a time. This way, you will still be able to fetch other projects while waiting for a single big project to sync up
[edit] Side-by-Side Comparison of Patch Sets in Gerrit
By default when you do a Side-by-Side diff in Gerrit the diff you see is the base on the left and Patch Set X changes on the right. However sometimes it is useful to be able to see what changed between two different Patch Sets. Gerrit supports this as well. To do this:
1. From a change record in Gerrit, click on the "Side-by-Side" link for the file you'd like to compare as usual. You will see a diff with base on the left, Patch X on the right. 2. In the upper left set of the page, click on the triangle next to the "Patch History" heading. You'll see something like this:
3. From here you can select which Patch Set to show on the left and the right, and click update to see the comparison.
[edit] An APK is Just a Zip File
An APK (Android Package) file is really just a zip file, so if you want to view the contents just rename it from Xxxxx.apk to Xxxxx.zip and WinZip can open it.
[edit] Filtering Logcat Output
To reduce the log output to a manageable level, you can restrict log output using filter expressions
Every Android log message has a tag and a priority associated with it.
- The tag of a log message is a short string indicating the system component from which the message originates. - The priority is one of the following character values, ordered from lowest to highest priority:
V — Verbose (lowest priority) D — Debug I — Info W — Warning E — Error F — Fatal S — Silent (highest priority, on which nothing is ever printed)
Ex:
If I am only interested in wpa_supplicant and WifiService logs I casn use the filter like this
logcat wpa_supplicant:V WifiService:V *:S
Source: Section "Filtering Log Output" in the below link http://developer.android.com/guide/developing/tools/adb.html
[edit] Further Detail on Logcat Logs
Usage: logcat [options] [filterspecs]
You can control the logcat logs by specifying various options. For eg:
- To get event information from logcat:
$ logcat –b events
- To get timestamps with logs
$ logcat –v time
- To get selective logs:
$ logcat:V *:S
This will make the logs corresponding to
options include:
-s Set default filter to silent. Like specifying filterspec '*:s' -fLog to file. Default to stdout -r [ ] Rotate log every kbytes. (16 if unspecified). Requires -f -n Sets max number of rotated logs to , default 4 -v Sets the log print format, where is one of: brief process tag thread raw time threadtime long -c clear (flush) the entire log and exit -d dump the log and then exit (don't block) -t print only the most recent lines (implies -d) -g get the size of the log's ring buffer and exit -b request alternate ring buffer ('main' (default), 'radio', 'events') -B output the log in binary
filterspecs are a series of
[:priority]
where
V Verbose D Debug I Info W Warn E Error F Fatal S Silent (supress all output)
'*' means '*:d' and
If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS. If no filterspec is found, filter defaults to '*:I'
If not specified with -v, format is set from ANDROID_PRINTF_LOG or defaults to "brief"
[edit] Capture Baseline Snapshot using repo manifest
When you're ready to do a "repo sync" to sync to the latest baseline, it's a good practice to first capture a snapshot of your current baseline. This is helpful in cases such as when everything was working fine before a repo sync but not working after a repo sync. Comparing a snapshot of the working baseline to the non-working baseline can give valuable data points for debugging. Here's how to do this:
- Before syncing to the latest baseline, type:
repo manifest -r -o oldbaseline.xml
- Then repo sync as usual
repo sync
- If you see a problem after the repo sync, generate a new manifest:
repo manifest -r -o newbaseline.xml
...then do a diff between oldbaseline.xml and newbaseline.xml to quickly see what changes could have caused the break.
[edit] Floating Pane Feature in Gerrit
When a patch involves many files for review, it can be tedious to use the left and right arrows to page through the files sequentially, or to select "Up to change" if you want to skip around. If you press the letter "f" you'll see a list of the files affected by the patch in a floating pane, allowing you to skip between them more easily.
[edit] Coding Standards for User Space and Kernel Space
As you probably know, both the Kernel and the Android File System have their own unique coding standards that we should comply with. Each Open Source Community will expect your patches to be in the correct format. Here are where you can find the coding standards:
Kernel:
The coding standards can be found within your kernel download. To read them:
cat $YOUR_DIRECTORY_STRUCTURE/documentation/CodingStyle
Android Filesystem:
The coding standards are listed here: http://source.android.com/source/code-style.html
Compliance with these coding standards are a good step towards looking professional to the open source communities we are dealing with.
[edit] Unlock home screen without touchscreen
To unlock the home screen from the console prompt, enter the following on the console/adb shell:
input keyevent 82
[edit] Boot Process Performance Visualization
Bootchart is a tool for performance analysis and visualization of the GNU/Linux boot process. Resource utilization and process information are collected during the boot process and are later rendered in a PNG, SVG or EPS encoded chart. Bootchart provides a shell script to be run by the kernel in the init phase. The script will run in background and collect process information, CPU statistics and disk usage statistics from the /proc file system. The performance data are stored in memory and are written to disk once the boot process completes. The boot log file is later processed using a Java application (or the web form) which builds the process tree and renders a performance chart in different formats To use Bootchart on an Android System, you need to perform the following steps:
- install the bootchart tool on your host machine
sudo apt-get install bootchart build 'init' with bootchart support $ cd mydroid $ export INIT_BOOTCHART=true $ make clean $ make $ touch system/core/init/init.c $ m INIT_BOOTCHART=true
- install 'init' into your system image
$ scp out/target/product/generic/root/init root@device:/
- trigger bootchart functionality on system boot
$ adb shell 'echo 120 > /data/bootchart-start'
- retrieve the collected data from the system
$ system/core/init/grab-bootchart.sh
- generate the graphic from the data
$ java -jar /usr/share/bootchart/bootchart.jar ./bootchart.tgz
- view the resulting graphic
Use any image viewer to examine the graphic, if you created a png image. If you output the graphic in SVG format, then you can open the file with an SVG-capable program (such as Inkscape or a web browser)
- interpret the results
For more information: http://elinux.org/Using_Bootchart_on_Android
[edit] Query All Changes in Gerrit
Has it ever happened that you had submitted a patch which never got merged either because it wasn't important or wasn't required at point of time, it was abandoned (not open) - And you need to find it now? Gerrit only shows the open, recently closed & the review requests of recent patches and not the ones which were abandoned years ago. The following query in the search bar of gerrit -> project:kernel/omap branch:p-android-omap-2.6.35 owner: enables one to dig up really old patches.
[edit] Creating a Call Log
Since not many development boards are connected to modem, and making a call isn't really enabled, the following commands enables to create a fake call log in Android. note: The number of fields to enter might vary from pastry to pastry.
sqlite3 data/data/com.android.providers.contacts/databases/contacts2.db insert into calls values (1, 1234, 20100420, 20, 1, 1, 'pqr', 1, 'abc'); - dialled insert into calls values (2, 5678, 20100420, 25, 2, 2, 'mno', 2, 'tnt'); - received insert into calls values (3, 9012, 20100420, 30, 3, 3, 'xyz', 3, 'cbs'); - missed
[edit] Query Gerrit for: commit id, url, and more, from terminal!
You can query gerrit and get data in JSON format and grep/sed from your command line like so:
echo $(ssh -p 29418 $GERRIT_USER@$GERRIT_SERVER gerrit query --format=JSON --current-patch-set $CHANGEID)
Here are two script examples of how this query can be useful:
script to get the gerrit url from a gerrit changeid:
######################## #!/bin/bash # # Get a gerrit url for a specific gerrit changeid by connecting to the review # server. # if [ $# -ne 1 ]; then echo "Usage: $0" exit 1; fi GERRIT_USER=a0273683 GERRIT_SERVER=review.omapzoom.org CHANGEID=$1 CHANGEID_URL=$(ssh -p 29418 $GERRIT_USER@$GERRIT_SERVER gerrit query --format=JSON --current-patch-set $CHANGEID | sed -rn 's_.*url":"__p' | sed 's_","last.*__') echo $CHANGEID_URL ########################
script to get the current git commit id from a gerrit changeid:
######################## #!/bin/bash # # Get a commit id for a specific gerrit changeid by connecting to the review # server. # if [ $# -ne 1 ]; then echo "Usage: $0" exit 1; fi GERRIT_USER=a0273683 GERRIT_SERVER=review.omapzoom.org CHANGEID=$1 COMMITID=$(ssh -p 29418 $GERRIT_USER@$GERRIT_SERVER gerrit query --format=JSON --current-patch-set $CHANGEID | sed -rn '\_revision_ s_.*revision":"__p' | sed 's_","ref.*__') echo $COMMITID ########################
And of course these can be built upon to do more batch processing.
[edit] Understanding the Android makefile
For those who started developing android recently, here is a quick summary of how to create a make file / what does make file contain
A makefile defines how to build a particular application. Makefiles typically include all of the following elements:
- Name: Give your build a name (LOCAL_MODULE :=
). - Local Variables: Clear local variables with CLEAR_VARS (include $(CLEAR_VARS)).
- Files: Determine which files your application depends upon (LOCAL_SRC_FILES := main.c).
- Tags: Define tags, as necessary (LOCAL_MODULE_TAGS := eng development).
- Libraries: Define whether your application links with other libraries (LOCAL_SHARED_LIBRARIES := cutils).
- Template file: Include a template file to define underlining make tools for a particular target (include $(BUILD_EXECUTABLE)).
The following snippet illustrates a typical makefile.
LOCAL_PATH := $(my-dir) include $(CLEAR_VARS) LOCAL_MODULE :=LOCAL_SRC_FILES := main.c LOCAL_MODULE_TAGS := eng development LOCAL_SHARED_LIBRARIES := cutils include $(BUILD_EXECUTABLE) (HOST_)EXECUTABLE, (HOST_)JAVA_LIBRARY, (HOST_)PREBUILT, (HOST_)SHARED_LIBRARY, (HOST_)STATIC_LIBRARY, PACKAGE, JAVADOC, RAW_EXECUTABLE, RAW_STATIC_LIBRARY, COPY_HEADERS, KEY_CHAR_MAP
[edit] Understanding the Variants options in Android "lunch" command
These are the currently-defined build variants:
- eng - This is the default flavor. A plain make is the same as make eng.
- Installs modules tagged with: eng, debug, user, and/or development.
- Installs non-APK modules that have no tags specified.
- Installs APKs according to the product definition files, in addition to tagged APKs.
- ro.secure=0
- ro.debuggable=1
- ro.kernel.android.checkjni=1
- adb is enabled by default.
- user - make user. This is the flavor intended to be the final release bits.
- Installs modules tagged with user.
- Installs non-APK modules that have no tags specified.
- Installs APKs according to the product definition files; tags are ignored for APK modules.
- ro.secure=1
- ro.debuggable=0
- adb is disabled by default.
- userdebug - make userdebug. The same as user, except:
- Also installs modules tagged with debug.
- ro.debuggable=1
- adb is enabled by default.
If you build one flavor and then want to build another, you should run "make installclean" between the two makes to guarantee that you don't pick up files installed by the previous flavor. "make clean" will also suffice, but it takes a lot longer.
[edit] Uploading a zImage to Ram for testing without flashing using fastboot
There is a way to upload a zImage into the RAM without flashing it into the eMMC or putting it on a SD Card.
By using fastboot you can use the following command:
fastboot -b 0x80008000 boot
Adding -c to this command will append additional bootargs to the command line.
fastboot -c "foo" -b 0x80008000 boot
This will add foo to the command line arguments.
You can also additionally flash this into the emmc using the following command.
fastboot -b 0x80008000 -c "foo" flash:raw boot
Tip started on the ICS mail list. This is the way to use it on the current HW.
[edit] Configuring a Git Alias
If you find that there's a particular git command which requires a lot of keystrokes that you tend to use a lot you can configure an alias. For instance if you frequently use:
git log --pretty=oneline
...you can configure an alias using the following:
git config --global alias.slog 'log --pretty=oneline'
...which you can invoke using:
git slog
[edit] Input From Command Line
At the Android console you can enter text or keyevents avoiding the usage of the touch screen and screen keyboard.
This is very useful for instance for entering a WPA Enterprise password =)
- Place the cursor wherever you want to enter the text
- Type:
input text mylongpassword
- After pressing enter you will see how is written in the screen
usage: input [text|keyevent] input textinput keyevent
[edit] Using git blame
Git blame is a nice tool that can be used for finding out who last modified a particular line of code and which commit made the change.
For instance if you want to see what were the most recent changes around line 50 of omap-mcbsp.c you could type:
git blame -L 50 sound/soc/omap/omap-mcbsp.c
...and would get output like the following.
2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 50) unsigned int bus_id; 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 51) struct omap_mcbsp_reg_cfg regs; ba9d0fd0 (Jarkko Nikula 2008-10-20 15:29:59 +0300 52) unsigned int fmt; 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 53) /* 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 54) * Flags indicating is the bus already activated and configured by 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 55) * another substream 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 56) */ 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 57) int active; 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 58) int configured; 5f63ef99 (Graeme Gregory 2009-11-09 19:02:15 +0000 59) unsigned int in_freq; 5f63ef99 (Graeme Gregory 2009-11-09 19:02:15 +0000 60) int clk_div; 3f024039 (Peter Ujfalusi 2010-06-03 07:39:35 +0300 61) int wlen; 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 62) }; 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 63) 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 64) static struct omap_mcbsp_data mcbsp_data[NUM_LINKS]; 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 65) 2e74796a (Jarkko Nikula 2008-04-25 13:55:19 +0200 66) /*
Then if you wanted to see the full patch for any of these commits you could use git show to see the entire patch:
git show 2e74796a
[edit] Adding a reviewer column to Gerrit
You can enable the ability to see the last reviewer of your patches or your watched patches in the code review dashboard view by:
- Going into and signing into gerrit
- Clicking on Settings (Usually next to your Name and email, top right corner).
- Click on Preferences on the left hand side
- Select "Display Person Name In Review Category"
And then you can see who was the last person to NACK your patch ;)
[edit] Show git branch name at command prompt
If you would like to be able to see what git branch you are currently on from the command line like this:
a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00]$
....you can add the following to your .bashrc file:
function parse_git_dirty { [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" } function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" }
This will also add an asterisk to the branch if the branch is "dirty" (if there are uncommitted changes on your branch) like this:
a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00*]$
[edit] Diverting logcat prints to kernel log
Method to divert the logcat prints to kernel log, with this logcat prints also will come along with the kernel time stamp.
Add the below lines to the init.rc script
*********************************************** service logcat /system/bin/logcat -f /dev/kmsg oneshot on property:ro.debuggable=1 start logcat ***********************************************
Along with -f all the filter options that comes by default with the logcat also can be given in the above service, i.e. below is also possible
service logcat /system/bin/logcat -s 'InputReader:*' -s 'InputDispatcher:*' -s 'EventHub:*' -s 'WindowManager:*' -s 'power:*' > /dev/kmsg
if we don't want to run in the service, then below also will work
logcat -s 'InputReader:*' -s 'InputDispatcher:*' -s 'EventHub:*' -s 'WindowManager:*' -s 'power:*' > /dev/kmsg
[edit] Show git branch name at command prompt
If you would like to be able to see what git branch you are currently on from the command line like this:
a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00]$
....you can add the following to your .bashrc file:
function parse_git_dirty { [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" } function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" }
This will also add an asterisk to the branch if the branch is "dirty" (if there are uncommitted changes on your branch) like this:
a0270655local@Dta0270655ub ~/ICS/kernel[barry/abe-00*]$
[edit] Debugging libs in /system/lib/hw
By default, the debugging symbols for the .so files in /system/lib/hw are not picked up when using gdbclient. This means, for instance, that you can't set breakpoints or get stack traces from the Audio Hal (/system/lib/hw/audio.primary.blaze_tablet.so).
Adding them is simple:
- edit build/envsetup.sh
- find where "function gdbclient()" is declared
- Near the bottom of the function make this change:
- echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS" + echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw"
- Save file.
- Now, re-source the 'envsetup.sh' file.
If you have the debugging symbols for your .so files in /system/lib/hw, they will now be picked up when you use gdbclient.
[edit] Using trace-cmd and kernelshark to get system traces
[edit] SUMMARY
The Linux kernel has a system that allows real-time tracing of many kinds of events, such as irq handler entry/exit, scheduler context switches, block device events, etc. When debugging strange slow-downs and system interactions, this is a very powerful tool. It is similar to systemtap, but it's easier to use. This uses "stock" kernel trace events, whereas systemtap allows highly customized tracing.
[edit] UBUNTU SET-UP
Install trace-cmd and kernelshark on ubuntu. You can use the same techniques on your laptop, since the traces are enabled in the kernel by default:
$ sudo apt-get install kernelshark trace-cmd
[edit] KERNEL CONFIG
Inside menuconfig:
Kernel hacking --> [*] Tracers --> [*] Kernel Function [*] Kernel Function Graph [ ] Interrupts-off Latency [ ] Preemption-off Latency [*] Scheduling Latency Branch Profiling (No branch profiling) ---> [ ] Trace max [*] Support for tracing block IO [*] enable/disable ftrace tracepoints dynamically [*] Kernel function profiler [ ] Perform a startup test on ftrace < > Ring buffer benchmark stress tester
Or add this to defconfig:
CONFIG_RELAY=y CONFIG_TRACEPOINTS=y CONFIG_NOP_TRACER=y CONFIG_TRACER_MAX_TRACE=y CONFIG_RING_BUFFER=y CONFIG_EVENT_TRACING=y CONFIG_EVENT_POWER_TRACING_DEPRECATED=y CONFIG_CONTEXT_SWITCH_TRACER=y CONFIG_TRACING=y CONFIG_GENERIC_TRACER=y CONFIG_FTRACE=y CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y CONFIG_SCHED_TRACER=y CONFIG_BRANCH_PROFILE_NONE=y CONFIG_BLK_DEV_IO_TRACE=y CONFIG_DYNAMIC_FTRACE=y CONFIG_FUNCTION_PROFILER=y CONFIG_FTRACE_MCOUNT_RECORD=y CONFIG_OLD_MCOUNT=y CONFIG_BINARY_PRINTF=y
[edit] BUILD TRACE-CMD FOR OMAP
Note that the patch you need is attached.
$ git clone \ git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git $ cd trace-cmd $ git am < 0001-omap-build.sh-Add-script-to-build-static-binary-for-.patch $ ./omap-build.sh $ adb push trace-cmd /system/bin
[edit] USING TRACE-CMD
To get a list of available tracers, use the 'list' command:
$ adb root $ adb shell trace-cmd list
For example, to get all sched:sched_switch events and all irq events:
$ adb root $ adb shell $ cd /sdcard $ trace-cmd record -e "sched:sched_switch" -e "irq:*" /sys/kernel/debug/tracing/events/irq/*/filter /sys/kernel/debug/tracing/events/sched/sched_switch/filter Hit Ctrl^C to stop recording
After you hit Ctrl^C, it will write the data to a file called trace.dat
[edit] ANALYZING TRACE.DAT WITH KERNELSHARK
Grab the data file from the device:
$ adb pull /sdcard/trace.dat .
Then open the file with the 'kernelshark' program.
[edit] TROUBLESHOOTING
- trace-cmd doesn't work
- Make sure it's compiled statically.
- Make sure that /sys/kernel/debug/tracing/ exists. If not, the kernel wasn't configured right.
- trace-cmd says it can't open the output file.
- Make sure that you have permission for trace-cmd to write "trace.dat" in the current directory.
[edit] LINKS TO MORE INFO
- Kernel Docs:
- Documentation/trace/*
- Documentation/trace/events.txt
- http://omappedia.org/wiki/Installing_and_Using_Ftrace#Using_FTrace_with_Trace-cmd
- http://lwn.net/Articles/341902/
- This article on OPBU wiki: http://opbuwiki.dal.design.ti.com/index.php/Using_trace-cmd_and_kernel_shark_to_get_system_traces
[edit] Automatic logging kernel log
Assume if
- We don't have the UART connection and need to take a kernel log during suspend(so adb is not possible)
- Forgot to take a previous log from the console.
- Need to capture many logs for multiple reboots.
- Outside testing with reboots involved, without having a computer in place.
- Maintaining the time and date stamp of kernel log
etc....
Then here is the tool we can use for logging.
Steps to use:-
- Push the kernellog.sh script to the /data folder of the filessystem through adb
- Add the following lines to the init.rc
service kernel_logging /system/bin/sh /data/kernellog.sh 10 oneshot on property:ro.debuggable=1 start kernel_logging
- Where 10 is the maximum number of kernel logs it can store, after that it will delete the older log and creates the newer one.
- All the logs will be created with the time stamp in the file name,for example --> /data/kernel_26-12-11_20:15:27.log
- Logs will be stored in /data folder, changeable by changing the script.
Note :- Please use "dos2unix kernellog.sh.sh" if the script doesn't start, before pushing.
[edit] Shell command to gather non consecutive GIT commits
In case you need to gather all commits with a same subject :
Example for omap_hsi driver:
i=1; for c in `git log --reverse drivers/omap_hsi | grep ^commit | awk '{print $2}'`; do git format-patch --start-number $i "$c^..$c"; let "i += 1"; done
Example for a particular author:
i=1; for c in `git log --reverse --author= | grep ^commit | awk '{print $2}'`; do git format-patch --start-number $i "$c^..$c"; let "i += 1"; done
etc...
[edit] Android Screen Caster
Are you using a board that doesn't have a display, are you using a Panda, or your display doesn't come up? Did you know that you can view the Android UI via ADB? Yes, screen caster can help you do that.
You can download Screen Caster from the following URL
Then you can simply invoke it using Sun Java as follows /usr/lib/jvm/java-6-sun-1.6.0.26/bin/javaws ~/androidscreencast.jnlp
Make sure ADB is connected and working, once launched you should see the android console in the screen caster app :-)
[edit] Multiple Build variants/targets on a single source
Assume if
- Your PC speed is a bit slow, and you need to maintain both the Engineering and user builds of android at a time on a single source,so you need not rebuild again for the other build variant,meaning there will be two out directories, or
- You want to build multiple targets, example for blaze_tablet, blaze and panda boards on the same source and wanted to maintain three out directories.
Then you can use the the attached two patches, if space is not a constraint for you Also one more advantage is we can trigger the builds parallel , meaning at a time we can trigger the user and Eng builds leaving it overnight, or at a time we can trigger the builds for blaze_tablet,blaze and panda.
[edit] Speed up Android builds with CCACHE
Ref: http://source.android.com/source/building.html, "Using ccache"
ccache caches previous compilations and detects when the same compilation is being done again. It can save a lot of time when rebuilding a repo sync'd AFS.
To enable set the USE_CCACHE env. variable before doing your Android build.
$ export USE_CCACHE=1
The following steps only need to be done once:
Set the location of your CCACHE directory
$ export CCACHE_DIR=//.ccache
By default the cache is limited to 1GB, you can increase this by using the prebuilt version of ccache (source.android.com gets the binary location wrong for JellyBean):
$ prebuilt/misc/linux-x86/ccache/ccache -M 20G
[edit] VIM:Taglist: Lists functions while editing a file in VIM/GVIM editor
Many of us still using VIM/GVIM editor to modify the source files. Here is a way to view function/variable names for the current file in VIM editor as in GUI IDEs such as SourceInsight and Eclipse.
- Download and install the taglist script.
mkdir ~/.vim #-> if you don't have one already. cd ~/.vim/ wget -O taglist_45.zip http://www.vim.org/scripts/download_script.php?src_id=7701 unzip taglist_45.zip
This will extract 2 files as below.
Archive: taglist_45.zip inflating: plugin/taglist.vim inflating: doc/taglist.txt
- Update your .vimrc file for some options and a shortcut key.
Add below lines in to your ~/.vimrc file
Tag list options let Tlist_WinWidth = 40 let Tlist_Auto_Open = 1 let Tlist_GainFocus_On_ToggleOpen = 1 nnoremap
:TlistToggle - Now open a c/cpp/java file.
- You will see a panel window at left side with list of tags/functions available in that current file.
- You can use F8 key to toggle the taglist window on/off.
- Use "Ctrl+w+w" to switch between taglist window and vi editor window.
For more details about the options and commands related to Taglist refer the document at ~/.vim/doc/taglist.txt.
Note: Taglist would require Exuberant ctags 5.0 or above. If you dont have the ctags installed, install that as follows:
sudo apt-get install exuberant-ctags
[edit] Generating Keyevents Through adb shell
We can automate any test scenario, by generating the key events in the adb shell.
Following is the syntax for generating the keyevents -
adb shell input keyevent
By generating the keyevents we can run, stop, launch apps and menus, select the options, lock and unlock the screen etc.
Examples:
adb shell input keyevent 82 - unlock adb shell input keyevent 3 - Goto Home screen
For more key events check http://developer.android.com/reference/android/view/KeyEvent.html