2009年8月17日 星期一

Android 技术专题系列之七 -- 输入法 框架

Android 技术专题系列之七 -- 输入法 框架(2009-03-02 14:25:25)
标签:android 中文 输入法 结构图 架构图 解析 手机操作系统 智能手机 it 分类:android
Android的输入法框架比价复杂。从进程的角度来讲,相关功能主要分布在下面三个位置:


客户端应用是一个包含有图形界面的应用,如地址本。图形界面上包含有能够接收输入的编辑框,如TextView。
输入法模块提供软键盘,将用户在软键盘上的按键输入根据某种算法(如Zi, T9, 国笔等)转换成单词,然后传递给客户端应用。目录development/samples/SoftKeyboard下提供了一个输入法模块实例。如果想要实现一个中文输入法,可参考这个实例。
平台部分实现一些管理功能,负责装载某个输入法模块,启动,终止该模块等。
相关代码主要位于下面几个位置。其中,位于3,5,6,7目录下的代码最值得关注。
1. frameworks/base/core/java/com/android/internal/view
这个目录下定义了几个重要的idl 接口。
IInputMethod.aidl 定义了IInputMethod idl 接口,用于客户端跨进程操作InputMethod接口。
IInputMethodSession.aidl 定义了IInputMethodSession接口,是IInputMethod的辅助接口。用于客户端跨进程操作InputMethodSession接口。

IInputMethodCallback.aidl定义了一个helper 接口,由客户端实现。IInputMethod.aidl和IInputMethodSession.aidl实例可以分别调用该接口中的不同方法

IInputMethodManager.aidl 定义了Input Method Manager的service接口。客户端通过InputMethodManager interface调用这个service。
InputMethodManagerService.java实现了IInputMethodManager.aidl接口

IInputMethodClient.aidl定义接口,标识一个Input Method Manager 的客户。这个service在客户端实现,提供给server端调用。

IInputContext.aidl定义了一个接口,由客户端提供InputMethod使用。InputMethod可以与客户端交互,调用客户端提供的callback。
IInputConnectionWrapper.java 实现了IInputContext接口。
IInputContextCallback.aidl定义了一个接口,定义了一组callback函数给IInputContext.aidl实例调用,从客户端返回信息给InputMethod。
InputConnectionWrapper.java实现了IInputContextCallback接口。

2. frameworks/base/services/java/com/android/server
InputMethodManagerService.java实现了IInputMethodManager.aidl接口

3. frameworks/base/core/java/android/view/inputmethod
这个目录下定义了几个重要的interface和类。
InputMethodManager.java实现了InputMethodManager 类。此类调用IInputMethodManager.aidl接口功能,而IInputMethodManager.aidl接口功能由InputMethodManagerService.java实现,并运行在不同于客户端进程的server进程中。

InputConnection.java定义了InputConnection interface。InputConnection 接口在输入法和客户端之间建立了一个连接,输入法可以使用该连接获取或发送信息给客户端。InputConnection实例由客户端创建之后传递给输入法使用。BaseInputConnection.java 实现了InputConnection接口的一个基类: BaseInputConnection。 EditableInputConnection.java实现了一个派生类

InputBinding.java 定义了类InputBinding,这个类实现了parcelable 接口。这个类的成员变量包含了客户端传向server的信息。

InputMethod.java定义了InputMethod interface。文件InputMethodService.java中类InputMethodImpl实现了这个接口。这个接口定义了一套操纵一个输入法的方法。如,createSession,startInput等。要编写一个具体输入法的话,就需要派生这个接口。

InputMethodSession.java定义了InputMethodSession接口。文件InputMethodService.java中类InputMethodSessionImpl实现了这个接口。InputMethodSession是InputMethod的辅助接口,用于具体和某个输入法客户端交互。

CompletionInfo.java 类描述一个text completion.
EditorInfo.java类描述一个接收输入的view的属性,如内容属性(text, digit, etc)。
ExtractedText.java类描述从view中提取的传递给输入法的文本属性。


4. frameworks/base/core/java/com/android/internal/widget
EditableInputConnection.java实现了BaseInputConnection的一个派生类。

5. frameworks/base/core/java/android/inputmethodservice
这个目录下的代码提供了实现一个具体输入法的框架类。从这些类派生,就可以定制一个输入法。
SoftInputWindow.java中的SoftInputWindow类是一个Dialog子类。它代表一个输入法的顶级窗口(由窗口管理器管理),这个窗口由上到下,包含extractArea, candidatesArea, 和 inputArea。

Keyboard.java 中的Keyboard类装载并解析一个描述虚拟键盘(Soft Keyboard)的xml文件(如development/samples/SoftKeyboard/res/xml),并存储该键盘的属性,如该虚拟键盘包含多上行,每行有哪些键等。
KeyboardView.java 中的KeyboardView类是一个View子类。它根据Keyboard数据结构真正的在screen上画出一个虚拟键盘。这个虚拟键盘就是SoftInputWindow中的inputArea。

