Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, April 22, 2015

How to host multiple OpenGrok

1. Install related packages

apt-get install ctags tomcat6

2. Start tomcat

sudo /etc/init.d/tomcat6 start

3. Download OpenGrok, unzip to ~/Downloads/opengrok

http://java.net/projects/opengrok/downloads/download/opengrok-0.12.1.tar.gz


4. Generate OpenGrok database ( using sudo )


#!/bin/bash -x

grok_one()
{
        SRC_FOLDER=$1
        WEB_ROOT=$2
        CFG_PORT=$3

        SRC_WAR=~/Downloads/opengrok/opengrok-0.12.1/lib/source.war
        TAR_WAR=/var/lib/tomcat6/webapps/${WEB_ROOT}.war
        DAT_ROOT=/var/opengrok_data/${WEB_ROOT}
        ORG_ROOT=/var/opengrok
        mkdir -p $DAT_ROOT

        OPENGROK_VERBOSE=true \
        OPENGROK_INSTANCE_BASE=$DAT_ROOT \
        OPENGROK_WEBAPP_CONTEXT=$WEB_ROOT \
        OPENGROK_WEBAPP_CFGADDR=localhost\:$CFG_PORT \
        ~/Downloads/opengrok/opengrok-0.12.1/bin/OpenGrok index $SRC_FOLDER

        rm -rf WEB-INF
        cp -f $SRC_WAR $TAR_WAR
        unzip $TAR_WAR WEB-INF/web.xml
        sed -i "s#$ORG_ROOT#$DAT_ROOT#g" WEB-INF/web.xml
        sed -i "s#2424#$CFG_PORT#g" WEB-INF/web.xml
        zip -u $TAR_WAR WEB-INF/web.xml
        rm -rf WEB-INF
}

grok_one ~/src/osloader osloader 2425
grok_one ~/src/aosp_mr1 aosp_mr1 2426

5. done 

http://127.0.0.1:8080/osloader
http://127.0.0.1:8080/aosp_mr1


Sunday, May 25, 2014

How to create a local mirror repository

1. Create / update local mirror :

#!/bin/bash
MIRROR_DIR=/android-mirror
SVR=https://source.android.com
cd $MIRROR_DIR
for p in `ssh $SVR gerrit ls-projects`
do
  if [ -d "$p.git" ]; then
  echo Update ... "$p.git"
     # update existing git db
     git --git-dir "$p.git" remote prune origin
git --git-dir "$p.git" fetch
  else
mkdir -p `dirname "$p"`
echo Mirror ... ${p}.git
     # fist time init
git clone --mirror "ssh://$SVR/$p.git" "$p.git"
  fi
done

2. Repo from local mirror :

repo init -u /android-mirror/mainfest -b xxx-branch -m xxx-mainfest --reference /android-mirror
repo sync

Pro :
1. Sync data locally, so faster.
2. Local mirror can offline move to other place, able to work from home.
3. Share .git data with local mirror, save space.

Con :
1. Not sure if git push working or not.


Tuesday, August 28, 2012

Use envsetup.sh at your own source tree

envsetup.sh that came with AOSP provide lots handy command when browse android source tree.

By default, it will require envsetup.sh reside at $TOP/build, so we could modify it to remove this requirement :


