2011年12月20日 星期二

Add external lib in Android.mk

1. add LOCAL_STATIC_JAVA_LIBRARIES += jar'sFileName . This line must be added above "include $(BUILD_PACKAGE)"

2. add LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := pathtoyourlib.jar This line must be added after "include $(BUILD_PACKAGE)"

3. add include $(BUILD_MULTI_PREBUILT)


then compile it

2011年11月16日 星期三

android remove preload app

get root permission

check which is target APK
pm path com.xxx.packagename

remount partition to let permission to be read/write
mount -o remount,rw -t yaffs2 /dev/block/mtdblk3 /system

we need get partition info from
cat /proc/mounts

2011年11月14日 星期一

android keycode

utf area code
android/external/icu4c/data/unidata/Blocks.txt

2011年10月28日 星期五

access UI thread

Some ways to access ui thread from other thread

1.Activity.runOnUiThread(Runnable)
2.View.post(Runnable)
3.View.postDelayed(Runnable, long)
4.Handler
when start service, we can use handler+message to access UI thread. Create a Handler in UI thread, and register this Handler in service. Send message to Handler in service, so we can access UI thread by Handler.

5.AsyncTask

Make sure that you access the Android UI toolkit only on the UI thread. 另外service也是run在UI thread之中,所以可以access UI.

service life cycle
1. if start service by Context.startService().
onCreate()->onStartCommand()->onDestroy(). 直到呼叫Context.stopService or stopSelf(). 如果多次呼叫startService. 只要呼叫一次stopService, 則所有呼叫的service都會停止。但service所create的thread不會停止,記得要在onDestroy中停止自己create的thread。

2. if start service by Context.bindService()
onCreate()(只有第一次啟動該service時才會呼叫)-> onDestroy()

2011年10月13日 星期四

Android Log

main log $adb shell logcat -b main -v threadtime
system log $ adb shell logcat -b system -d *:i
kernel log $ adb shell dmesg (or adb shell cat /proc/kmsg)


system app
/system/app
user app(internal storage)
/data/app
user app(external)
/mnt/asec
/mnt/secure/asec

set system log level per application

       adb shell setprop log.tag.XXXX VERBOSE

2011年9月6日 星期二

complie Android source to emulator

依照android source的指示, 但安裝所需套件時, 參考以下套件
Ubuntu Linux (32-bit x86):
sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

Ubuntu Linux (64-bit x86):
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl sun-java5-jdk zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev

java5 is for Froyo, java6 is for gingerbread
complie完之後,if we want to run emulator. 在environment path中加上"ANDROID_PRODUCT_OUT=target/product/generic"
and exec "./out/host/linux-x86/bin/emulator"

if use gcc4.6 to compile Donut, also need to change some things.reference Here
change ./frameworks/base/libs/utils/Android.mk
from
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
to
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

change ./development/emulator/qtools/Android.mk
from
common_cflags := -O0 -g
to
common_cflags := -O0 -g -Wwrite-strings -fpermissive

Change ./frameworks/base/tools/localize/Android.mk
from
LOCAL_LDLIBS += -lrt
to
LOCAL_LDLIBS += -lrt -lpthread

change frameworks/base/tools/appt/Android.mk
from
LOCAL_LDLIBS += -lrt
to
LOCAL_LDLIBS += -lrt -lpthread

host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp :0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] :0:0: note: this is the location of the previous definition cc1plus: all warnings being treated as errors make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1 To fix this, refer to this patch. https://github.com/CyanogenMod/android_build/commit/e9cbfa60c8dd60d04570d8bf7bd0d54a4304baf5 It will patch line 61 in build/core/combo/HOST_linux-x86.mk as following. -HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0 +HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1 change external/mesa3d/src/glsl/linker.cpp Adding a "#include
from
unsigned output_index = offsetof(VertexOutput,varyings) / sizeof(Vector4); /*VERT_RESULT_VAR0*/;
to
unsigned output_index = offsetof(VertexOutput,varyings) / sizeof(Vector4); /*VERT_RESULT_VAR0;*/


make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1
change external/oprofile/libpp/format_output.h
from
mutable counts_t & counts;
to
counts_t & counts;

make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error change external/gtest/include/gtest/internal/gtest-param-util.h
add
#include <cstddef>

make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
change external/llvm/llvm-host-build.mk
add
LOCAL_LDLIBS := -lpthread -ldl

查看編譯版本等資訊
getprop




