Android How-tos

= Android Configuration Options =

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
 * 1) BOARD_USES_ALSA_AUDIO := true
 * 2) BUILD_WITH_ALSA_UTILS := true

Camera
USE_CAMERA_STUB := true

this define allows a dummy camera device to be built for initial testing.

OMAP
OMAP_ENHANCEMENT := true

this define enables a wide range of android enhancements targeted towards the usage of OMAP3 and OMAP4 platforms.

= Root File System =

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

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.

= GFX Suppport =

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.

Verify Kernel GFX Version
cat drivers/gpu/pvr/pvrversion.h | grep -e PVRVERSION
 * 1) ifndef _PVRVERSION_H_
 * 2) define _PVRVERSION_H_
 * 3) define PVRVERSION_MAJ 1
 * 4) define PVRVERSION_MIN 7
 * 5) define PVRVERSION_BRANCH 17
 * 6) define PVRVERSION_BUILD 4403
 * 7) define PVRVERSION_STRING "1.7.17.4403"
 * 8) 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.

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

= 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

=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.

Note: oz is an alias for omapzoom review site in my ~/.ssh/config

Then you can simply use


 * 1) 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

=To Clean Build a Subdirectory (mm -B)=

Top up tips on cleaning build.

mm -B
 * To clean all modules under a sub directory (reverse of mm).

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)

make clean-
 * To clean one or multiple library

eg: $make clean-libOMX_CoreOsal  (cleans libOMX_CoreOsal.so) $make clean-libOMX_Core clean-libOMX_CoreOsal (cleans libOMX_Core.so, libOMX_CoreOsal.so)

=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://$USERNAME@review.omapzoom.org: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

=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: 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
 * 1) cd /
 * 2) scp -p -P 29418 @review.omapzoom.org:hooks/commit-msg .git/hooks/

=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

=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: The commit in bold is the one you thought you lost, you can then recover that commit by executing

git merge 8431bc0

=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.

=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

=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 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

=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

=Repo Commands and Their Equivalent git Commands= Occasionally the repo commands fail. Whenever such a problem occurs try using git equivalent commands:

=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:

In this example 16bf9a3 is the commit ID this Kernel is based on.

=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

= 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.

=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/

=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”.

=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.

=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. ..]

=The Power of Rebasing a Commit= Rebasing a commit is very powerful. It allows you to perform actions on a commit
 * 1) Change the wording on a commit
 * 2) Squash changes from one commit to another
 * 3) Remove commits
 * 4) 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
 * 1) reword
 * 2) squash
 * 3) edit
 * 4) pick
 * 5) 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:

In order to squash the second commit into the first I change the second line so that the entry looks like this

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 my original commit

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.

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.

Move the commit and then change pick to squash: (NOTE: DO NOT DELETE ANY COMMITS HERE OR THEY WILL BE LOST!!!!)

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

=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

=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:
 * 1) Access the command line of a device
 * 2) Reboot the device to the operating system or to the bootloader
 * 3) Access the logcat logs in the device.
 * 4) Push or pull libraries to/from the device
 * 5) Install or unintstall apks (Android applications).
 * 6) 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

=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, LOCAL_CFLAGS += -DLOG_NDEBUG=0 COMMON_GLOBAL_CFLAGS += -DLOG_NDEBUG=0
 * for a single file, enable below macro in top of the file
 * 1) define LOG_NDEBUG 0
 * for a library, add below flag to Android.mk and clean build
 * for multiple files across android setup,
 * build whole android
 * add below macro to $MYDROID/device/ti//BoardConfig.mk,
 * 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)

=Prelinking in Android= Ever wondered how stagefright library (say) is loaded at same address irrespective of different processes?

=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

=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

=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... <BR>

http://www.youtube.com/watch?v=8Ug3lIN-r9o

(Works on blaze)

=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)))

external/clearsilver/cgi/Android.mk external/clearsilver/java-jni/Android.mk external/clearsilver/util/Android.mk external/clearsilver/cs/Android.mk
 * In the following files

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

=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.

<BR> <run alias from any where, which builds,copies zimage, generates boot.img, flashes it in 1 command>

kinc

=eMMC boot: Steps to Update init.rc Changes =

<update init.rc, or init.omap4430.rc in device/ti/blaze as required.. then steps to create ramdisk.img, further boot.img and flash..>

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

=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

=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.

=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.

=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