AbstractInputMethodService是Service的派生类,并实现了KeyEvent.Callback 接口。实现了InputMethod 和 InputMethodSession的基类。dispatchKeyEvent 函数将收到的key event传给相应的key 处理函数(在派生类中实现)。当这个service被客户端绑定时,其onBind()函数给客户端返回了一个IInputMethodWrapper实例,这个实例实现了IInputMethod idl接口。客户端可以使用该接口的相关功能。

IInputMethodWrapper.java 实现了IInputMethod idl 接口。这个类收到客户端的跨进程命令后,调用InputMethod完成相应功能。
IInputMethodSessionWrapper.java 实现了IInputMethodSession idl接口。这个类收到客户端的跨进程命令后,调用InputMethodSession完成相应功能。


6. frameworks/base/core/res/res/layout
这个目录下存放着一些系统资源。其中,
input_method.xml描述了一个输入法的窗口(即SoftInputWindow)布局,从上往下,依次排列extractArea, candidatesArea 和 inputArea。
input_method_extract_view.xml。

7. development/samples/SoftKeyboard
这个目录下代码实现了一个的输入法实例--软键盘英文/数字输入法。这里面实现的类大都是从frameworks/base/core/java/android/inputmethodservice 中的类派生而来。
AndroidManifest.xml:描述这个.apk提供的service以及关于这个输入法的一些信息。
res/xml/目录下存储着几个描述不同虚拟键盘的xml文件。
LatinKeyboard.java中的LatinKeyboard类是Keyboard的子类。
LatinKeyboardView.java中的LatinKeyboardView类是KeyboardView的子类。

8. frameworks/base/core/java/android/widget
在这里TextView.java是使用Input Method Framework (IMF)的客户端。TextView创建了一个InputMethodManager的实例并调用其restartInput 函数。
InputMethodManager::restartInput函数创建了一个InputConnection 实例并调用IInputMethodManager::startInput。
IInputMethodManager::startInput 函数使用mContext.bindService启动一个InputMethod service, 如 Sample Soft Keyboard。

9. frameworks/base/core/java/com/android/internal/widget

Android 技术专题系列之十一 -- DRM(2009-04-26 13:10:45)

Android 技术专题系列之十一 -- DRM(2009-04-26 13:10:45)
标签:drm android it 分类:android
简而言之,DRM系统提供一套机制对用户使用手机上的媒体内容(如ringtong, mp3等)进行限制,如限制拷贝给第三方,限制使用次数或时限等,从而保护内容提供商的权利。建议读者可以阅读OMA DRM 的规范,以便更好的了解代码。

相关代码主要位于下列目录:
frameworks/base/media/java/android/drm/mobile1
frameworks/base/media/libdrm/moblile1
frameworks/base/media/libdrm/mobile2
packages/apps/Mms/src/com/android/mms/drm: drm
packages/providers/DrmProvider/src/com/android/providers/drm

下面先作简要分析:
frameworks/base/media/libdrm/moblile1应该是提供OMA DMA1.0的本地/c++ 实现
frameworks/base/media/libdrm/moblile2应该是提供OMA DAM2.0的本地/c++ 实现。

frameworks/base/media/java/android/drm/mobile1 对应用提供OMA DRM 1.0 (即frameworks/base/media/libdrm/moblile1)的java接口。目前尚没有OMA DRM 2.0的java接口,也就意味着OMA DRM 2.0在Android中尚未应用。

packages/apps/Mms/src/com/android/mms/drm 实现在MMS中如何使用DRM。
packages/providers/DrmProvider/src/com/android/providers/drm ?

下面再作具体介绍:
一 目录 frameworks/base/media/java/android/drm/mobile1
这个目录是OMA DRM 1.0的java 接口。
OMA DRM 1.0 定义了几个重要概念:
DRM消息(DRM message):用户下载的一条DRM内容。根据下面介绍的DRM内容 传输方式的不同,DRM消息中包含的内容亦有所不同,可能只包含一个未经加密的媒体对象;也可能即包含未加密的媒体对象,也包含一个权利对象;也可能只包含一个经过加密的媒体对象(.dcf)。
媒体对象 (media object):包含媒体资源,如一个mp3, ringtone等。
权利对象(Right object): 限制用户如何使用媒体对象。


OMA DRM 1.0 定义了DRM内容的四种传输方式:
1. Combined delivery: 这种传输方式中,媒体对象以未经加密的方式(plain) 与Right object打成一个包,一块传输。这个包下载到手机设备上后,不允许转发给其他设备。
2. Forward lock: 这种传输方式是combined delivery的一个特例。媒体对象没有对应的Rigth object。媒体对象不允许转发给其他设备
3. Separate delivery: 媒体对象和权利对象分别传输。媒体对象采用对称密钥加密,文件以.dcf为后缀。权利对象中则包含对应的密钥。
4. Superdistribution:类似separate delivery, 但媒体内容允许转发给其他设备。

相应地,本目录的代码中:

