Tuesday, April 27, 2010

[video] Use 3G modem card in Android (devkit8000)

Use 3G modem data card in Android

We found Android-x86 had a new feature about telephony. It's about to use a 3G modem data card in EeePC and it can use 3G network to browse Internet. Therefore, I followed up this issue and verified it in Devkit8000 device. Now, it's one of our new released features and it comes with 0xdroid 0x4 release pre-built image too. In the beginning, I was trying to use a Quanta Q101 data card in Android emulator. How to run this experiment in my Ubuntu 9.10 manchine?

Set up Quanta Q101

Check this long discussion, I added a new rule file as below. When I plug-in q101 card, it can auto-mount to GSM modem mode with 4 ports.

erin@midnight:~$ cat /etc/udev/rules.d/30-q101.rules
# first, q101 will be detected as usb_storage of 0408:1000
# you have to force it suspend to change running mode from
# storage to 3.5g card

SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ACTION=="add", ATTRS{idVendor}=="0408", ATTRS{idProduct}=="1000", RUN+="/bin/sh -c 'cd /sys$env{DEVPATH};until test -f power/level;do cd ..;done;if [ -f power/level ];then echo suspend > power/level;fi'"

Wait about 10 seconds, then you can check these devices. RIL is /dev/ttyUSB3, PPP is /dev/ttyUSB1. When you use in Android emulator, it would become /dev/ttyS2 and /dev/ttyS3.

erin@midnight:~$ ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 1 2010-04-27 16:34 /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 2 2010-04-27 15:55 /dev/ttyUSB2
crw-rw---- 1 root dialout 188, 3 2010-04-27 17:16 /dev/ttyUSB3
crw-rw---- 1 root dialout 188, 4 2010-04-27 15:50 /dev/ttyUSB4

Need Kernel support PPP
I read this discussion and download Android kernel source code to rebuild kernel.

# git clone git://android.git.kernel.org/kernel/common.git
# cd kernel
# git checkout -b android-goldfish korg/android-goldfish-2.6.29
# cd $MYDROID/out
# ./host/linux-x86/bin/emulator -system ./target/product/generic/system.img -sysdir ./target/product/generic/system -data ./target/product/generic/userdata.img -kernel ../prebuilt/android-arm/kernel/kernel-qemu -ramdisk ./target/product/generic/ramdisk.img
# adb pull /proc/config.gz $MYDROID/kernel/
# cd $MYDROID/kernel/
# gunzip config.gz
# mv config .config
# make ARCH=arm menuconfig
(Add PPP in)
# make ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- zImage

Start the emulator again with new kernel image and then check /dev/ppp device!

# cd $MYDROID/out
# ./host/linux-x86/bin/emulator -system ./target/product/generic/system.img -sysdir ./target/product/generic/system -data ./target/product/generic/userdata.img -kernel ../kernel/arch/arm/boot/zImage -ramdisk ./target/product/generic/ramdisk.img
# adb shell ls -l /dev/ppp
crw-rw---- radio vpn 108, 0 2010-04-27 15:36 ppp

Modify Android source code
I applied the patches from Android-x86 and re-modified some code for Quanta q101 card. Also modify gprs script, since I am using Taiwan GSM netowork.

external ppp

hardware ril

system core

Since I am using Android emulator, the device names are different from Devkit8000.

Change the device permissions:

