Screen ON And Unlock keypad

February 3, 2011 Leave a comment

Screen ON: Required when activity is in foreground and performing long running task
Use below code snippet And add "android.permission.WAKE_LOCK" in app manifest

PowerManager powermgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = powermgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
// call long running task

Unlock keypad: Required when using intents. example: Making a phone call with user activity and after completing phone call user acitivity shall not be held with a keylock

Use below code snippet inside Onresume() method of the activity. And add "android.permission.DISABLE_KEYGUARD" in app manifest
public void checkKeypadLock()
KeyguardManager Keylockmgr = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
Keylockmgr.newKeyguardLock("My Tag").disableKeyguard();

Complete Usage of Disabling and Reenabling keyguard on Android

if (mKeyguardManager == null) {
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock1 = mKeyguardManager.newKeyguardLock("QApp");
mKeyguardEnabled = true;

PowerManager powermgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = powermgr.newWakeLock(PowerManager.FULL_WAKE_LOCK| PowerManager.ON_AFTER_RELEASE| PowerManager.ACQUIRE_CAUSES_WAKEUP,"QApp");


if (mKeyguardEnabled) {

if(mProductID == 1)
retval = mCalculator.Calc(mcalcJob,isOnline);
else if(mProductID == 2)
retval = m_pCalculator.Calc(mcalcJob,isOnline);


// ON sony ericsson the keylock is very quick, so we wait for 3Sec before reenabling keyguard only on Xperia 10i
try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block

Categories: Android Dev

Android Application Screen Orientation issues

January 20, 2011 1 comment

Screen Orientation issues to know when designing Android Application

1. To design application in Portrait Mode only add screen orientation attribute in manifest.xml, make sure you add inside activity,


2. Sometimes views/Controls in the application initializes on change in Orientation. add android:configChanges in manifest.xml, inside activity attribute


wish to manipulate with Keyboard use

android:configChanges="keyboardHidden|Orientation" this is more useful when application is installed on hard keyboard devices.

Categories: Android Dev

How to get Base address/PHYS_OFFSET for specific hardware

December 30, 2010 Leave a comment

::::Quick description:::
Search for PHYS_OFFSET  in .config if not See at kernel sources at the file: arch\arm\mach-msm\include\mach\memory.h

HTC- Buzz

/* physical offset of RAM */
#if defined(CONFIG_ARCH_QSD8X50)
#define PHYS_OFFSET        UL(0x20000000)
#elif defined(CONFIG_ARCH_MSM7225) // make sure CONFIG_ARCH_MSM7225 is set to ‘y’ in .config
#define PHYS_OFFSET        UL(0x02E00000)
#elif defined(CONFIG_ARCH_MSM7200A)
#define PHYS_OFFSET        UL(0x19200000)
#elif defined(CONFIG_ARCH_MSM7201A)
#define PHYS_OFFSET        UL(0x19200000)
#elif defined(CONFIG_ARCH_MSM7X00A) && defined(CONFIG_MACH_DESIREC)
#define PHYS_OFFSET        UL(0x11200000)
#elif defined(CONFIG_ARCH_MSM7X00A)
#define PHYS_OFFSET        UL(0x19200000)
#elif defined(CONFIG_ARCH_MSM7227)
#define PHYS_OFFSET        UL(0x12C00000)
#define PHYS_OFFSET        UL(0x10000000)

For LG-GT540 Base address is PHYS_OFFSET  UL(0x00200000)

Categories: MOD and HACK

How to compile Android Device Driver as a Module(.ko)

December 28, 2010 2 comments

Here are the quick steps to be followed.

1. kernel sources from vendor say HTC wildfire(2.1 update-1)
2. Android source code for Éclair
3. Create a new folder called Kernel and copy the contents from the sources download via vendor

Step1: Copy config.gz from running hardware

adb pull /proc/config.gz
gunzip config.gz
mv config .config

Step 2: Copy/Overwrite the .config file to the kenel root directory

open .config file and search for

and replace ‘y’ with ‘m’, we use CONFIG_MODULE_NAME1 as module


Step 3: Check the active kernel version on the hardware using ‘OR’ if you are using own Boot.img then skip this and move on to step 4:

adb shell
# uname -a

or you may get the details of the kernel from the Settings->Aboutphone->SoftwareInformation: Kernel version

2.6.29-6fb59e13 HTC-kernel@xxxxxxxx

open Makefile in the kernel folder, search and replace “EXTRAVERSION =” with “EXTRAVERSION =-6fb59e13

Step 4: Set the Env variables

export ARCH=arm
exprot CROSS_COMPILE=arm-eabi-
export PATH=$PATH:~/eclair/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/

now perform make modules for make from the kernel sources

kernel:$ make modules or make

after successful compilation, check out the .ko files next to the sources in the same directory

Complete example: How to get LG headset sources compile in to kernel module(.ko)

Categories: MOD and HACK

How to get LG headset sources compile in to kernel module(.ko).

December 28, 2010 1 comment

This article is about compiling specific sources into Kernel Module in Android, read this first before you proceed further

I have taken Headset Driver as a use case.

1. Create a folder headset_lg at location: ~/gt540_2.1/kernel/arch/arm/mach-msm/headset_LG

2. Copy board-swift-headset.c from ~/gt540_2.1/kernel/arch/arm/mach-msm/swift to headset_LG folder and make changes to it below

change //static int __init lge_hsd_init(void) to static int lge_hsd_init(void)
change // actuall call is static void __exit lge_hsd_exit(void) to static void lge_hsd_exit(void)
also comment this line

write make file to compile the .c file

# Makefile for the swift specific files

#obj-y += board-swift-bl-rt9393.o
obj-m = board-swift-headset.o // replace obj-y to obj-m // were m stand for Module

3. also change need to be made inside /home/br/gt540_2.1/kernel/arch/arm/mach-msm/rpc_server_misc.c

comment the global variable “headset_inserted” which is used to udpate the status of actual hardware

4. change to root folder of the kernel and run make. you shall see the .ko file at location given below

 Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
Building modules, stage 2.
MODPOST 16 modules
LD [M] arch/arm/mach-msm/headset_LG/board-swift-headset.ko

Installing Kernel Module

~/arch/arm/mach-msm/headset_LG/$adb push /sdcard/board-swift-headset.ko
~/arch/arm/mach-msm/headset_LG/$adb shell
# insmod /sdcard/board-swift-headset.ko //dont panic, filesystem should restart after executing insmod stmt
# lsmod // to verify the driver
# rmmod board-swift-headset.ko // to remove kernel module

Categories: MOD and HACK

Android – Accessing Input device "msm_pcm_in" from User space

December 14, 2010 6 comments

This article shows code snippet on how to access input device driver from user space.

Recording from input device (msm_pcm_in: a char Device Driver) follows the below events

Open device :

int ret = open("/dev/msm_pcm_in", O_RDWR); // open device

struct msm_audio_config confg;

ioctl(ret, AUDIO_GET_CONFIG, &confg) // this call fill the structure with default driver values.

cfg.channel_count = 1; // assign new number of channel(1= mono, 2 = stereo)
cfg.sample_rate = 8000;// assign sampling rate such as 8000 or 16000,.....
int val = ioctl(ret, AUDIO_SET_CONFIG, &confg);// set the new audio configuration

Before we being to start audio read/write operations, create a file to store buffers
const char *fn = /sdcard/tmp/file1;
int file = open(fn, O_CREAT | O_RDWR, 0666);

bool isrecording = true; // use this flag to stop recording (true default, false to disable reading)

ioctl(ret, AUDIO_START, 0);

fcntl(0, F_SETFL, O_NONBLOCK);// provides control of open file descriptors.

unsigned char buf[4092];

for (;;) {
while (!isrecording) {
// close all file descriptors and exit
if (read(ret, buf,confg.buffer_size ) != confg.buffer_size) {
// if fail to read
// close all file descriptors and exit

if (write(file, buf, confg.buffer_size) != confg.buffer_size) {
// if fail to read
// close all file descriptors and exit


Close device:

close (file);

Note: To run this as a recorder app, make sure you have root privileges.

Categories: MOD and HACK

Android- How to Create Executable

December 10, 2010 Leave a comment

1. Setup ndk project with and native sources file should include BUILD_EXECUTABLE, sample is below.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := Modulename
LOCAL_SRC_FILES := file1.c\


2. Building executable.

$ ndk-buld

3. Run executable

copy to device say /sdcard/data/Modulename
xxxx@xx:$> adb shell

Note:Make sure you place file along with source(c/c++) in same folder and name it as jni. as libs and obj folders are created next to jni folder.

Categories: Android-NDK