Friday, December 24, 2010

compile with hidden classes on android

in Android SDK (not AOSP)
sometimes you need to use some 'hidden' classes ( with @hide annotations)

here is how I do it with ant build

first you need to get the whole Android framework jars
it's located in 
mydroid/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar

1:
copy it to your project/lib/   
(not libs/,  because ant build will include the jars in libs, but here we just need to use it for symbol resolution)

2: 
customize your ant build.xml
copy the templates from 
  • for cupcake donut
    • platforms/$API_LEVEL/templates/android_rules.xml
  • for eclair froyo
    • platforms/$API_LEVEL/ant/ant_rules_r2.xml
  • gingerbread 
    • tools/ant/main_rules.xml

3.
  add a path before the compile task <compile>
 <path id="boot.class.ref">
        <fileset dir="./lib">
            <include name="*.jar" />
        </fileset>
    </path>

then

add a line after <javac>

<compilerarg value="-Xbootclasspath/p:${toString:boot.class.ref}"/$gt;

here I try to update the boot class path with -Xbootclasspath/p option






Monday, December 20, 2010

vim 的達文西密碼

:help holy-grail


本來標題差點打成達爾文的密碼.....

Friday, December 17, 2010

cpp的member variable

member variable, or field
跟member function (or method)不一樣
不是存在v-table裡的
而是存在每個class裡

在 http://www.go4expert.com/forums/showthread.php?t=8403
的Exmaple 2裡
可以發現 dTest其實有另外存一份 Test的a 跟b
即使 a ,b 是private的
所以他的size是12

所以可以像Example 5一樣  加上 dTest 並來改 Test的a,b
Test 裡的 a ,b 是public的
所以也可以從dTest直接修改a b
像Example 5的例子 是用pointer來改
所以即使a, b是private的話也可以work

Thursday, December 16, 2010

3gpp format

介紹3gpp的網站

簡中:
http://www.cnitblog.com/zouzheng/archive/2007/04/04/25155.html

這個有點看不洞
http://blog.csdn.net/zblue78/archive/2010/12/15/6078040.aspx

parse atom的tool
http://atomicparsley.sourceforge.net/mpeg-4files.html

spec:
http://standards.iso.org/ittf/PubliclyAvailableStandards/c051533_ISO_IEC_14496-12_2008.zip

video broadacast on android


http://www.mattakis.hu/blog/kisg/20090708/broadcasting-video-with-android-without-local-files
談論到如何將recorder錄下來的video 藉由socket 送出去
(與onPreviewFrame不同的是  recorder已經把這data encode過了
onPreviewFrame是 raw data)

但其實在Android上 camrecorder 是在stop record之後
才把moov atom送出去
所以即使另一邊用socket來收這個stream
也無法來作streaming play的動作

而在上面那個link的comment 也討論到
即使是把他作成RTP  也還是要產生SDP


PS:
將moov從後面搬到前面的tool MP4BOX
http://gpac.cvs.sourceforge.net/viewvc/gpac/gpac/applications/mp4box/

Tuesday, December 7, 2010

javascript的arguments Object


http://dmitrysoshnikov.com/ecmascript/chapter-2-variable-object/
提到了 arguments

特別的是
他在foo(x,y,z)裡提到了一個例子 並且還在例子後註明了這是個chrome的bug


例子是:
如果改了arguments[2] 那z 同時也會改變嗎?
一般的javascript variable是不會的
但這裡是個特別的例子 blog的作者可能有點誤會了
在這裡  arguments[2]跟z是shared同個reference的


但ECMA  spec裡講到

10.1.8 Arguments Object
...........略
• For each non-negative integer, arg, less than the value of the length property, a property is created with name
ToString(arg) and property attributes { DontEnum }. The initial value of this property is the value of the
corresponding actual parameter supplied by the caller. The first actual parameter value corresponds to arg = 0,
the second to arg = 1, and so on. In the case when arg is less than the number of formal parameters for the
Function object, this property shares its value with the corresponding property of the activation object. This
means that changing this property changes the corresponding property of the activation object and vice versa.

在Javascript: The Definitive Guide也有提到這件事





Section 8.2.2
page 130

龍馬傳 #16 勝麟太郎

昨天作的劇情是 龍馬去跟勝麟太郎拜師
但有一說是當時龍馬是要去暗殺勝麟太郎的 
從あつひめ劇中就是這樣作的



http://ja.wikipedia.org/wiki/%E5%9D%82%E6%9C%AC%E9%BE%8D%E9%A6%AC#cite_note-115

Tuesday, November 30, 2010

meta tag support on Android

在Android froyo 上  
他也有support meta的tag

在Android external webkit的
找 ANDROID_META_SUPPORT 這個keyword

然後在這可以找到他support 哪些attribute

http://android.git.kernel.org/?p=platform/external/webkit.git;a=blob;f=WebCore/page/Settings.cpp;h=c495a230a9bc4d1c0383e67d293ec22e3c036f3c;hb=HEAD#l443

Javascript的 setTimeout