on Mac OS
Mac OS:10.6.6(snow leopard)
xCode: 
4.3.3 (10G)
macport:for snow leopard
gmake:3.81

download and install package by step on Android source website.
1. need HFS+ disk format and disk size is suppose be bigger 25G.
2. download xCode.(4.2G). Build Android needs macOS.sdk 10.6. If download xCode4.5, it will not include MacOS10.6. It still need to download old version xCode to get 10.6SDK.
3. setup macport and install some packages (see Android source doc)
4. change gmake version to 3.81
5. Download source code in HFS disk
6. change JDK1.5, snow leopard uses 1.6 by default.
7. Change the gcc alias. This is needed by Qemu.

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.0 /usr/bin/gcc
8. To fix this error go to “external/qemu/” and open Makefile.Android file and edit the following line
MY_CC := $(HOST_CC)
to
MY_CC := gcc
9.

2011年9月1日 星期四

samsung device

unlock MSL: http://www.instinct-samsung.com/how-to/msl-%28merged%29/

remove UICCcheck
mv Android.mk Android.mk.bak(let builder ignore this app)
remove system/app/xxUICCxx.apk

2011年8月28日 星期日

Ubuntu指令, 設定

開啟具root權限的視窗
sudo nautilus

執行32位元程式,需要安裝ia32-libs。執行adb的時候出現no such file or diretory,才發現64不能直接跑
apt-get install ia32-libs
會安裝lib32asound2, lib32bz2-1.0, lib32gccl, lib32gccl, lib32ncurse5, lib32ncursesw5, lib32stdc++6, lib32v41, lib32zl, libc6-i386

vi預設無法使用backspace
home/xxx/.vimrc or /etc/vim/vimr
加入
set nocompatible
set backspace=2

apt-get install vim-full

2011年4月4日 星期一

Xpath with prefix

XML file:

<ns:authenticateResponse xmlns:ns='http://webservices.surfbi.fcs.com'>
   <ns:return xmlns:ax27='http://exception.surfbi.fcs.com/xsd' xmlns:ax210='http://dto.surfbi.fcs.com/xsd' type='com.fcs.surfbi.dto.UserDTO'>
      <ax210:first_name>SurfBI</ax210:first_name>
    </ns:return>
</ns:authenticateResponse>



java程式碼, 在使用Xpath時要用xpath.setNamespaceContext()設定Namespace。

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true); 
DocumentBuilder builder = domFactory.newDocumentBuilder();
 
InputStream is = new ByteArrayInputStream(xmlInput.getBytes("UTF-8"));
Document doc = builder.parse(is);
            
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(new FCSNamespaceContext());
 
String nil = xpath.evaluate("//ns:authenticateResponse/ns:return/@xsi:nil", doc);
XPathExpression expr = xpath.compile("//ns:authenticateResponse/ns:return/ax210:first_name");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
 for (int i = 0; i < nodes.getLength(); i++) {
 
  String test = nodes.item(i).getTextContent();
 }



NamespaceContext

public class FCSNamespaceContext implements NamespaceContext{
    public String getNamespaceURI(String prefix)
    {
        if (prefix.equals("ns"))
            return "http://webservices.surfbi.fcs.com";
        else if (prefix.equals("ax210"))
            return "http://dto.surfbi.fcs.com/xsd";
        else if (prefix.equals("ax27"))
            return "http://exception.surfbi.fcs.com/xsd";
        else if (prefix.equals("xsi"))
            return "http://www.w3.org/2001/XMLSchema-instance";
        else
            return XMLConstants.NULL_NS_URI;
    }
    
    public String getPrefix(String namespace)
    {
        if (namespace.equals("http://webservices.surfbi.fcs.com"))
            return "ns";
        else if (namespace.equals("http://dto.surfbi.fcs.com/xsd"))
            return "ax210";
        else if (namespace.equals("http://exception.surfbi.fcs.com/xsd"))
            return "ax27";
        else if (namespace.equals("http://www.w3.org/2001/XMLSchema-instance"))
            return "xsi";
        else
            return null;
    }
 
    public Iterator getPrefixes(String namespace)
    {
        ArrayList list = new ArrayList();
        
        if ( namespace.equals( "http://webservices.surfbi.fcs.com")) {
          list.add( "ns");
        } else if ( namespace.equals( "http://dto.surfbi.fcs.com/xsd")) 
            list.add( "ax210");
        
      
        return list.iterator();
 
    }
}