DrmConstraintInfo对象描述了(对媒体内容的)一组限制属性,如开始/结束使用日期,使用次数等;

DrmRights对象代表了一个OMA 权利对象。

DrmRightsManager管理设备上的Rigth Objects。所有下载的权利对象,不论是由separate delivery 还是 combined delivery,权利对象都要首先安装到设备上。

DrmRawContent代表一条DRM内容,分为两类:DRM_MIMETYPE_MESSAGE_STRING --DRM内容是经combined delivery 或 forward lock传输的 (也即媒体对象没有加密,没有或者有一个权利对象); DRM_MIMETYPE_CONTENT_STRING -- DRM内容是经 separate delivery传输的(也即媒体对象是经过加密的dcf格式,不包含权利对象)。

DrmInputStream:这个对象从一个DrmRawContent对象中读出经过权利对象验证并解密后的(需要的话)媒体对象内容。这个内容之后就可以传给相关应用输出给用户。


二 目录frameworks/base/media/libdrm/moblile1
本目录真正实现DRM DRM 1.0。
drm1_jni.c提供对DrmRawContent中方法的本地实现;
objmng目录下是具体实现。frameworks/base/media/libdrm/mobile1/include/objmng/svc_drm.h中有关于每个方法的详细解释,基本思路是每打开一个Drm 内容,就创建一个session,然后提供一系列方法,以此session为参数,对Drm进行各种操作,如获取属性,读取解密后内容等。这里不再赘述。

Android 技术专题系列之十二 -- Alarm manager(2009-04-27 11:21:35)

Android 技术专题系列之十二 -- Alarm manager(2009-04-27 11:21:35)
标签:alarm manager android it 分类:android
Alarm manager 主要管理硬件时钟。一些与时间相关的应用,如日历,闹钟等需要使用Alarm Manager的服务。Alarm manager功能相对比较简单,相关代码位于
frameworks/base/core/jni/server/com_android_server_AlarmManagerService.cpp
frameworks/base/services/java/com/android/server/AlarmManagerService.java

一. frameworks/base/core/jni/server/com_android_server_AlarmManagerService.cpp
这部分代码直接管理硬件时钟,设备名为/dev/alarm。包括打开设备,关闭设备,设置时区,设置触发时间 (timeout),以及等待时钟触发。
二. frameworks/base/services/java/com/android/server/AlarmManagerService.java
这部分封装目录一中的代码,向上提供java接口,同时与客户端(如calendar)交互,接收来自客户端的时钟设置请求,并在时钟触发时通知客户端。

ndroid 技术专题系列之十五 -- 更新开发手机到1.5

ndroid 技术专题系列之十五 -- 更新开发手机到1.5(2009-05-15 11:14:18)
标签:dev phone 开发手机 升级 image android it 分类:android
参照http://www.htc.com/www/support/android/adp.html,下面是在Android 开发手机上更新1.5 image的步骤 (主机是ubuntu Hardy):
1. 下载必要的image。
Radio image: ota-radio-2_22_19_26I.zip
Recovery image: signed-dream_devphone-ota-147201.zip

2. 在主机上创建文件/etc/udev/rules.d/50-android.rules,内容:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
并修改文件属性:
chmod a+rx /etc/udev/rules.d/50-android.rules
然后重启机器

3. 将主机和Android开发手机通过usb 相连,运行命令 (./adb 命令来自sdk的tools)
./adb devices

应当看到一个device被列出。

4.参见http://www.htc.com/www/support/android/adp.html的 Update the Device Radio Firmware一节 ,更新firmware

5.参见http://www.htc.com/www/support/android/adp.html的 Copy the Recovery Image Package to the device一节 ,更新系统。

6. 切换到中文环境
./adb shell
$ su -
# setprop persist.sys.language zh;setprop persist.sys.country CN;stop;sleep 5;start

运行步骤6后,能看到有些应用的图标是中文,如"google 地图“。但大部分图标/环境仍然是英文。这应该是由于应用没有带中文语言包的缘故。读者可以试着安装一些带中文语言报的测试程序验证是否能够显示中文

Android 技术专题系列之十六 -- 在模拟器上安装 sd(2009-05-18 17:25:26)

Android 技术专题系列之十六 -- 在模拟器上安装 sd(2009-05-18 17:25:26)
标签:sd music 安装 mount emulator android it 分类:android
本文基于http://blog.jayway.com/2009/04/22/working-with-sd-cards-in-the-android-emulator/。特此申明。

今天想玩玩Android模拟上的music应用,可总是报告没有sd卡。网上搜了一下,有一哥们有一完整的解决方案(见上述连接)。这儿我将要点列在下面:
1.创建sd card image:
./mksdcard 1024M sdcard.img

2. 拷贝媒体文件, 如xxx.mp3, 到sd card image上。我考了一个我最喜欢的《滚滚长江东逝水》,呵呵。
sudo mount -o loop sdcard.img /mnt
cp xxx.mp3 /mnt
sudo umount /mnt