最近發現 Javascript的setTimeout有兩種call 法

1. pass a Function Object

   function fired () {

   }
    setTimeout(fired, 1000);

2. Pass a String Object

    function fired () {

   }
    setTimeout("fired();", 1000);

  而這會用eval()的方法來執行他


特別的是 我剛剛把這兩種用法搞混了
變成

setTimeout(fired(), 1000);

把fired 變成  fired()
也就是變成先call fired() 這function , 才把這function的return值傳給setTimeout
變成 1st argument

難怪我的code一直不對

touchstart event on Android Webkit(froyo)

Android Webkit (Froyo) 目前support 的touch event有

touchstart
touchmove
touchend
touchcancel
touchlongpress
touchdoubletap

這些定義在
http://android.git.kernel.org/?p=platform/external/webkit.git;a=blob;f=WebCore/dom/EventNames.h;h=b20eaa8e1de56b97be408f0a3a27e050921e5573;hb=HEAD#l149

以及在這些被處理的
http://android.git.kernel.org/?p=platform/external/webkit.git;a=blob;f=WebKit/android/jni/WebViewCore.cpp;h=70e96cd8a4dece9312717778b2497ad6ac945170;hb=HEAD#l2041

這裡有個網頁可以來測試
http://kangax.github.com/iseventsupported/

Saturday, November 27, 2010

N82拆機

今天手機的鍵盤又壞掉了
已經用了兩年半了但覺得很好甩 所以沒換新機的打算
於是上網找了N82的拆機教學
雖然沒有Nokia的toolkit 但拿了平時鎖眼鏡用的起子
一樣把keyboard前的面板給拆開了

把位置調一調
再裝回去  果然我的N82又復活了~


Friday, November 26, 2010

一個介紹 c++ vptr的好例子

http://www.go4expert.com/forums/showthread.php?t=8403

這個網頁從以前到現在 看了再看
都還是覺得很有趣

Thursday, November 25, 2010

Android PREBUILT_PACKAGE

最近發現 Prebuilt java libaray 的style 跟一般的BUILD_PACKAGE大不相同呀

http://groups.google.com/group/android-building/browse_thread/thread/26c5ec332fe924a2

http://groups.google.com/group/android-building/browse_thread/thread/f7f57432a677ca85

c 的offsetof

在wiki上看到的offsetof的macro
http://en.wikipedia.org/wiki/Offsetof

http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Offsetof.html

http://blog.linux.org.tw/~jserv/archives/001399.html

而他有兩個argument
第一個是struct type 第二個是member

The C++ Programming Language的問題

1.在Chap3 3.11 Advice p.66 裡 第七條
Using string rather than char*

請問即使我對char * 用了簡單的strcat strcpy這些library
會比string 還要來的慢嗎???

或者是可以說明在處理字串時(就ascii就好了)
什麼時候用string,when to use char*呢?



2.在10.2.8 Structurs and Classes的最後 p.235
他講了一句
allowing many access sepcifiers in a class is useful for
machine generated code.
就是他上面有講個例子 public,private可以一直加的

class Data4 {
public :
 ...
private :
 ...
public:
...
}

這裡的machine generated code是指什麼?
是某些tool產生出的c++ code還是compile完產生的code
(IR, assembly, or machine code)
為什麼會useful??



3. 在10.4.6.2 Member Constants p249
他說可以initialize a static integral constant member
為什麼只有int 可以 float那些為什麼不行呢???



4.在11.2.3 p265
第一段要結束時他說
it is not possible to define an operator function that
operates exclusively on pointers



5.Sec13.4 Using Template Arguments to Specify Policy
主要在講用Template class來specify operation(less,eq,..)

在p339 倒數第三段最後面 他說了
whereas inlining a call through a pointer to function
requires exceptional attention from a compiler
在這裡指的exceptional attention是指什麼呢?

寫C寫久了會很習慣用pointer to function
但想知道這裡不建議使用pfn的原因







6. Sec14.2 Grouping of Exceptions
第一段的第三行有說
the effect of a throw is to unwind the stack until a
suitable catch is found

他說的unwind是什麼意思呢
是指一般function return時stack會清掉的意思嗎?
(esp回到ebp)
如果是這樣的話
throw 出來的那個object(or pointer,reference)
他是存在哪裡的??
stack被清掉那exception應該也會被清吧???

Wednesday, November 24, 2010

webkit 的resource loading

不太了解Webkit在resource loading時的pipeline是怎麼作的

http://webkit.org/blog/1188/how-webkit-loads-a-web-page/


LOCAL_USER_TAGS on Gingerbrand branch

http://groups.google.com/group/android-building/browse_thread/thread/26c5ec332fe924a2

in this post JBQ mentioned that the build will fail if it uses LOCAL_USER_TAGS := user
and the APK isnt contained in PRODUCT_PACKAGES

about the PRODUCT_PACKAGES  
it is located in build/target/product/{generic, sdk}.mk

Thursday, November 18, 2010

signature check in Android PluginManager