2011年3月10日 星期四

美國找軟體開發工作

到美國幾個月了,景氣很差,整理一下工作種類。由於是到了美國才開始找工作,遇到的問題不少,首先是工作簽證,再過來是開始工作,該不該因工作搬家,總之問題很多。我把工作種類分成三種:
1. 知名大公司,例如MS, Google, IBM,….
    大公司的面試流程長,投履歷,電話面試幾次,在過來現場面試。現場面試會再細分不同的面試官,等等都通過,在過來還有簽證申請流程,等開始進辦公室上班,可能要花上幾個月時間。不過大公司資源多,錄取後,在簽證方面公司會請律師幫忙辦到完。之後也較容易幫忙申請綠卡。再來大公司求職者多,面試機會不容易取得,面試由於有好幾次,所以難度也較深,面試者較有時間談的深入。

2. 規模較小的公司。可能是剛起步但營收跟成長率都很好,也有可能真的就一家小公司。這方面需要多做功課才會知道公司狀況。規模小,面試流程也稍快,不過至少HR面試,工程師/部門經理面試,現場面試這些還是都有的。簽證這方面就要看公司,可能會有公司要錄取者赴簽證費用,也可能連申請都不幫忙申請,另外綠卡也不一定會有,錄取後要問一下HR。

3. 短期工作。市場上幾乎都是這種工作,如果不是有人幫忙推薦的話,直接到工作網站另如linkedin, careerbuilder等,幾乎都是短期工作,從2 個月到1年不等。有可能是在知名大公司上班,但大部分都是小公司。這種工作也幾乎都是透過人力仲介(recruiter, consulting, staff…名稱不一樣但是都是做一樣的事情),由仲介推薦候選者給公司選,有的公司可能直接現場面試,有的也是先電話面試,之後在現場面試。這種工作公司不可能發簽證,但是可以問仲介,仲介反而很容易幫忙申請簽證。原因是甚麼勒?  因為幫你申請簽證後,你就是仲介的員工,工作的公司會發薪水給仲介公司,仲介公司再發給你,當然仲介公司可以抽成,至於抽幾成就看仲介公司有沒有良心了…。有的黑心仲介會抽到4~5成。這還是你有在上班的情況,當你的短期工作結束,在找到下一個短期工作之間的期間,黑心仲介是不發薪水的。所以你有工作他就賺錢,你沒工作他也沒虧錢,所以仲介公司很高興給你簽證。

最近都在面試,也多少知道一些美國公司的狀況,希望再找工作的人,都能找到好工作

Asurion interview(write a code sample)

THe hiring procedure includes HR interview, Engineer interview, write three codes. I just descript 3 code questions and my answer below.

1. Write a function in JAVA, which input a int array and return a int. The result int  means one of the index of array. The index let the sum of left side equal with right side. The function can find a index. For example, intput a array{-1, 7, 3, 2,4} and result is 2. becasue array[2] = 3. The left side is –1+7 = 6. The right side is 2+4=6.

private int equi(int[] A){
   int left=0;
   int right = 0;
   int k=0;
   if(A.length ==1){
      return 0;
   }
 
   for(int i=1; i<A.length; i++){
       right += A[i]; 
    }
   for(int i=0; i< A.length; i++){
       if(left == right){
            return k;
       }
       left +=A[i];
       right = right-A[i+1];
       k=i+1;
     }
     return -1;
}



2. Write a function in JAVA. The function should find a gap in the binary array……

private int binary_gap(int n){
   Integer integer = new Integer(n);
   String binaryString= integer.toBinaryString(n);
   int length = binaryString.length();
   int gap=0;
   int gap_Max=0;
   for(int i=0; i<length; i++){
      if(binaryString.substring(i, i+1).equals("0")){   
         gap++;
      }else{
         if(gap>gap_Max){
            gap_Max = gap;
         }
         gap=0;
      }
   }
   return gap_Max;
}


3. write a function in Javascript. Input is a string. For example,
’asurion’
0 –> ’asurion’
1 –>’suriona’
2 –>’urionas’
3 –>’rionasu’
4 –>’ionasur’


function cyclic_automorphisms(ori) {
        var temp = ori;
        var automorphisms=0;
        for (i = 1; i < ori.length; i++) {
            temp = ori.substring(i, ori.length) + ori.substring(0, i);
            if (ori.match(temp) == ori) {
                automorphisms = i-1;
            }
        }
        return automorphisms;
 }