Showing posts with label Android tools and tips. Show all posts
Showing posts with label Android tools and tips. Show all posts

Thursday, July 14, 2011

How to get a console with root if Motorola XOOM is working as USB Host and connected with USB devices

If Motorola XOOM is connected with USB devices and working as USB Host mode, you will not be able to have adb shell work on PC. The only USB connection is used for other purpose. Here is a tip to have a console with root even the USB connection is used for USB device.
  • Motorola XOOM is rooted
  • Push a busybox to Motorola XOOM, make it executable
  • Connect Motorola XOOM with PC, in a PC cmd window, adb shell to the device, the shell must be a root shell.
  • Start telnetd: busybox telnetd -l /system/bin/sh
  • Download a telnet APP for Motorola XOOM, e.g. BlowTorch. Launch telnet client (BlowTorch), telnet to device, a root console is served.

Friday, August 27, 2010

patch the kernel image boot.img

Tools list:
  1. split_bootimg.pl
  2. mkbootimg
  3. mkbootfs
boot.img contains the linux kernel and the ramdisk, while the default.prop in ramdisk can enable/disable the adb root permission. following is the default.prop contents for a droid product device:
  • ro.secure=1
  • ro.allow.mock.location=0
  • ro.debuggable=0
  • persist.service.adb.enable=0
droid product device with above default.prop has no adb root permissions if the device is not hacked. the default.prop with the following contents has the adb root permissions by default:
  • ro.secure=0
  • ro.allow.mock.location=0
  • ro.debuggable=1
  • persist.service.adb.enable=1
to create a boot.img with such default.prop, here is the steps:
  1. split the boot.img: split_bootimg.pl boot.img, after running the command, two files are generated: boot.img-kernel and boot.img-ramdisk.gz.
  2. create a temp folder (e.g. ramdisk), change to that folder, run the following command to extract the boot.img-ramdisk.gz: cat ../boot.img-ramdisk.gz | gzip -d | cpio -idm.
  3. make the changes to the ramdisk file system in ramdisk folder, e.g. change the default.prop file to get adb root permissions.
  4. return the parent folder, and run the following command to recreate the ramdisk package: mkbootfs ./ramdisk | gzip > ramdisk-new.gz
  5. recreate the boot image: mkbootimg --kernel boot.img-kernel --ramdisk ramdisk-new.gz -o boot-new.img
done. flash the boot-new.img to the device with fastboot.
more things can be done with the above steps, such as change the boot up sequence by modify the init.rc.

Tuesday, August 24, 2010

unyaffs the android image

unyaffs is a tool to extract files from a yaffs file system image. It supports extract images created by mkyaffs2image. It is useful to patch the system.img and re-generate the system.img.
How to get it:
  1. download a pre-build binary for linux: http://unyaffs.googlecode.com/files/unyaffs
  2. download the source and compile with gcc -o unyaffs unyaffs.c:
  • http://unyaffs.googlecode.com/files/unyaffs.c
  • http://unyaffs.googlecode.com/files/unyaffs.h

Monday, June 8, 2009

Tools to monitor your android system memory and performance

Tools to monitor your android/linux system memory and performance:
  • ps -x
  • top
  • cat /proc/meminfo
  • dumpsys meminfo proc-id
  • procrank
  • DDMS (Android SDK tool)
  • time command-line
  • vmstat

Thursday, February 26, 2009