常常看到有人在問android PluginManager裡面的signature 是幹嘛用的
http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/webkit/PluginManager.java;h=cdcb662e057c4d41b7e7af235991d53037d1e19d;hb=HEAD#l75


查了一下commit的log
原來是當初要給flash on android


commit 73477e7336cd1bdd67984a0f6374c79108a8f098
Author: Grace Kloba
Date:   Wed Sep 30 17:45:46 2009 -0700

    Add the signature checking for WebView plugins. The
    first one is for SampleBrowserPlugin. The second
    one is for Flash.

diff --git a/core/java/android/webkit/PluginManager.java b/core/java/android/webkit/PluginManager.java
index 766bd75..edba446 100644
--- a/core/java/android/webkit/PluginManager.java
+++ b/core/java/android/webkit/PluginManager.java
@@ -65,6 +65,15 @@ public class PluginManager {

     private ArrayList mPackageInfoCache;

+    // Only plugin matches one of the signatures in the list can be loaded
+    // inside the WebView process
+    private static final String SIGNATURE_1 = "308204a830820390a003020102020900936eacbe07f201df300d06092a864886f70d0101050500308194310b3009060355040613025553311330110603550408130a43616c69666f726e69613116301
+    private static final String SIGNATURE_2 = "308204c5308203ada003020102020900d7cb412f75f4887e300d06092a864886f70d010105050030819d310b3009060355040613025553311330110603550408130a43616c69666f726e69613111300
+
+    private static final Signature[] SIGNATURES = new Signature[] {
+        new Signature(SIGNATURE_1), new Signature(SIGNATURE_2)
+    };
+
     private PluginManager(Context context) {
         mContext = context;
         mPackageInfoCache = new ArrayList();
@@ -148,9 +157,12 @@ public class PluginManager {
                 }
                 boolean signatureMatch = false;
                 for (Signature signature : signatures) {
-                    // TODO: check signature against Google provided one
-                    signatureMatch = true;
-                    break;
+                    for (int i = 0; i < SIGNATURES.length; i++) {
+                        if (SIGNATURES[i].equals(signature)) {
+                            signatureMatch = true;
+                            break;
+                        }
+                    }
                 }
                 if (!signatureMatch) {
                     continue;

Tuesday, November 16, 2010

龍馬傳 #1 上士と下士

第一集出現了 岩崎弥太郎 這個人

沒聽過所以查了一下他
http://ja.wikipedia.org/wiki/%E5%B2%A9%E5%B4%8E%E5%BC%A5%E5%A4%AA%E9%83%8E


不過發現了一件事

慶応3年(1867年)、後藤象二郎に藩の商務組織・土佐商会主任・長崎留守居役に抜擢され、藩の貿易に従事する。坂本龍馬が脱藩の罪を許されて亀山社中海援隊として土佐藩の外郭機関となると、藩命を受け隊の経理を担当した。記録上確認出来る弥太郎と龍馬の最初の接点はこの時である。

而在龍馬傳裡
他們在很小就認識了
所以這部分是不合史實的地方

另外還注意到了龍馬的三姐  乙女
http://ja.wikipedia.org/wiki/%E5%9D%82%E6%9C%AC%E4%B9%99%E5%A5%B3

其實是個很大隻的女生!!
身長5尺8寸(約174cm)・体重30貫(約112kg)

Jar signing and verifying

Android Media stack

這張是很久之前作的(donut)
忽然發現 所以把他放出來


現在Froyo上底層的engine換StageFright了

Monday, November 15, 2010

Thursday, November 11, 2010

拿到一隻hbbot是0.35的nexus one

昨天拿到一隻nexus one
想燒自己的image進去

結果在fastboot flashall的時候發現
這隻hboot是0.35的

他一直說要0.33才能燒
在xda找了看能不能回復到0.33好像也沒什麼用
那個link的mtb0.img已經不見了


最後只有慢慢的fastboot flash system system.img 這樣一個一個的燒進去
不過也只有三四個image喔
system, boot, recovery,
頂多一個userdata

在Eclair之前Browser的的exploit

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-1807

source code:
http://www.exploit-db.com/exploits/15423/

不過還沒找到patch在哪

Wednesday, November 10, 2010

Android的Google Group

一開始覺得那些Android的Engineer會跟我一樣每天讀那些post
像Dianne Hackborn, David Turner,JBQ, fadden, Xavi.....

但是現在覺得Android的Google Group是有人來專門每天讀那些post
然後過濾過後再把真正有問題的post轉到相關的人員身上

Monday, November 1, 2010

android 的FileObserver

之前很好奇 為什麼
adb push test.apk /system/app
就可以把test.apk裝起來

然後把adb shell rm /system/app/test.apk
就可以把他刪除

原來是PackageManagerService裡有個AppDirObserver

其實就是extend android.os.FileObserver
然後再看FileObserver

原來他是用了linux裡的inotify這個feature
http://en.wikipedia.org/wiki/Inotify

kawakami-san離職了

上星期五請病假
不過今天打開email收信時
卻發現 kawakami-san上星期五寄給我的信
說 今天已經是他最後一天在這了  接下來他就離職了

kawakami是之前在英國認識的同事
我們是一起要到London出差的
雖然只有一星期 雖然我們只能用破破的英文聊天
從一開始他只是笑笑的回答我
到最後也會跟我聊很多事 (當然是灌他幾杯米露之後)

而且到最後一天我才發現 他的職位是
Division Supervisor
囧了...........我一直開部門主管的玩笑...................
雖然在這裡這種事我也常作...................................

Good Luck , Kawakami-san

wish I can see you again

kawakami-san在新的UK office被我偷拍到

Thursday, October 28, 2010

html5 audio tag on Android(froyo)

目前audio tag在android是動不了的
除了那controller只是一個白框之外

但在白框點了下去後
發現在external/webkit/WebKit/android/WebCoreSupport/MediaPlayerPrivateAndroid.cpp裡

MediaPlayerPrivate::play

只有處理video的case
m_glue->m_javaProxy  是null的

而這javaProxy只有在 createJavaPlayerIfNeeded
, setVisible(true)時才會被create
也就是 only for video case 才會處理

================================================
PS: 2010/12/07 update
Android 2.3 (Gingerbrand) already supports HTML5 audio tag

Wednesday, October 27, 2010

在webview上跑video

目前的Android 的html5要在webview上跑video
都是用 fullscreen來跑

最近拿了Browser Plugin的例子來改
就是利用Browser Plugin來play video
而不是利用Html5  video tag

有點麻煩的是 Browser Plugin在Android2.0後多了一些限制
通常你要在 eng build裡才能跑  就是 ro.secure要等於0

code裡用了上次講的MEDIA_OVERLAY的field
讓video能embedded在webview裡

有點特別的是
整個view hierarchy是webcorethread 建立的
所以反而不要在 UI Thread裡去動view的東西




git@github.com:allstarschh/SampleBrowserPlugin.git

html5 video tag on Android

找到了幾個可以在android上跑video tag的url

http://broken-links.com/tests/video/

http://www.awakecoding.com/android/

不過發現這幾個video的codec 在emulator上都沒support
所以只是有聲沒影

Wednesday, October 20, 2010

在Android上讓兩個SurfaceView 疊在一起

在android的設計上
兩個surfaceview是不能疊在一起的

例如想要一個小小的VideoView疊在一個一直在畫圖的SurfaceView上
你會發現videoview一直是出不來的  (不過是可以有聽到video聲音)

之前發現 在WindowManager有一個hidden的field
(也太賊了吧  SDK都找不到 某天在source code才看到)

TYPE_APPLICATION_MEDIA_OVERLAY


所以magic就是
SurfaceView.setWindowType(WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY);


不過後來在1.6或2.0有開一個API 在SurfaceView上
 public void setZOrderMediaOverlay
其實這就是會接回到上面講的那個hidden field

Friday, October 15, 2010

在v8的javascript file加log

最近發現v8一直死在從native call javascript function call的時候一直死掉
苦無log可尋

可以想學 d8.cc中 create 一個 FunctionTemplete 來印
可是後來發現  其實runtime.cc 中有一個Runtime_Log  function就可以用了

不過要先把log_runtime 的option 打開
跟define  ENABLE_LOGGING_AND_PROFILING

不過還不確定詳細的功能就是了

簡單的印log就
%Log('hello', [""]);

要用c的printf   後面是 valist那種  後面的js array還不知道怎麼用就是了

Tuesday, October 12, 2010

resources.arsc不一樣了

在android的apk 裡
都會夾著一個resource.arsc
他是從 res/裡的像 values/strings.xml 轉過來的

可是最近在android-2.2.1上發現(可能是Gingerbread了)
resoures.arsc格式有點不一樣了

本來是UTF-16LE
就是每個字元會兩個byte的

但是2.2.1上  只剩一個byte了
變成有點像ascii還是utf-8了

不知道為什麼resources.arsc要變就是了........

PS 2010/12/07
在Android 新出來的SDK 2.3 Gingerbrand
發現並沒有這問題
看來是AOSP那個build有些改變吧..........

Thursday, September 9, 2010

在froyo上找native memory leak

link

setprop libc.debug.malloc 1 or 5 or 10

javascript:void(0)

Tuesday, August 17, 2010

gcin on ubuntu

sudo vi /usr/lib/gtk-2.0/2.10.0/immodule-files.d/gcin.immodules

"gcin" "gcin Input Method" "gcin" "/usr/share/locale" "" <- 最後面本來是 "*" 把*拿掉

Wednesday, August 11, 2010

ubuntu lucid on lenovo x201

boot option 後面的 -- 刪除
加上xforcevesa i915.modeset=0

Tuesday, August 10, 2010

illegal forware reference in java

case 1:  比較常見的
class Test {
  String s = "hello";

  class inner {
    inner () {
        String s = s;  // <- illegal forward reference
    }
  }
}


case 2:  比較特別的 即使sStr是static也會


class Test2 {
  static {
    System.out.println(sStr);  // <- illegal forward reference
  }

  private static String sStr = "hello World";
}

Friday, July 30, 2010

android emulator support

SMS
    - external/qemu/telephony/modem_driver.c
    see http://developer.android.com/guide/developing/tools/emulator.html#sms for usage

MMS
    - N/A

Geolocation/GPS
    - external/qemu/android/gps.[c|h]

    - how to set
        - ddms :
            Emulator Control -> Location Controls -> {Manual, GPX, KML}

        - shell:
            $>telnet localhost
            gps fix
      
Sensor
    emulator has defined 4 sensors
    - acceleration
    - magnetic_field
    - orientation
    - temperature
    only accelerometer is enable, others need to be tested
    see external/qemu/android/hw-sensors.[c|h]
        external/qemu/android/avd/hardware-properties.ini
    for the changing orientation in emulator( Ctrl + F11),
    Android framework computes the orientation by looking at the accelerometer
    see external/qemu/android/hw-sensors.c _hwSensors_setCoarseOrientation

    for the measure units, see hardware/libhardware/include/hardware/sensors.h
  
Camera
    it forks a preview thread, and keeps generating a YUV422 SurfaceView

    see
    - frameworks/base/camera/libcameraservice/FakeCameara.[cpp|h]
    - frameworks/base/camera/libcameraservice/CameraHardwareStub.[cpp|h]
    to modify it to generate different preview screen


Vibration
    not implemented in emulator
    external/qemu/android/hw-control.c # hw_control_do_query only handles power:light:brightness
    and see /sys/class/timed_output/vibrator/enable on device

Backlight
    - external/qemu/android/hw-control.c

    there are 3 kinds of backlight:
        - lcd_backlight
        - keyboard_backlight
        - button_backlight
    but 'Documents' says only lcd_backlight is supported
    see extenal/qemu/docs/ANDROID-QEMUD-SERVICES.TXT #hw-control services

    but actually even lcd_backlight can not work
    because hardware module 'LIGHTS_HARDWARE_MODULE_ID' is only available when
    TARGET_BOARD_PLATFORM is msm7k or qsd8k_dirs
    see hardware/
  
    also see /sys/class/leds on device

Battery Level
    the implementation is in external/qemu/hw/goldfish_battery.c
    - adb shell dumpsys battery

    also it will create a file /sys/class/power_supply/battery on device

Signal Strength
    the implementation is in external/qemu/telephony/android_modem.c
    see the line
    '{ "+CSQ", "+CSQ: 7,99", NULL },  /* XXX: TODO: implement variable signal strength and error rates */'
    modify 7 to change to signal strength

CPU frequency
    N/A
    but we can get cpu usage by issuing adb
    - adb shell dumpsys cpuinfo

    before cupcake, in Development.apk, there's a option for displaying cpu usage on screen,
    but this isn't supported anymore
    see frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp  #SurfaceFlinger::onTransact

Wednesday, July 21, 2010

在dalvik跟v8中把jit code印出來

dalvik
 mydroid/dalvik/vm/Init.c
   see gDvmJit.printMe = true;


v8
mydroid/external/v8/src/flag-definitions.h
print_code
print_builtin_code

android kernel qemu-armv7

http://groups.google.com/group/android-ndk/browse_thread/thread/a19fc6df3d661d79?hl=en

Wednesday, July 14, 2010

在mydroid build D8

這篇有問題  是錯的

後來發現 d8 中JS2C要的是
把d8.js 轉成d8-js.cc

原因是d8.cc裡面用的是NativesCollection
而這就在產生的d8-js.cc裡




# ===================================================
LOCAL_MODULE := d8
LOCAL_MODULE_CLASS := EXECUTABLES
intermediates := $(call local-intermediates-dir)

include $(LOCAL_PATH)/Android.v8common.mk
LOCAL_JS_LIBRARY_FILES := $(addprefix $(LOCAL_PATH)/,1 $(V8_LOCAL_JS_LIBRARY_FILES))

# Copy js2c.py to intermediates directory and invoke there to avoid generating
# jsmin.pyc in the source directory
JS2C_PY := $(intermediates)/js2c.py $(intermediates)/jsmin.py
$(JS2C_PY): $(intermediates)/%.py : $(LOCAL_PATH)/tools/%.py | $(ACP)
@echo "Copying $@"
$(copy-file-to-target)

# Generate libraries.cc
GEN3 := $(intermediates)/libraries-d8.cc $(intermediates)/libraries-d8-empty.cc
$(GEN3): SCRIPT := $(intermediates)/js2c.py
$(GEN3): $(LOCAL_JS_LIBRARY_FILES) $(JS2C_PY)
 @echo "Generating XXXX libraries.cc"
@mkdir -p $(dir $@)
python $(SCRIPT) $(GEN3) D8 $(LOCAL_JS_LIBRARY_FILES)
V8_GENERATED_LIBRARIES := $(intermediates)/libraries-d8-empty.cc
LOCAL_GENERATED_SOURCES += $(V8_GENERATED_LIBRARIES)

LOCAL_SRC_FILES := src/d8.cc src/d8-debug.cc src/d8-posix.cc
LOCAL_CFLAGS := -DENABLE_DEBUGGER_SUPPORT
ifeq ($(TARGET_ARCH),arm)
    LOCAL_CFLAGS += -DARM -DV8_TARGET_ARCH_ARM
endif


LOCAL_C_INCLUDES := bionic/libc/include $(LOCAL_PATH)/src $(LOCAL_PATH)/include
LOCAL_CPP_EXTENSION := .cc
LOCAL_STATIC_LIBRARIES := libv8
LOCAL_SHARED_LIBRARIES := libcutils

include $(BUILD_EXECUTABLE)

HTML5 Websocket 筆記 2010-07-06


Reply
12:23 pm

Monday, July 5, 2010

add prebuild lib in apk under mydroid

在mydroid build中
有個LOCAL_JNI_SHARED_LIBRARY可以指定自己的jni

但是這前提是這jni lib也是在某個LOCAL_MODULE中編出來的

如果想直接把這lib包進apk中
看了看build/core/package.mk

可以使用下面的:
$(shell cp $(wildcard $(LOCAL_PATH)/libs/armeabi/*.so) $(TARGET_OUT_INTERMEDIATE_LIBRARIES))

LOCAL_JNI_SHARED_LIBRARIES:= your_prebuild_lib

Tuesday, June 22, 2010

android branch name A-Z?

話說這個talk裡面 List view的demo
好像是用android 的每個branch的code name來作例子
http://code.google.com/events/io/2010/sessions/writing-zippy-android-apps.html

source code:
http://code.google.com/p/zippy-android/

private static final String[] CODE_NAMES = new String[] {
"1.0",
"Petit Four",
"Cupcake",
"Donut",
"Eclair",
"Froyo",
"Gingerbread",
"Haggis",
"Icelandic Icing",
"Jalape\u00f1o",
"Koala Krisps",
"Liver",
"Minced Meat",
"Nuts",
"Otter",
"Penguin",
"Quail",
"Rabbit",
"Salad",
"Taco",
"Umbilical Cord",
"Vodka",
"Wurst",
"Xiaodianxin",
"Yoghurt",
"Zatar",
};

Monday, June 21, 2010

糟糟糟 blog被aloha內侵!!!

Danger Danger
幸好我沒在這講公司八掛
科科

Wednesday, June 9, 2010

enable webkit debug

目前是指gtk上

--enable-debug後build

然後要export WEBKIT_DEBUG='LEVEL'

其中LEVEL要看WebCore/platform/Logging.cpp

Friday, June 4, 2010

vptr 跟 pointer to member function

good article on vptr
http://www.dreamincode.net/forums/topic/45816-detail-about-how-vptr-and-virtual-table-works/


and 一兩年前的信


Hi
我昨天在看WebKitcode  有看到一行怪怪的code

(m_object->*m_function)(this);  //請注意  ->*

我本身對c++不熟 但是問了一些熟c++的朋友 他們也不是很清楚
回去看了Stroustup的書 也不是講的很清楚 只有一頁 ( 媽的爛書.....)
不過大概知道這是pointer to member function
pointer to member function 是一個比較少人知道c++特有的feature

不過有整理出一些point出來

1.  pointer to member function is NOT pointer to function

void (Test::*pmfn)(void)      void (*pfn)(void)       是不一樣的  即使他們的return type, signature是一樣的
另外也不能把他castgeneric pointer (void *)
可以參考 c++ lite faqpage
http://www.parashift.com/c++-faq-lite/pointers-to-members.html


2. pointer to member function is NOT a pointer to some address

一個pointer to member function , 他只是一個class offset的位置而已
( EX: c++ 有個virtual function table的東西 而這pointer to member function只是這table中的offset)
而不是指到Memory中某段的address
另外 他的sizeof 不一定是4(on 32bit), 有些compiler會給他8 bytelength

3. dereference pointer to member function 要用 .*  or ->*
這也就是我看到那行怪怪code的東西
. -> 的時機就跟C一樣 object pointer時就用 ->


然後我寫個test 給大家看看

#include
using namespace std;
class test {
    public:
        void func();
        void func1();
        void (test::*pmfn)();  //注意這是個 pointer to member function
                                        // 而且要加test:: ,如果沒有 他就只是一般的pointer to function
                                        // 就是下面那行的  (*pfn)()
        void (*pfn)();
        void call_pmfn(test&); //這是要用 test::*pmfn call function的一個wrapper
};
void test::func()
{
    cout<<"test::func\n";
}
void test::func1()
{
    cout<<"test::func1\n";
}
void func()
{
    cout<<"func\n";
}
void test::call_pmfn(test& t)
{
//    (this->*pmfn)();  //這就是call pointer to member function的地方
    (t.*pmfn)();          //在這裡我用兩個範例  , both can work
}
int main()
{
    test t;

    /* pointer to function */
    t.pfn = &func;  //這裡就是我們一般熟悉的pointer to function
    (t.pfn)();

    /* general pointer to member function */
    void (test::*pmfn1)() = &test::func1; //這裡是一般書上跟網頁上教你如何使用pointer to member function的東西
    (t.*pmfn1)();                                    //  請看待會後面的註解1

    /* pointer to member function
     * declared inside class, it is also a member of this class */
    t.pmfn = &test::func;

    //後記20090224  最後發現 (t.*t.pmfn)()也可以
    //(t.*pmfn)(); /*error here!  'pmfn' was not declared in this scope*/  
    //我在上面這行一直遇到compile error 這也是我的朋友們無法回答我問題的地方
    // 請看後面的註解2
    t.call_pmfn(t);
  
    return 0;
}


註解1
注意這個pmfn1 不是 test裡的member , 即使他有 test::開頭
因為他並沒有declaretest 裡面
其他的 test::func , test::func1可以definetest 外面  是因為他們也有在test 裡面被declared

加了test::開頭 是要告訴compile 這個pointer to member是要指到哪個class裡的member
compile 在這行 同時也會把test refernce傳給這個 pmfn1
(Recall第二點, pointer to member function 並沒有指到memory中的address
所以這時compiler要把class 的資訊告訴 pmfn1)


註解2
如果這裡 pmfn pmfn1一樣用 (t.*pmfn)()的話
是會有compile error出來的
大概原因(大概指的是我沒有很確定  我是從gdb猜的 而不是看gccsource code)
在這 compile沒有像  pmfn1一樣 有把testinformation pmfn
因為compiler在這就把pmfn當作一般的class member一樣
所以當 (t.*pfmn)()  ,compiler找不到pfmn是哪個classpointer to member /*這裡就是我不確定的地方*/
so compile will issue a error here

解決的辦法是
member function 跟一般的function有個不一樣的地方
就是他多了一個hiddenparameter , this
所以我作了一個wrapper member function
藉由this (也可以傳 test&進來) refernce call pointer to member function
也就是code裡的 test::call_pmfn()

不過至於pointer to member function什麼時候用
就要參考一些design pattern的書了

與大家分享一下C++特別的地方

thanks

Thursday, May 20, 2010

使用TARGET_GLOBAL_LD_DIRS

在這個hack裡
http://go2.wordpress.com/?id=725X1342&site=xorl.wordpress.com&url=http%3A%2F%2Fwww.frasunek.com%2Fproto_ops.tgz&sref=http%3A%2F%2Fxorl.wordpress.com%2F2009%2F08%2F18%2Fcve-2009-2692-linux-kernel-proto_ops-null-pointer-dereference%2F

用了TARGET_GLOBAL_LD_DIRS
來用自己的linker script

Monday, May 17, 2010

__thread inside struct

忽然想到
如果__thread可以放到struct裡不就很刺激

小試了一下

26 struct test_t {
 27     int a;
 28     __thread int b;
 29 };

當然是會有compile error ......

Thursday, May 6, 2010

android build system

在combo/linux-arm.mk
default 是 build for  armv5te

另外在這makefile裡還有很多compiler flags

會找到這是因為要試試LOCAL_NO_DEFAULT_COMPILER_FLAGS=true
不然compile都會先找framework裡的header (無奈)

Friday, April 30, 2010

為什麼mmap size跟root有關系?

http://groups.google.com/group/android-kernel/browse_thread/thread/497ba1a48c3cd710

原因在這
http://lwn.net/Articles/342330/
http://xorl.wordpress.com/2009/08/18/cve-2009-2692-linux-kernel-proto_ops-null-pointer-dereference/
http://www.securityfocus.com/archive/1/archive/1/505751/100/0/threaded

第二個link http://xorl.wordpress.com/2009/08/18/cve-2009-2692-linux-kernel-proto_ops-null-pointer-dereference/

有講到三個hack

http://go2.wordpress.com/?id=725X1342&site=xorl.wordpress.com&url=http%3A%2F%2Fwww.grsecurity.net%2F~spender%2Fwunderbar_emporium.tgz&sref=http%3A%2F%2Fxorl.wordpress.com%2F2009%2F08%2F18%2Fcve-2009-2692-linux-kernel-proto_ops-null-pointer-dereference%2F
這用了
oxff
0x25

0xff 0x25其實就是jmp的opcode
找個例子 objdump -D 就看出來了

http://go2.wordpress.com/?id=725X1342&site=xorl.wordpress.com&url=http%3A%2F%2Fwww.frasunek.com%2Fproto_ops.tgz&sref=http%3A%2F%2Fxorl.wordpress.com%2F2009%2F08%2F18%2Fcve-2009-2692-linux-kernel-proto_ops-null-pointer-dereference%2F

這用了0x90 0xe9

跟最後一個比較簡單的
http://go2.wordpress.com/?id=725X1342&site=xorl.wordpress.com&url=http%3A%2F%2Fmilw0rm.com%2Fsploits%2Fandroid-root-20090816.tar.gz&sref=http%3A%2F%2Fxorl.wordpress.com%2F2009%2F08%2F18%2Fcve-2009-2692-linux-kernel-proto_ops-null-pointer-dereference%2F

opengl from donut to eclair

從donut到eclair,  loading OPENGLES 的方式有點不一樣
there is some difference of loading opengles lib from donut to eclair

check EGL first if you dont know what it is
http://www.khronos.org/egl/

on donut,
software impl for OPENGLES is /system/lib/libagl,
hardware is /system/lib/libhgl

on eclair
software impl is moved to /system/lib/egl/libGLES_android.so
hardware impl is moved to /system/lib/egl/lib{EGL,GLESv1_CM,GLESv2}_"vendor"
for example, on Acer A1 , it's system/lib/egl/libEGL_adreno200.so
                                                                      libGLESv1_CM_adreno200.so
                                                                      libGLESv2_adreno200.so


check framework/base/opengl/libs/EGL/egl.cpp on both branches to see the difference

Wednesday, April 28, 2010

using JNI in pthread

有人問到為什麼不能在native pthread create出來的 thread "直接" 使用 JNI

在這explain 一下 background

大家知道Thread之間是會shared memory的 (不過stack當然還是自己的)
所以大家寫code 有時會用個global 變數  然後兩三個thread來對這global變數作read/write

不過大概在2000年吧?   ABI (Binary Interface)那時有作一些update 
http://www.sco.com/developers/gabi/2000-07-17/contents.html
主要就是多個TLS - Thread Local Storage
就是讓thread 有自己的global 變數 其他的thread並不會踩到別thread的memory

例如  原本的 int g_is_vm_started;
GCC的話 :  在前面加個 __thread  就變成 thread variable了
__thread int g_is_vm_started;
在這看你自己喜歡的compile怎麼改
http://en.wikipedia.org/wiki/Thread-local_storage

而JNI 也是有用到這東西
所以在call JNI時  VM會去拿TLS裡的pointer  裡面存著vm在這個thread裡的context
如果想看Dalvik的code的話
就是在vm/Jni.c裡的 JNI_ENTER() 這macro裡
( 不過Android上其實並沒有Runtime support TLS
用readelf dump library裡其實並沒有.tdata .tbss的section
上面講的TLS 其實是bionic 裡的pthread 自己作出來的
)


想在pthread create出來的thread裡使用JNI
可以先看這
http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/invocation.html

還有個在pthread裡的ClassLoader的問題
http://groups.google.com/group/android-ndk/browse_thread/thread/7982fdb5892f79fb

Monday, April 12, 2010

android emulator的cpu

http://groups.google.com/group/android-ndk/browse_thread/thread/b41d13b517abe69d?hl=en



不知道中間Dave Buther講的這段話
On the emulator I suspect it is being (correctly) treated as an
UNDEFINED instruction (the emulator is running as an ARM926 I
believe), under user-mode on an ARM1176 or an ARMv7-a processor it
will still be treated as an UNDEFINED
while in user mode. 



是什麼意思............

Thursday, April 1, 2010

gcc的extension

# define PLUGIN_LOG(A, B...) do { LOGI( A , ## B ); } while(0)

看得懂上面那段code嗎
不要以為##是多的

當你的arg只有一個時 PLUGIN_LOG(A) 你就發現它的重要性了

http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

enable native WebKit log

最近一直試著要在native WebKit加log
但就是看不到

最後看到
external/webkit/WebCore/platform/android/ScreenAndroid.cpp
的一段話

35 #undef LOG // FIXME: Still have to do this to get the log to show up
36 #include "utils/Log.h"

照著他的方式來作

媽呀 真的log出現了

原來在WebCore/config.h 會去include
而這裡面也有定義LOG

所以我加的LOG[VDIWE]全都跑到wtf/Assertions.h裡面了
(事實上是空的 因為LOG_DISABLE被設為1了)

Friday, March 19, 2010

test

MediaPlayer::~MediaPlayer()
{
    LOGV("destructor");
    removeObitRecipient(this);
    disconnect();
    IPCThreadState::self()->flushCommands();
}

void MediaPlayer::disconnect()
{
    LOGV("disconnect");
    sp p;
    {
        Mutex::Autolock _l(mLock);
        p = mPlayer;
        mPlayer.clear();
    }

    if (p != 0) {
        p->disconnect();
    }
}

// always call with lock held
void MediaPlayer::clear_l()
{
    mDuration = -1;
    mCurrentPosition = -1;
    mSeekPosition = -1;
    mVideoWidth = mVideoHeight = 0;
}


神奇的preprocessor

gcc -x c++ -E -P

Tuesday, January 19, 2010

enable pv log

除了 make -j 4 ENABLE_PV_LOGGER=1後
發現 也要在opencore/android/Android.mk裡


LOCAL_CFLAGS += -UNDEBUG

因為opencore/android/裡的source並不會用到PV_CFLAGS