3. 创建一个AVD (Android Virtual Device)
./android create avd --name myAVD --target 2 --sdcard sdcard.img

这个命令会有很多选项让你确认,我只管一路回车。

4. 启动emulator
./emulator -avd myAVD

现在就可以打开music应用,欣赏音乐了。

Android 技术专题系列之十八-- 媒体文件管理

Android 技术专题系列之十八-- 媒体文件管理(2009-05-19 17:32:47)
本文引用了http://letsgoustc.spaces.live.com/Blog/cns!89AD27DFB5E249BA!473.entry部分内容,特此申明。

Android平台上的媒体文件管理和桌面系统不同。在桌面系统上,不同目录下的媒体文件呈树状结构显示给用户,用户需要进入不同目录寻找该目录下的文件。而在Android平台上,不同目录下的媒体文件则以一层列表方式显示给用户,用户不需进入子目录就可以列出(某种类型的)所有媒体文件。

在Android上,为了实现这种模式的媒体文件管理,对所有管理的媒体文件抽取其元数据(mp3文件包含的元数据可参考http://en.wikipedia.org/wiki/ID3),存储在数据库中,并作为一个content provider提供给其他应用使用。用户的每一次显示媒体文件的操作,就是对这个数据库的一次查询操作。

实现这一功能的代码位于
frameworks/base/core/java/android/provider/MediaStore.java
packages/providers/MediaProvider/src/com/android/providers/media.
frameworks/base/media/java/android/media/MediaScanner*
frameworks/base/media/jni/android_media_*
external/opencore/android/mediascanner.cpp

下面略作分析:

external/opencore/android/mediascanner.cpp负责从媒体文件(mp3, mp4, wma等)中提取元数据。

Android 技术专题系列之九 -- 图形系统

Android 技术专题系列之九 -- 图形系统(2009-04-03 10:45:41)
本文试图讲述Android图形系统的底层实现。Android图形系统底层实现非常复杂,文档较少,没有使用比较流行的图形组建如X window, Cairo等。

Android中的图形系统采用Client/Server架构。Server (即SurfaceFlinger)主要由c++代码编写而成。Client端代码分为两部分,一部分是由Java提供的供应用使用的api,另一部分则是由c++写成的底层实现。下图概要介绍了android图形系统的架构以及使用到的主要组件。



Android图形系统中一个重要的概念和线索是surface。View及其子类(如TextView, Button)要画在surface上。每个surface创建一个Canvas对象 (但属性时常改变),用来管理view在surface上的绘图操作,如画点画线。每个canvas对象对应一个bitmap,存储画在surface上的内容。

每个Surface通常对应两个buffer,一个front buffer, 一个back buffer。其中,back buffer就是canvas绘图时对应的bitmap (研究android_view_Surface.cpp::lockCanvas)因此,绘画总是在back buffer上,需要更新时,则将back buffer和front buffer互换。

The window is tied to a Surface and the ViewRoot asks the Surface for a
Canvas that is then used by the Views to draw onto. After View draw its data to canvas, ViewRoot
will call surface.unlockCanvasAndPost(canvas) to schedule surfaceFlinger::composeSurfaces() which do the actually display to display panel. SurfaceFlinger handles to transfers drawn data in canvas to surface front buffer or backbuffer

Except for SurfaceViews, different views within the same ViewRoot share the same surface.

Layer的概念:
每个surface又对应一个layer, SurfaceFlinger负责将各个layer的front buffer合成(composite)绘制到屏幕上。
A Layer is something that can be composited by SurfaceFlinger (should have been called LayerFlinger). There are several types of Layers if you look in the code, in particular the regular ones (Layer.cpp) , they are backed by a Surface, and the LayerBuffer (very badly chosen name) which don't have a backing store, but receive one from their client. . Note that the GGLSurface type, should have been called GGLBuffer

Multiple layers are just composited to the final buffer in their Z order.

有几个对象与Surface概念紧密相关:
1. Java Surface (frameworks/base/core/java/android/view/Surface.java)。该对象被应用间接调用(通过SurfaceView, ViewRoot等), 应用需要创建surface,(并同时创建canvas), 将图形绘制到这个对象上并最终投递到屏幕上。
2. C++ Surface (frameworks/base/libs/ui/Surface.cpp。 这个对象被Java Surface通过Jni 调用,实现Java Surface 的功能
3. ISurface (以及其派生类BnSurface)。这个对象是应用和server之间的接口。C++ Surface创建这个ISurface (BnSurface)并发送命令,如更新surface内容到屏幕上。Server端接受这个命令并执行相应操作。

研究一个surface如何创建的关键路径如下:
1. frameworks/base/core/java/android/view/Surface.java -- Surface::Surface ()
2. frameworks/base/core/jni/android_view_Surface.cpp -- Surface_init ()。在这个函数中SurfaceComposerClient 对象被创建。
3. frameworks/base/libs/ui/SurfaceComposerClient.cpp -- SurfaceComposerClient::SurfaceComposerClient (). 这个函数非常重要,在这里建立了client和server之间的桥梁。通过函数_get_surface_manager()获得了一个指向server的IBinder 对象(具有ISurfaceComposer接口),之后通过这个IBinder就可以跨进程访问Server的功能。接着调用ISurfaceComposer::createConnection()创建并返回了一个ISurfaceFlingerClient的IBinder。
4. frameworks/base/libs/ui/SurfaceComposerClient.cpp -- SurfaceComposerClient::createSurface().这个函数中,利用前面获得的ISurfaceFlingerClient的IBinder,调用其createSurface接口。
5.frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp -- BClient::createSurface ()。BClient由ISurfaceFlingerClient派生而来。
6. frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp -- SurfaceFlinger:: createSurface()。这个函数为Surface创建一个对应的Layer。

上述关键路径中,1,2,3,4运行于client进程中,而5,6运行与server进程中。server作为一个service提供给client访问。

与图形相关的代码主要位于下列目录:
1、frameworks/base/graphics/java/android/graphics
2、frameworks/base/core/java/android/view
3、frameworks/base/core/java/android/widget
4、frameworks/base/opengl/
5、frameworks/base/libs/ui
6、frameworks/base/libs/surfaceflinger
7、frameworks/base/core/jni/android/graphics
8、frameworks/base/core/jni/android/opengl
9、frameworks/base/core/jni/android/android_view_*.cpp
10、external/skia


一、下列目录中的部分代码:
1、frameworks/base/graphics/java/android/graphics
2、frameworks/base/core/java/android/view
3、frameworks/base/core/java/android/widget

android.graphics, android.view和android.widget功能和其他类似的图形库如Qt/Gtk+差不多,分别提供基本的图形原语(如画点画线,设置图形上下文等),事件机制,以及开发图形用户界面的控件等。canvas 用于开发2D图形, Surface 代表一个可供图形系统绘制的surface。可在其上绘制2D活3D图形。


二. frameworks/base/opengl/
这个目录包含opengel的接口以及软件实现。在http://developer.android.com/guide/topics/graphics/opengl.html有详细介绍如何使用android.opengl开发3d graphics。

三.external/skia,台湾的Jserv先生有一篇比较好的介绍,感兴趣的读者可以参考他的博文(http: //blog.linux.org.tw/~jserv/archives/002095.html)。简而言之,skia与cairo功能相当,封装底 层的图形硬件,为上面的图形库提供最基础的操作图形硬件的原语。

四. frameworks/base/libs/ui 和 frameworks/base/libs/surfaceflinger
ISurface 定义了基础的Surface接口,供图形系统客户端 (应用)和server端(即surfaceflinger)交互。
BpSurface是ISurface的派生类,提供接口供server 调用客户端功能;
BnSurface是ISurface的另一个派生类,提供接口供客户端调用server功能。当 server 收到来自客户端 (通过BnSurace)的调用请求后,如registerBuffers, postBuffer等,BnSurface::onTransact被触发。
Surface (LayerBaseClient的私有类)是BnSurface的派生类。
SurfaceBuffer (SurfaceBuffer的私有类)是Surface的派生类。

ISurfaceComposer 定义了基础的接口,供客户端和server端交互。
BpSurfaceComposer是一个派生类,提供接口供server调用客户端功能;
BnSurfaceComposer是另一派生类,提供接口供客户端调用server功能。类 SurfaceFlinger 由BnSurfaceComposer派生而来。

SurfaceComposerClient直接供客户端使用,调用ISurface (BnSurface)和 ISurfaceComposer (BnSurfaceComposer)以及 ISurfaceFlingerClient 接口,与server交互。

BClient 派生自ISurfaceFlingerClient (BnSurfaceFlingerClient),调用server的createSurface,真正创建一个surface。每个surface对应一个layer.

egl_native_window_t 定义了一个本地window类 。这个类提供了对本地window的所有描述以及用于egl (opengl 与本地图形系统的接口)操作本地windwo的所有方法。
EGLNativeSurface是egl_native_window_t的一个派生类。
EGLDisplaySurface是EGLNativeSurface的派生类。 EGLDisplaySurface 是一个非常重要的类,在这个类里,真正打开framebuffer设备(/dev/graphics/fb0 或者/dev/fb0),并将这个设备封装成EGLDisplaySurface的形式供server使用。函数mapFrameBuffer打开framebuffer, 创建两个缓冲区,(一个是on screen front 缓冲区, 另一个back buffer, 可能位于offscreen framebuffer,也可能位于系统内存)。 函数swapBuffers将back buffer内容拷贝到front buffer中。

DisplayHardware 类中初始化了egl系统,并为本地窗口对象EGLDisplaySurface 创建了对应的EGLSurface 对象。surfaceflinger 使用DisplayHardware去和本地窗口打交道。



五、下列目录中的部分代码
7、frameworks/base/core/jni/android/graphics
8、frameworks/base/core/jni/android/opengl
9、frameworks/base/core/jni/android/android_view_*.cpp

这些目录下的代码在Java层的graphics 组件和native (c++)组件之间衔接,将java层的功能调用转换到对应的本地调用。

hardware/libhardware实现了HAL(Hardware Abstraction Layer)层,copybit device是其中一个模块。

Android 技术专题系列之十 -- Audio manager

(2009-04-25 20:11:57)
Android的Audio Manager (即AudioFlinger)相对比较简单,代码主要集中在目录
frameworks/base/libs/audioflinger, frameworks/base/media 和 hardware/libhardware_legacy/include/hardware_legacy下面。 Audio Manager的主要功能如下
1. 接收来自各个track的PCM data, 如普通的audio playback, ringtone, voice call等,
2. 管理多个输入输出设备,如mic,handset, speaker, bluetooth等
3. 将一路track上的数据输出到某个输出设备上
4.将多路track上的数据混音(mix)后再输出到某个设备上。
5. 录音。

Android 技术专题系列之十 -- Audio manager

(2009-04-25 20:11:57)
Android的Audio Manager (即AudioFlinger)相对比较简单,代码主要集中在目录
frameworks/base/libs/audioflinger, frameworks/base/media 和 hardware/libhardware_legacy/include/hardware_legacy下面。 Audio Manager的主要功能如下
1. 接收来自各个track的PCM data, 如普通的audio playback, ringtone, voice call等,
2. 管理多个输入输出设备,如mic,handset, speaker, bluetooth等
3. 将一路track上的数据输出到某个输出设备上
4.将多路track上的数据混音(mix)后再输出到某个设备上。
5. 录音。

2009年8月7日 星期五

Android debug

http://letsgoustc.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3DGoogle%2520Android

Android battery status

应用程序为了取得电池的状态,通常的做法是监听ACTION_BATTERY_CHANGED这个intent,只能在收到这个intent的时候才能取得电池的状态信息,有没有同步取得电池信息的办法呢?

实际上,系统driver维护着保存电池信息的一组文件。

/sys/class/power_supply/ac/online AC电源连接状态
/sys/class/power_supply/usb/online USB电源连接状态
/sys/class/power_supply/battery/status 充电状态
/sys/class/power_supply/battery/health 电池状态
/sys/class/power_supply/battery/present 使用状态
/sys/class/power_supply/battery/capacity 电池level
/sys/class/power_supply/battery/batt_vol 电池电压
/sys/class/power_supply/battery/batt_temp 电池温度
/sys/class/power_supply/battery/technology 电池技术

当电池状态发生变化时,driver会更新这些文件,因此在应用程序中通过读取这些文件的办法,可以做到同步取得电池信息。经过验证可行。

看看batteryservice的代码,也是通过读取这些文件内容到内存中,然后对系统上层提供电池信息,当信息发生变化的时候,向系统中广播ACTION_BATTERY_CHANGED这个intent。但是因为一般应用程序无法取得batteryservice的实例,因此无法直接使用batteryservice的方法。

G1-phone crack

Home About Us ServicesForumsArcadeSticker Gallery
Posts Tagged “Android”
Jun
29
2009

Tether on your Rooted Android G1 (wifi)
Posted by Abolfazl in Other, tags: Android
Tethering allows you to use your internet connection on your G1 on your laptop or computer, giving your computer access to the internet wherever you go. This will require a rooted G1 as this is an unsupported feature and actually has the possibility of violating your cellular contract. However as long as you don’t use this as your primary internet source, download from p2p networks, or download large files; your cellular provider won’t even know. This is great for those times you want to check a page or chat but are tired of using the small device to di it.
If you wish to Root your Android G1 we have a guide here.

Installing Wifi Tether
Navigate to http://code.google.com/p/android-wifi-tether/ from your phone’s browser or email yourself the download link
If you know what QR Code is you can scan the code found at the bottom of their page
Click on the download found on the right side of the above page
Open the download once it is finished, If it complains about it not being from the google market:
Click settings and check “Unknown Sources”
Click Ok and then reopen the download
Click Install
When install is done click “Open”
Tethering

Launch the App
Touch the green symbol.
Join your computer to the wireless network your Android G1 just made.
Browse the web.
Configuration (Menu > Setup)

Enable/Disable Bluetooth Tether.
Wifi Encryption / Passphrase (Require Password to Get on the Network, must be a 13-character key)
Change SSID (Wireless Network Name)
Enable Access Control (Only computers you specify can access, uses MAC Addresses.)
Helpful Hints

Enable 3G on your phone (Settings>Wireless>Mobile Networks). Your Tether speed is only as fast as your G1’s Speed
Have your phone be charging (AC or USB) because 3G drains your phones battery
Don’t make your passcode easy to guess. Be sure to change it often
No Comments »

Jun
29
2009

Windows: Tether Andriod to Your Computer via USB with PDANet
Posted by ipp in Other, tags: Android
This software will support HTTP(web browser) communication free for lifetime, however for a one time fee of $30 you will have a full tether. Beware this may violate your contract with your cellular provider and if you use too much bandwidth you will get a call from them, just don’t: Replace your internet with this, Use p2p programs(limewire, torrents, etc), download large files, etc and you should be in the clear!

If you want to have full tether for free, check out this guide.

Download PDANet for Android here
Launch the application you just downloaded
It will go through several screens of instructions to get the application onto your phone
Once it is installed launch the application on your phone
Ensure your phone is connected via USB
Right click on your the PDANet icon of your systray(lower right hand corner by your clock, you may have to click on the arrows to see it)
If you do not see the icon, try launching PDANet, it should be somwhere in: Start > All Programs
Click Connect
No Comments »

Jun
27
2009

Root (jailbreak) an Android G1
Posted by Abolfazl in Other, tags: Android
With all the hype about jailbreaking the iPhone, we figured we would give you a guide on “jailbreaking”(rooting) the G-1. You will lose the ability to upgrade OTA (Over-The-Air) as it would kill your root, your phone is still upgradable, it just won’t do it on its own. We are going to reflash the device, so please backup any data you may need such as your contacts!

This process should take the average user 15-30 minutes to do and will “void” your warranty, however it is possible to hide the evidence so you are still covered!(Details at the bottom)

Note: This guide is US Only, UK People please ask in the forums if you need a help with rooting your device.

What you gain:

Ability to alter system files, this means you can now do things like installing a new theme
Run special apps such as tether.
Backup your entire system
Relocate your applications/cache to your /sdcard
The Process

Downgrade to RC29
Obtain root
Upgrade to desired ROM
Downgrading to RC29


Download the RC29 NBH file.
Connect your Android G1 to your computer so we can write to your SDCard
Place this file on your sd card (it is best if you format the card to FAT32 before this step, if you run into errors try that).
Turn the device power off and make sure your sd card is inserted.
Hold down the camera button while you turn on your phone to enter bootloader.
Once in the bootloader press the camera button.
After it finishes, press the trackball and perform a soft reset by pressing “Call” + “Menu” + “End” to reboot.
Obtain Root


Once your phone boots to the desktop hit the key twice and then type “telnetd” and press again (Yes, it will start up a contact search, don’t worry. Just type it.)
On your phone download Android Telnet client run it and connect to “localhost”. If you are unable to connect, try steps 1 and 2 over again until you can. Also, you can try doing a factory wipe (alt+w in the recovery menu) and retrying if all else fails.
Upgrading ROM



Download CyanogenMod v3.4.6 ROM to /sdcard and rename it to update.zip (when you are done it should be “/sdcard/update.zip”).
Download the modified recovery and unzip it.
Place”cm-recovery-1.2.img” in /sdcard
We will now need to flash the modified recovery so go back to the “root-terminal” previously used and Enter the following commands:
mount -o remount,rw /dev/block/mtdblock3 /system
rm -f /system/recovery.img
flash_image recovery /sdcard/cm-recovery-1.2.img
Reboot your phone, but do not do a recovery yet.
Once fully rebooted, power off your phone (hold power and select “Power Off”),
Turn your device on and hold home until you enter the recovery console
When you enter the recovery console hit “alt+S” on your phone. This will flash the update.zip file that you downloaded and placed there. If you have any problems with this step you missed something above.
Back Out / Unroot

Incase you started this process or wish to restore it back in order to go back “in warranty” we have a guide here.

[via: Android Unleashed]

No Comments »

Jun
27
2009

Unroot and Restore your Android G1 to Factory Settings
Posted by Abolfazl in Other, tags: Android
This will completely restore your G1 software to what it was like out of the box. We recommend doing this whenever you will be giving physical possession of your phone away for long periods of time, such as when you sell, replace, and/or send it in for repair. Not only will this hide any software modifications you have done which basically “unvoids” your warranty but also clear out your personal data.

If you have custom splash2:
You will need to erase it before you start this tutorial
On your computer extract this to your desktop
Turn off your phone
Plug it into your computer by USB
Load into fastboot (Hold Camera & Power button)
If you see “serial0″ hit the “back” key and it should say “FASTBOOT” now
On your computer go to Start>Run. Type in “cmd” and push enter
type in “cd desktop” then enter
Then type “fasboot erase splash2″ then push enter
Once your custom splash(if had) is gone:

Ensure your phone is connected and you can write to /SDCard
Download the Original G1 SPL and rename it to “update.zip”
Copy update.zip to /SDCard
Go into your phones recovery (Hold the home & power button)
Push Alt+S on your G1 to flash it with update.zip
Download the RC29 NBH and place it in the root of your SDCard
Load your phones bootloader (Hold the Camera & Power button)
Press the Power button to start the update (Do NOT interrupt this process)
Hit the action key (Trackball down) and your phone will reboot.
At this point your phone will be unrooted but it will have the out-of-date RC29. Your phone should download updates OTA(Over The Air) soon but you can also force this by going to Settings>About phone>System Updates
No Comments »

Search

Support
Have a Problem?? Ask Us Here!
Recent Tutorials
Download Any File/Video from a Website
Jailbreak iPhone 3.0.1 redsn0w
Use Math to “Guess” the Number of M&Ms in a Jar!
Windows: iPhone 3GS Jailbreak 3.0
Share Your Mac’s Internet Connection!
Hacked iPhone? Say no to the Beta!



Recent Forum Posts
What are you listening to?
- By: TeamMerciless
Guess Who's Next
- By: TeamMerciless
Web
- By: fear frantic
Sc 2 & d3
- By: slucifer
capture card?
- By: Unregistered
Our Sponsors


Categories
Economics
Games
Interesting & Fun
Other
Technology
Archives
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
December 2006
November 2006
Our CO2Stats


Powered by WordPress, Mandigo Theme Mod by Java & Henry Hoffman.
Entries (RSS) and Comments (RSS).

2009年8月6日 星期四

build android app

Hello World C program using Android Toolchain
I had reported earlier how I had gotten a C Hello World statically-linked program running on my Android phone using CodeSourcery's toolchain (on linux). Today I got a dynamically-linked Hello World program running on the phone, compiled using Android's prebuilt toolchain from the source.

It's well known that Android uses a stripped down version of libc, called bionic. When you compile your program with static linking, you don't use bionic because well, you linked statically. This is non-ideal. You want to use the bionic library on the phone, and besides you want to compile using Android's prebuilt cross-compiler arm-eabi-gcc

If you are anxious to get things working, use agcc, a perl wrapper over arm-eabi-gcc that sets up everything for you so that you can just:
$ agcc hello.c -o hello
and the resulting binary (hello) just works. Of course you should have the directory containing arm-eabi-gcc in your PATH for agcc to work.

Let's explore a bit deeper. But let me first simplify my hello program to contain just a main
$ cat hello.c int main(int argc, char* argv[]) {
return 0;
}

The minimal set of flags to pass to arm-eabi-gcc to get this working is:
$ arm-eabi-gcc -o hello hello.c -Wl,-rpath-link=/Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib -L/Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib -nostdlib /Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib/crtbegin_dynamic.o -lc

Here /Users/nirnimesh/NIR/android/mydroid/cupcake is the root of my Android source.

$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

Note that the executable binary is dynamically linked.

If you leave out -Wl,-rpath-link=/Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib you get
/Users/nirnimesh/NIR/android/mydroid/cupcake/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld: warning: libdl.so, needed by /Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib/libc.so, not found (try using -rpath or -rpath-link) /Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib/libc.so: undefined reference to `dl_unwind_find_exidx' collect2: ld returned 1 exit status

If you leave out -L/Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib you get
/Users/nirnimesh/NIR/android/mydroid/cupcake/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld: cannot find -lc collect2: ld returned 1 exit status

If you leave out -nostdlib you get
/Users/nirnimesh/NIR/android/mydroid/cupcake/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld: crt0.o: No such file: No such file or directory collect2: ld returned 1 exit status

If you leave out /Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib/crtbegin_dynamic.o you get
/Users/nirnimesh/NIR/android/mydroid/cupcake/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/../../../../arm-eabi/bin/ld: crt0.o: No such file: No such file or directory collect2: ld returned 1 exit status

And finally, f you leave out -lc your compilation fails with:
/Users/nirnimesh/NIR/android/mydroid/cupcake/out/target/product/generic/obj/lib/crtbegin_dynamic.o: In function `_start': bionic/libc/arch-arm/bionic/crtbegin_dynamic.S:(.text+0x10): undefined reference to `__libc_init' collect2: ld returned 1 exit status

So far we've been able to compile C programs using Androids toolchain and run on the phone.
To summarize, it's the most convenient to use agcc as the compiler so you don't have to bother.
Posted by Nirnimesh at 1:16 AM

2009年8月5日 星期三

Android Wifi Compilation

First verify your drivers are getting inserted and you are able to connect
AP with static Ip adress (use wlan_cfg). This is independent of Android and
it should work FIRST.
1. Add HAVE_CUSTOM_WIFI_DRIVER_2 := true to
build/target/board/generic/BoardConfig.mk file.
2. make sure external/wpa_supplicant/.config has got below entries
CONFIG_WIRELESS_EXTENSION=y
CONFIG_CTRL_IFACE=y
CONFIG_DRIVER_WEXT=y
3. Build android with this you will get support for WEXt and wpa_supplicant
client.
4. After the system boot, insert driver and know the interface (in my case
it is eth1)
5. Modify wpa_supplicant.conf file for AP configuration and Run
/system/bin/wpa_supplicant -Dwext -ieth1 -c/sdcard/wpa_supplicant.conf
5. Run dhcp to get the IP
/system/bin/dhcpcd -d eth1
6. Ping to AP to check connectivity.


- 顯示被引用文字 -