neomacbookair:home neo$ diff envsetup.sh nenvsetup.sh 
18c18
<     for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
---
>     for i in `cat ~/Dropbox/home/nenvsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
555,556c555,556
<     local TOPFILE=build/core/envsetup.mk
<     if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
---
>     local TOPFILE=~/Dropbox/home/nenvsetup.sh
>     if [ -n "$TOP" -a -f "$TOPFILE" ] ; then


I rename envsetup.sh into nenvsetup.sh, and placed in ~/Dropbox/home folder. In my source tree, I could simply type :


neomacbookair:mp007 neo$ export TOP=`pwd`
neomacbookair:mp007 neo$ . ~/Dropbox/home/nenvsetup.sh 

Then you could use it's utility to travel your source tree :

neomacbookair:mp007 neo$ godir Config.java
Creating index... Done

   [1] ./gen/com/wong/mprj/mp007
   [2] ./src/com/wong/mprj/mp007

Select one: 2
neomacbookair:mp007 neo$ ls -l Config.java 
-rw-r--r--  1 neo  staff  906  8 27 14:13 Config.java

neomacbookair:mp007 neo$ godir mprj-jni.cpp
   [1] ./jni/libmprj
   [2] ./jni/libtest

Select one: 2
neomacbookair:libtest neo$ ls -l mprj-jni.cpp 
-rw-r--r--  1 neo  staff  1808  8 18 23:10 mprj-jni.cpp


neomacbookair:libtest neo$ croot
neomacbookair:mp007 neo$ 

Of course you may use cgrep, jgrep too, for those m, mm utility it may require more hack before you can use, but I am fine with croot, godir, that's enough for me.


Wednesday, December 07, 2011

repo -b

repo 是 google 在 Android Open Source Project 導入的原始碼管理工具,  用來同步許多 git repository 的動作, 同時也協助 source code review server 溝通。
用 repo 來開始抓遠端的 source code 時, 必須先指定 URL 及想抓取的分支, 如以下的指令就是抓出 AOSP 上 tag 為 android-4.0.1_r1 的版本 :

$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1

在下 repo sync 之前, 可以先看看抓下來的 manifest.xml 檔案 :

$ cat .repo/manifest.xml  | head -9
<!--?xml version="1.0" encoding="UTF-8"?-->
<manifest>

 <remote  name="aosp" <="" p="">
           fetch=".." />
 <default <="" p="" revision="refs/tags/android-4.0.1_r1">
           remote="aosp"
           sync-j="4" />

很明顯, 剛剛所下的分支版號就紀錄於此, 此時我們再下一次 init, 改抓另個分支 :

$ repo init -b android-2.3.7_r1
.repo/manifests/: manifest switched android-4.0.1_r1...android-2.3.7_r1
.repo/manifests/: discarding 10 commits removed from upstream

再看一次 manifest.xml :

$ cat .repo/manifest.xml | head -9
<!--?xml version="1.0" encoding="UTF-8"?-->
<manifest>

  <remote  name="aosp" <="" p="">
           fetch=".." />
  <default <="" p="" revision="refs/tags/android-2.3.7_r1">
           remote="aosp"
           sync-j="4" />

的確紀錄的版本改變了, manifest.xml 上面所紀錄的分支名稱, 會用來當執行 repo sync 時, 把各個 git repository 照這分支抓下來。

$ repo sync bionic
Downloading bionic: 100% (3MB/3MB), done.
...
Unpacking objects: 100% (61/61), done.
From https://android.googlesource.com/platform/bionic
...
Fetching projects: 100% (1/1), done.

$ cd bionic/
$ git branch -a
* (no branch)
...
  remotes/m/android-2.3.7_r1 -> refs/tags/android-2.3.7_r1

此時抓下來的分支, 就是後面改設的 android-2.3.7_r1, 這時試著改切回 4.0.1_r1 的分支

$ repo init -b android-4.0.1_r1
.repo/manifests/: manifest switched android-2.3.7_r1...android-4.0.1_r1
.repo/manifests/: discarding 1 commits removed from upstream

$ repo sync bionic
Fetching projects: 100% (1/1), done.

$ cd bionic/
$ git branch -a
* (no branch)
...
  remotes/m/android-2.3.7_r1 -> refs/tags/android-2.3.7_r1
  remotes/m/android-4.0.1_r1 -> refs/tags/android-4.0.1_r1

可以看到有兩個跟遠端的依從關係, 理論上這裡紀錄了 local repository 跟 remote repository 分支版本的關係, 這裡的資訊會來 commit 檔案到遠端的時候, 選擇正確的 branch, 不過這裡我尚無法實驗釐清。

當我們單獨 git clone 一個 project 時, -b 亦會產生相同的效果


Thursday, December 01, 2011

Vibrator function support in Android

Android application connect to HAL by JNI interface, for vibrator, the JNI interface is defined very simple.


JNI: frameworks/base/services/jni/com_android_server_VibratorService.cpp


static jboolean vibratorExists(JNIEnv *env, jobject clazz)
{
    return vibrator_exists() > 0 ? JNI_TRUE : JNI_FALSE;
}


static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms)
{
    // LOGI("vibratorOn\n");
    vibrator_on(timeout_ms);
}

static void vibratorOff(JNIEnv *env, jobject clazz)
{
    // LOGI("vibratorOff\n");
    vibrator_off();
}

static JNINativeMethod method_table[] = {
{ "vibratorExists", "()Z", (void*)vibratorExists },
{ "vibratorOn", "(J)V", (void*)vibratorOn },
{ "vibratorOff", "()V", (void*)vibratorOff }
};


vibratorOn, vibratorOff and vibratorExists just simple wrapper of vibrator_on, vibrator_off and vibrator_exists, which is provide by device maker, through HAL interface.

HAL: hardware/libhardware_legacy/vibrator/vibrator.c


#define THE_DEVICE "/sys/class/timed_output/vibrator/enable"


int vibrator_exists()
{
    int fd;


#ifdef QEMU_HARDWARE
    if (qemu_check()) {
        return 1;
    }
#endif


    fd = open(THE_DEVICE, O_RDWR);
    if(fd < 0)
        return 0;
    close(fd);
    return 1;
}



int vibrator_on(int timeout_ms)
{
    /* constant on, up to maximum allowed time */
    return sendit(timeout_ms);
}


int vibrator_off()
{
    return sendit(0);
}


HAL call into kernel space by sysfs, path at "/sys/class/timed_output/vibrator/enable"
It's a Android designed feature, a timed_output or timed_gpio device.

If you echo 10000 into this sysfs, then it will vibrate for ten seconds :


$ echo 10000 > /sys/class/timed_output/vibrator/enable 

If you cat it during the vibration, you will saw how many ms before it back to quiet :

$ cat /sys/class/timed_output/vibrator/enable
315


Inside kernel space, Android defined two new platform driver to be use for vibrator : timed_gpio and timed_output.

By grab HC kernel source that released by Acer/ASUS, found that they are using different of implementation.

Acer use a gpio pin, config with a timed_gpio driver, hook up with platform_device driver, and also to timed_output driver to provide vibrator interface from sysfs.

ASUS use an IC max1749, directly register a timed_output interface to provide vibrator interface from sysfs.

PS. Beside kernel source, above source code is trace from AOSP 4.0.1.

Thursday, March 03, 2011

Android-x86 ginerbread build failed

Same as below :

https://groups.google.com/group/android-building/browse_thread/thread/e9baa16a0b1e96f

Inside fedora14, update "make", then problem solved.
So seems newer version of make had released.

Tuesday, April 06, 2010

Init program of Android

Android did not use shell script to do it's init, instead, it maintain a C program to do so.

Source of this init program is located at system/core/init folder of android platform source.
By default, it will load /init.rc to parse, and do init job.
Tracing into system/core/init/init.c, you will see it's him to print out " A N D R O I D" in the start up menu ( or by display a embedded image if in graphic mode )

init.rc is very similar with normal linux boot script, just as it's interpret and execute by by /init

We could look into /init.rc, then we could know what service/module is necessary for bring up a Android OS.
 Below is grab from android sdk emulator image :


on init

sysclktz 0

loglevel 3

# setup the global environment
export PATH /sbin:/system/sbin:/system/bin:/system/xbin
export LD_LIBRARY_PATH /system/lib
export ANDROID_BOOTLOGO 1
export ANDROID_ROOT /system
export ANDROID_ASSETS /system/app
export ANDROID_DATA /data
export EXTERNAL_STORAGE /sdcard
export BOOTCLASSPATH /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar

# Backward compatibility
symlink system/etc /etc
symlink system/lib /lib

# create mountpoints and mount tmpfs on sqlite_stmt_journals and debugfs on d
mkdir /d
chown system system /sdcard
chmod 0777 /sdcard
mkdir /data 0771 system system
mkdir /cache 0770 system cache
mkdir /sqlite_stmt_journals 01777 root root
mount tmpfs tmpfs /sqlite_stmt_journals size=4m
mount debugfs debugfs /d

mount rootfs rootfs / ro remount

write /proc/sys/kernel/panic_on_oops 1
write /proc/sys/kernel/hung_task_timeout_secs 0
write /proc/cpu/alignment 4
write /proc/sys/kernel/sched_latency_ns 10000000
write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000

# mount mtd partitions
# TODO: this should be mounted by fs vol id (i.e. /dev/block-by-volid/system),
# once init gets that functionality.
# mount ext3 /dev/block/sda6 /system
# mount ext3 /dev/block/sda6 /system ro remount

# We chown/chmod /data again so because mount is run as root + defaults
# mount ext3 /dev/block/sda8 /data
chown system system /data
chmod 0771 /data

# Same reason as /data above
# mount ext3 /dev/block/sda5 /cache
chown system cache /cache
chmod 0770 /cache

# This may have been created by the recovery system with odd permissions
chown system system /cache/recovery
chmod 0770 /cache/recovery

# create basic filesystem structure
mkdir /data/misc 01771 system misc
mkdir /data/misc/hcid 0770 bluetooth bluetooth
mkdir /data/local 0771 shell shell
mkdir /data/local/tmp 0771 shell shell
mkdir /data/data 0771 system system
mkdir /data/app-private 0771 system system
mkdir /data/app 0771 system system
mkdir /data/property 0700 root root

mkdir /data/misc/wifi 0770 wifi wifi
mkdir /data/misc/wifi/sockets 0770 wifi wifi
mkdir /data/system/wpa_supplicant 0770 wifi wifi
mkdir /data/misc/dhcp 0770 dhcp dhcp
chown dhcp dhcp /data/misc/dhcp

# create dalvik-cache and double-check the perms
mkdir /data/dalvik-cache 0771 system system
chown system system /data/dalvik-cache
chmod 0771 /data/dalvik-cache

# create the lost+found directories, so as to enforce our permissions
mkdir /data/lost+found 0770
mkdir /cache/lost+found 0770

# double check the perms, in case lost+found already exists, and set owner
chown root root /data/lost+found
chmod 0770 /data/lost+found
chown root root /cache/lost+found
chmod 0770 /cache/lost+found


### Load some modules

on boot
# basic network init
ifup lo
hostname localhost
domainname localdomain

# set RLIMIT_NICE to allow priorities from 19 to -20
setrlimit 13 40 40

# Define the oom_adj values for the classes of processes that can be
# killed by the kernel. These are used in ActivityManagerService.
setprop ro.FOREGROUND_APP_ADJ 0
setprop ro.VISIBLE_APP_ADJ 1
setprop ro.SECONDARY_SERVER_ADJ 2
setprop ro.BACKUP_APP_ADJ 2
setprop ro.HOME_APP_ADJ 4
setprop ro.HIDDEN_APP_MIN_ADJ 7
setprop ro.CONTENT_PROVIDER_ADJ 14
setprop ro.EMPTY_APP_ADJ 15

# Define the memory thresholds at which the above process classes will
# be killed. These numbers are in pages (4k).
setprop ro.FOREGROUND_APP_MEM 1536
setprop ro.VISIBLE_APP_MEM 2048
setprop ro.SECONDARY_SERVER_MEM 4096
setprop ro.BACKUP_APP_MEM 4096
setprop ro.HOME_APP_MEM 4096
setprop ro.HIDDEN_APP_MEM 8192
setprop ro.CONTENT_PROVIDER_MEM 8704
setprop ro.EMPTY_APP_MEM 16384

# Write value must be consistent with the above properties.
write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15

write /proc/sys/vm/overcommit_memory 1
write /proc/sys/vm/min_free_order_shift 4
write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,8192,8704,16384

# Set init its forked children's oom_adj.
write /proc/1/oom_adj -16

# Permissions for System Server and daemons.
chown radio system /sys/android_power/state
chown radio system /sys/android_power/request_state
chown radio system /sys/android_power/acquire_full_wake_lock
chown radio system /sys/android_power/acquire_partial_wake_lock
chown radio system /sys/android_power/release_wake_lock
chown radio system /sys/power/state
chown radio system /sys/power/wake_lock
chown radio system /sys/power/wake_unlock
chmod 0660 /sys/power/state
chmod 0660 /sys/power/wake_lock
chmod 0660 /sys/power/wake_unlock
chown system system /sys/class/timed_output/vibrator/enable
chown system system /sys/class/leds/keyboard-backlight/brightness
chown system system /sys/class/leds/lcd-backlight/brightness
chown system system /sys/class/leds/button-backlight/brightness
chown system system /sys/class/leds/red/brightness
chown system system /sys/class/leds/green/brightness
chown system system /sys/class/leds/blue/brightness
chown system system /sys/class/leds/red/device/grpfreq
chown system system /sys/class/leds/red/device/grppwm
chown system system /sys/class/leds/red/device/blink
chown system system /sys/class/leds/red/brightness
chown system system /sys/class/leds/green/brightness
chown system system /sys/class/leds/blue/brightness
chown system system /sys/class/leds/red/device/grpfreq
chown system system /sys/class/leds/red/device/grppwm
chown system system /sys/class/leds/red/device/blink
chown system system /sys/class/timed_output/vibrator/enable
chown system system /sys/module/sco/parameters/disable_esco
chown system system /sys/kernel/ipv4/tcp_wmem_min
chown system system /sys/kernel/ipv4/tcp_wmem_def
chown system system /sys/kernel/ipv4/tcp_wmem_max
chown system system /sys/kernel/ipv4/tcp_rmem_min
chown system system /sys/kernel/ipv4/tcp_rmem_def
chown system system /sys/kernel/ipv4/tcp_rmem_max
chown root radio /proc/cmdline

# Define TCP buffer sizes for various networks
# ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208
setprop net.tcp.buffersize.wifi 4095,87380,110208,4096,16384,110208
setprop net.tcp.buffersize.umts 4094,87380,110208,4096,16384,110208
setprop net.tcp.buffersize.edge 4093,26280,35040,4096,16384,35040
setprop net.tcp.buffersize.gprs 4092,8760,11680,4096,8760,11680

setprop EXTERNAL_STORAGE_STATE unmounted

class_start default

## Daemon processes to be run by init.
##
service console /system/bin/sh
console

# adbd is controlled by the persist.service.adb.enable system property
service adbd /sbin/adbd

on property:persist.service.adb.enable=1
start adbd

on property:persist.service.adb.enable=0
stop adbd

service servicemanager /system/bin/servicemanager
user system
critical
onrestart restart zygote
onrestart restart media

service vold /system/bin/vold
socket vold stream 0660 root mount

#service mountd /system/bin/mountd
# socket mountd stream 0660 root mount

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
socket zygote stream 666
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on

service media /system/bin/mediaserver
user media
group system audio camera graphics inet net_bt net_bt_admin

service bootanim /system/bin/bootanimation
user graphics
group graphics
disabled
oneshot

service installd /system/bin/installd
socket installd stream 600 system system

service wpa_supplicant /system/bin/wpa_supplicant -Dwext -iwlan0 -c /data/misc/wifi/wpa_supplicant.conf
group system wifi
disabled
oneshot

service dbus /system/bin/dbus-daemon --system --nofork
socket dbus stream 660 bluetooth bluetooth
user bluetooth
group bluetooth net_bt_admin

service hcid /system/bin/hcid -d -s -n -f /etc/bluez/hcid.conf
socket bluetooth stream 660 bluetooth bluetooth
socket dbus_bluetooth stream 660 bluetooth bluetooth
group bluetooth net_bt_admin misc
disabled

service hfag /system/bin/sdptool add --channel=10 HFAG
user bluetooth
group bluetooth net_bt_admin misc
disabled
oneshot

service hsag /system/bin/sdptool add --channel=11 HSAG
user bluetooth
group bluetooth net_bt_admin misc
disabled
oneshot

service ril-daemon /system/bin/rild -l /system/lib/libreference-ril.so -- -d /dev/ttyUSB1
socket rild stream 660 root radio
socket rild-debug stream 660 radio system
user root
group radio cache inet misc

service ppp /system/bin/pppd call gprs
user root
group system radio
disabled
oneshot

#Please do not change anything below this line. If you want to add new service, add it above this line
#REMOVE FROM HERE
service dhcpcd /system/bin/dhcpcd wlan0
group system dhcp
disabled
oneshot
Files inside android emulator :

neomac2:images neo$ pwd
/Users/neo/Downloads/android/android-sdk-mac_86/platforms/android-2.1/images
neomac2:images neo$ file *
NOTICE.txt:   ISO-8859 English text
kernel-qemu:  data
ramdisk.img:  gzip compressed data, from Unix
system.img:   VMS Alpha executable
userdata.img: VMS Alpha executable
neomac2:images neo$

system.img, userdata.img is actually yaffs image files, could use unyaffs to unpack :

http://code.google.com/p/unyaffs/downloads/list

Friday, March 05, 2010

Use Android phone as 3G modem on Mac OSX

** Only tested at Google Nexus One

Reference from :
Using Android Phone as a USB Tether on Mac OS X
Tethering android and OSX without root
Mac OS X Droid Tethering (USB/Wired)

1. Download and install necessary applications at OSX :
- TunnelBlick OpenVPN for Mac OS X
- tuntap for Mac OS X
* need to reboot to make sure kext got loaded at startup.
* or manually load them by blow command w/o reboot :
sudo kextload /Library/Extensions/tun.kext
sudo kextload /Library/Extensions/tap.kext

2. Download and install azilink.apk at android phone :
- azilink for google android
* execute azilink at android phone, enable service

3. Download Android SDK, cp tools/adb into executable path ( like /usr/sbin )

4. Enable USB debugging on the Android phone :
- Settings>Applications>Development>USB debugging.

5. Save blow script into ~/azilink.sh ( from http://pastie.org/701122 ), and execute it :

#!/bin/bash
#
# azilink for OS X
# based on http://pastie.org/405289 but works with Tunnelblick only
# (no need to install a separate copy of OpenVPN2 from macports
# or building from source by hand, thankfully)
# Requires:
# - azilink running on android phone (http://code.google.com/p/azilink/)
# (run the app and check the box to start the service).
# - adb on system path (comes with the Android SDK;
# add its tools folder to your PATH in ~/.profile or
# place or symlink the sdk's tools/adb file in e.g. usr/local/bin or somewhere else on the PATH)
# - Tunnelblick, a nice OS X packaging of OpenVPN (http://code.google.com/p/tunnelblick/)
# Install Tunnelblick to Applications. Tested with Tunnelblick 3.0b22

init() {
adb forward tcp:41927 tcp:41927
sudo /Applications/Tunnelblick.app/Contents/Resources/openvpn --dev tun \
--script-security 2\
--remote 127.0.0.1 41927 \
--proto tcp-client \
--ifconfig 192.168.56.2 192.168.56.1 \
--route 0.0.0.0 128.0.0.0 \
--route 128.0.0.0 128.0.0.0 \
--keepalive 10 30 \
--up "$0 up" \
--down "$0 down"
}

up() {
tun_dev=$1
ns=192.168.56.1
sudo /usr/sbin/scutil << EOF
open
d.init
get State:/Network/Interface/$tun_dev/IPv4
d.add InterfaceName $tun_dev
set State:/Network/Service/openvpn-$tun_dev/IPv4

d.init
d.add ServerAddresses * $ns
set State:/Network/Service/openvpn-$tun_dev/DNS
quit
EOF
}


down() {
tun_dev=$1
sudo /usr/sbin/scutil << EOF
open
remove State:/Network/Service/openvpn-$tun_dev/IPv4
remove State:/Network/Service/openvpn-$tun_dev/DNS
quit
EOF
}


case $1 in
up ) up $2 ;; # openvpn will pass tun/tap dev as $2
down) down $2 ;;
* ) init ;;
esac