UI/Application Exerciser Monkey

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
Basic usage of monkey:
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
[-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
[--ignore-crashes] [--ignore-timeouts]
[--ignore-security-exceptions] [--monitor-native-crashes]
[--kill-process-after-error] [--hprof]
[--pct-touch PERCENT] [--pct-motion PERCENT]
[--pct-trackball PERCENT] [--pct-syskeys PERCENT]
[--pct-nav PERCENT] [--pct-majornav PERCENT]
[--pct-appswitch PERCENT] [--pct-anyevent PERCENT]
[--wait-dbg] [--dbg-no-events]
[-s SEED] [-v [-v] ...] [--throttle MILLISEC]
COUNT
Example: adb shell monkey 1000
#send 1000 events to all applications

Tuesday, October 21, 2008

Sunday, March 2, 2008

Using busybox for google android

Busybox is a very good tool. Here is some tips to make your android developing life easier:
1. busybox telnetd -l /sbin/sh, this is to start telnetd so you can telnet to the android
2. busybox ftpget/ftpput, this is a ftp tool to download/upload files to/from android
3. busybox telnet, telnet tool
4. busybox tftp, tftp tool
5. busybox wget, wget tool
6. more ...

Thursday, January 31, 2008

trying building shared library for google android

There is an article Shared library "Hello World!" for Android, describes how to create a simple shared library for google android, and shows how to link with the shared library to create a dynamic linked executable. The steps are correct, but it is not easy to create a shared library for google android with an existing linux distribution open source software.

Here is some findings when I tried to create a shared library for google android with a open source software:
1. pthread related functions are implemented in google android libc.so
2. no stderr, stdin, stdout definition are found in google android
3. some function mangling is different, such as strtod, strtol, isspace, and etc. Some can be fixed with some MACRO variable, such as __NO_INLINE__. Need to identify one by one, read the include head files in CROSS_COMPILE_FOLDER /arm-none-linux-gnueabi/libc/usr/include/
4. no mkstemp64, open64, and other xxx64 functions found

Following are the pthread found in google android /system/lib/libc.so:
42: 0000a41c 32 FUNC GLOBAL DEFAULT 7 pthread_cond_signal
61: 0000a26c 56 FUNC GLOBAL DEFAULT 7 pthread_mutexattr_gettype
64: 0000a510 32 FUNC GLOBAL DEFAULT 7 pthread_attr_destroy
69: 0000a144 16 FUNC GLOBAL DEFAULT 7 pthread_attr_getstacksize
71: 0000afa0 620 FUNC GLOBAL DEFAULT 7 pthread_create
75: 0000a3a8 28 FUNC GLOBAL DEFAULT 7 pthread_getspecific
86: 0000a050 72 FUNC GLOBAL DEFAULT 7 pthread_attr_init
92: 0000ad60 304 FUNC GLOBAL DEFAULT 7 pthread_exit
119: 0000a1b0 24 FUNC GLOBAL DEFAULT 7 pthread_attr_getstack
165: 0000a15c 24 FUNC GLOBAL DEFAULT 7 pthread_attr_getstackaddr
177: 0000a8c8 228 FUNC GLOBAL DEFAULT 7 pthread_key_delete
202: 0000a254 24 FUNC GLOBAL DEFAULT 7 pthread_mutexattr_destroy
208: 0000a22c 16 FUNC GLOBAL DEFAULT 7 pthread_equal
265: 0000a1ec 16 FUNC GLOBAL DEFAULT 7 pthread_attr_getguardsize
299: 0000aad8 188 FUNC GLOBAL DEFAULT 7 pthread_cond_timedwait_mo
340: 0000ac58 176 FUNC GLOBAL DEFAULT 7 pthread_detach
352: 0000a0f0 16 FUNC GLOBAL DEFAULT 7 pthread_attr_getschedpoli
368: 0000a154 8 FUNC GLOBAL DEFAULT 7 pthread_attr_setstackaddr
387: 0000a4b0 96 FUNC GLOBAL DEFAULT 7 pthread_getschedparam
441: 0000a43c 32 FUNC GLOBAL DEFAULT 7 pthread_cond_broadcast
459: 0000a45c 84 FUNC GLOBAL DEFAULT 7 pthread_setschedparam
471: 0000a9ac 176 FUNC GLOBAL DEFAULT 7 pthread_key_create
499: 0000a3cc 80 FUNC GLOBAL DEFAULT 7 pthread_kill
505: 0000aa5c 124 FUNC GLOBAL DEFAULT 7 pthread_cond_timeout_np
512: 0000a1fc 44 FUNC GLOBAL DEFAULT 7 pthread_getattr_np
514: 0000a120 36 FUNC GLOBAL DEFAULT 7 pthread_attr_setstacksize
546: 0000a3c4 8 FUNC GLOBAL DEFAULT 7 pthread_sigmask
559: 0000a35c 16 FUNC GLOBAL DEFAULT 7 pthread_cond_init
643: 0000a174 60 FUNC GLOBAL DEFAULT 7 pthread_attr_setstack
647: 0000a2a4 64 FUNC GLOBAL DEFAULT 7 pthread_mutexattr_settype
681: 0000a0d0 20 FUNC GLOBAL DEFAULT 7 pthread_attr_getdetachsta
694: 0000a690 180 FUNC GLOBAL DEFAULT 7 pthread_mutex_unlock
772: 0000a228 4 FUNC GLOBAL DEFAULT 7 pthread_self
778: 0000a23c 24 FUNC GLOBAL DEFAULT 7 pthread_mutexattr_init
788: 00009630 0 FUNC GLOBAL DEFAULT 7 __pthread_clone
818: 0000a344 24 FUNC GLOBAL DEFAULT 7 pthread_mutex_destroy
826: 0000a744 388 FUNC GLOBAL DEFAULT 7 pthread_mutex_lock
831: 0000ac50 8 FUNC GLOBAL DEFAULT 7 pthread_cond_wait
845: 0000a1c8 36 FUNC GLOBAL DEFAULT 7 pthread_attr_setguardsize
858: 0000a55c 308 FUNC GLOBAL DEFAULT 7 pthread_mutex_trylock
869: 0000a36c 24 FUNC GLOBAL DEFAULT 7 pthread_cond_destroy
874: 0000a0e4 12 FUNC GLOBAL DEFAULT 7 pthread_attr_setschedpoli
886: 0000a2e4 96 FUNC GLOBAL DEFAULT 7 pthread_mutex_init
920: 0000a100 16 FUNC GLOBAL DEFAULT 7 pthread_attr_setschedpara
936: 0000a098 56 FUNC GLOBAL DEFAULT 7 pthread_attr_setdetachsta
942: 0000ad08 88 FUNC GLOBAL DEFAULT 7 pthread_join
952: 0000ab94 188 FUNC GLOBAL DEFAULT 7 pthread_cond_timedwait
963: 0000a110 16 FUNC GLOBAL DEFAULT 7 pthread_attr_getschedpara
967: 0000a384 36 FUNC GLOBAL DEFAULT 7 pthread_setspecific

Wednesday, January 16, 2008

Create google android strace tool

Prerequisite, you already have the cross compiler downloaded from download GNU toolchain site, make sure you select ARM GNU/Linux, and IA32 GNU/Linux.

  1. Download the strace source distribution from SourceForge strace project
  2. Extract the strace package on your linux machine
  3. Set your cross compiler information with command: # export CC=your_cross_compiler_folder/bin/arm-none-linux-gnueabi-gcc
  4. Add your_cross_compiler_folder/bin into your $PATH for path searching
  5. Change your current folder to strace package extract folder, use command: # ./configure -host=arm-linux
  6. You have the Makefile generated, edit it, append -static after CFLAGS variable in Makefile
  7. Compile it with simple command: # make
  8. You have the strace now, verify it with command: # file strace, you shall see "strace: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, statically linked, not stripped"
Done, you have another powerful tool for your android

Tuesday, January 15, 2008

Can't execute native command on google android emulator

I created hello.c, compiled successfully with the cross compiler.
But I failed to run it on the target google android emulator. The error is: xxx: not found.
I checked the compiled file, it looks just fine. It really puzzled me.

At last, I got hints that it is because of there is no base libraries necessary on the google android emulator. For example, there is no /usr/lib directory, which should contain many .so files.

Simply re-create your native command with '-static' parameter, and try again.
Check your compiled file with the following command to ensure:
# file a.out
possible output looks like:
a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, statically linked, not stripped

Customize google android system.img for emulator

The google android emulator included in the google android sdk is limited. Although you can use 'adb push' to upload more tools, but one has to do it again next time. Follow the steps to create a enhanced system.img:
  1. system.img is yaffs2 flash file system, so firstly you need the mkfs.yaffs2 tool, download it in the following link: Release Android Yaffs2 Tool (Both X86 And ARM). One has to be a registered user to download the tools.
  2. use the 'adb push' to upload tools to android emulator, executables in /system/bin/, libraries in /system/lib, one can also create folder. One need change the file mode necessary.
  3. upload the ARM mkfs.yaffs2 tool, use the following command to create system.img: # mkfs.yaffs2 /system /system.img
  4. download the system.img to local with command 'adb pull', replace the system.img in your emulator folder/tools/lib/images/

Monday, January 14, 2008

Step by step to create/modify ramdisk.img

Benno's blog has an article to change the ramdisk image, I tried it and give more details here.

ramdisk.img is included in the google android sdk, it exists in folder $SDK_ROOT/tools/lib/images/ramdisk.img. The ramdisk.img included in the google android sdk is a gzipped ramdisk.cpio file.

Here is the steps:
  1. Upload the ramdisk.img to your linux machine
  2. Change the ramdisk.img name to ramdisk.cpio.gz, and extract it by: # gzip -d ramdisk.cpio.gz
  3. Create a temporary folder, say tmp, copy ramdisk.cpio to tmp folder
  4. Extract the ramdisk.cpio in the tmp folder with command: # cpio -i -F ramdisk.cpio
  5. Remove the ramdisk.cpio in the tmp folder, and make any changes you want to the extracted ramdisk.cpio in tmp folder
  6. Recreate the ramdisk.cpio with command: # cpio -i -t -F ../ramdisk.cpio | cpio -o -H newc -O ../ramdisk_new.cpio
Some notes:
  1. I change ramdisk.img to ramdisk.cpio.gz, and unzip it. It is because I find the -z parameter is not supported with my cpio. I tried the latest cpio (2.9), it doesn't work too.
  2. Check cpio version by # cpio --version. I'm using cpio version 2.4.
  3. Find the latest cpio (v 2.9) on site: gnu cpio
  4. Notice that in step 6, the command includes two O's. First o is lower-case, second is up-case.
  5. Notice in step 6, please remain ramdisk.cpio in up folder of tmp folder. The command need it there.

Friday, January 11, 2008

Extract google android file system image

To run google android on the truely hardware, you may need the google android file system image.

Google android file system consists of two parts: system and data.
You can find the google android file system image on benno's website: Android filesystem images

You can also extract the google android file system by yourself from the android emulator by the following way:
1. download the google android sdk and extract onto your platform
2. start up the google android emulator
3. upload a busybox tool to the google android emulator, you can find a busybox binary on benno's website: busybox for android, you can also find the cross-compiler (select ARM GNU/Linux, and IA32 GNU/Linux) and create a busybox tool by yourself.
4. to upload files to the google android emulator, run the following command:
# adb push filename /target_folder/filename
the target_folder is the folder on the file system of google android emulator. e.g. /system/bin/
put the busybox to /system/bin, so you can see busybox tool in the extracted file system.
5. open a google android shell command window:
# adb shell
6. change the busybox mode to 555:
# chmod 555 /system/bin/busybox
7. create the tarball for /system and /data:
# busybox tar cvf /system.tar /system
# busybox tar cvf /data.tar /data
8. pull the tarball file from the google android emulator:
# adb pull system.tar /system.tar
# adb pull data.tar /data.tar

a note: when you want run google android on your truely hardware, the data.tar is not a must.

Create adb shell in android emulator

Type the following command to start the adb shell:
# adb shell
For the full usage of adb, please refer the following link: Android Debug Bridge Tool

Rotate Android Screen to Landscape/Portrait

Here are some tips of android screen rotation.

On the emulator, after the Android system is started up, open another command window, type the following command line in the adb shell to change the screen to landscape:
# service call window 18 i32 1
type the following command line to change the screen to portrait:
# service call window 18 i32 0