=Further Detail on Logcat Logs= Usage: logcat [options] [filterspecs]

You can control the logcat logs by specifying various options. For eg: $ logcat –b events $ logcat –v time $ logcat :V *:S This will make the logs corresponding to verbose and rest all the logs to silent.
 * To get event information from logcat:
 * To get timestamps with logs
 * To get selective logs:

options include: -s                         Set default filter to silent. Like specifying filterspec '*:s' -f        Log 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 is a log component tag (or * for all) and priority is: V   Verbose D   Debug I   Info W   Warn E   Error F   Fatal S   Silent (supress all output)

'*' means '*:d' and by itself means :v

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"

=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

repo sync
 * Then repo sync as usual

repo manifest -r -o newbaseline.xml
 * If you see a problem after the repo sync, generate a new manifest:

...then do a diff between oldbaseline.xml and newbaseline.xml to quickly see what changes could have caused the break.

=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.

=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. =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

=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: 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 the bootchart tool on your host machine

$ scp out/target/product/generic/root/init root@device:/ $ adb shell 'echo 120 > /data/bootchart-start' $ system/core/init/grab-bootchart.sh $ java -jar /usr/share/bootchart/bootchart.jar ./bootchart.tgz 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)
 * install 'init' into your system image
 * trigger bootchart functionality on system boot
 * retrieve the collected data from the system
 * generate the graphic from the data
 * view the resulting graphic
 * interpret the results

For more information: http://elinux.org/Using_Bootchart_on_Android

=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:pavan_savoy@ti.com enables one to dig up really old patches.

=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

=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: script to get the current git commit id from a gerrit changeid:

And of course these can be built upon to do more batch processing.

=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:


 * 1) Name: Give your build a name (LOCAL_MODULE := <build_name>).
 * 2) Local Variables: Clear local variables with CLEAR_VARS (include $(CLEAR_VARS)).
 * 3) Files: Determine which files your application depends upon (LOCAL_SRC_FILES := main.c).
 * 4) Tags: Define tags, as necessary (LOCAL_MODULE_TAGS := eng development).
 * 5) Libraries: Define whether your application links with other libraries (LOCAL_SHARED_LIBRARIES := cutils).
 * 6) 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.

=Understanding the Variants options in Android "lunch" command = These are the currently-defined build variants:


 * 1) eng - This is the default flavor. A plain make is the same as make eng.
 * 2) Installs modules tagged with: eng, debug, user, and/or development.
 * 3) Installs non-APK modules that have no tags specified.
 * 4) Installs APKs according to the product definition files, in addition to tagged APKs.
 * 5) ro.secure=0
 * 6) ro.debuggable=1
 * 7) ro.kernel.android.checkjni=1
 * 8) adb is enabled by default.
 * 9) user - make user.  This is the flavor intended to be the final release bits.
 * 10) Installs modules tagged with user.
 * 11) Installs non-APK modules that have no tags specified.
 * 12) Installs APKs according to the product definition files; tags are ignored for APK modules.
 * 13) ro.secure=1
 * 14) ro.debuggable=0
 * 15) adb is disabled by default.
 * 16) userdebug - make userdebug. The same as user, except:
 * 17) Also installs modules tagged with debug.
 * 18) ro.debuggable=1
 * 19) 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.

=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 <path to zImage>

Adding -c to this command will append additional bootargs to the command line.

fastboot -c "foo" -b 0x80008000 boot <path to zImage>

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 <path to zImage>

Tip started on the ICS mail list. This is the way to use it on the current HW.

=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

=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 =) input text mylongpassword
 * Place the cursor wherever you want to enter the text
 * Type:
 * After pressing enter you will see how is written in the screen

usage: input [text|keyevent] input text input keyevent <event_code>

=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

=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:


 * 1) Going into and signing into gerrit
 * 2) Clicking on Settings (Usually next to your Name and email, top right corner).
 * 3) Click on Preferences on the left hand side
 * 4) Select "Display Person Name In Review Category"

And then you can see who was the last person to NACK your patch ;)

=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 { 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*]$

=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

=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 { 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*]$

=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</li> find where "function gdbclient" is declared</li> Near the bottom of the function make this change:</li>

-      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.</li> Now, re-source the 'envsetup.sh' file.</li> </ol>

If you have the debugging symbols for your .so files in /system/lib/hw, they will now be picked up when you use gdbclient.