diff --git a/init/devices.c b/init/devices.c
index 4d93b44..0023cc3 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -108,6 +108,8 @@ static struct perms_ devperms[] = {
{ "/dev/android_adb_enable", 0660, AID_ADB, AID_ADB, 0 },
{ "/dev/ttyMSM0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
{ "/dev/ttyHS0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
+ { "/dev/ttyS2", 0660, AID_RADIO, AID_RADIO, 0 },
+ { "/dev/ttyS3", 0660, AID_RADIO, AID_RADIO, 0 },
{ "/dev/uinput", 0660, AID_SYSTEM, AID_BLUETOOTH, 0 },
{ "/dev/alarm", 0664, AID_SYSTEM, AID_RADIO, 0 },
{ "/dev/tty0", 0660, AID_ROOT, AID_SYSTEM, 0 },

Modify RIL argument and add ppp service from init:

erin@midnight:~/eclair/mydroid/build/target/board/generic$ cat system.prop
# system.prop for generic sdk

rild.libargs=-d /dev/ttyS2

# add these lines in system/core/rootdir/init.rc
service ppp /system/bin/pppd call gprs
user root
group system radio

Run Android Emulator
After changing these code, rebuilt Android again. Then we can run Android emulator from below command:

erin@midnight:~/eclair/mydroid/out$ ./host/linux-x86/bin/emulator -system ./target/product/generic/system.img -sysdir ./target/product/generic/system -data ./target/product/generic/userdata.img -kernel ../kernel/arch/arm/boot/zImage -ramdisk ./target/product/generic/ramdisk.img -sdcard ./target/product/generic/sdcard.img -qemu -serial /dev/ttyUSB3 -serial /dev/ttyUSB1

Run ppp manually
After starting ppp service, it would appear one network connection called 'ppp'.

# adb shell
# start ppp
# netcfg
lo UP 0x00000049
eth0 UP 0x00001043
tunl0 DOWN 0x00000080
gre0 DOWN 0x00000080
ppp0 UP 0x000010d1

Add APN for Taiwan GSM network

Sunday, April 25, 2010

Android CTS (Compatibility Test Suite) introduction

What is CTS?

Compatibility Test Suite is a command mode tool to run a series of test cases in Android. They published all CTS source codes from Eclair branch on January 2010.

git repository


How to run CTS in host machine?

$ . build/envsetup.sh
$ make cts

(it would generate all test plans, packages, cases, result report format and then zip to a android-cts.zip file)

  • Package CTS: out/host/linux-x86/cts/android-cts.zip
  • cts make file: mydroid/build/core/tasks/cts.mk
  • run cts program: mydroid/out/host/linux-x86/bin/cts
  • test plans: mydroid/out/host/linux-x86/cts/android-cts/repository/plans
  • test packages: mydroid/out/host/linux-x86/cts/android-cts/repository/testcases
  • test results: mydroid/out/host/linux-x86/cts/android-cts/repository/results
  • CTS program settings value: mydroid/cts/tools/utils/host_config.xml

run cts
$ cd $mydroid/out/host/linux-x86/bin/
$ ./cts

Screen would like this:

erin@midnight:~/eclair/mydroid/out/host/linux-x86/bin$ ./cts
Android CTS version 2.1_r1
cts_host > help
Usage: command options
Avaiable commands and options:
help: show this message
exit: exit cts command line
ls --plan: list available plans
ls --plan plan_name: list contents of the plan with specified name
add --plan plan_name: add a new plan with specified name
add --derivedplan plan_name -s/--session session_id -r/--result result_type: derive a plan from the given session
rm --plan plan_name/all: remove a plan or all plans from repository
start --plan test_plan_name: run a test plan
start --plan test_plan_name -d/--device device_ID: run a test plan using the specified device
start --plan test_plan_name -t/--test test_name: run a specific test
start --plan test_plan_name -p/--package java_package_name: run a specific java package
start --plan test_plan_name -t/--test test_name -d/--device device_ID: run a specific test using the specified device
start --plan test_plan_name -p/--package java_package_name -d/--device device_ID: run a specific java package using the specified device
ls -p/--package: list available packages
ls -p/--package package_name: list contents of the package with specified name
add -p/--package root: add packages from root to repository
rm -p/--package package_name/all: remove a package or all packages from repository
ls -r/--result: list all result of sessions
ls -r/--result -s/--session session_id: list detail case result of a specified session
ls -r/--result [pass/fail/notExecuted/timeout] -s/--session session_id: list detail cases of a specified session by the specified result.
history/h: list all commands in command history
history/h count: list the latest count records in command history
history/h -e num: run the command designated by 'num' in command history
ls -d/--device: list available devices

How to add test plan, test packages to CTS?

  1. Add test package name to cts.mk, it would generate apk file when we build cts.
  2. Add all source folder (includes src java files, Android.mk and its Manifest file) to mydroid/cts/tests/tests
  3. If you'd like to create a test plan for this test package. Modify this python script: mydroid/cts/tools/utils/buildCts.py

Adjust CTS program settings?

Modify $mydroid/cts/tools/utils/host_config.xml
  • Number of tests executed between reboots. A value <= 0 disables reboots. (maxTestCount)
  • Max size [tests] for a package to be run in batch mode. (maxTestInBatchMode)
  • Max time [ms] between test status updates. (testStatusTimeoutMs)
  • Max time [ms] from start of package in batch mode and the first test status update. (batchStartTimeoutMs)
  • Max time [ms] from start of test in individual mode to the first test status update. (individualStartTimeoutMs)
  • Timeout [ms] for the signature check. (signatureTestTimeoutMs)
  • Timeout [ms] for package installations. (packageInstallTimeoutMs)
  • Time to wait [ms] after a package installation or removal. (postInstallWaitMs)
Write your own testing package?

If you would like to write your own testing package, you may reference the Instrumentation Testing document from Android porting guide. Also, you could reference the source code from few Android application, like Browser, Messages, Gallery, Email, Camera, Calculator....etc. You can build its test apk file and upload it to device.

How to write test cases?
Each instrumentation test case is similar to an Android application with the distinction that it starts another application. For example, have a look in the $MYDROID/packages/apps/Music directory.
  • There should be a Makefile and an Android Manifest file
  • Tests are located in $MYDROID/packages/apps/Music/tests.
  • The Instrumentation Test Runner is located at packages/apps/Music/tests/src/com/android/music/MusicPlayerFunctionalTestRunner.java.

Build package apk file

erin@midnight:~/eclair/mydroid/packages/apps/Music/tests$ mm
Install: out/target/product/generic/data/app/MusicTests.apk

Install it to the device
erin@midnight:~/eclair/mydroid/packages/apps/Music/tests$ adb install ../../../../out/target/product/generic/data/app/MusicTests.apk

How to run test cases in device?

Running Tests

erin@midnight:~/$ adb shell pm list instrumentation
instrumentation:com.android.music.tests/.MusicPlayerStressTestRunner (target=com.android.music)
instrumentation:com.android.music.tests/.MusicPlayerFunctionalTestRunner (target=com.android.music)
instrumentation:com.android.music.tests/.MusicPlayerLaunchPerformance (target=com.android.music)

The am command is a command-line interface to the ActivityManager. 'am' is used to start and instrument activities using the adb shell command, as shown in the snippet below:

> adb shell am
usage: am [start|instrument]
am start [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-n <COMPONENT>] [-D] [<URI>]
am instrument [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]

For example, to start the Contacts application you can use
> adb shell am start -n com.google.android.contacts/.ContactsActivity

Eg. verify Music player launcher performance

erin@midnight:~/$ adb shell am instrument -w -r com.android.music.tests/.MusicPlayerLaunchPerformance

Eg. verify Music player stress test

erin@midnight:~/$ adb shell am instrument -w -r com.android.music.tests/.MusicPlayerStressTestRunner

Here is a video about running a cts test case by Android emulator!