<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title>meisw's blog</title>
		<link>http://meisw.wdlinux.cn//</link>
		<description>工作,学习,生活,这里将会有一些记录.     备用域名:http://meisw.wdlinux.cn</description>
		<copyright>Copyright (C) 2004 Security Angel Team [S4T] All Rights Reserved.</copyright>
		<generator>SaBlog-X Version 1.6 Build 20080806</generator>
		<lastBuildDate>Fri, 05 Jun 2026 06:07:10 +0000</lastBuildDate>
		<ttl>30</ttl>
		<item>
			<guid>http://meisw.wdlinux.cn//show-602-1.html</guid>
			<title>反编译与回编译android的framework.jar（其他jar文件也可参考）</title>
			<author>admin</author>
			<description><![CDATA[<p>最近对android 2.3.3的framework.jar进行了一些反编译和回编译的操作，写下来备忘。</p>
<p><strong>一、framework.jar反编译为smali文件</strong></p>
<p>1、下载<a style="font-size: 140%" href="http://smali.googlecode.com/files/smali-1.2.6.jar"><span style="color: #0000cc; font-size: 14px">smali-1.2.6.jar</span></a>和<a style="white-space: nowrap" href="http://code.google.com/p/smali/downloads/detail?name=baksmali-1.2.6.jar&amp;can=2&amp;q=">baksmali-1.2.6.jar</a>这两个工具（下载地址：<a href="http://code.google.com/p/smali/downloads/list">http://code.google.com/p/smali/downloads/list</a>）</p>
<p>2、将framework.jar中的classes.dex解压出来（好像不解压，直接用framework.jar也行）</p>
<p>3、使用baksmali.jar对classes.dex进行反编译（前提是安装了jdk，并且设置好了环境变量），执行命令：</p>
<p style="text-align: center">java -jar <span style="color: #0f9932">baksmali-1.2.6.jar&nbsp;</span><span style="color: #0055ff">classes.dex <strong><span style="color: #ff0000">-o</span></strong> <span style="color: #ff0000">out/</span></span></p>
<p><span style="color: #000000">其中<span style="color: #0055ff">classes.dex</span>是要反编译的文件，<span style="color: #ff0000">out/</span>是要把反编译后的文件存放到的文件夹，如果不是在当前目录下，那么<span style="color: #0f9932">baksmali-1.2.6.jar</span>还要加上路径</span></p>
<p><span style="color: #000000">这样就OK了，在out文件夹中可以看到一堆扩展名为.smali的文件，用记事本就可以打开它们，从中可以窥到一些信息。但是与.java文件还是有一些不同，我也不太清楚这是什么结构。</span></p>
<p><strong><span style="color: #000000">二、smali文件回编译为classes.dex</span></strong></p>
<p><span style="color: #000000">1、一条命令就OK了：java -jar <span style="color: #ffa900">smali-1.2.6.jar </span><span style="color: #5500ff">out/</span> <strong><span style="color: #ff0000">-o</span></strong><span style="color: #ff0000"> classes.dex</span></span></p>
<p><span style="color: #000000">2、再把编译好的classes.dex放回到framework.jar中就行了（可以使用winrar、winzip之类的工具作为辅助）。</span></p>
<p><strong><span style="color: #000000">三、framework.jar反编译为.class和.java文件</span></strong></p>
<p><span style="color: #000000">1、下载以下工具：</span></p>
<p><span style="color: #000000">（1）dex2jar（<a href="http://code.google.com/p/dex2jar/">http://code.google.com/p/dex2jar/</a>）</span></p>
<p><span style="color: #000000">（2）xjad（<a href="http://www.skycn.com/soft/41898.html">http://www.skycn.com/soft/41898.html</a>）或jd-gui（<a href="http://java.decompiler.free.fr/?q=jdgui">http://java.decompiler.free.fr/?q=jdgui</a>）</span></p>
<p>2、使用dex2jar对framework.jar进行转换，执行命令：<span style="color: #ff0000">dex2jar.bat</span><span style="color: #0055ff"> framework.jar&nbsp;&nbsp; </span>将会生成一个framework.jar.dex2jar.jar</p>
<p>3、直接对该jar文件解压，可以看到里面都是.class文件了</p>
<p>4、如果还需要转换成.java文件，可以使用xjad或jd-gui，均可将class文件变为java文件。</p>
<p>注：dex2jar工具也可以处理.dex文件，因此也可以不直接处理framework.jar。而是先将framework.jar解压，生成classes.dex后再处理也行。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-602-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-30 18:43</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-600-1.html</guid>
			<title>android触摸屏坐标手工校准/调整成功</title>
			<author>admin</author>
			<description><![CDATA[<p><span class="oblog_text">1.简述<br />
android 的坐标转换处理：<br />
This implementation is a linear transformation using 7 parameters <br />
(a, b, c, d, e, f and s) to transform the device coordinates (Xd, Yd) <br />
into screen coordinates (Xs, Ys) using the following equations:<br />
<br />
s*Xs = a*Xd + b*Yd + c<br />
s*Ys = d*Xd + e*Yd + f<br />
<br />
Xs,Ys：LCD坐标<br />
Xd,Yd：触摸屏坐标<br />
<br />
在编译好了的ANDROID根文件系统的system/etc/pointercal这个文件内，存放着7个数，<br />
这7个数就是对应上面公式的a,b,c,d,e,f,s<br />
比如我原来的：(如果表格没对齐，请拷到记事本里面看)<br />
+----+-----+--------+------+--+--------+----+<br />
| a | b | c&nbsp;&nbsp;&nbsp;&nbsp; | d&nbsp;&nbsp;&nbsp; |e |&nbsp;&nbsp; f&nbsp;&nbsp;&nbsp; | s |<br />
+----+-----+--------+------+--+--------+----+<br />
|-411|37818|-3636780|-51325|39|47065584|6553|<br />
+----+-----+--------+------+--+--------+----+<br />
<br />
2.处理说明：<br />
&ldquo;system/etc/pointercal&rdquo;这个文件是被java程序读取使用的，文件目录：<br />
f rameworks/base/services/java/com/android/server/InputDevice.java<br />
---注：我用的是koolu的源码(http://git.koolu.org/)，官方的源码请自行搜索。<br />
该文件的第32行定义了：static final String CALIBRATION_FILE = &quot;/system/etc/pointercal&quot;;<br />
这个CALIBRATION_FILE变量在第237行被使用于打开该文件：<br />
FileInputStream is = new FileInputStream(CALIBRATION_FILE);<br />
后面的代码就是从这个文件里读取那7个数据，用于上层函数的坐标转换。<br />
所以只要根据该公式通过手工计算出那7个值，就可以准确的进行触摸操作了。<br />
<br />
3.计算<br />
计算前需要取得4个触摸屏的坐标，我们取LCD 4个对角的坐标，因为只有这4个坐标知道确切的LCD坐标。<br />
要取坐标必须打开内核中触摸屏的调试代码，启动后在console上使用dmesg命令来跟踪取得。<br />
我是在一个角上用笔点一下，再用dmesg调出记录，然后记录下来。如下是我的320x240屏记录的结果：<br />
坐标轴里小括号()里面的是调试信息给的触摸屏坐标，中括号[]里的是对应的LCD坐标。<br />
<br />
x坐标<br />
/|\<br />
|(X:870, Y:140)&nbsp;&nbsp; (X:870, Y:890)<br />
| [320,0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [320,240]<br />
|<br />
|<br />
|<br />
+-------------------------------&gt; y坐标<br />
(X:120, Y:140)&nbsp;&nbsp;&nbsp; (X:120, Y:890)<br />
&nbsp;&nbsp;&nbsp;&nbsp; [0,0]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [0,240]<br />
<br />
*LCD 分辨率：320 x 240 ，也是LCD坐标的最大值<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp; y<br />
<br />
设定s=65536<br />
将那4个坐标代入那个公式，可以得出8个方程组<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 = a*120 + b*140 + c<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 = d*120 + e*140 + f<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 = a*120 + b*890 + c<br />
65536*240 = d*120 + e*890 + f<br />
65536*320 = a*870 + b*140 + c<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 = d*870 + e*140 + f<br />
65536*320 = a*870 + b*890 + c<br />
65536*240 = d*870 + e*890 + f<br />
解方程组后就可得：<br />
a = 0<br />
b = 20971<br />
c = -2935940<br />
d = 27962<br />
e = 0<br />
f = -3355440<br />
s = 65535<br />
然后用工具打开andriod的&ldquo;system/etc/pointercal&rdquo;文件，把这几个数输进去，用空格分开，<br />
注意不要改文件结尾的两个字节0x00 0x0A,我是用Ghex工具打开的，在右边窗口中进行输入，在编辑里可以切换插入和覆盖模式。<br />
此时启动试试。<br />
<br />
////////////////////////////<br />
我的屏到这个步骤后触摸操作的左右变成了上下，上下变成了左右操作，<br />
处理方法：把a,b,c值和d,e,f值分别对调。<br />
再启动试试。。<br />
还是不行，左右是正确的，上下是反的。<br />
处理方法：<br />
把Y坐标再反向的公式：<br />
Ys&lsquo; = 320 - Ys = 320 - (a*Xd + b*Yd + c)/s<br />
重新计算a,b,c的值，就OK了。<br />
<br />
现在我点击计算器的按钮等操作都很准了，指哪打哪。<br />
<br />
前面发的那个视频里的坐标是在内核里调的坐标，不是很准。<br />
<br />
这是手工调的方法，如果要用程序校准的话可以用tslib，有时间再玩下。<br />
</span></p>
<p><span class="oblog_text">转</span></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-600-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-25 14:29</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-598-1.html</guid>
			<title>Android 开机画面</title>
			<author>admin</author>
			<description><![CDATA[<p><span id="ctl00_MainContentPlaceholder_ctl01_ctl00_lblEntry"><strong>Android 开机会出现3个画面：</strong> <br />
a.&nbsp; Bootloader启动，出现Android机器人图像；<br />
b.&nbsp; Android平台启动初始化，出现&quot;A N D R I O D&quot;文字字样画面；<br />
c.&nbsp; Android平台图形系统启动，出现含闪动的ANDROID字样的动画图片(start)。</span></p>
<p>&nbsp;</p>
<p><span><strong>a. Bootloader显示的Android机器人图像</strong> <br />
</span></p>
<p>&nbsp;</p>
<p><strong><span>b.</span> 开机文字(&quot;A N D R I O D&quot;) </strong></p>
<p>&nbsp;</p>
<p>Android 系统启动后，读取 /initlogo.rle（一张565 rle压缩的位图），如果读取成功，测在/dev/graphics/fb0显示Logo图片；如果读取失败，则将/dev/tty0设为TEXT模式，并打开/dev/tty0，输出文本&ldquo;A N D R I O D&rdquo;字样。</p>
<p>相关代码：</p>
<p>/system/core/init/init.c<br />
/system/core/init/init.h<br />
/system/core/init/init.rc<br />
/system/core/init/logo.c</p>
<p>*.rle文件的制作步骤:<br />
1. 使用GIMP或者Advanced Batch Converter软件，将图象转换为RAW格式；<br />
2. 使用android自带的rgb2565工具，将RAW格式文件转换为RLE格式(如：rgb2565 -rle &lt; initlogo.raw &gt; initlogo.rle)。</p>
<p>&nbsp;</p>
<p><strong>c. Android平台图形系统启动</strong></p>
<p>&nbsp;</p>
<p>Android的系统登录动画类似于Windows系统的滚动条，是由前景和背景两张PNG图片组成。前景图片（android-logo-mask.png）上的Android文字部分镂空，背景图片（android-logo-shine.png）则是简单的纹理。系统登录时，前景图片在最上层显示，程序代码控制背景图片连续滚动，透过前景图片文字镂空部分滚动显示背景纹理，从而实现动画效果。</p>
<p>相关代码：<br />
frameworks/base/cmds/bootanimation/BootAnimation.h<br />
frameworks/base/cmds/bootanimation/BootAnimation.cpp</p>
<p>frameworks/base/core/res/assets/images/android-logo-mask.png<br />
Android默认的前景图片，文字部分镂空，大小256&times;64<br />
<span id="ctl00_MainContentPlaceholder_ctl01_ctl00_lblEntry"><span id="ctl00_MainContentPlaceholder_ctl01_ctl00_lblEntry">frameworks/base/core/res/assets/images/</span> </span>android-logo-shine.png<br />
Android默认的背景图片，有动感效果，大小512&times;64</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-598-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-17 14:32</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-597-1.html</guid>
			<title>修改Android开机画面</title>
			<author>admin</author>
			<description><![CDATA[<p>Android系统开机动画包括两部分：<br />
开机显示的 ANDROID 文字；<br />
ANDROID发光动画。<br />
这篇文章说的开机动画是第一种，下面开始正文！</p>
<p>1. 制作当前屏幕像素的图片(模拟器默认为320*480)<br />
使用PS制作一张320*480的图片，保存时选&ldquo;保存为 Web 所用格式&rdquo;，然后在弹开的窗口上，&ldquo;预设&rdquo;项选择&ldquo;PNG-24&rdquo;，保存为android_logo.png<br />
注：好像只支持png-24，其他格式生成的rle文件显示不正常，有兴趣大家可以再验证一下。</p>
<p>2. 将图片转换为raw格式<br />
使用linux下的ImageMagick自带的convert命令，进行raw格式转换，命令为：<br />
&nbsp; convert -depth 8 android_logo.png rgb:android_logo.raw<br />
注：ubuntu 10.04 默认已经安装ImgageMagick工具，如果当前系统没有安装，可以执行下面的命令安装：<br />
&nbsp; sudo apt-get install imagemagick</p>
<p>3. 将raw格式转化为rle文件<br />
需要用到android编译后的rgb2565工具，在android/out/host/linux-x86/bin目录下(android为当前源码所在目录)，转换命令如下：<br />
rgb2565 -rle &lt; android_logo.raw &gt; initlogo.rle<br />
到目前为止，启动需要显示的图像已经做好了，就是initlogo.rle，注意文件名必须是这个，如果想改文件名，需要修改android/system/core/init/init.h中的宏：<br />
#define INIT_IMAGE_FILE &quot;/initlogo.rle&quot; <br />
============================================================================================</p>
<p>下面需要将initlogo.rle加入的android文件系统中<br />
4. 找到ramdisk.img文件(android/out/target/product/generic/ramdisk.img)，将文件名改为ramdisk.img.gz，然后使用下面的命令解压：<br />
gunzip ramdisk.img.gz<br />
解压后得到ramdisk.img，可能有人要问，怎么文件名又改回去了？其实不然，使用file ramdisk.img查看一下就知道了：<br />
解压前：ramdisk.img: gzip compressed data, from Unix<br />
解压后：ramdisk.img: ASCII cpio archive (SVR4 with no CRC)<br />
跑题了，还是说正事儿。</p>
<p>5. 使用cpio提取文件：<br />
新建一个temp目录：<br />
mkdir temp<br />
cd temp<br />
cpio -i -F ../ramdisk.img</p>
<p>6. 导出文件列表：<br />
cpio -i -t -F ../ramdisk.img &gt; list&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
注：list是一个文本文件，里面存储了ramdisk.img的文件结构，我们需要在这个文件中加入initlogo.rle这一行，修改后的文件如下：<br />
data<br />
default.prop<br />
dev<br />
init<br />
init.goldfish.rc<br />
init.rc<br />
initlogo.rle <br />
proc<br />
sbin<br />
sbin/adbd<br />
sys<br />
system</p>
<p>7. 生成ramdisk.img<br />
cpio -o -H newc -O ramdisk.img &lt; list <br />
注：根据list文件的描述,生成ramdisk.img文件</p>
<p>8. 用ramdisk.img覆盖sdk目录下的ramdisk.img(android-sdk-windows/platforms/android-2.1/images/ramdisk.img)，最好先备份一下。</p>
<p>9. 启动模拟器，就可以看到我们自己做的的开机界面了。<br />
/////////////////////////<br />
开机图片设置 的下载地址为：http://docs.google.com/leaf?id=0 ... TIzOGQ5OWQ3&amp;amp;hl=en</p>
<p>init 文件下载地址 http://docs.google.com/leaf?id=0 ... 2RiYjZjNjM2&amp;amp;hl=en</p>
<p>split_bootimg.pl 下载地址：http://android-dls.com/files/linux/split_bootimg.zip</p>
<p>T卡文件下载地址：http://docs.google.com/leaf?id=0 ... GVjYzVhMjg4&amp;amp;hl=en</p>
<p><br />
开机图片设置 软件原理：<br />
&nbsp;&nbsp;&nbsp;&nbsp; 根据android 系统 开机LOGO和开机动画的存放路径：/initlogo.rle 和 /data/local/bootanimation.zip 在init.rc 中 建立两个链接：<br />
/initlogo.rle -&gt;/data/data/com.android.e139.gallery/initlogo.rle 和 /data/local/bootanimation.zip -&gt;/data/data/com.android.e139.gallery/bootanimation.zip&nbsp; <br />
来完成开机LOGO和开机动画的动态设定</p>
<p>安装要求：</p>
<p>1.本apk文件只能安装在android 2.1 或 2.0的操作系统 中<br />
2.必须修改android 根目录下面的两个文件：init.rc 和 init 功能才能实现设置开机LOGO和开机动画的功能</p>
<p><br />
修改init.rc 和 init 的方法：</p>
<p>1.修改 init.rc 和init文件需要修改手机中的 boot.img<br />
导出方法：<br />
cat /dev/mtd/mtd2 &gt; /sdcard/root.img</p>
<p>然后</p>
<p>adb pull /sdcard/root.img ./</p>
<p>这样就把root.img拷贝到本地目录下了。</p>
<p>boot.img的组成结构是</p>
<p>+&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;+<br />
| boot header | 1 page<br />
+&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;+<br />
| kernel | n pages<br />
+&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;+<br />
| ramdisk | m pages<br />
+&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;+<br />
| second stage | o pages<br />
+&mdash;&mdash;&mdash;&mdash;&mdash;&ndash;+</p>
<p><br />
那我们要做的就是把这几个部分分别分离出来</p>
<p>我们现在先进行镜像分离。用命令</p>
<p>./split_bootimg.pl boot.img</p>
<p>&nbsp;</p>
<p>成功执行后，可以得到两个文件，一个是boot.img-kernel，另一个是boot.img-ramdisk.gz。我们这里以修改ramdisk为例，所以将其解包</p>
<p>mkdir ramdisk</p>
<p>cd ramdisk</p>
<p>gzip -dc ../boot.img-ramdisk.gz | cpio -i</p>
<p>cd ..</p>
<p>2.进入ramdisk 修改init.rc 在init.rc 中增加：</p>
<p>on logo-init</p>
<p>&nbsp;&nbsp;&nbsp; mkdir /data 0775 system system</p>
<p># We chown/chmod /data again so because mount is run as root + defaults<br />
&nbsp;&nbsp;&nbsp; mount yaffs2 mtd@userdata /data nosuid nodev<br />
&nbsp;&nbsp;&nbsp; chown system system /data<br />
&nbsp;&nbsp;&nbsp; #for other user can read this dir<br />
&nbsp;&nbsp;&nbsp; chmod 0775 /data</p>
<p>&nbsp;&nbsp;&nbsp; symlink /data/data/com.android.e139.gallery/initlogo.rle /initlogo.rle</p>
<p>on early-boot<br />
# copy file&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; symlink /data/data/com.android.e139.gallery/bootanimation.zip /data/local/bootanimation.zip<br />
&nbsp;&nbsp;&nbsp; chmod 0666 /data/local/bootanimation.zip</p>
<p>再将已经下载的init文件覆盖到目录下面的init文件<br />
3.生成新img 回到ramdisk 的上一级目录后执行：<br />
mkbootfs ./ramdisk | gzip &gt; ramdisk-new.gz mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel boot.img-kernel --ramdisk ramdisk-new.gz -o boot-new.img<br />
就会重新生成 boot-new.img<br />
3.刷入新img</p>
<p>生成了新的img后，我们如何在系统上应用我们的新boot.img呢？首先，把img文件放到sdcard上去</p>
<p>adb push ./boot_new.img /sdcard</p>
<p>然后执行这两个操作</p>
<p>cat /dev/zero &gt; /dev/mtd/mtd2<br />
flash_image boot /sdcard/mynewimage.img</p>
<p>执行第一个操作时，可能会提示你</p>
<p>write: No space left on device</p>
<p>这个信息没关系，不用管它。两个命令都执行后，最后adb shell reboot即可。如果重启顺利，那么恭喜你，你刷成功了.</p>
<p><br />
安装步骤：<br />
1.按上面的步骤修改手机中的init.rc 和init文件<br />
2.把下载的T卡文件放到T卡中<br />
3.安装 开机图片设置.apk文件</p>
<p>修改boot.img的方法参考：http://www.kunli.info/2009/09/14/how-to-modify-ramdisk-android/ 和<br />
http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack,_Edit,_and_Re-Pack_Boot_Images</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-597-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-17 14:29</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-596-1.html</guid>
			<title>关于boot.img和recovery.img的编辑和修改( 转)</title>
			<author>admin</author>
			<description><![CDATA[<p>以下是偶翻译的关于boot.img和recovery.img的编辑和修改方面的文章，希望能够为感兴趣的朋友节约一些看资料的时间。感谢本文的作者：Alansj, DarkriftX, RyeBrye, Will, Try OP9, Tonyb486, Timmmm, Lxrose还有好多不知名的作者们在wiki上的不懈努力。<br />
<br />
如何解包／编辑／大包boot.img文件<br />
<br />
很多人用自己的方式解决了boot.img的解包／编辑／打包的问题，有人要求我来写一篇关于boot和recovery映像的文件结构和如何对其编辑的文章，于是就有了下面这篇文章。<br />
<br />
目录<br />
1、背景知识<br />
2、boot和recovery映像的文件结构<br />
3、对映像文件进行解包、编辑、打包的常规方法<br />
3.1、另一种解包、编辑、打包的方法<br />
4、将新的映像刷回到手机<br />
5、解包、编辑、打包为我们带来了什么<br />
6、本文讲的内容与使用update.zip刷机包不是一码事<br />
<br />
正文<br />
<br />
1、背景知识<br />
<br />
Android手机的文件系统有许多存储器组成，以下是在adb shell下面的输出：<br />
#cat /proc/mtd<br />
dev:&nbsp; &nbsp; size&nbsp; &nbsp;erasesize&nbsp;&nbsp;name<br />
mtd0: 00040000 00020000 &quot;misc&quot;<br />
mtd1: 00500000 00020000 &quot;recovery&quot;<br />
mtd2: 00280000 00020000 &quot;boot&quot;<br />
mtd3: 04380000 00020000 &quot;system&quot;<br />
mtd4: 04380000 00020000 &quot;cache&quot;<br />
mtd5: 04ac0000 00020000 &quot;userdata&quot;<br />
<br />
注意，不同的手机在上述存储设备的顺序可能会各不相同!一定要检查您的手机，确定在以下的操作中选择正确的设备号（mtdX，这个X的序号一定要检查清楚）。<br />
在本向导中，我们主要描述对&quot;recovery&quot;和&quot;boot&quot;的存储设备进行操作；&quot;system&quot;存储设备保存了android系统目录的所有数据（在系统启动后会挂载到&ldquo;system/&rdquo;目录）；&ldquo;userdata&rdquo;存储设备将保存了android数据目录中的所有数据（在系统启动后会挂载到&ldquo;data/&rdquo;目录，里面是会有很多应用数据以及用户的preference之类的配置数据）。<br />
<br />
从上面的输出可以看出来，recovery和boot分区对应着/dev/mtd/mtd1和/dev/mtd/mtd2，在你您开始做任何修改之前一定要做两件事情，第一件事情，一定要先对这两个分区进行备份。<br />
<br />
可以使用如下命令进行备份：<br />
# cat /dev/mtd/mtd1 &gt; /sdcard/recovery.img<br />
# cat /dev/mtd/mtd2 &gt; /sdcard/boot.img<br />
（注意added by lxros，只有手机获取了ROOT权限以后才能够执行上述的备份命令）<br />
<br />
第二件事情，你您应该把你您最喜欢的update.zip刷机包放置到你您的sd卡的根目录上面。如此一来，即使你您在后续的操作中出了问题，也可以启动到recovery模式进行恢复。<br />
<br />
另外一个你您需要知道的重要文件是在android系统目录下的/system/recovery.img，此文件是mtd1存储设备的完全拷贝。这个文件在每次关机的时候，会自动地被写回到mtd1存储设备里面。<br />
<br />
这会意味着两个事情：<br />
(1)任何对/dev/mtd/mtd1中数据的直接修改都会在下一次重启手机以后消失。<br />
<br />
(2)如果希望对/dev/mtd/mtd1进行修改，最简单的做法是用你您自己的recovery.img替换掉/system/recovery.img。当你您创建自己的update.zip刷机包的时候（特别是在做刷机包的适配的时候），如果你您忘记替换这个/system/recovery.img,这个recovery.img就会在关机的时候被烧写到mtd1里面去或许会变砖。一定要注意这一点！<br />
（译者的话，关于这个/system/recovery.img文件，在2.1的android的平台里面并没有找到，或许这个机制已经out了？！或者偶本人对这段话的理解不够深入？！希望明白的朋友不吝斧正）<br />
<br />
2、boot和recovery映像的文件结构<br />
<br />
boot和recovery映像并不是一个完整的文件系统，它们是一种android自定义的文件格式，该格式包括了2K的文件头，后面紧跟着是用gzip压缩过的内核，再后面是一个ramdisk内存盘，然后紧跟着第二阶段的载入器程序（这个载入器程序是可选的，在某些映像中或许没有这部分）。此类文件的定义可以从源代码android-src/system/core/mkbootimg找到一个叫做bootimg.h的文件。<br />
<br />
（译者的话，原文是一个叫做mkbootimg.h的文件，但从Android 2.1的代码来看，该文件名应该是改为bootimg.h了）。<br />
/*<br />
** +-----------------+ <br />
** | boot header&nbsp; &nbsp;&nbsp;&nbsp;| 1 page<br />
** +-----------------+<br />
** | kernel&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | n pages&nbsp;&nbsp;<br />
** +-----------------+<br />
** | ramdisk&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| m pages&nbsp;&nbsp;<br />
** +-----------------+<br />
** | second stage&nbsp; &nbsp; | o pages<br />
** +-----------------+<br />
**<br />
** n = (kernel_size + page_size - 1) / page_size<br />
** m = (ramdisk_size + page_size - 1) / page_size<br />
** o = (second_size + page_size - 1) / page_size<br />
**<br />
** 0. all entities are page_size aligned in flash<br />
** 1. kernel and ramdisk are required (size != 0)<br />
** 2. second is optional (second_size == 0 -&gt; no second)<br />
** 3. load each element (kernel, ramdisk, second) at<br />
**&nbsp; &nbsp; the specified physical address (kernel_addr, etc)<br />
** 4. prepare tags at tag_addr.&nbsp;&nbsp;kernel_args[] is<br />
**&nbsp; &nbsp; appended to the kernel commandline in the tags.<br />
** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr<br />
** 6. if second_size != 0: jump to second_addr<br />
**&nbsp; &nbsp; else: jump to kernel_addr<br />
*/<br />
ramdisk映像是一个最基础的小型文件系统，它包括了初始化系统所需要的全部核心文件，例如:初始化init进程以及init.rc（可以用于设置很多系统的参数）等文件。如果你您希望了解更多关于此文件的信息可以参考以下网址：<br />
http://git.source.android.com/?p=kernel/common.git;a=blob;f=Documentation/filesystems/ramfs-rootfs-initramfs.txt<br />
以下是一个典型的ramdisk中包含的文件列表：<br />
./init.trout.rc<br />
./default.prop<br />
./proc<br />
./dev<br />
./init.rc<br />
./init<br />
./sys<br />
./init.goldfish.rc<br />
./sbin<br />
./sbin/adbd<br />
./system<br />
./data<br />
recovery映像包含了一些额外的文件，例如一个叫做recovery的二进制程序，以及一些对该程序支持性的资源图片文件（当你您按下home+power组合键的时候就会运行这个recovery程序）。<br />
典型的文件列表如下：<br />
./res<br />
./res/images<br />
./res/images/progress_bar_empty_left_round.bmp<br />
./res/images/icon_firmware_install.bmp<br />
./res/images/indeterminate3.bmp<br />
./res/images/progress_bar_fill.bmp<br />
./res/images/progress_bar_left_round.bmp<br />
./res/images/icon_error.bmp<br />
./res/images/indeterminate1.bmp<br />
./res/images/progress_bar_empty_right_round.bmp<br />
./res/images/icon_firmware_error.bmp<br />
./res/images/progress_bar_right_round.bmp<br />
./res/images/indeterminate4.bmp<br />
./res/images/indeterminate5.bmp<br />
./res/images/indeterminate6.bmp<br />
./res/images/progress_bar_empty.bmp<br />
./res/images/indeterminate2.bmp<br />
./res/images/icon_unpacking.bmp<br />
./res/images/icon_installing.bmp<br />
./sbin/recovery<br />
<br />
3、对映像文件进行解包、编辑、打包的常规方法<br />
<br />
（注意，下面我给你您介绍的是手工命令行方式进行解包以及重新打包的方法，但是我仍然创建了两个perl脚本，这两个脚本可以让你您的解包和打包工作变得轻松许多。可以参考本文的附件unpack-bootimg.zip和repack-bootimg.zip）<br />
<br />
如果你您很擅长使用16进制编辑器的话，你您可以打开boot.img或者recovery.img，然后跳过开始的2K的头数据，然后寻找一大堆0的数据，在这一堆0的数据后面，紧跟着1F 8B这两个数字（1F 8B是gzip格式的文件的结束标记）。从此文件开始的地方（跳过2K的头），一大堆0后面紧跟着到1F 8B这两个数字为止的全部数据，就是gzip压缩过的linux内核。从1F 8B后面紧跟着的数据一直到文件的结尾包含的全部数据，就是ramdisk内存盘的数据。你您可以把把内核和ramdisk两个文件分别保存下来，在进行分别的修改和处理。我们可以通过un-cpio和un-gzip操作来读取ramdisk文件中的数据，可以使用如下的命令来实现这个目的，以下操作会生成一个目录，直接cd进去就可以看到ramdisk中的数据了：<br />
gunzip -c ../your-ramdisk-file | cpio -i<br />
此命令可以将ramdisk中的所有的文件解包到当前的工作目录下面，然后就可以对它进行编辑了。<br />
<br />
当需要重新打包ramdisk的时候，就需要re-cpio然后re-gzip这些数据和目录，可以通过如下命令来实现：（cpio会把所有当前目录下面的文件都打包进去，因此，在进行此步骤之前，请把不需要的文件都清除掉。）<br />
find . | cpio -o -H newc | gzip &gt; ../newramdisk.cpio.gz<br />
最后一步就是通过mkbootimg这个工具，把kernel和ramdisk打包在一起，生成一个boot.img：<br />
mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel your-kernel-file --ramdisk newramdisk.cpio.gz -o mynewimage.img<br />
这里的mkbootimg工具会在编译android的源代码的时候会在~/android-src/out/host/linux-x86/bin目录下面自动生成。<br />
下载地址：<br />
http://git.source.android.com/?p=platform/system/core.git;a=tree;f=mkbootimg<br />
<br />
现在，如果不想背这些复杂的命令或者摆弄那个让人眩晕的16进制编辑器的话，可以尝试使用我编写的用于解包和打包的perl脚本了。希望这些脚本能够节约各位的键盘。<br />
<br />
3.1、另一种解包、编辑、打包的方法<br />
<br />
下载split_bootimg.zip文件（译者注，会在本文的附件中提供），在此zip文件中包含一个perl文件，split_bootimg.pl脚本，该脚本可以读取boot.img头（根据Android源码中的bootimg.h读取）将kernel和ramdisk读取出来，此脚本也会输出内核命令行和板子名字。<br />
（注意，不要使用从/dev/mtd/mtd2直接拷贝出来的boot.img，此映像可能在读取过程遭到损坏。）<br />
下面是一个从TC4-RC28更新中提取出来的boot.img进行解包操作：<br />
% ./split_bootimg.pl boot.img <br />
Page size: 2048 (0x00000800)<br />
Kernel size: 1388548 (0x00153004)<br />
Ramdisk size: 141518 (0x000228ce)<br />
Second size: 0 (0x00000000)<br />
Board name: <br />
Command line: no_console_suspend=1<br />
Writing boot.img-kernel ... complete.<br />
Writing boot.img-ramdisk.gz ... complete.<br />
解包ramdisk的命令如下：<br />
% mkdir ramdisk<br />
% cd ramdisk<br />
% gzip -dc ../boot.img-ramdisk.gz | cpio -i<br />
% cd ..<br />
解码完毕后，就可以修改了（例如，在default.prop设置ro.secure=0等等）<br />
<br />
使用mkbootfs工具（mkbootfs工具是编译完毕Android源代码以后，就会在~/android-src/out/host/linux-x86/bin自动生成）来重新创建ramdisk，可以使用如下命令来操作：<br />
% mkbootfs ./ramdisk | gzip &gt; ramdisk-new.gz<br />
使用mkbootimg来重新创建boot.img，mkbootimg也可以在~/android-src/out/host/linux-x86/bin目录中可以找到：<br />
% mkbootimg --cmdline 'no_console_suspend=1 console=null' --kernel boot.img-kernel --ramdisk ramdisk-new.gz -o boot-new.img<br />
（注意：console=null的命令行选现是从TC4-RC30的boot.img引入的，用以去掉root shell）<br />
<br />
4、将新的映像刷回到手机<br />
<br />
可以将recovery.img拷贝到/system目录下面，然后重新启动手机，让手机自动为你您刷写到mtd里面（工作原理在上面已经提过了）。对于boot.img可以通过将其拷贝到sd卡的根目录，然后通过手机内的刷写工具将此映像写入到手机中。<br />
<br />
例如，使用adb工具将boot.img拷贝到手机的sd卡的根目录：<br />
adb push ./mynewimage.img /sdcard<br />
然后通过adb shell登录手机的shell交互模式，利用命令行进行交互：<br />
# cat /dev/zero &gt; /dev/mtd/mtd2<br />
&nbsp; &nbsp;write: No space left on device [this is ok, you can ignore]<br />
# flash_image boot /sdcard/mynewimage.img<br />
然后重启。<br />
如果能够正常启动，那么祝贺你您，你您的修改和替换已经成功了；如果不能够顺利启动，则需要重新启动进入recovery模式，并且使用update.zip来恢复。<br />
<br />
5、解包、编辑、打包为我们带来了什么<br />
<br />
可以修改开机启动时候的画面，具体的操作的地址为：<br />
http://forum.xda-developers.com/showthread.php?t=443431<br />
<br />
6、本文讲的内容与使用update.zip刷机包不是一码事<br />
<br />
您可以很容易地在其他论坛上看到关于如何自制update.zip刷机包的方法，也可以下载到很多在网络上共享的自制刷机包。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-596-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-17 14:28</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-595-1.html</guid>
			<title>Android System Services 环境浅析</title>
			<author>admin</author>
			<description><![CDATA[<p>原创文章欢迎转载，转载请注明住处rickleaf</p>
<h3>1.System Services</h3>
<p>首先我要声明一下，我讲的System Services并非Android 开发应用程序时，所涉及的Service（后台应用服务程序）的概念。</p>
<p>我要讲的System Services是Android操作系统Java应用程序下层的，伴随操作系统启动而运行的系统后台服务程序。</p>
<p>它是Android系统运行的基石，它配合binder（Android多进程通讯方法）、dalvik虚拟机和Android应用程序构成了一个多进程</p>
<p>交互通讯，交互服务的Android系统。</p>
<h3>2.浏览一下Android系统的service</h3>
<p>启动shell</p>
<p><strong>adb shell</strong></p>
<p>执行下面指令</p>
<p><strong>#service list</strong></p>
<p>Found 47 services:<br />
0&nbsp;&nbsp;&nbsp; phone: [com.android.internal.telephony.ITelephony]<br />
1&nbsp;&nbsp;&nbsp; iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]<br />
2&nbsp;&nbsp;&nbsp; simphonebook: [com.android.internal.telephony.IIccPhoneBook]<br />
3&nbsp;&nbsp;&nbsp; isms: [com.android.internal.telephony.ISms]<br />
4&nbsp;&nbsp;&nbsp; appwidget: [com.android.internal.appwidget.IAppWidgetService]<br />
42&nbsp;&nbsp;&nbsp; SurfaceFlinger: [android.ui.ISurfaceComposer]<br />
43&nbsp;&nbsp;&nbsp; media.audio_policy: [android.media.IAudioPolicyService]<br />
46&nbsp;&nbsp;&nbsp; media.audio_flinger: [android.media.IAudioFlinger]<br />
#</p>
<p><br />
从结果看来Android后台有很多的service，他们是分散在不同进程中的线程实体（有点绕嘴，但是我认为这样说比较确切）。</p>
<p>&nbsp;</p>
<h3>3.什么是Service Manager</h3>
<p>里面理解一下就可以了，Service manager是管理以上services的一个进程，他是实际存在的。</p>
<p>您可以在adb shell中运行ps看看进程列表就知道了。</p>
<p>&nbsp;</p>
<p>源代码位于：</p>
<p>frameworks/base/cmds/servicemanager</p>
<p>执行方式：</p>
<p>他是用c和c++语言编写的natvie可以执行文件。在Android中称之为EXECUTABLE，这个名称很重要因为Android.mk文件中</p>
<p>用这个名字来确定他是可以执行的二进制文件。</p>
<p>&nbsp;</p>
<h3>4.探究一下Service Manager的启动过程和方法</h3>
<p>开始有点复杂了，也该开始进入真正的Linux阶段了。</p>
<p>众所周知Linux的启动和文件系统的加载需要一个ramdisk，ramdisk负责让Linux kernel加载第一个进程<span style="color: #ff0000"><strong>init进程</strong> </span></p>
<p>&nbsp;</p>
<p>在Android的ramdisk中就有这样一个可执行文件init，</p>
<p>在深入一下，我们可以去看一下</p>
<p>&nbsp;</p>
<p>system/core/init/init.c</p>
<p>&nbsp;</p>
<p><span style="color: #008000">int main(int argc, char **argv)<br />
{<br />
&nbsp;&nbsp;&nbsp; 。。。。。。<br />
&nbsp;&nbsp;&nbsp; parse_config_file(&quot;/init.rc&quot;);</span></p>
<p><span style="color: #008000">&nbsp;&nbsp;&nbsp; 。。。。。。</span></p>
<p>&nbsp;</p>
<p>对的，没看错。这个文件会编译出一个init的二进制可执行文件，并且去读init.rc文件。</p>
<p>&nbsp;</p>
<p>至此，我们称init.rc文件为Android启动配置脚本。</p>
<p>&nbsp;</p>
<p>现在我们打开init.rc文件，（如果您不知道init.rc，请参考google吧）</p>
<p>&nbsp;</p>
<p>## Daemon processes to be run by init.<br />
##<br />
service servicemanager /system/bin/servicemanager<br />
&nbsp;&nbsp;&nbsp; user system<br />
&nbsp;&nbsp;&nbsp; critical<br />
&nbsp;&nbsp;&nbsp; <span style="color: #ff0000">onrestart restart zygote</span> <br />
&nbsp;&nbsp;&nbsp; <span style="color: #ff0000">onrestart restart media</span></p>
<p>&nbsp;</p>
<p>看到吗，servicemanager 是init通过init.rc加载的第一个进程</p>
<p>接下来启动了zygote和media</p>
<h3>4.system server进程</h3>
<p>继续阅读init.rc</p>
<p>servicemanager进程运行起来以后，我们就可以应用binder来应用servicemanager提供的服务函数去创建</p>
<p>system-server和mediaserver了，下面是init.rc中的代码</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000">service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server</span></p>
<p>#system-server的创建是通过app_process这个二进制程序去加载的<br />
&nbsp;&nbsp;&nbsp; socket zygote stream 666<br />
&nbsp;&nbsp;&nbsp; onrestart write /sys/android_power/request_state wake<br />
&nbsp;&nbsp;&nbsp; onrestart write /sys/power/state on<br />
&nbsp;&nbsp;&nbsp; onrestart restart media<br />
<br />
<span style="color: #ff0000">service media /system/bin/mediaserver</span> &nbsp; #mediaserver的启动代码比较简单，看看就知道了不用参数就创建了<br />
&nbsp;&nbsp;&nbsp; user media<br />
&nbsp;&nbsp;&nbsp; group system audio camera graphics inet net_bt net_bt_admin</p>
<p>&nbsp;</p>
<h3>5.回过头再看系统的进程列表</h3>
<p># ps<br />
USER&nbsp;&nbsp;&nbsp;&nbsp; PID&nbsp;&nbsp; PPID&nbsp; VSIZE&nbsp; RSS&nbsp;&nbsp;&nbsp;&nbsp; WCHAN&nbsp;&nbsp;&nbsp; PC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NAME<br />
<span style="color: #ff0000">root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp; 296&nbsp;&nbsp;&nbsp; 204&nbsp;&nbsp; c009a694 0000c93c S /init</span> <br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp; c004dea0 00000000 S kthreadd<br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 25&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 728&nbsp;&nbsp;&nbsp; 316&nbsp;&nbsp; c003d444 afe0d6ac S /system/bin/sh<br />
<span style="color: #ff0000">system&nbsp;&nbsp;&nbsp; 26&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 796&nbsp;&nbsp;&nbsp; 256&nbsp;&nbsp; c019a810 afe0ca7c S /system/bin/servicemanager</span> <br />
<strong><span style="color: #ff0000">root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 82860&nbsp; 26580 c009a694 afe0cba4 S zygote</span> </strong><br />
<span style="color: #ff0000">media&nbsp;&nbsp;&nbsp;&nbsp; 31&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 20944&nbsp; 3184&nbsp; ffffffff afe0ca7c S /system/bin/mediaserver</span> <br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 32&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 784&nbsp;&nbsp;&nbsp; 280&nbsp;&nbsp; c0209468 afe0c7dc S /system/bin/installd<br />
keystore&nbsp; 33&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 1616&nbsp;&nbsp; 396&nbsp;&nbsp; c01a65a4 afe0d40c S /system/bin/keystore<br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 34&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 728&nbsp;&nbsp;&nbsp; 272&nbsp;&nbsp; c003d444 afe0d6ac S /system/bin/sh<br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 35&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 824&nbsp;&nbsp;&nbsp; 332&nbsp;&nbsp; c00b7dd0 afe0d7fc S /system/bin/qemud<br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 37&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp; 1308&nbsp;&nbsp; 152&nbsp;&nbsp; ffffffff 0000eca4 S /sbin/adbd<br />
root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 44&nbsp;&nbsp;&nbsp; 34&nbsp;&nbsp;&nbsp; 780&nbsp;&nbsp;&nbsp; 304&nbsp;&nbsp; c0209468 afe0c7dc S /system/bin/qemu-props<br />
<strong><span style="color: #ff0000">system&nbsp;&nbsp;&nbsp; 52&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp; 158356 37804 ffffffff afe0ca7c S system_server</span> </strong><br />
app_1&nbsp;&nbsp;&nbsp;&nbsp; 92&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp; 108640 20580 ffffffff afe0da04 S com.android.inputmethod.pinyin<br />
radio&nbsp;&nbsp;&nbsp;&nbsp; 93&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp; 122852 23340 ffffffff afe0da04 S com.android.phone<br />
app_1&nbsp;&nbsp;&nbsp;&nbsp; 98&nbsp;&nbsp;&nbsp; 30&nbsp;&nbsp;&nbsp; 143244 34888 ffffffff afe0da04 S android.process.acore</p>
<p>&nbsp;</p>
<p>有点复杂了，请大家跟上思路。我们注意观察进程列表的PID和PPID，我们要通过实际的列表去理清他们的亲缘关系。</p>
<p>&nbsp;</p>
<p>servicemanager是init的子进程</p>
<p>mediaserver是init的子进程</p>
<p>zygote是init的子进程</p>
<p>system_server和所有的java应用程序是zygote的子进程</p>
<p>&nbsp;</p>
<p>休息一下我们看看他们的应用程序代码方式</p>
<p><span style="color: #008000">Java script caller (executable)<br />
frameworks/base/cmds/app_process/<br />
app_main.cpp</span></p>
<p>app_process是android系统下面基于命令行的java的应用程序的调用工具</p>
<p>&nbsp;</p>
<p><strong>system_server executable（c/c++写的程序）</strong></p>
<p><br />
frameworks/base/cmds/system_server/</p>
<p>system_main.cpp<br />
library/system_init.cpp</p>
<p>&nbsp;</p>
<p><strong>SystemServer （java程序）</strong> <br />
frameworks/base/services/java/com/android/server/<br />
SystemServer.java</p>
<p><br />
<strong>Zygote （java程序）</strong> <br />
frameworks/base/core/java/com/android/internal/os/<br />
ZygoteInit.java</p>
<p>&nbsp;</p>
<h3>6.分析具体的调用过程（很痛苦）</h3>
<p><strong>app_main 调用 zygoteInit</strong></p>
<p><span style="font-size: small"><font size="2">p { margin-bottom: 0.21cm; } </font></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">/ </span></span></span>Next arg is startup classname or <span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;--zygote&quot; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #b1b100"><span style="font-style: normal"><span style="font-weight: normal">if </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span>i <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">&lt; </span></span></span>argc <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">arg <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">= </span></span></span>argv <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">[ </span></span></span>i <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">++]; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #b1b100"><span style="font-style: normal"><span style="font-weight: normal">if </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #0000dd"><span style="font-style: normal"><span style="font-weight: normal">0 </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">== </span></span></span>strcmp <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;--zygote&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">, </span></span></span>arg <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">)) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">bool startSystemServer <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">= </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span>i <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">&lt; </span></span></span>argc <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">? </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">strcmp <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span>argv <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">[ </span></span></span>i <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">], </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;--start-system-server&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">== </span></span></span><span style="color: #0000dd"><span style="font-style: normal"><span style="font-weight: normal">0 </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">: </span></span></span><span style="color: #000000"><span style="font-style: normal"><strong>false </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">setArgv0 <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span>argv0 <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">, </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;zygote&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">set_process_name <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;zygote&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><strong>runtime.</strong> <span style="color: #202020"><span style="font-style: normal"><span style="font-weight: normal"><strong>start</strong> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><strong>(</strong> </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal"><strong>&quot;com.android.internal.os.ZygoteInit&quot;</strong> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><strong>,</strong> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><strong>startSystemServer</strong> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><strong>);</strong> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">} </span></span></span><span style="color: #b1b100"><span style="font-style: normal"><span style="font-weight: normal">else </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">set_process_name <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span>argv0 <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">runtime. <span style="color: #202020"><span style="font-style: normal"><span style="font-weight: normal">mClassName </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">= </span></span></span>arg <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">// </span></span></span>Remainder of args get passed to startup class main <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">() </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">runtime. <span style="color: #202020"><span style="font-style: normal"><span style="font-weight: normal">mArgC </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">= </span></span></span>argc <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">- </span></span></span>i <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">runtime. <span style="color: #202020"><span style="font-style: normal"><span style="font-weight: normal">mArgV </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">= </span></span></span>argv <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">+ </span></span></span>i <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">LOGV <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;App process is starting with pid=%d, class=%s. </span></span></span><span style="color: #000099"><span style="font-style: normal"><strong>/n </strong></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">, </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">getpid <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">(), </span></span></span>runtime. <span style="color: #202020"><span style="font-style: normal"><span style="font-weight: normal">getClassName </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">()); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">runtime. <span style="color: #202020"><span style="font-style: normal"><span style="font-weight: normal">start </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">(); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><font size="2">} </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><font size="2">} </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #000000"><strong><br />
</strong></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><font size="2"><span style="color: #000000"><strong>Zygote 分裂出 system_server</strong> </span><br />
</font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p><span style="font-size: small"><br />
</span></p>
<p><span style="font-size: small"><font size="2">p { margin-bottom: 0.21cm; } </font></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>public </strong></span></span><span style="color: #000000"><span style="font-style: normal"><strong>static </strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong>void </strong></span></span><span style="font-style: normal"><span style="font-weight: normal">main</span> </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong>String </strong></span></span><span style="font-style: normal"><span style="font-weight: normal">argv</span> </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">[]) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>try </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><span style="color: #666666"><em><span style="font-weight: normal"><font size="2">// Start profiling the zygote initialization. </font></span></em></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>if </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="font-style: normal"><span style="font-weight: normal">argv</span> </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">[ </span></span></span><span style="color: #cc66cc"><span style="font-style: normal"><span style="font-weight: normal">1 </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">] </span></span></span><span style="font-style: normal"><span style="font-weight: normal">.</span> </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal">equals </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal">&quot;true&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">)) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="font-style: normal"><span style="text-decoration: none"><strong>startSystemServer</strong> </span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="text-decoration: none"><strong>();</strong> </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">} </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="font-style: normal"><span style="font-weight: normal">Log.</span> </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal">i </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="font-style: normal"><span style="font-weight: normal">TAG, </span></span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal">&quot;Accepting command socket connections&quot; </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">); </span></span></span></font></span></span></p>
<p style="font-style: normal; margin-bottom: 0cm; font-weight: normal"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>if </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="font-style: normal"><span style="font-weight: normal">ZYGOTE_FORK_MODE</span> </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">) </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="font-style: normal"><span style="font-weight: normal">runForkMode</span> </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">(); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">} </span></span></span><span style="color: #000000"><span style="font-style: normal"><strong>else </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="font-style: normal"><span style="font-weight: normal">runSelectLoopMode</span> </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">(); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">} </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><font size="2">} </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><font size="2">frameworks/base/core/java/com/android/internal/os/<br />
ZygoteInit.java</font></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><font size="2">p { margin-bottom: 0.21cm; } </font></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>private </strong></span></span><span style="color: #000000"><span style="font-style: normal"><strong>static </strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong>boolean </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">startSystemServer() </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>throws </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">MethodAndArgsCaller, </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong>RuntimeException </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #666666"><em><span style="font-weight: normal">/* Hardcoded command line to start the system server */ </span></em></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>try </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">{ </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #666666"><em><span style="font-weight: normal">/* Request to fork the system server process */ </span></em></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>pid = Zygote.</strong> </span></span></span></span></span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>forkSystemServer</strong> </span></span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>( </strong></span></span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><font size="2"><span style="text-decoration: none"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><strong>parsedArgs.</strong> </span></span></span></span></span><span style="font-family: 微软雅黑"><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>uid</strong> </span></span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>, parsedArgs.</strong> </span></span></span></span></span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>gid</strong> </span></span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>, </strong></span></span></span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><font size="2"><span style="text-decoration: none"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><strong>parsedArgs.</strong> </span></span></span></span></span><span style="font-family: 微软雅黑"><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>gids</strong> </span></span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>, debugFlags, </strong></span></span></span></span></span><span style="color: #006600"><span style="font-style: normal"><strong><span style="font-style: normal"><span style="text-decoration: none">null</span> </span></strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-style: normal"><span style="text-decoration: none"><strong>); </strong></span></span></span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><font size="2"><span style="font-style: normal"><span style="font-weight: normal">} </span></span><span style="color: #000000"><span style="font-style: normal"><strong>catch </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong>IllegalArgumentException </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">ex) { </span></span></span></font></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>throw </strong></span></span><span style="color: #000000"><span style="font-style: normal"><strong>new </strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong>RuntimeException </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">(ex); </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><font size="2">} </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #666666"><em><span style="font-weight: normal">/* For child process */ </span></em></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>if </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">(pid == </span></span></span><span style="color: #cc66cc"><span style="font-style: normal"><span style="font-weight: normal">0 </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">) { </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="text-decoration: underline"><span style="font-weight: normal"><font size="2">handleSystemServerProcess(parsedArgs); </font></span></span></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><font size="2">} </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong>return </strong></span></span><span style="color: #006600"><span style="font-style: normal"><strong>true </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal">; </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><font size="2">} </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><span style="color: #000000"><font size="2"><strong>1.如果大家还能看到这里请复习一下 Linux的两个系统调用 fork和exec</strong> </font></span></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><span style="color: #000000"><strong><br />
</strong></span></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><font size="2"><span style="color: #000000">frameworks/base/services/java/com/android/server/SystemService.java</span> </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><font size="2">p { margin-bottom: 0.21cm; } </font></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">public </span></strong></span></span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">static </span></strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">void </span></strong></span></span><span style="font-family: 微软雅黑">main </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">( </span></span></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">String </span></strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">[] </span></span></span></span><span style="font-family: 微软雅黑">args </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">) </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{ </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">if </span></strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">( </span></span></span></span><span style="font-family: 微软雅黑">SamplingProfilerIntegration. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">isEnabled </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">()) </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{ </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">SamplingProfilerIntegration. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">start </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">timer </span></strong></span></span><span style="font-family: 微软雅黑">= </span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">new </span></strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">Timer </span></strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">timer </span></strong></span></span><span style="font-family: 微软雅黑">. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">schedule </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">( </span></span></span></span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">new </span></strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">TimerTask </span></strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">() </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{ </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">@ </span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">Override </span></strong></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">public </span></strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">void </span></strong></span></span><span style="font-family: 微软雅黑">run </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">() </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{ </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">SamplingProfilerIntegration. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">writeSnapshot </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">( </span></span></span></span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;system_server&quot; </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">} </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">} </span></span></span></span><span style="font-family: 微软雅黑">, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">} </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">VMRuntime. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">getRuntime </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">() </span></span></span></span><span style="font-family: 微软雅黑">. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">setTargetHeapUtilization </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">( </span></span></span></span><span style="color: #cc66cc"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">0 </span></span></span></span><span style="font-family: 微软雅黑">.8f </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">System </span></strong></span></span><span style="font-family: 微软雅黑"><strong>.</strong> </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong>loadLibrary</strong> </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong>(</strong> </span></span></span></span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong>&quot;android_servers&quot;</strong> </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong>);</strong> </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #ff0000"><strong>init1</strong> </span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal"><strong>(</strong> </span></span></span><span style="color: #ff0000"><strong>args</strong> </span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal"><strong>);------------------&gt;</strong> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">} </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">public </span></strong></span></span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">static </span></strong></span></span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">final </span></strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">void </span></strong></span></span><span style="font-family: 微软雅黑">init2 </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">() </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{ </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">Log. </span><span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">i </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">( </span></span></span></span><span style="font-family: 微软雅黑">TAG, </span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;Entered the Android system server!&quot; </span></span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">Thread </span></strong></span></span><span style="font-family: 微软雅黑">thr = </span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">new </span></strong></span></span><span style="font-family: 微软雅黑">ServerThread </span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(); </span></span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><strong><span style="color: #ff0000">thr. </span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">setName </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">( </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">&quot;android.server.ServerThread&quot; </span></span></span><span style="color: #ff0000"><span style="font-style: normal"><span style="font-weight: normal">);--------------&gt; </span></span></span></strong></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">thr.start(); </font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: 微软雅黑"><font size="2">} </font></span></span></p>
<p><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
<strong><font size="2"><span style="color: #ff0000">红色的部分最后会执行我们上面列出的jni代码</span> </font></strong></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><strong><font size="2"><span style="color: #ff0000">frameworks/base/cmds/system_server/<br />
library/system_init.cpp</span> </font></strong></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><strong><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><font size="2"><span style="color: #000000">Init2 这里启动了java的system service</span> </font></span></span></span></span></strong></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><strong><span style="color: #339933"><span style="font-family: 微软雅黑"><span style="font-style: normal"><span style="font-weight: normal"><span style="color: #000000"><br />
</span></span></span></span></span></strong></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><font size="2">p { margin-bottom: 0.21cm; } </font></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">class</span> </strong></span></span><span style="font-family: 微软雅黑">ServerThread </span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">extends</span> </strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">Thread</span> </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">@</span> <span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">Override</span> </strong></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">public</span> </strong></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">void</span> </strong></span></span><span style="font-family: 微软雅黑">run</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">()</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">{</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">Log.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">i</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="font-family: 微软雅黑">TAG, </span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;System Content Providers&quot;</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">ActivityManagerService.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">installSystemProviders</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">();</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">Log.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">i</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="font-family: 微软雅黑">TAG, </span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;Battery Service&quot;</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">battery = </span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">new</span> </strong></span></span><span style="font-family: 微软雅黑">BatteryService</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">context</span> </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">ServiceManager.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">addService</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;battery&quot;</span> </span></span></span><span style="font-family: 微软雅黑">, battery</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">Log.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">i</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="font-family: 微软雅黑">TAG, </span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;Hardware Service&quot;</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">hardware = </span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">new</span> </strong></span></span><span style="font-family: 微软雅黑">HardwareService</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">context</span> </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">ServiceManager.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">addService</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;hardware&quot;</span> </span></span></span><span style="font-family: 微软雅黑">, hardware</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">Log.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">i</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="font-family: 微软雅黑">TAG, </span><span style="color: #0000ff"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">&quot;Alarm Manager&quot;</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">AlarmManagerService alarm = </span><span style="color: #000000"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">new</span> </strong></span></span><span style="font-family: 微软雅黑">AlarmManagerService</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">context</span> </strong></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="font-family: 微软雅黑">ServiceManager.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">addService</span> </span></span></span><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">(</span> </span></span></span><span style="color: #003399"><span style="font-style: normal"><strong><span style="font-family: 微软雅黑">Context</span> </strong></span></span><span style="font-family: 微软雅黑">.</span> <span style="color: #006633"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">ALARM_SERVICE</span> </span></span></span><span style="font-family: 微软雅黑">, alarm</span> <span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">);</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><br />
</span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><font size="2"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑">}</span> </span></span></span></font></span></span></p>
<p style="margin-bottom: 0cm"><span style="font-size: small"><span style="font-family: DejaVu Serif, serif"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><font size="2"><span style="font-family: 微软雅黑">}</span> </font></span></span></span></span></span></p>
<p style="margin-bottom: 0cm">&nbsp;</p>
<p style="margin-bottom: 0cm">原创文章欢迎转载，转载请注明住处rickleaf</p>
<h3 style="margin-bottom: 0cm"><span style="font-family: DejaVu Serif, serif"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong><span style="color: #000000">7. 整理Android系统启动流程</span> </strong></span></span></span></span></span></h3>
<p>&nbsp;</p>
<p><span style="font-family: DejaVu Serif, serif"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><span style="color: #000000">至此System Service的服务环境启动起来了</span> <strong><span style="color: #000000"><br />
</span></strong></span></span></span></span></span></p>
<h3 style="margin-bottom: 0cm"><span style="font-family: DejaVu Serif, serif"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong><span style="color: #000000"><br />
</span></strong></span></span></span></span></span></h3>
<p>&nbsp;&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-family: DejaVu Serif, serif"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong><span style="color: #000000">8. 最后引用霍金的一句话：&ldquo;懂与不懂都是收获&rdquo;</span></strong></span></span></span></span></span></p>
<p><span style="font-family: DejaVu Serif, serif"><span style="color: #339933"><span style="font-style: normal"><span style="font-weight: normal"><span style="font-family: 微软雅黑"><strong><span style="color: #000000">http://blog.csdn.net/rickleaf/article/details/6369720</span></strong></span></span></span></span></span></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-595-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-10 12:36</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-594-1.html</guid>
			<title>Android虚拟平台的编译和整合</title>
			<author>admin</author>
			<description><![CDATA[<h2>概要</h2>
<p>&nbsp;</p>
<p>Android从2008年开始到本文写的2011年，短短三年的时间里成为手机行业首屈一指的操作系统，在平板电脑，GPS PND甚至工业控制等领域也迅速流行起来。</p>
<p>越来越多的CPU厂商提供完整的Android解决方案使得Android的编译方法千差万别。</p>
<p>本文从Google原生态的Android系统入手，试图跳过所有的CPU厂商从Android自带的ARM QEMU入手一步步的编译出定制的Android系统。</p>
<p>&nbsp;</p>
<p>（本文原创：欢迎转载请注明出处和作者 Ricky.Wu rickleaf.wu@gmail.com）</p>
<h2>资源</h2>
<p>&nbsp;</p>
<p>Android 2.1 r2<br />
Android Goldfish kernel 2.6.29<br />
ubuntu 10.04 LTS AMD64</p>
<p>&nbsp;</p>
<h2>下载源代码</h2>
<h3>&nbsp;</h3>
<h3>安装工具包</h3>
<h4>&nbsp;</h4>
<h4>安装必要的工具包</h4>
<p>&nbsp;</p>
<p>$sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev&nbsp; lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev</p>
<p>&nbsp;</p>
<h4>安装64bit Linux编译32位系统需要的工具包</h4>
<p>&nbsp;</p>
<p>$ sudo apt-get install gcc-multilib g++-multilib libc6-i386 libc6-dev-i386</p>
<p>&nbsp;</p>
<h4>看需要安装下面工具包</h4>
<p>&nbsp;</p>
<p>$ sudo apt-get install make gcc g++ libc6-dev&nbsp; patch texinfo<br />
&nbsp;Zlib1g-dev valgrind python</p>
<p>&nbsp;</p>
<h3>下载源代码</h3>
<p>&nbsp;</p>
<p>下载repo工具，更改为可执行权限，并确保安装路径包含在PATH中<br />
$ curl http://android.git.kernel.org/repo &gt; ~/bin/repo<br />
$ chmod a+x ~/bin/repo<br />
建立Android工作目录<br />
$cd ~<br />
$mkdir android_platform<br />
下载Android 2.1 r2源代码<br />
$repo init -u git://android.git.kernel.org/platform/manifest.git /<br />
-b android-2.1_r2<br />
$repo sync</p>
<p>&nbsp;</p>
<h2>定制化Vendor</h2>
<h3>&nbsp;</h3>
<h3>Android系统的vendor</h3>
<p>&nbsp;</p>
<p>记下Android系统的代码仓库网页<br />
http://android.git.kernel.org/<br />
网页浏览platform/vendor目录</p>
<p>&nbsp;</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303958936jE0h.gif" /></p>
<p>&nbsp;</p>
<h3>vendor目录的作用</h3>
<p>&nbsp;</p>
<p>vendor的英文单词有&ldquo;提供商&rdquo;的意思，我们结合刚才看到的Android源码仓库中的vendor子目录就可以看出，在Google的Android原始代码里vendor目录包含了CPU硬件提供商的一些信息。<br />
Android系统作为开放的手持设备操作系统，在发布之初必须要提供配置接口给CPU提供商，这样Android的系统才能在不同的CPU上运行。<br />
实际上vendor目录就是Android系统预留给我们加入定制化信息的目录。在这个目录中可以完成对系统默认应用程序的添加移除、及其背光，GPS和OpenGL硬件适应层的vendor库文件或者代码。</p>
<p>&nbsp;</p>
<h3>加入自己的vendor目录</h3>
<p>&nbsp;</p>
<p>参考sample和htc dream建立rickleaf作为一个新的cpu厂商，在rickleaf建立一个heaven的目录作为厂商的一个特别设备</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303959077r2aB.gif" /></p>
<p>&nbsp;</p>
<h3>Android.mk</h3>
<p>&nbsp;</p>
<p>在android的platform代码中，如果你的代码需要编译或者一些二进制文件和库需要复制到目标板，就必须有个Android.mk文件来管理。<br />
Vendor里面的Android.mk文件主要负责编译CPU厂商的特定代码和复制文件到目标半<br />
Heaven中的Android.mk文件内容如下：</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_13039591550gqQ.gif" /></p>
<h3>BoardConfig.mk</h3>
<p>&nbsp;</p>
<p>这个文件负责对Android系统的一些配置，包括如下等<br />
ARM CPU的版本<br />
Audio的架构类型<br />
GPS的适应层名字<br />
是否vendor有自己的init.rc文件<br />
Android的image类型(inand需要yaffs2的image，mmc需要ext3或者ext4（android2.3）的image<br />
如果在platform中加入了自己的模块，也可以加入配置机制，并且在这个文件中决定是否加入到系统中来</p>
<p>Heaven下面BoardConfig.mk的内容</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303959246Trtt.gif" /></p>
<h3>AndroidProducts.mk</h3>
<p>&nbsp;</p>
<p>这个文件为PRODUCT_MAKEFILES指定一个mk文件<br />
在指定的mk文件中完成对Android系统中APP层面的一些配置，下面简单列举：<br />
添加默认的Android应用程序<br />
采用哪种dpi<br />
采用哪种图资<br />
为android添加vendor的信息<br />
加入默认铃声</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303959360aJFn.gif" /></p>
<p>&nbsp;</p>
<p>PRODUCT_PROPERTY_OVERRIDES<br />
修改一些默认的property设置，关于什么是property请大家去浏览google的文档，可以粗略的理解为类似注册表的东西驻留在内存中，可以供应用程序读写</p>
<p>&nbsp;</p>
<p>PRODUCT_PACKAGES<br />
PRODUCT_COPY_FILES<br />
Android通过以上两个变量来对android packages和一些系统文件进行添加和移除</p>
<p>&nbsp;</p>
<p>PRODUCT_LOCALES<br />
这个变有两个作用一个是加入系统支持的语言类型；另一个是决定默认用哪一种图资，比如ldpi,mdpi还是hdpi</p>
<p>&nbsp;</p>
<p>PRODUCT_BRAND<br />
厂商名字<br />
PRODUCT_NAME<br />
产品名字<br />
PRODUCT_DEVICE<br />
设备名字</p>
<p>&nbsp;</p>
<h2>Linux kernel集成化</h2>
<h3>&nbsp;</h3>
<h3>获得内核源代码</h3>
<p>&nbsp;</p>
<p>克隆kernel到android_platform根目录<br />
$ git clone git://android.git.kernel.org/kernel/common.git kernel<br />
切换kernel分支到2.6.29<br />
$ cd kernel<br />
$ git checkout -b android-goldfish-2.6.29 origin/android-goldfish-2.6.29</p>
<p>&nbsp;</p>
<h3>增加kernel编译到系统</h3>
<p>&nbsp;</p>
<p>修改platform下面的build</p>
<p>------------------------------- core/Makefile --------------------------------</p>
<p>index 2f316ca..7a92961 100644</p>
<p>@@ -288,6 +288,9 @@ endif</p>
<p>&nbsp;</p>
<p>&nbsp;INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img</p>
<p>&nbsp;</p>
<p>+kernel: $(INSTALLED_BOOTIMAGE_TARGET)</p>
<p>+.PHONY:kernel</p>
<p>+</p>
<p>&nbsp;ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)</p>
<p>&nbsp;tmp_dir_for_image := $(call intermediates-dir-for,EXECUTABLES,boot_img)/bootimg</p>
<p>&nbsp;INTERNAL_BOOTIMAGE_ARGS += --tmpdir $(tmp_dir_for_image)</p>
<p>&nbsp;</p>
<h3>AndroidBoard.mk</h3>
<p>&nbsp;</p>
<h3><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303959572C64Y.gif" /></h3>
<h3>&nbsp;</h3>
<h3>kernel配置</h3>
<p>&nbsp;</p>
<p>make kernelconfig</p>
<p>&nbsp;</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303959716p1s3.gif" /></p>
<p>&nbsp;</p>
<p>make kernelgconfig</p>
<p>&nbsp;</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_13039597530Iut.gif" /></p>
<p>&nbsp;</p>
<h2>Android系统的编译命令集</h2>
<h3>&nbsp;</h3>
<h3>Android编译命令</h3>
<p>&nbsp;</p>
<p>执行环境配置命令<br />
$ . build/envsetup.sh （.后面有空格）<br />
当前终端会多出一些命令：<br />
- croot:&nbsp;&nbsp; Changes directory to the top of the tree.<br />
- m:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Makes from the top of the tree.<br />
- mm:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Builds all of the modules in the current directory.<br />
- mmm:&nbsp;&nbsp;&nbsp;&nbsp; Builds all of the modules in the supplied directories.<br />
- cgrep:&nbsp;&nbsp; Greps on all local C/C++ files.<br />
- jgrep:&nbsp;&nbsp; Greps on all local Java files.<br />
- resgrep: Greps on all local res/*.xml files.<br />
- godir:&nbsp;&nbsp; Go to the directory containing a file.</p>
<p>&nbsp;</p>
<p>&mdash;help查看帮助</p>
<p>&nbsp;</p>
<h3>编译模块</h3>
<p>&nbsp;</p>
<p>使用mmm来编译指定目录的模块，如编译Launcher：<br />
$ mmm packages/apps/Launcher/<br />
编完之后生成两个文件：<br />
out/target/product/heaven/data/app/LauncherTests.apk<br />
out/target/product/heaven/system/app/Launcher.apk<br />
可以使用<br />
$ make snod<br />
重新生成system.img，再运行模拟器</p>
<p>&nbsp;</p>
<h3>选择product编译</h3>
<p>&nbsp;</p>
<p>按照如下图的方式，可以选择heaven这个Product</p>
<p>&nbsp;</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303960043CIVi.gif" /></p>
<h3>用OpenJDK骗过Android的</h3>
<p>既然我们在虚拟系统编译，就不用非要去安装官方推荐的java sdk 1.5了。</p>
<p>只要我们在out目录建立这个文件就可以了</p>
<p>&nbsp;</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303961042uzUH.gif" /></p>
<h3>编译整个系统</h3>
<p>&nbsp;</p>
<p>make -j2 (2表示我有的两个cpu)</p>
<p>&nbsp;</p>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303960119I7g5.gif" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>模拟器加载Android系统</h2>
<h3>&nbsp;</h3>
<h3>创建Heaven模拟环境</h3>
<p>创建标准Android 2.1模拟器命名为heaven<br />
更改~/.android/avd/heaven/config.ini文件<br />
hw.lcd.density=240<br />
sdcard.size=64M<br />
skin.name=WVGA800-L<br />
skin.path=platforms/android-2.1/skins/WVGA800-L<br />
vm.heapSize=24<br />
image.sysdir.1=platforms/android-2.1/heaven/<br />
更改以后，我们只要我们把我们编译好的image放到SDK的<br />
platforms/android-2.1/heaven/目录就可以用emualtor了</p>
<p>把out目录中编译好的zimage改名成qemu-kernel放到Heaven仿真目录中<br />
重新冷启动emulator<br />
emulator -avd heaven -wipe-data<br />
这时候heaven的emualtor的所以image都是我们自己生成的了，当然也可以调试apk到这个emulator</p>
<p>&nbsp;</p>
<h3>加入kernel logo</h3>
<h3><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303960255LUdx.gif" width="769" height="714" /></h3>
<h3>&nbsp;</h3>
<h3>手机的about信息</h3>
<p><img alt="" src="http://hi.csdn.net/attachment/201104/28/0_1303960300sca6.gif" width="774" height="719" /></p>
<p>http://blog.csdn.net/rickleaf/article/details/6369065</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-594-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-10 09:52</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-593-1.html</guid>
			<title>android中修改默认语言</title>
			<author>admin</author>
			<description><![CDATA[<p>本文是主要对android定制多语言的问题进行深入研究后，总结了其定制的 机制和其具体实现方法。如果想深入了解其定制的机制，可阅读本文第一部分，如 果只想了解如何定制，请参考第二部分。&nbsp;<br />
<br />
<br />
第一部分 多语言定制的机制&nbsp;<br />
<br />
<br />
1、ICU4C简介&nbsp;<br />
<br />
ICU4C(ICU for C，&nbsp;<a href="http://site.icu-project.org/" rel="nofollow" target="_blank">http://site.icu-project.org/</a>&nbsp;) 是ICU在C/C++平台下的版本, ICU(International Component for Unicode)是基于&quot;IBM公共许可证&quot;的，与开源组织合作研究的, 用于支持软件国际化的开源项目。ICU4C提供了C/C++平台强大的国际化开发能力，软件开发者几乎可以使用ICU4C解决任何国际化的问题，根据各地 的风俗和语言习惯，实现对数字、货币、时间、日期、和消息的格式化、解析，对字符串进行大小写转换、整理、搜索和排序等功能，必须一提的是，ICU4C提 供了强大的BIDI算法，对阿拉伯语等BIDI语言提供了完善的支持。&nbsp;<br />
<br />
ICU首先是由Taligent公司开发的，Taligent公司现在被合并为IBM?公司全球化认证中心的Unicode研究组，然后ICU由IBM和 开源组织合作继续开发，开源组织给与了ICU极大的帮助。&nbsp;<br />
开始ICU只有Java平台的版本，后来这个平台下的ICU类被吸纳入SUN公司开发的JDK1.1，并在JDK以后的版本中不断改进。C++和C平台下 的ICU是由JAVA平台下的ICU移植过来的，移植过的版本被称为ICU4C，来支持这C/C++两个平台下的国际化应用。 ICU4J和ICU4C区别不大，但由于ICU4C是开源的，并且紧密跟进Unicode标准，ICU4C支持的Unicode标准总是最新的；同时，因 为JAVA平台的ICU4J的发布需要和JDK绑定，ICU4C支持Unicode标准改变的速度要比ICU4J快的多。&nbsp;<br />
<br />
2、 ANDROID语言包&nbsp;<br />
<br />
Android 使用的语言包就是ICU4C，位置：external/icu4c。Android支持的语言有： Locale CANADA&nbsp;<br />
Locale constant for en_CA.&nbsp;<br />
Locale CANADA_FRENCH&nbsp;<br />
Locale constant for fr_CA.&nbsp;<br />
Locale CHINA&nbsp;<br />
Locale constant for zh_CN.&nbsp;<br />
Locale CHINESE&nbsp;<br />
Locale constant for zh.&nbsp;<br />
Locale ENGLISH&nbsp;<br />
Locale constant for en.&nbsp;<br />
Locale FRANCE&nbsp;<br />
Locale constant for fr_FR.&nbsp;<br />
Locale FRENCH&nbsp;<br />
Locale constant for fr.&nbsp;<br />
Locale GERMAN&nbsp;<br />
Locale constant for de.&nbsp;<br />
Locale GERMANY&nbsp;<br />
Locale constant for de_DE.&nbsp;<br />
Locale ITALIAN&nbsp;<br />
Locale constant for it.&nbsp;<br />
Locale ITALY&nbsp;<br />
Locale constant for it_IT.&nbsp;<br />
Locale JAPAN&nbsp;<br />
Locale constant for ja_JP.&nbsp;<br />
Locale JAPANESE&nbsp;<br />
Locale constant for ja.&nbsp;<br />
Locale KOREA&nbsp;<br />
Locale constant for ko_KR.&nbsp;<br />
Locale KOREAN&nbsp;<br />
Locale constant for ko.&nbsp;<br />
Locale PRC&nbsp;<br />
Locale constant for zh_CN.&nbsp;<br />
Locale SIMPLIFIED_CHINESE&nbsp;<br />
Locale constant for zh_CN.&nbsp;<br />
Locale TAIWAN&nbsp;<br />
Locale constant for zh_TW.&nbsp;<br />
Locale TRADITIONAL_CHINESE&nbsp;<br />
Locale constant for zh_TW.&nbsp;<br />
Locale UK&nbsp;<br />
Locale constant for en_GB.&nbsp;<br />
Locale US&nbsp;<br />
Locale constant for en_US.&nbsp;<br />
<br />
3、定制语言&nbsp;<br />
<br />
定制语言在PRODUCT_LOCALES字段里添加需要语言，如： PRODUCT_LOCALES := en_US zh_CN，则系统里只有英语和汉语两种语言。然后语言的选择处理是在external/icu4c/stubdata/Android.mk里进行的， 如下：&nbsp;<br />
config := $(word 1, / $(if $(findstring ar,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring da,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring el,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring fi,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring he,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring hr,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring hu,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring id,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring ko,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring nb,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring pt,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring ro,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring ru,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring sk,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring sr,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring sv,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring th,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring tr,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring uk,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring zh,$(PRODUCT_LOCALES)),large) /&nbsp;<br />
$(if $(findstring ja,$(PRODUCT_LOCALES)),us-japan) /&nbsp;<br />
$(if $(findstring it,$(PRODUCT_LOCALES)),us-euro) /&nbsp;<br />
$(if $(findstring pl,$(PRODUCT_LOCALES)),us-euro) /&nbsp;<br />
$(if $(findstring cs,$(PRODUCT_LOCALES)),default) /&nbsp;<br />
$(if $(findstring de,$(PRODUCT_LOCALES)),default) /&nbsp;<br />
$(if $(findstring fr,$(PRODUCT_LOCALES)),default) /&nbsp;<br />
$(if $(findstring nl,$(PRODUCT_LOCALES)),default) /&nbsp;<br />
us)&nbsp;<br />
<br />
4、默认语言&nbsp;<br />
默认语言的选择实现是在build/core/Makefile里，从PRODUCT_LOCALES里选择第一个语言作为默认语言，如下：&nbsp;<br />
define default-locale $(subst _, , $(firstword $(1)))&nbsp;<br />
endef&nbsp;<br />
# Selects the first locale in the list given as the argument&nbsp;<br />
# and returns the language (or the region)&nbsp;<br />
define default-locale-language $(word 2, 2, $(call default-locale, $(1)))&nbsp;<br />
endef&nbsp;<br />
define default-locale-region $(word 3, 3, $(call default-locale, $(1)))&nbsp;<br />
Endef ... PRODUCT_DEFAULT_LANGUAGE=&quot;$(call default-locale-language,$(PRODUCT_LOCALES))&quot; /&nbsp;<br />
PRODUCT_DEFAULT_REGION=&quot;$(call default-locale-region,$(PRODUCT_LOCALES))&quot;&nbsp;<br />
然后通过build/tool/buildinfo.sh文件将如下段写到文件build.prop，如下：&nbsp;<br />
echo &quot;ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE&quot;&nbsp;<br />
echo &quot;ro.product.locale.region=$PRODUCT_DEFAULT_REGION&quot; 。&nbsp;<br />
<br />
因此，要改变默认语言用下面两种方法中的一种就行了：&nbsp;<br />
<br />
4.1、在PRODUCT_LOCALES字段里，将要选择的语言放在第一位，</p>
<p>如： PRODUCT_LOCALES := en_US zh_CN 默认语言是英语；&nbsp;</p>
<p><br />
4.2、在persist.sys.language 和persist.sys.country 里指定语言，如下：</p>
<p>PRODUCT_PROPERTY_OVERRIDES := /&nbsp;<br />
persist.sys.language=zh /&nbsp;<br />
persist.sys.country=CN /</p>
<p>&nbsp;</p>
<p>rickleaf我测试后发现需要再添加两个值，算是对原作者的补充吧</p>
<p>&nbsp;</p>
<p><span style="font-family: mceinline">ro.product.locale.language=zh /</span></p>
<p><span style="font-family: mceinline">ro.product.locale.region=CN</span></p>
<p>（在编译的时候一定要删除system下面的build.prop，在编译才有效，否则这个文件不会被更新）</p>
<p>&nbsp;</p>
<p>build.prop文件的处理是在system/core/init/property_service.c。&nbsp;<br />
<br />
<br />
第二部分 多语言定制的方法&nbsp;<br />
<br />
<br />
1、多语言定制的实现步骤&nbsp;<br />
<br />
1)进入build/target/product目录，在languages_full.mk或languages_small.mk文件中， 修改PRODUCT_LOCALES的值，来定制语言,比如PRODUCT_LOCALES := en_US zh_CN zh_TW en_GB fr_FR it_IT de_DE es_ES；&nbsp;<br />
<br />
2)相同目录下，修改full.mk文件的&nbsp;<br />
$(call inherit-product, build/target/product/languages_small|full.mk)语句来切换所使用的文件;&nbsp;<br />
<br />
3)重新编译即可。&nbsp;<br />
<br />
2、设置默认语言的实现步骤&nbsp;<br />
1)进入build/target/product目录，修改文件core.mk的PRODUCT_PROPERTY_OVERRIDES 值，例如，欲修改为默认中文，则增加&nbsp;<br />
&ldquo;/ persist.sys.language=zh / persist.sys.country=CN&rdquo;，增加后的语句如PRODUCT_PROPERTY_OVERRIDES := /&nbsp;<br />
<br />
ro.config.notification_sound=OnTheHunt.ogg /&nbsp;<br />
<br />
ro.config.alarm_alert=Alarm_Classic.ogg / persist.sys.language=zh / persist.sys.country=CN&nbsp;<br />
2)重新编译即可。&nbsp;<br />
<br />
3、与多语言定制相关的字段及其所在的文件&nbsp;<br />
<br />
PREVIOUS_BUILD_CONFIG out/target/product/dream/previous_build_config.mk&nbsp;<br />
<br />
NO_FALLBACK_FONT的定义 device/htc/dream-sapphire/BoardConfigCommon.mk&nbsp;<br />
<br />
NO_FALLBACK_FONT的调用 frameworks/base/data/fonts/Android.mk&nbsp;<br />
<br />
extra_locales CUSTOM_LOCALES nodpi mdpi hdpi build/core/product_config.mk&nbsp;<br />
<br />
PRODUCT_PROPERTY_OVERRIDES build/target/product&nbsp;<br />
build.prop out/target/product/generic/system</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-593-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-08-10 08:51</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-575-1.html</guid>
			<title>更改Android网络路由</title>
			<author>admin</author>
			<description><![CDATA[<p>使用的i909手机的免费流量是2G，不过如果要用手机看美剧，这个流量就有点不足。但是，当前我所被覆盖的无线网，上网需要手动设置上网路由。Android里面我还没有找到现成的能够设置路由的软件，不过经摸索，却找出了通过终端使用超级用户模式手工设置路由的办法。</p>
<p>首先确保机器已经root了，还安装了busybox和Emulator。</p>
<p>启动Emulator，然后输入命令：</p>
<p># ip route show <br />
172.18.0.0/16 dev eth0 src 172.18.3.80 <br />
default via 172.18.1.170 dev eth0</p>
<p>有井号的行是命令，没有的是输出结果。上述命令用于显示手机当前的路由。下面的命令删除手机的默认路由。如果出错，说明可能没有安装好busybox。</p>
<p>查看路由只需要普通权限，删除、添加、修改路由都需要超级用户权限。</p>
<p># su ip route del default</p>
<p>然后，添加默认路由和一条通往内网另一个网段的路由</p>
<p># su route add default gw 172.18.1.252 <br />
# su route add -net 192.30.1.0 netmask 255.255.255.0 gw 172.18.1.170</p>
<p>最后查看新的路由设置，下面的结果表示设置成功了。</p>
<p>#ip route show <br />
192.30.1.0/24 via 172.18.1.170 dev eth0 <br />
172.18.0.0/16 dev eth0 src 172.18.3.80 <br />
default via 172.18.1.252 dev eth0</p>
<p>当前我使用的busybox有个问题就是命令返回出错结果，它也不会提示任何信息。此外，使用手机键盘输入实在麻烦，解决的一个办法是使用SSH，通过电脑来控制手机。</p>
<p>注意：不同版本的emulator， busybox， 命令稍微有差异，例如最近升级后，su命令需要而且只要首次单独执行一次，此后都不用su， 其次，route add 命令的格式也与电脑版本Linux更接近，需要用route add -net 此类的语法了。</p>
<p>近期升级后，我手机上修改路由的语句变成了： <br />
su <br />
ip route del default <br />
route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.18.1.252 <br />
route add -net 192.30.1.0 netmask 255.255.255.0 gw 172.18.1.170</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-575-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-28 18:39</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-574-1.html</guid>
			<title>发一份反编译的东东。感觉还不错</title>
			<author>admin</author>
			<description><![CDATA[<p>反编译（绝好！）<br />
注意点：<br />
1、需要软件<br />
AXMLPrinter2.jar<br />
baksmali.jar<br />
smali.jar<br />
2、用 AXMLPrinter2.jar查看apk中的布局xml文件<br />
过程：<br />
（1）将AXMLprinter2.jar放入某一文件夹中，建议放入SDK中的Tools中，（能不能放入到其它地方倒没试过！）<br />
（2）然后在CMD中启动此文件，格式为：<br />
D:\\android-sdk_r05-windows\\android-sdk-windows\\tools&gt;<br />
java -jar AXMLprinter2.jar&nbsp; &nbsp;main.xml &gt;main.txt<br />
解释：将当前路径下的main.xml输出至当前下main.txt中。（输出之前，main.xml是乱码，输出后是个文件文件，所有东东全在里面，太TMD强了！）<br />
3、用baksmali.jar反编译classes.dex: <br />
（1）将baksmali.jar放入某一文件夹中，建议放入SDK中的Tools中，（能不能放入到其它地方倒没试过！）<br />
（2）然后在CMD中启动此文件，格式为：<br />
D:\\android-sdk_r05-windows\\android-sdk-windows\\tools&gt;java -jar baksmali-1.2.5.jar -o classout/ classes.dex <br />
（3）此时会在当前目录下生成一个classout文件夹，好东东全在里面了。<br />
<br />
4、用smali.jar编译classout成classes.dex: <br />
上一步已经将classes.dex反编译成了.smali文件，好了，我们看看smali文件看够了，在偿试把它编译成classes.dex吧，<br />
输入如下命令:java -jar smali.jar classout/ -o classes.dex.<br />
可以将新生成的classes.dex塞入ApkInstaller.apk里覆盖原来的classes.dex文件，这样我们的apk还是一样能用的哦~<br />
5、特别注意：<br />
反编译可将APK中的各种资源直接利用，例如图标等，特别好用。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-574-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-28 12:58</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-573-1.html</guid>
			<title>关于android中的ramdisk.img及uImage无法包含驱动模块（*.ko）的问题</title>
			<author>admin</author>
			<description><![CDATA[<h2>关于android中的ramdisk.img及uImage无法包含驱动模块（*.ko）的问题</h2>
<div id="cnblogs_post_body">
<p>这几天一起在整理freescale的imx53的android源码，今天在编译android kernel的时候发现make menuconfig中配置成&lt;M&gt;模式的驱动模块没有加入编译</p>
<p>之前一直是按照原厂的资料运行下面命令编译内核的：</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:false;">make uImage</pre>
</div>
<p>通过查看kernel的makefile发些了一些蛛丝马迹，现在将工作笔记记录如下：</p>
<p>在imx_kernel下运行终端，输入如下命令查看kernel编译相关的一些信息</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:false;">make help</pre>
</div>
<p>将会看到如下和编译相关的命令和信息</p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:false;">Cleaning targets:
  clean		  - Remove most generated files but keep the config and
                    enough build support to build external modules
  mrproper	  - Remove all generated files + config + various backup files
  distclean	  - mrproper + remove editor backup and patch files

Configuration targets:
  config	  - Update current config utilising a line-oriented program
  nconfig         - Update current config utilising a ncurses menu based program
  menuconfig	  - Update current config utilising a menu based program
  xconfig	  - Update current config utilising a QT based front-end
  gconfig	  - Update current config utilising a GTK based front-end
  oldconfig	  - Update current config utilising a provided .config as base
  localmodconfig  - Update current config disabling modules not loaded
  localyesconfig  - Update current config converting local mods to core
  silentoldconfig - Same as oldconfig, but quietly, additionally update deps
  randconfig	  - New config with random answer to all options
  defconfig	  - New config with default answer to all options
  allmodconfig	  - New config selecting modules when possible
  allyesconfig	  - New config where all options are accepted with yes
  allnoconfig	  - New config where all options are answered with no

Other generic targets:
  all		  - Build all targets marked with [*]
* vmlinux	  - Build the bare kernel
* modules	  - Build all modules
  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
  firmware_install- Install all firmware to INSTALL_FW_PATH
                    (default: $(INSTALL_MOD_PATH)/lib/firmware)
  dir/            - Build all files in dir and below
  dir/file.[oisS] - Build specified target only
  dir/file.lst    - Build specified mixed source/assembly target only
                    (requires a recent binutils and recent build (System.map))
  dir/file.ko     - Build module including final link
  modules_prepare - Set up for building external modules
  tags/TAGS	  - Generate tags file for editors
  cscope	  - Generate cscope index
  kernelrelease	  - Output the release version string
  kernelversion	  - Output the version stored in Makefile
  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
                    (default: /data/EN3/freescale/i.MX536/i.MX53-QSB-Android-Release3.3/src/kernel_imx/usr)

Static analysers
  checkstack      - Generate a list of stack hogs
  namespacecheck  - Name space analysis on compiled kernel
  versioncheck    - Sanity check on version.h usage
  includecheck    - Check for duplicate included header files
  export_report   - List the usages of all exported symbols
  headers_check   - Sanity check on exported headers
  headerdep       - Detect inclusion cycles in headers

Kernel packaging:
  rpm-pkg         - Build both source and binary RPM kernel packages
  binrpm-pkg      - Build only the binary kernel package
  deb-pkg         - Build the kernel as an deb package
  tar-pkg         - Build the kernel as an uncompressed tarball
  targz-pkg       - Build the kernel as a gzip compressed tarball
  tarbz2-pkg      - Build the kernel as a bzip2 compressed tarball

Documentation targets:
 Linux kernel internal documentation in different formats:
  htmldocs        - HTML
  pdfdocs         - PDF
  psdocs          - Postscript
  xmldocs         - XML DocBook
  mandocs         - man pages
  installmandocs  - install man pages generated by mandocs
  cleandocs       - clean all generated DocBook files

Architecture specific targets (arm):
* zImage        - Compressed kernel image (arch/arm/boot/zImage)
  Image         - Uncompressed kernel image (arch/arm/boot/Image)
* xipImage      - XIP kernel image, if configured (arch/arm/boot/xipImage)
  uImage        - U-Boot wrapped zImage
  bootpImage    - Combined zImage and initial RAM disk
                  (supply initrd image via make variable INITRD=&lt;path&gt;)
  install       - Install uncompressed kernel
  zinstall      - Install compressed kernel
                  Install using (your) ~/bin/installkernel or
                  (distribution) /sbin/installkernel or
                  install to $(INSTALL_PATH) and run lilo</pre>
</div>
</div>
<p>ellip;&hellip; &hellip;&hellip;&hellip;&hellip;&hellip;&hellip;</p>
<pre>&nbsp;</pre>
<p>可以看到很多编译相关的命令，如：make, make all, make clean, make uImage等等</p>
<p>经过测试发现运行make命令之后，在make menuconfig中配置成&lt;M&gt;的驱动模块都可以加入编译，但是再make uImage生成uImage文件烧到板子上的时候，在目标板上的文件系统里怎么也找不到那些*.ko文件，看了一上午android filesystem相关的资料，总算是找到了解决办法，就是通过修改android生成的ramdisk.img，用脚本把这些*.ko文件导入到android的filesystem中，下面代码就是实现整个过程的脚本：</p>
<div class="cnblogs_Highlighter">
<pre class="brush:python;gutter:false;">#!/bin/sh
MAKE_KERNEL=$1

#root dir
KERNEL_DIR=$(pwd)

#out dir
OUT_DIR=${KERNEL_DIR}/．．／．．/out

#modules install path
RAMDISK_DIR=ramdisk
INSTALL_MOD_PATH=${OUT_DIR}/tmp/${RAMDISK_DIR}

#echo &quot;make kernel?(y,n)&quot;;read MAKE_KERNEL

echo    &quot;******************************&quot;
echo    &quot;*        Make Kernel         *&quot;
echo    &quot;******************************&quot;
if [ &quot;$MAKE_KERNEL&quot;x = &quot;n&quot;x ]; then
	echo &quot;*** skip ***&quot;
else
	make -j4
	make uImage -j4
	cp arch/arm/boot/uImage ${OUT_DIR}
fi


echo    &quot;******************************&quot;
echo    &quot;*    Install modules         *&quot;
echo    &quot;******************************&quot;
	cd ${OUT_DIR}
	[ -e &quot;tmp&quot; ] || { echo &quot;mkdir tmp&quot;; mkdir tmp; }
	cp ./ramdisk.img ./tmp
	
#上一次退出状态: 判断ramdisk.img是否存在
case &quot;$?&quot; in
	&quot;0&quot;)
		cd tmp
		mv ramdisk.img ramdisk.img.gz
		cd ./${RAMDISK_DIR}
		gunzip ramdisk.img.gz
		[ -e &quot;${RAMDISK_DIR}&quot; ] || { echo &quot;mkdir ${RAMDISK_DIR}&quot;; mkdir ${RAMDISK_DIR}; }
		cd ${RAMDISK_DIR}
		cpio -i -F ../ramdisk.img
		cd ${KERNEL_DIR}
		make modules_install             #重点在这里，在kernel目录下运行此命令时，会把相关的*.ko文件install到由INSTALL_MOD_PATH指定的目录下！！
		cd ${INSTALL_MOD_PATH}
		find . | cpio -o -H newc | gzip &gt; ../ramdisk.img
		cd ..

		echo    &quot;******************************&quot;
		echo    &quot;*    Make uramdisk.img       *&quot;
		echo    &quot;******************************&quot;
		mkimage -A arm -O linux -T ramdisk -C none -a 0x70308000 -n &quot;Android Root Filesystem&quot; -d ./ramdisk.img ./uramdisk.img	
		mv uramdisk.img ./..
		cd ..
		rm -rf ./tmp
		cd ${KERNEL_DIR}
		echo &quot;***OKAY***&quot;
		;;

	&quot;1&quot;)
		echo &quot;ramdisk.img文件不存在！！！！！！&quot;
		rm -rf ./tmp
		cd ${KERNEL_DIR}
		;;
esac</pre>
</div>
<p>经过这样的处理就可以向android源码生成的ramdisk.img中install任何我们自己的东西了，把uImage和uramdisk.img一起烧到板子上，通过串口查看，得到了我想要的东西，如下：</p>
<div class="cnblogs_Highlighter">
<pre class="brush:python;gutter:false;">lrwxrwxrwx radio    radio             2011-07-06 08:58 build -&gt; /data/EN3/freescale/i.MX536/i.MX53-QSB-Android-Release3.3/src/kernel_imx
-rw-r--r-- radio    radio          81 2011-07-06 08:58 modules.isapnpmap
-rw-r--r-- radio    radio          74 2011-07-06 08:58 modules.ofmap
-rw-r--r-- radio    radio          43 2011-07-06 08:58 modules.seriomap
-rw-r--r-- radio    radio        2908 2011-07-06 08:58 modules.dep.bin
-rw-r--r-- radio    radio        1671 2011-07-06 08:58 modules.symbols.bin
lrwxrwxrwx radio    radio             2011-07-06 08:58 source -&gt; /data/EN3/freescale/i.MX536/i.MX53-QSB-Android-Release3.3/src/kernel_imx
-rw-r--r-- radio    radio         141 2011-07-06 08:58 modules.inputmap
-rw-r--r-- radio    radio       11595 2011-07-06 08:58 modules.builtin
-rw-r--r-- radio    radio          99 2011-07-06 08:58 modules.pcimap
-rw-r--r-- radio    radio        1072 2011-07-06 08:58 modules.symbols
drwxr-xr-x radio    radio             2011-07-06 08:58 kernel
-rw-r--r-- radio    radio       13189 2011-07-06 08:58 modules.builtin.bin
-rw-r--r-- radio    radio        3795 2011-07-06 08:58 modules.alias.bin
-rw-r--r-- radio    radio         189 2011-07-06 08:58 modules.usbmap
-rw-r--r-- radio    radio        1189 2011-07-06 08:58 modules.dep
-rw-r--r-- radio    radio        4404 2011-07-06 08:58 modules.alias
-rw-r--r-- radio    radio        1042 2011-07-06 08:58 modules.order
-rw-r--r-- radio    radio          69 2011-07-06 08:58 modules.ccwmap
-rw-r--r-- radio    radio          73 2011-07-06 08:58 modules.ieee1394map</pre>
</div>
<p>相关的*.ko驱动模块就在kernel目录下!</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-573-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-28 10:31</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-562-1.html</guid>
			<title>HTC 发布 Desire Z 和 Flyer 源代码</title>
			<author>admin</author>
			<description><![CDATA[<p><span style="font-weight: bold">据国外媒体报道，HTC近日发布了其部分最受欢迎的Android智能手机和新发布的Flyer平板电脑的源代码。公司在自己的<a href="http://developer.htc.com/">开发者页面</a>上贴出了 HTC&nbsp;Desire&nbsp;Z、Incredible&nbsp;S和Flyer平板电脑的2.6.35内核源代码，</span>开发者们可以籍此将Android操作系统输出到其 它HTC设备上，或者创建自定义内核。</p>
<p>此举主要是应消费者要求，之前有消费者在HTC的Facebook页面上抱怨没有提供相关设备，如Evo&nbsp;4G的源代码共享。用户 Gregory&nbsp;Marton写道，&ldquo;我很失望HTc违背了GNU公共许可，没有公布Evo&nbsp;4G操作系统源代码的更改部分。作为一家公司，不能说等它完 备了再发布出来，这就违背了你们签订的协议。既然在我的手机上发布了二进制代码，就需要公开其所有源代码，我们希望能看到改动的部分。&rdquo;</p>
<p>该协议要求任何修改代码的一方都需要将其公开。HTC在用户发帖之初并未作出回应，而对应产品Desire&nbsp;Z于11月在英国发布，Flyer则在5月发布。</p>
<p>Google支持的Android项目已经遵循GNU的公开协议GPL公布了手机OS的代码。</p>
<p>同时在5月，HTC还许诺对启动加载程序进行解锁，以便开发者在自己的手机上安装非官方的软件等。然而，截止到7月11日&ldquo;要安装新的软件仍然需要进行大 量测试，面临很多挑战。&rdquo;据悉，HTC&nbsp;Sensation&nbsp;4G和EVO&nbsp;3D上使用的启动加载程序，将于8月在美国成为首款获解锁的程序。</p>
<p>进入 HTC 开发者页面: <a href="http://developer.htc.com/" target="_blank">http://developer.htc.com/</a></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-562-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-20 09:32</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-561-1.html</guid>
			<title>updater-script语法说明及文件系统说明【更新命令和常识】</title>
			<author>admin</author>
			<description><![CDATA[<p>update-script脚本语法说明(根据android源代码中的recovery.c进行的定义):</p>
<p align="left"><font face="宋体">1.copy_dir</font></p>
<p align="left"><font face="宋体">语法：copy_dir &lt;src-dir&gt; &lt;dst-dir&gt; [&lt;timestamp&gt;]</font></p>
<p align="left"><font face="宋体">&lt;src-dir&gt;表示原文件夹，&lt;dst-dir&gt;表示目的文件夹，[&lt;timestamp&gt;]表示时间戳</font></p>
<p align="left"><font face="宋体">作用：将&lt;src-dir&gt;文件夹中的内容复制到&lt;dst-dir&gt;文件夹中。&lt;dst-dir&gt;文件夹中的原始内容将会保存不变，除非&lt;src-dir&gt;文件夹中有相同的内容，这样&lt;dst-dir&gt;中的内容将被覆盖</font></p>
<p align="left"><font face="宋体">举例：copy_dir PACKAGE:system SYSTEM:（将升级包中的system文件夹复制到手机中）</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">2.</font><font face="宋体">format</font></p>
<p align="left"><font face="宋体">语法：format &lt;root&gt;</font></p>
<p align="left"><font face="宋体">&lt;root&gt;表示要格式化的分区</font></p>
<p align="left"><font face="宋体">作用：格式化一个分区</font></p>
<p align="left"><font face="宋体">举例：format SYSTEM:（将手机/system分区完全格式化）</font></p>
<p align="left"><font face="宋体">注意：格式化之后的数据是不可以恢复的</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">3.</font><font face="宋体">delete</font></p>
<p align="left"><font face="宋体">语法：delete &lt;file1&gt; [... &lt;fileN&gt;]</font></p>
<p align="left"><font face="宋体">&lt;file1&gt; [... &lt;fileN&gt;]表示要格式化的文件，可以是多个文件用空格隔开</font></p>
<p align="left"><font face="宋体">作用：删除文件1，2到n</font></p>
<p align="left"><font face="宋体">举例：delete SYSTEM:app/Calculator.apk（删除手机systen文件夹中app中的Calculator.apk文件）</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">4.</font><font face="宋体">delete_recursive</font></p>
<p align="left"><font face="宋体">语法：</font><font face="宋体">delete_recursive &lt;file-or-dir1&gt; [... &lt;file-or-dirN&gt;]</font></p>
<p align="left"><font face="宋体">&lt;file-or-dir1&gt; [... &lt;file-or-dirN&gt;]表示要删除的文件或文件夹，可以使多个，中间用空格隔开</font></p>
<p align="left"><font face="宋体">作用：删除文件或者目录，删除目录时会将目录中的所有内容全部删除</font></p>
<p align="left"><font face="宋体">举例：delete_recursive DATA:dalvik-cache（删除/data/dalvik-cache文件夹下的所有内容）</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">5.</font><font face="宋体">run_program</font></p>
<p align="left"><font face="宋体">语法：</font><font face="宋体">run_program &lt;program-file&gt; [&lt;args&gt; ...]</font></p>
<p align="left"><font face="宋体">&lt;program-file&gt;表示要运行的程序，[&lt;args&gt; ...]表示运行程序所加的参数</font></p>
<p align="left"><font face="宋体">作用：运行终端程序</font></p>
<p align="left"><font face="宋体">举例：run_program PACKAGE:install_busybox.sh（执行升级包中的install_busybox.sh脚本）</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">6.</font><font face="宋体">set_perm</font></p>
<p align="left"><font face="宋体">语法：set_perm &lt;uid&gt; &lt;gid&gt; &lt;mode&gt; &lt;path&gt; [... &lt;pathN&gt;]</font></p>
<p align="left"><font face="宋体">&lt;uid&gt;表示用户名称，&lt;gid&gt;表示用户组名称，&lt;mode&gt;，表示权限模式，&lt;path&gt; [... &lt;pathN&gt;]表示文件路径，可以使多个，用空格隔开</font></p>
<p align="left"><font face="宋体">作用：设置单个文件或目录的所有者和权限，像linux中的chmod、chown或chgrp命令一样，只是集中在了一个命令当中</font></p>
<p align="left"><font face="宋体">举例：set_perm 0 2000 0550 SYSTEM:etc/init.goldfish.sh（设置手机system中的etc/init.goldfish.sh的用户为root，用户组为shell，所有者以及所属用户组成员可以进行读取和执行操作，其他用户无操作权限）</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">7.</font><font face="宋体">set_perm_recursive</font></p>
<p align="left"><font face="宋体">语法：</font><font face="宋体">set_perm_recursive &lt;uid&gt; &lt;gid&gt; &lt;dir-mode&gt; &lt;file-mode&gt; &lt;path&gt; [... &lt;pathN&gt;]</font></p>
<p align="left"><font face="宋体">&lt;uid&gt;表示用户，&lt;gid&gt;表示用户组，&lt;dir-mode&gt;表示文件夹的权限，&lt;file-mode&gt;表示文件的权限，&lt;path&gt; [... &lt;pathN&gt;]表示文件夹的路径，可以多个，用空格分开</font></p>
<p align="left"><font face="宋体">作用：设置文件夹及文件夹中的文件的所有者和用户组</font></p>
<p align="left"><font face="宋体">举例：set_perm_recursive 0 0 0755 0644 SYSTEM:app（设置手机system/app文件夹及其中文件的用户为root，用户组为root，app文件夹权限为所有者可以进行读、写、执行操作，其他用户可以进行读取和执行操作，其中的文件的权限为所有者可以进行读写操作，其他用户可以进行读取操作<strong>）</strong></font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">8.</font><font face="宋体">show_progress</font></p>
<p align="left"><font face="宋体">语法：show_progress &lt;fraction&gt; &lt;duration&gt;</font></p>
<p align="left"><font face="宋体">&lt;表示一个小部分&gt; &lt;表示一个小部分的持续时间&gt;</font></p>
<p align="left"><font face="宋体">作用：为下面进行的程序操作显示进度条，进度条会根据&lt;duration&gt;进行前进，当操作时间是确定的时候会更快</font></p>
<p align="left"><font face="宋体">举例：show_progress 0.1 0（显示进度条当操作完成后前进10%）</font></p>
<p>&nbsp;</p>
<p align="left"><font face="宋体">9.</font><font face="宋体">symlink</font></p>
<p align="left"><font face="宋体">语法：symlink &lt;link-target&gt; &lt;link-path&gt;</font></p>
<p align="left"><font face="宋体">&lt;link-target&gt;表示链接到的目标，&lt;link-path&gt;表示快捷方式的路径</font></p>
<p align="left"><font face="宋体">作用：相当于linux中的ln命令，将&lt;link-target&gt;在&lt;link-path&gt;处创建一个软链接，&lt;link-target&gt;的格式应为绝对路径（或许相对路径也可以），&lt;link-path&gt;为&ldquo;根目录：路径&rdquo;的形式</font></p>
<p align="left"><font face="宋体">举例：symlink /system/bin/su SYSTEM:xbin/su（在手机中system中的xbin中建立一个/system/bin/su的快捷方式）</font></p>
<p><br />
<br />
<br />
<font face="宋体">android文件系统和分区的定义方式（根据android的源代码的root.c获得）：</font></p>
<table class="t_table" cellspacing="0">
    <tbody>
        <tr>
            <td width="83"><font face="宋体">根目录</font></td>
            <td width="123"><font face="宋体">Linux块设备</font></td>
            <td width="57"><font face="宋体">挂载点</font></td>
            <td width="85"><font face="宋体">文件系统</font></td>
            <td width="76"><font face="宋体">大小</font></td>
            <td width="145"><font face="宋体">描述</font></td>
        </tr>
        <tr>
            <td width="83"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">BOOT:</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mtdblock[?] </font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">RAM</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">RAW</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">内核，内存，系统启动引导信息</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">DATA:</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mtdblock5</font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/data</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">yaffs2</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">91904kb</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">用户，系统设置，程序设置和应用程序，不包括</font></font></font><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">app2sd</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">CACHE</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mtdblock4</font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/cache</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">yaffs2</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">30720kb</font></font></font></td>
            <td width="145"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">OTA</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">方式下载的缓存，恢复和升级时的设置以及临时文件</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">MISC</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mtdblock[?]</font></font></font></td>
            <td width="57"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">无</font></font></font></td>
            <td width="85"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">未知</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">RAW</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">暂时未知</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">PACKAGE</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">相对于升级包而存在</font></font></font></td>
            <td width="57"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">无</font></font></font></td>
            <td width="85"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">相对于升级包存在的文件系统</font></font></font></td>
            <td width="76"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">不确定</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">升级包</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">RECOVERY</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mtdblock[?] </font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">RAM</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">RAW</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">恢复模式和系统升级所需要的内核和内存部分，与</font></font></font><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">BOOT</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">分区类似</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">SDCARD</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mmcblk0(p1) </font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/sdcard</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">fat32</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">32MB-32GB</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">内存卡，</font></font></font><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">update.zip</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">升级包通常放在这里</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">SYSTEM</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/dev/mtdblock3</font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/system</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">yaffs2</font></font></font></td>
            <td width="76"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">92160kb</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">系统分区，静态并且只读的</font></font></font></td>
        </tr>
        <tr>
            <td width="83"><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">TMP</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">：</font></font></font></td>
            <td width="123"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">无</font></font></font></td>
            <td width="57"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">/tmp</font></font></font></td>
            <td width="85"><font face="Calibri"><font color="#000000"><font style="font-size: 11pt">RAM</font></font></font></td>
            <td width="76"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">　</font></font></font></td>
            <td width="145"><font color="#000000"><font face="宋体"><font style="font-size: 11pt">标准的</font></font></font><font color="#000000"><font style="font-size: 11pt"><font face="Calibri">Linux</font></font></font><font color="#000000"><font face="宋体"><font style="font-size: 11pt">缓存文件系统</font></font></font></td>
        </tr>
    </tbody>
</table>
<p><br />
<br />
<font face="宋体"><strong>更新部分update-script命令：</strong></font></p>
<p align="left"><strong><font face="宋体">1.</font><font face="宋体">assert &lt;boolexpr&gt;</font></strong></p>
<p align="left"><font face="宋体"><strong>作用：此命令用来判断表达式boolexpr的正确与否，当表达式错误时程序终止执行</strong></font></p>
<p align="left"><font face="宋体"><strong>※此作用有待验证</strong></font></p>
<p>&nbsp;</p>
<p align="left"><strong><font face="宋体">2.</font><font face="宋体">write_radio_image &lt;src-image&gt;</font></strong></p>
<p align="left"><font face="宋体"><strong>作用：将基带部分的镜像写入手机，&lt;src-image&gt;表示镜像文件</strong></font></p>
<p align="left"><font face="宋体"><strong>举例：write_radio_image PACKAGE:radio.img</strong></font></p>
<p align="left"><font face="宋体"><br />
</font></p>
<p align="left"><strong><font face="宋体">3.</font><font face="宋体">write_hboot_image &lt;src-image&gt;</font></strong></p>
<p align="left"><font face="宋体"><strong>作用：将系统bootloader镜像写入手机，&lt;src-image&gt;表示镜像位置，此命令在直到在所有的程序安装结束之后才会起作用</strong></font></p>
<p align="left"><font face="宋体"><strong>举例：write_hboot_image PACKAGE:hboot.img</strong></font></p>
<p align="left"><font face="宋体"><br />
</font></p>
<p align="left"><strong><font face="宋体">4.</font><font face="宋体">write_raw_image &lt;src-image&gt; &lt;dest-root&gt;</font></strong></p>
<p align="left"><font face="宋体"><strong>作用：将boot.img写入手机，里面包含了内核和ram盘</strong></font></p>
<p align="left"><font face="宋体"><strong>举例：write_raw_image PACKAGE:boot.img BOOT:</strong></font></p>
<p align="left"><font face="宋体"><br />
</font></p>
<p align="left"><font face="宋体"><br />
</font></p>
<p><font face="宋体">
<p align="left"><font face="宋体"><strong>更新手机常识理解：</strong></font></p>
<p align="left"><font face="宋体"><strong>system:系统分区.我们刷机器一般就是刷的这个分区.</strong></font></p>
<p align="left"><font face="宋体"><strong>userdata:数据分区.</strong></font></p>
<p align="left"><font face="宋体"><strong>cache:缓存分区</strong></font></p>
<p align="left"><font face="宋体"><strong>recovery:Recovery分区，相当于建立在hboot与android系统间的一个中间层，如名字一般，主要用于系统调试和恢复。.</strong></font></p>
<p align="left"><font face="宋体"><strong>boot:存放内核和ramdisk的分区.</strong></font></p>
<p align="left"><font face="宋体"><strong>hboot:这个是SPL所在的分区，即 bootloader</strong></font></p>
<p align="left"><font face="宋体"><strong>splash1:这个就是开机第一屏幕了.</strong></font></p>
<p align="left"><font face="宋体"><strong>radio:这个是无线所在的分区.</strong></font></p>
<p align="left"><font face="宋体"><strong>misc:其他分区</strong></font></p>
</font></p>]]></description>
			<link>http://meisw.wdlinux.cn//show-561-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 17:16</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-558-1.html</guid>
			<title>Ubuntu10.0.4下CyanogenMod编译环境的搭建和可刷机文件的编译及打包（For HTC Dream）【转】</title>
			<author>admin</author>
			<description><![CDATA[<p><span>本文只是叙述</span><span>Ubuntu</span><span>下编译环境的搭建和ROM的编译过程，过程中可能会需要一些Ubuntu的常规操作技巧，在本文里就不详细介绍了，Ubuntu的新手可以通过谷歌学习一下，笔者也是新手，刚用没多久，谷歌一下并不难，另外由于源码和编译后生成的文件都比较大，如果想要折腾起来的话，Ubuntu的分区最好能有30G，20G的话一会就用完了，笔者之前也是分了20G，但不一会就空间不足了，故最后格掉分区，重新分了100G给Ubuntu。</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>编译环境的搭建</p>
<p>JDK安装<br />
a) JDK是Ubuntu下使用Android&nbsp;SDK，编译源代码等必备的软件包，首先我们现来装这个</p>
<p>b) 从sun官方网站下载最新版的JDK，一般是个.bin的文件，笔者下载的是jdk-6u20-linux-i586.bin（根据文件不同，命令的也会有所变化，大家在使用的时候要注意，主要是文件名和路径的变化）。</p>
<p>c) 由于JDK运行时会在当前目录下安装，所以在安装前，先把它移动到你想要安装的目录，比如笔者将其安装在/usr/lib/jvm/java目录下，如果你也想安装在相同目录，可以照着我下面的命令来做</p>
<p>代码：</p>
<p>sudo &ndash;i</p>
<p>cd /usr/lib</p>
<p>mkdir jvm</p>
<p>cd jvm</p>
<p>mkdir java</p>
<p>cd java</p>
<p>cp &ldquo;jdk-6u20-linux-i586.bin所在目录&ldquo;/jdk-6u20-linux-i586.bin /usr/lib/jvm/java</p>
<p>chmod u+x jdk-6u20-linux-i586.bin</p>
<p>jdk-6u20-linux-i586.bin</p>
<p>此时会出现JDK的安装提示说明，按着回车不放，提示说明会持续滚动，www.linuxidc.com直到屏幕提示需要输入Yes/NO，输入YES后，即开始安装，安装完成后提示按回车继续，按完回车后，安装即告成功</p>
<p>d) 与Windows不同，Ubuntu是没有注册表的，故安装完成后，我们需要把我们安装JDK的目录告诉系统，故在刚才的终端里执行如下命令（如果是新开的终端，没有执行过&ldquo;sudo -i&rdquo;,则需要在命令前+&ldquo;sudo&rdquo;获得权限）</p>
<p>代码：</p>
<p>gedit /etc/environment</p>
<p>此时在会弹出一个文本编辑器，里面显示</p>
<p>代码：</p>
<p>PATH＝&rdquo;&hellip;&hellip;&rdquo;</p>
<p>其中省略号部分是其默认的路径，这里我们不要动它，我们需要对这个进行一些修改，将我们的JDK安装路径写进去，告诉系统我们的JDK装在哪里，去哪里调用，故做如下修改：</p>
<p>i. 在原有的 PATH＝&rdquo;&hellip;&hellip;&rdquo; 的省略号里面添加：</p>
<p>代码：</p>
<p>PATH＝&rdquo;&hellip;&hellip;:/usr/lib/jvm/java/jdk1.6.0_20/bin&rdquo;</p>
<p>ii. 添加两行，输入如下内容：</p>
<p>代码：</p>
<p>CLASSPATH=.:/usr/lib/jvm/java/jdk1.6.0_20/lib</p>
<p>JAVA_HOME=/usr/lib/jvm/java/jdk1.6.0_20</p>
<p>最后生成如下形式：</p>
<p>代码：</p>
<p>PATH＝&rdquo;&hellip;&hellip;:/usr/lib/jvm/java/jdk1.6.0_20/bin&rdquo;</p>
<p>CLASSPATH=.:/usr/lib/jvm/java/jdk1.6.0_20/lib</p>
<p>JAVA_HOME=/usr/lib/jvm/java/jdk1.6.0_20</p>
<p>其中，省略号部分是文件原有内容，我们在后面新加了一部分内容和两个新行。修改完成后保存退出。</p>
<p>e)&nbsp;Ubuntu有可能会自带JDK或者安装多个JDK，此时需要将我们安装的这个设置为默认</p>
<p>i. 首先，将我们的JDK安装目录加入到JDK的选择菜单，执行如下代码：</p>
<p>代码：</p>
<p>update-alternatives &ndash;install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_12/bin/java 300</p>
<p>update-alternatives &ndash;install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_12/bin/javac 300</p>
<p>ii. 其次，通过命令来选择默认的JDK，执行如下代码：</p>
<p>代码：</p>
<p>update-alternatives &ndash;config java</p>
<p>iii. 最后，再来检查一下系统当前的JDK版本，输入以下代码查看：</p>
<p>代码：</p>
<p>java -version</p>
<p>f) 至此，JDK即告安装成功。</p>
<p>Android&nbsp;SDK安装<br />
a) 既然是做rom，那肯定需要调试和测试的工具，Android的官方SDK同样提供官方版本，我们直接下载安装即可。</p>
<p>b) 去谷歌的官网下载最新的SDK版本，前几天刚跟新了支持2.2的r6，不过SDK的官方网站在墙后，我们只能FQ过去下载，这点比较无奈。官方提供Windows，Mac OS X，Linux三个版本，毫无疑问，我们需要下载Linux的版本。</p>
<p>c) SDK不需要安装，直接解压就可以使用。建议放在主目录下，方便调用。</p>
<p>d) 为了方便adb命令的使用，我们同样需要将adb命令所在的目录添加到系统环境变量中去，这样，在任何目录下都能直接调用adb，不需要现cd到SDK目录，这样会比较方便，实现方法如下：</p>
<p>代码：</p>
<p>sudo gedit ~/.bashrc</p>
<p>用文本编辑器打开.bashrc文件，然后在最后添加一行：</p>
<p>代码：</p>
<p>export PATH=${PATH}:&lt;你sdk的目录&gt;/tools</p>
<p>这里的需要将你sdk的安装目录添写进去，保存后即可。</p>
<p>e) 把手机连上usb，然后在终端中输入：</p>
<p>代码：</p>
<p>adb devices</p>
<p>会列出所有连接在电脑上的Android设备，如果看到一串数字和字母的序列号的显示的话，即表示SDK安装成功。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>软件安装<br />
a) 配置源，更新源之类的问题就不再说了，直接说我们需要的软件，从同步源码到编译rom我们总计需要用到以下几个软件，有部分软件在我们更新过程中可能已经自动安装了，但这不影响我们工作，我把所有需要用到的程序列了出来：</p>
<p>? git-core</p>
<p>? gnupg</p>
<p>? flex</p>
<p>? bison</p>
<p>&nbsp;</p>
<p>? gperf</p>
<table border="0" width="97%" align="center">
    <tbody>
        <tr>
            <td style="font-size: 12px" colspan="3">&nbsp;</td>
        </tr>
    </tbody>
</table>
<p>&nbsp;</p>
<p>? libsdl-dev</p>
<p>? libesd0-dev</p>
<p>? libwxgtk2.6-dev</p>
<p>? build-essential</p>
<p>? zip</p>
<p>? curl</p>
<p>? libncurses5-dev</p>
<p>? zlib1g-dev</p>
<p>? valgrind</p>
<p>? libreadline5-dev</p>
<p>b) 以上这些程序均通过apt-get命令来安装，比如要安装git-core软件，我们通过输入如下命令来实现：</p>
<p>代码：</p>
<p>sudo apt-get install git-core</p>
<p>c) 其它软件的安装过程类似，替换掉最后的软件名称即可。</p>
<p>d) 安装完所有软件后，编译CyanogenMod所需要的所有环境均搭建完成了。</p>
<p>&nbsp;</p>
<p>源码同步<br />
repo的安装<br />
a) CyanogenMod的源码地址是http://github.com/cyanogen/android，你可以通过网址右上角的Download Source来下载源码。不过我们并不推荐这种方式下载，因为源码的变化较为频繁，每次一旦源码有变化，我们就需要重新下载完整的源码包，既费时又费力，效率也很低，故推荐通过repo同步的方式来做，在同步过程中，仅会同步源码的变化部分，效率较高。</p>
<p>b) Repo的安装</p>
<p>i. repo的安装比较方便，之需要下载一个文件，并设置成可执行权限，并添加到系统环境中去即可，具体命令如下：</p>
<p>代码：</p>
<p>cd ~</p>
<p>mkdir bin</p>
<p>在你的home根目录下创建名为bin的文件夹。</p>
<p>代码：</p>
<p>sudo gedit ~./bashrc</p>
<p>打开你的环境变量配置文件，在最后加一行：</p>
<p>代码：</p>
<p>export PATH=$PATH:~/bin</p>
<p>修改后保存文件退出，关闭终端，重新打开一个终端，输入如下命令验证路径是否成功添加到环境变量中去了：</p>
<p>代码：</p>
<p>echo $PATH</p>
<p>确认完后，开始安装repo，执行如下命令：</p>
<p>代码：</p>
<p>curl http://Android.git.kernel.org/repo &gt; ~/bin/repo<br />
chmod a+x ~/bin/repo</p>
<p>通过curl命令将repo下载到bin中，并将其权限修改为可执行文件，至此repo的安装结束。</p>
<p>Repo的配置和同步<br />
i. 在主目录下新建一个文件夹，作为源码的存放目录</p>
<p>代码：</p>
<p>cd ~</p>
<p>mkdir cyanogenmod</p>
<p>cd cyanogenmod</p>
<p>ii. 在cyanogenmod目录执行repo命令，设定需要同步的源码内容：</p>
<p>代码：</p>
<p>repo init -u git://github.com/cyanogen/Android.git -b eclair</p>
<p>网址即为cyanogenmod的地址，-b表示我们选择需要同步的分支，cyanogenmod有不少分支，比如dount，eclair，以后还会有froyo，我们目前需要编译的是2.1，即eclair，则通过-b eclair来选择2.1的分支。</p>
<p>iii. 在配置过程中，会让你选择名字和邮箱，这个会显示在你最后编译出来的rom的基础信息里，可以选择你喜欢的来写</p>
<p>iv. 配置完成后，就可以开始同步源码了:</p>
<p>代码：</p>
<p>repo sync</p>
<p>同步的过程会比较长，建议在晚上睡觉前开始同步，一般早上起来就能好了。</p>
<p>编译环境的设置<br />
编译环境的建立<br />
a) 同步玩源码后，首先需要建立编译环境，CM的源码把这些命令都写成了脚本，我们只需运行相应的脚本即可，首先，先cd到源码的根目录，然后执行如下命令：</p>
<p>代码：</p>
<p>./build/envsetup.sh</p>
<p>执行后，屏幕上会显示：</p>
<p>代码：</p>
<p>including vendor/cyanogen/vendorsetup.sh</p>
<p>此时，编译环境设置成功。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>专属文件的提取<br />
a) 虽然Android系统是开源的，但有部分Dream的专属文件是不开源的，所以并不包含在源码树中。但如果希望rom能在Dream真机上运行，又需要这些文件，所以需要将这些文件提取出来，在CM中，这个操作比较简单，Steve已经给我们做好脚本了。</p>
<p>b) 首先你要确保安装成功了上述所有软件，然后，将Dream通过usb连接到电脑上。</p>
<p>c) cd到源码的/vendor/htc/dream_sapphire目录，然后执行脚本：</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>代码：</p>
<p>./extract-files.sh</p>
<p>d) 这个操作会调用adb命令，从你的手机里pull所需要的专属文件到vendor目录。</p>
<p>编译文件的修改<br />
a) 默认的编译过程包含了所有的语言和程序，但其实我们并不需要这些，可以通过编译文件的修改来定义需要输出的语言和软件</p>
<p>b) 打开/vendor/cyanogen/products 目录下的cyanogen.mk文件，里面定义了要输出的软件和语言，对于不需要的软件，可以直接删除。但不建议在这里修改，可以从最后的输出目录里删除不需要的，直接在这里改容易出错</p>
<p>c) 在文件的最后，有一行&rdquo;PRODUCT_LOCALES&rdquo;,这里就包含了rom支持的语言类型，默认有几十种，编译出来后，软件会比较大，一般我们只需要保留其中的常用语言即可，笔者选择保留了en_US,zh_CN和zh_TW这三种语言，编译出来的软件就小了很多。</p>
<p>Kernel编译<br />
1. kernel是Android的核心，也是最重要的部分，虽然CM源码中自带了编译完成的kernel，但既然是自主编译，那你肯定想改改kernel的信息吧，比如kernel的名字，比如打上BFS补丁、超频补丁等等，那你就需要自己来编译kernel了。</p>
<p>2. 编译kernel也非常简单，首先你需要一个kernel的配置文件，CM提供了现成的，直接去/kernel-msm/arch/arm/configs 目录里找，有个配置文件叫cyanogen_msm_defconfig，这个就是我们需要的配额之文件了（如果是给Nexus编译kernel的话，需要选择cyanogen_mahimahi_defconfig）。将它复制到/kernel-msm 的根目录，然后重命名为 .config</p>
<p>3. 用文本编辑器打开.config,其中有一条参数为CONFIG_LOCALVERSION=&rdquo;-cyanogenmod&rdquo;，这里即为kernel编译完成后显示的名字，可以把cyanogenmod改成任意你喜欢的名字。</p>
<p>4. 设置完成后，就可以开始编译了。先cd到/kernel-msm目录，然后执行如下命令</p>
<p>代码：</p>
<p>export ARCH=arm</p>
<p>export CROSS_COMPILE=arm-eabi-</p>
<p>export PATH=$PATH:~/cyanogenmod/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin</p>
<p>这些命令定义了编译kernel时所需要用到的环境和设置。注意第三条命令在输入的时候，路径要和自己实际安放源码的路径一致，另外，每次编译kernel前，都需要重新输入这三个命令。</p>
<p>5. 命令输入完后，就可以开始make了：</p>
<p>代码：</p>
<p>make -j3</p>
<p>make就是开始编译的命令，后面的参数-j3表示用于编译的cpu核心数量，一般是cpu核心数量+1，比如双核cpu，就用-j3这个参数。</p>
<p>6. 编译过程根据配置不同而有所不同，笔者笔记本用的T6400是双核2G的，一般编译kernel的时间在10分钟内。编译后的kernel生成在/kernel-msm/arch/arm/boot/目录下，名字叫zImage</p>
<p>CyanogenMod编译<br />
1. 编译完kernel后，就可以开始编译主菜CM了。编译前需要先生成一个buildspec.mk文件，来定义需要编译的rom的基本信息。先cd到源码的根目录，新建一个空文件，名字叫buildspec.mk，并用记事本打开，输入如下信息：</p>
<p>代码：</p>
<p>TARGET_PRODUCT:=cyanogen_dream_sapphire</p>
<p>TARGET_BUILD_VARIANT:=eng</p>
<p>TARGET_BUILD_TYPE:=release</p>
<p>TARGET_PREBUILT_KERNEL:=kernel/arch/arm/boot/zImage</p>
<p>a) 第一条命令表示需要编译的rom的选择，我们现在编译的是G1的rom，故选择cyanogen_dream_sapphire；</p>
<p>b) 第二条命令表示编译的rom的种类，有eng和userdebug两个类型可选，我们当然选在eng；</p>
<p>c) 第三个命令表示编译的rom的类型，我们选择release</p>
<p>d) 第四个命令表示基于哪个kernel来编译rom，如果不设这个命令，则会基于自带的kernel来编译，既然我们自己编译了kernel，那当然用我们自己的，故设置了已经编译好的kernel的目录，供make过程调用。</p>
<p>2. buildspec.mk文件建立好后，就可以开始编译rom了，cd到源码根目录，然后使用命令：</p>
<p>代码：</p>
<p>make -j3</p>
<p>开始编译源码，源码的编译过程会比较长，试配置不同，需要的时间也不一样，笔者的T6400编译完整的CM差不多需要2个小时。</p>
<p>3. 编译完成后，我们的成品就在/out/target/product目录中，里面包含了system.img,recovery.img,boot.img和system文件夹等，到这里，有点制作rom经验的朋友就不需要我再多说了吧。可以在fastboot里直接刷system.img,和boot.img；也可以将system文件夹和boot.img打包成zip包，添加更新脚本并签名，通过recovery刷到机器里，至此，我们自己编译的CyanogenMod for HTC Dream就大功告成了。</p>
<p>-----------------------</p>
<div class="comment_content">1.&nbsp; 查看Android源码的各个版本分支，首先下载 android.git.kernel.org/platform/manifest.git ，得到清单文件后执行git branch -a 即可，该命令执行后会查看清单中的packed-refs。</div>
<div class="comment_content">&nbsp;</div>
<div class="comment_content">
<div class="comment_content">$ repo sync -j 10<br />
多线程同步下载</div>
<div class="comment_content">&nbsp;</div>
<div class="comment_content">-----------------------------</div>
<div class="comment_content">
<div class="comment_content">Android带给我们的不仅仅是优秀的触控，漂亮的界面，快速的事件处理，让我们爱不释手!最重要的，它是开源的，任何android的爱好者都可以在它许可的权限范围内对android的源码做修改，移植，定制，以满足自己的需求。由此，目前非官方的第三方ROM受到了众多手机玩家以及android开发者的热爱，他们或者厌倦了原有的桌面程序，想换换口味，或者是为了优化手机处理能力，去掉一些厂家自带的应用程序。而本文，将引领大家尝试亲自手动编译android的源代码，并且将它移植到自己心爱的手机上。<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 本文以CyanogenMod团队优化过的基于android2.1的源代码讲述如何将它移植到htc legend(g6)手机上。<br />
<br />
&nbsp;&nbsp; 个人认为CyanogenMod团队是目前非官方ROM开发中非常优秀的，它们制作的android源代码不仅仅可以移植到htc dream,margic,legend,hero，还可以移植到moto xt701,xt702等手机上，实属不容易。<br />
<br />
&nbsp;&nbsp; 成功将android2.1移植到手机上，需经过以下几个步骤：<br />
<br />
&nbsp;&nbsp; 一，准备好android2.1源码编译环境以及手机USB调试环境。<br />
<br />
&nbsp;&nbsp; 二，将手机上硬件驱动程序以及相关的配置文件通过ADB命令保存好。<br />
<br />
&nbsp;&nbsp; 三，针对不同的手机机型，制作相应的vendor配置文件。<br />
<br />
&nbsp;&nbsp; 四，编译源码。<br />
<br />
&nbsp;&nbsp; 五，通过手机提供的bootloader刷机或者直接以recovery的方式更新ROM。<br />
<br />
&nbsp;&nbsp; 在以上五个步骤中，其中最难处理的便是第2个步骤，这个步骤需要熟悉每个手机机型的硬件参数，并且能够在手机上找到相关的驱动程序以及了解他们如何配置。而CyanogenMod团队公布的源码当中，己经将相关的工作做好了，编译源码之前仅仅需要执行相应的shell命令，便可顺利的下载相应的手机驱动程序以及配置文件。<br />
<br />
下面是移植步骤，供参考：<br />
<br />
&nbsp;&nbsp; 一，首先需要下载CyanogenMod 5.0.8的源码：<br />
<br />
&nbsp;&nbsp; $ mkdir android-cm5<br />
<br />
&nbsp;&nbsp; $ cd android-cm5<br />
<br />
&nbsp;&nbsp; $ repo init -u git://github.com/CyanogenMod/android.git -b eclair <br />
<br />
&nbsp;&nbsp; $ repo sync<br />
<br />
&nbsp; 二，下载CyanogenMod需要的一些共同文件，如果想最终版本中不需要这些APK，也可以通过配置/vendor/cyanogen/cyanogen.mk文件将这些需要的APK COPY命令注释掉。<br />
<br />
&nbsp; $ cd vendor/cyanogen/<br />
<br />
&nbsp; $ ./get-rommanager&nbsp;&nbsp; #下载一个RomManager.apk包，主要是刷ROM用的。我没用过。<br />
<br />
&nbsp; $ ./get-google-files #其它的一些google开发的android apk包，我也没有用过!<br />
<br />
&nbsp; 三，下载针对htc legend(g6)的vendor.<br />
<br />
&nbsp; $ cd ../../vendor/htc<br />
<br />
&nbsp; $ git clone git://github.com/aleho/android_vendor_htc_legend.git #下载针对htc legend(g6)手机的vendor，里面包括相关的配置参数，以及从手机上下载驱动程序的SHELL命令。<br />
<br />
&nbsp; $ mv android_vendor_htc_legend/ legend<br />
<br />
&nbsp; $ cd legend<br />
<br />
&nbsp; $ ./extract-files.sh&nbsp; #确保这个命令执行将你的手机连接好电脑并且开了手机USB调试，adb命令可以连接手机。这个过程主要是下载htc legend(g6)驱动程序以及配置文件。<br />
<br />
&nbsp; 四，针对CyanogenMod 5.0.8源码打上htc legend(g6)的补丁包，这个补丁包主要是wifi和触摸屏的，如果不做，触摸屏将无法触摸以及wifi功能无法启动。可参数地址：<br />
<br />
&nbsp;&nbsp; http://forum.xda-developers.com/archive/index.php/t-702776.html<br />
<br />
五，好了，根据自己的爱好，定制自己的一些vendor参数。然后make otapackage便可编译recovery方式的htc legend(g6)包。</div>
</div>
</div>]]></description>
			<link>http://meisw.wdlinux.cn//show-558-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:51</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-557-1.html</guid>
			<title>[转]下载并编译Android 2.3源码</title>
			<author>admin</author>
			<description><![CDATA[<p>原文<a href="http://www.blogjava.net/TiGERTiAN/archive/2011/01/20/343283.html" target="_blank">http://www.blogjava.net/TiGERTiAN/archive/2011/01/20/343283.html</a> <br />
<br />
前几天下载了Android 2.3.1的源代码并在Ubuntu 10.04(32位)上编译通过。这篇文章简要记录了下载、编译的过程。 <br />
<br />
关于搭建Android开发环境的文章已经有很多，本文只简要介绍一下，做为备忘。 <br />
<br />
[ 编译前的准备 ] <br />
<br />
这一步安装获取源代码以及编译所需要的软件，使用如下命令： <br />
<br />
$ sudo aptitude install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev <br />
另外，参考别人编译Android 2.3的经验，安装了下列软件包： <br />
<br />
$ sudo apt-get install lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6 <br />
虽然Android官方网站上讲不支持Java 6，不过我使用Java 6也可以编译通过，所以在这里Easwy安装的是Java 6。首先去掉/etc/apt/sources.list中这两行的注释，使能Java 6源： <br />
<br />
deb http://archive.canonical.com/ubuntu lucid partner <br />
deb-src http://archive.canonical.com/ubuntu lucid partner <br />
然后安装Java 6 JDK： <br />
<br />
$ sudo aptitude install sun-java6-jdk <br />
接下来下载repo工具，这是Google提供的一个Python脚本，方便管理多个Git版本库： <br />
<br />
$ cd ~ <br />
$ mkdir bin <br />
$ curl http://android.git.kernel.org/repo &gt;~/bin/repo <br />
$ chmod a+x ~/bin/repo <br />
记得把repo加到你的路径中，方便以后使用。编辑~/.bashrc，加入下面一行： <br />
<br />
PATH=$PATH:~/bin <br />
export PATH <br />
然后用命令. ~/.bashrc，以后就可以直接使用repo命令了。 <br />
<br />
接下来获取Android 2.3.1的源代码： <br />
<br />
$ mkdir mydroid <br />
$ cd mydroid <br />
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b android-2.3.1_r1 <br />
$ repo sync <br />
[ 编译Android ] <br />
<br />
接下来开始编译： <br />
<br />
$ make -j`grep '^processor' /proc/cpuinfo | wc -l` <br />
上面的命令中，-j参数告诉make启动多个并行任务进行编译，在支持多核的CPU上能加快编译速度。如果你知道你CPU是几核的，可以直接把这部分替换成-j2(双核)。 <br />
<br />
我在编译的过程中遇到下面的错误： <br />
<br />
************************************************************ <br />
<br />
You are attempting to build on a 32-bit system. <br />
<br />
Only 64-bit build environments are supported beyond froyo/2.2. <br />
<br />
************************************************************ <br />
<br />
这是因为在Makefile中检测了CPU的字长。我直接把build/core/main.mk中下面的话注释掉： <br />
<br />
#ifneq (64,$(findstring 64,$(build_arch))) <br />
#$(warning ************************************************************) <br />
#$(warning You are attempting to build on a 32-bit system.) <br />
#$(warning Only 64-bit build environments are supported beyond froyo/2.2.) <br />
#$(warning ************************************************************) <br />
#$(error stop) <br />
#endif <br />
接下来又遇到下面的错误： <br />
<br />
Docs droiddoc: out/target/common/docs/api-stubs <br />
<br />
Could not load &lsquo;clearsilver-jni&rsquo; <br />
<br />
java.library.path = out/host/linux-x86/lib <br />
<br />
make: *** [out/target/common/docs/api-stubs-timestamp] Error 45 <br />
<br />
make: *** Waiting for unfinished jobs&hellip;. <br />
<br />
Could not load &lsquo;clearsilver-jni&rsquo; <br />
<br />
java.library.path = out/host/linux-x86/lib <br />
<br />
make: *** [out/target/common/docs/doc-comment-check-timestamp] Error 45 <br />
<br />
这是由于clearsilver在编译时如果检测到使用Java JDK 6，就使用64位编译。要避开此错误，需要修改下面四个文件： <br />
<br />
external/clearsilver/cgi/Android.mk <br />
external/clearsilver/java-jni/Android.mk <br />
external/clearsilver/util/Android.mk <br />
external/clearsilver/cs/Android.mk <br />
把这四个Makefile中的下列语句注掉即可： <br />
<br />
# This forces a 64-bit build for Java6 <br />
# Comment by Easwy <br />
# LOCAL_CFLAGS += -m64 <br />
# LOCAL_LDFLAGS += -m64 <br />
然后在external/clearsilver目录中执行一下make clean，然后回到项目根目录，继续make即可。 <br />
<br />
当编译完成时，生成的image文件放在out/target/product/generic目录中。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-557-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:47</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-555-1.html</guid>
			<title>Android 应用程序快速启动的秘诀</title>
			<author>admin</author>
			<description><![CDATA[<p>Android系统框架和上层应用是类java(不是正统的sun java)开发的，实现了自己的java虚拟机dalvik，既然用java虚拟机和java开发，一般都会认为效率低下。其实不然，在基本主流的智能手机的软件平台上，android的执行速度是最快的。 <br />
<br />
<br />
<br />
那么android效率为什么这么的高呢?特别是一个应用程序的启动时间很短，本文主要从以下个八方面进行分析： <br />
<br />
<br />
<br />
1、 资源文件的优化读取。 <br />
<br />
<br />
我们知道android在UI开发时有个很大的好处是xml文件来描述UI，这样有个好处是只要修改UI不用修改代码就可以修改界面的布局、显示风格和字体大小等。界面定义变得灵活方便。xml配置UI在qtopia运用也有但是这么强大并且也不广泛，因为xml文件有个不足是解析xml的效率很低。 <br />
<br />
<br />
Android是怎么做的呢? <br />
<br />
<br />
Android在编译的时候就把xml文件进行了优化，android应用程序在解析时变得非常的高效。我们看到apk文件解压后会有个优化过的资源文件。 <br />
<br />
<br />
<br />
2、 安装时进行优化dex文件 <br />
<br />
<br />
Android的应用程序都打包成一个apk文件，实际上就是一个zip文件。系统第一次起来或应用程序第一次安装时，系统就把apk文件解压了，把可执行文件dex优化成odex文件并放在/data/dalvik-cache目录下。优化后的dex文件启动速度会加快。这解释了为什么 android系统第一次启动是比较慢，以后起来很快了。 <br />
<br />
<br />
可能有人会问：为什么不在编译时直接优化呢?第⑤项会回答这个问题。 <br />
<br />
<br />
<br />
3、 制作数据库 <br />
<br />
<br />
Android的图形应用是加载整个sd卡内的所有图像的，但是为什么很快呢?其实android提前把数据做成了数据库，所以不用每次扫描整个这个sd卡，大大加快了启动速度。 <br />
<br />
<br />
<br />
4、 高效的虚拟机 <br />
<br />
<br />
Android是基于类java虚拟机dalvik，一般的java虚拟机是基于栈的，而dalvik是基于寄存器的。实事求是说我对两者的区别了解不是很深入，不过网上有专门的相关文论进行分析。我的简单理解是栈的实现方式相对容易，相关数据是在内存中的栈里，而操作寄存器里数据的速度明显快与内存里的数据处理。 <br />
<br />
<br />
<br />
5、 充分挖掘CPU的性能 <br />
<br />
<br />
Android刚出来的时候虽然支持arm cpu，实际上只支持armv5te的指令集的，因为android系统专门为armv5te 进行了优化，充分利用armv5te的执行流水线来提高执行的效率，这也是在500M的三星2440运行效果不是很好，而在200M的omap cpu上运行比较流畅的原因了，所以在最新的代码中有专门针对x86和armv4的优化部分。 <br />
<br />
<br />
<br />
6、 优化和裁剪的libc库 <br />
<br />
<br />
Libc库几乎是所以库和程序的基础，但是android没有直接利用libc库，而是自己开发了一个库：bionic，它实现了libc库的绝大多数的函数并根据平台进行了优化，但是有系统很少用并且消耗资源的少数函数是不支持的。它只有几百k，节省了空间同时也提高了执行效率。实际上体现了 20-80原则，抓住少数重要的适当舍弃不必要的。 <br />
<br />
<br />
<br />
7、 充分利用linux系统特性 <br />
<br />
<br />
分析过linux内核的朋友知道，linux fork一个新的进程是非常高效的，利用了COW机制。Android是每个进程是个独立的虚拟机(听说这么设计是为安全考虑，某个时候进程崩溃了不会影响这个系统和其他进程。)android里每个进程都是基于虚拟机的，并且也要加载基本的库，实际上这些都是共享。所以android启动一个新的程序实际上并不消耗很多的内存和cpu资源。 <br />
<br />
<br />
同时android在后台有个empty process运行，实际上就是运行一个虚拟机，当要启动一个应用时就直接在其上继续运行，qtopia也有这个机制。 <br />
<br />
<br />
Android系统在开机流程中：启动虚拟机&mdash;》启动system server ?》启动launcher。当初分析代码时疑惑为什么不直接启动system server?(qtopia就是直接启动server)，实际上也利用了linux的这个特性。 <br />
<br />
<br />
这个特性说的比较简略，不过要真的把他解释清楚可能需要很大的篇幅。 <br />
<br />
<br />
<br />
<br />
8、 高效的paint机制 <br />
<br />
<br />
这个特性可能跟启动关系不大，但是也是android高效的特性之一。界面变化时大部分实际上不是全屏内容变化的，只是局部变化，android 会根据变化的内容只是跟新局部的内容，也提高了效率。这个也提醒我们在开发应用程序时，重载paint方法时尽量不要paint全屏内容</p>
<p>&nbsp;</p>
<p>转</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-555-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:43</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-553-1.html</guid>
			<title>Android权限之三共享UID和签名 .</title>
			<author>admin</author>
			<description><![CDATA[<p>共享UID</p>
<p>安装在设备中的每一个Android包文件（.apk）都会被分配到一个属于自己的统一的Linux用户ID，并且为它创建一个沙箱，以防止影响其他应用程序（或者其他应用程序影响它）。用户ID 在应用程序安装到设备中时被分配，并且在这个设备中保持它的永久性。</p>
<p>通过Shared User id,拥有同一个User id的多个APK可以配置成运行在同一个进程中.所以默认就是可以互相访问任意数据. 也可以配置成运行成不同的进程, 同时可以访问其他APK的数据目录下的数据库和文件.就像访问本程序的数据一样.</p>
<p>对于一个APK来说，如果要使用某个共享UID的话，必须做三步：</p>
<p>1、在Manifest节点中增加android:sharedUserId属性。</p>
<p>2、在Android.mk中增加LOCAL_CERTIFICATE的定义。</p>
<p>如果增加了上面的属性但没有定义与之对应的LOCAL_CERTIFICATE的话，APK是安装不上去的。提示错误是：Package com.test.MyTest has no signatures that match those in shared user android.uid.system; ignoring!也就是说，仅有相同签名和相同sharedUserID标签的两个应用程序签名都会被分配相同的用户ID。例如所有和media/download相关的APK都使用android.media作为sharedUserId的话，那么它们必须有相同的签名media。</p>
<p>3、把APK的源码放到packages/apps/目录下，用mm进行编译。</p>
<p>举例说明一下。</p>
<p>系统中所有使用android.uid.system作为共享UID的APK，都会首先在manifest节点中增加android:sharedUserId=&quot;android.uid.system&quot;，然后在Android.mk中增加LOCAL_CERTIFICATE := platform。可以参见Settings等</p>
<p>系统中所有使用android.uid.shared作为共享UID的APK，都会在manifest节点中增加android:sharedUserId=&quot;android.uid.shared&quot;，然后在Android.mk中增加LOCAL_CERTIFICATE := shared。可以参见Launcher等</p>
<p>系统中所有使用android.media作为共享UID的APK，都会在manifest节点中增加android:sharedUserId=&quot;android.media&quot;，然后在Android.mk中增加LOCAL_CERTIFICATE := media。可以参见Gallery等。</p>
<p>&nbsp;</p>
<p>另外，应用创建的任何文件都会被赋予应用的用户标识，并且正常情况下不能被其他包访问。当通过getSharedPreferences（String，int）、openFileOutput（String、int）或者openOrCreate Database（String、int、SQLiteDatabase.CursorFactory）创建一个新文件时，开发者可以同时或分别使用MODE_WORLD_READABLE和MODE_WORLD_RITEABLE标志允许其他包读/写此文件。当设置了这些标志后，这个文件仍然属于自己的应用程序，但是它的全局读/写和读/写权限已经设置，所以其他任何应用程序可以看到它。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>关于签名：</p>
<p>&nbsp;</p>
<p>build/target/product/security目录中有四组默认签名供Android.mk在编译APK使用：</p>
<p>1、testkey：普通APK，默认情况下使用。</p>
<p>2、platform：该APK完成一些系统的核心功能。经过对系统中存在的文件夹的访问测试，这种方式编译出来的APK所在进程的UID为system。</p>
<p>3、shared：该APK需要和home/contacts进程共享数据。</p>
<p>4、media：该APK是media/download系统中的一环。</p>
<p>应用程序的Android.mk中有一个LOCAL_CERTIFICATE字段，由它指定用哪个key签名，未指定的默认用testkey.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>参考文档：</p>
<p>&nbsp;</p>
<p>Android中如何修改系统时间（应用程序获得系统权限）</p>
<p>http://blog.csdn.net/liujian885/archive/2010/03/22/5404834.aspx</p>
<p>Android-sharedUserId数据权限</p>
<p>http://wallage.blog.163.com/blog/static/17389624201011010539408/</p>
<p>Runtime.exec权限问题</p>
<p>http://blog.csdn.net/yihua0001/archive/2010/07/23/5758980.aspx</p>
<p>关于签名</p>
<p>http://blog.csdn.net/duandianGG/archive/2010/07/21/5752568.aspx</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-553-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:19</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-552-1.html</guid>
			<title>Android中如何修改系统时间（应用程序获得系统权限） .</title>
			<author>admin</author>
			<description><![CDATA[<p>在 android 的API中有提供 SystemClock.setCurrentTimeMillis()函数来修改系统时间，可惜无论你怎么调用这个函数都是没用的，无论模拟器还是真机，在logcat中总会得到&quot;Unable to open alarm driver: Permission denied &quot;.这个函数需要root权限或者运行与系统进程中才可以用。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 本来以为就没有办法在应用程序这一层改系统时间了，后来在网上搜了好久，知道这个目的还是可以达到的。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第一个方法简单点，不过需要在Android系统源码的环境下用make来编译：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 在应用程序的AndroidManifest.xml中的manifest节点中加入android:sharedUserId=&quot;android.uid.system&quot;这个属性。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 修改Android.mk文件，加入LOCAL_CERTIFICATE := platform这一行</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. 使用mm命令来编译，生成的apk就有修改系统时间的权限了。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第二个方法麻烦点，不过不用开虚拟机跑到源码环境下用make来编译：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 同上，加入android:sharedUserId=&quot;android.uid.system&quot;这个属性。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 使用eclipse编译出apk文件，但是这个apk文件是不能用的。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. 用压缩软件打开apk文件，删掉META-INF目录下的CERT.SF和CERT.RSA两个文件。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4. 使用目标系统的platform密钥来重新给apk文件签名。这步比较麻烦，首先找到密钥文件，在我的Android源码目录中的位置是&quot;build/target/product/security&quot;，下面的platform.pk8和platform.x509.pem两个文件。然后用Android提供的Signapk工具来签名，signapk的源代码是在&quot;build/tools/signapk&quot;下，用法为&quot;signapk platform.x509.pem platform.pk8 input.apk output.apk&quot;，文件名最好使用绝对路径防止找不到，也可以修改源代码直接使用。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样最后得到的apk和第一个方法是一样的。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最后解释一下原理，首先加入android:sharedUserId=&quot;android.uid.system&quot;这个属性。通过Shared User id,拥有同一个User id的多个APK可以配置成运行在同一个进程中。那么把程序的UID配成android.uid.system，也就是要让程序运行在系统进程中，这样就有权限来修改系统时间了。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只是加入UID还不够，如果这时候安装APK的话发现无法安装，提示签名不符，原因是程序想要运行在系统进程中还要有目标系统的platform key，就是上面第二个方法提到的platform.pk8和platform.x509.pem两个文件。用这两个key签名后apk才真正可以放入系统进程中。第一个方法中加入LOCAL_CERTIFICATE := platform其实就是用这两个key来签名。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这也有一个问题，就是这样生成的程序只有在原始的Android系统或者是自己编译的系统中才可以用，因为这样的系统才可以拿到platform.pk8和platform.x509.pem两个文件。要是别家公司做的Android上连安装都安装不了。试试原始的Android中的key来签名，程序在模拟器上运行OK，不过放到G3上安装直接提示&quot;Package ... has no signatures that match those in shared user android.uid.system&quot;，这样也是保护了系统的安全。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最最后还说下，这个android:sharedUserId属性不只可以把apk放到系统进程中，也可以配置多个APK运行在一个进程中，这样可以共享数据，应该会很有用的。</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-552-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:19</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-551-1.html</guid>
			<title>关于adbd进程的ROOT权限问题</title>
			<author>admin</author>
			<description><![CDATA[<p>adbd源码位于system/core/adb/目录下，可执行文件位于/sbin/adbd。通过adb执行ps命令，结果如下：</p>
<p>USER &nbsp; &nbsp; PID &nbsp; PPID &nbsp;VSIZE &nbsp;RSS &nbsp; &nbsp; WCHAN &nbsp; &nbsp;PC &nbsp; &nbsp; &nbsp; &nbsp; NAME</p>
<p>root &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; 0 &nbsp; &nbsp; 296 &nbsp; &nbsp;212 &nbsp; c00b0124 0000d9ec S /init</p>
<p>... ...</p>
<p>shell &nbsp; &nbsp; 2183 &nbsp;1 &nbsp; &nbsp; 3372 &nbsp; 184 &nbsp; ffffffff 0000eca4 S /sbin/adbd</p>
<p>root &nbsp; &nbsp; &nbsp;2204 &nbsp;1859 &nbsp;832 &nbsp; &nbsp;336 &nbsp; 00000000 afe0c7dc R ps</p>
<p>看一下倒数第二行，adbd所在进程的父进程是root，本身的user是shell。对于一个发布状态的产品，这个是最正常不过了。但现在开发中遇到这样一个需求，产品已经处在发布状态（编译模式已经改成user）的情况下，因为BSP需要处理一些内核上的东西，需要在PC上执行adb shell后具有root权限。也就是这种效果：</p>
<p>USER &nbsp; &nbsp; PID &nbsp; PPID &nbsp;VSIZE &nbsp;RSS &nbsp; &nbsp; WCHAN &nbsp; &nbsp;PC &nbsp; &nbsp; &nbsp; &nbsp; NAME</p>
<p>root &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; 0 &nbsp; &nbsp; 296 &nbsp; &nbsp;212 &nbsp; c00b0124 0000d9ec S /init</p>
<p>... ...</p>
<p>root &nbsp; &nbsp; &nbsp;1911 &nbsp;1 &nbsp; &nbsp; 3376 &nbsp; 184 &nbsp; ffffffff 0000eca4 S /sbin/adbd</p>
<p>root &nbsp; &nbsp; &nbsp;2198 &nbsp;2197 &nbsp;828 &nbsp; &nbsp;332 &nbsp; 00000000 afe0c7dc R ps</p>
<p>要达到这个效果，就是要在启动adbd时，以root用户启动。那么，先看一下在Android中怎么启动adbd。</p>
<p>&nbsp;</p>
<p>可以看一下Android系统根目录下的/init.rc的片段：</p>
<p>... ...</p>
<p># adbd is controlled by the persist.service.adb.enable system property</p>
<p>service adbd /sbin/adbd</p>
<p>&nbsp;&nbsp; &nbsp;disabled</p>
<p># adbd on at boot in emulator</p>
<p>on property:ro.kernel.qemu=1</p>
<p>&nbsp;&nbsp; &nbsp;start adbd</p>
<p>on property:persist.service.adb.enable=1</p>
<p>&nbsp;&nbsp; &nbsp;start adbd</p>
<p>on property:persist.service.adb.enable=0</p>
<p>&nbsp;&nbsp; &nbsp;stop adbd</p>
<p>... ...</p>
<p>这里定义了一个触发器，只要persist.service.adb.enable值被置为1，就会启动/sbin/adbd。</p>
<p>&nbsp;</p>
<p>怎么样设置persist.service.adb.enable的值呢？这里涉及到一个属性服务/system/core/init/property_service.c。看下面的东西之前先看一下我之前翻译过来的这篇StevGuo的文档，他对属性服务描述得很仔细，也很有条理。</p>
<p>http://blog.csdn.net/a345017062/archive/2010/12/17/6083026.aspx</p>
<p>今天搜资料的时候才发现网上N多人翻译了这篇文章，有点儿晕晕的。。。</p>
<p>我们继续。。。</p>
<p>通过阅读上面的文档，我们知道了属性服务启动时加载了四个文件，这四个文件里面都可以设置系统属性，还可以通过APK设置系统属性。但我把这些方式都，结果都一样，adbd是启动起来了，用户都是shell，还是没有root权限的。看来差异应该在编译模式上，是改为user编译模式后，系统改变了adbd启动时的权限。在build目录下搜索一下，发现了main.mk中有这样的代码片段</p>
<p>## user/userdebug ##</p>
<p>&nbsp;</p>
<p>user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))</p>
<p>enable_target_debugging := true</p>
<p>ifneq (,$(user_variant))</p>
<p>&nbsp;&nbsp;# Target is secure in user builds.</p>
<p>&nbsp;&nbsp;ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;tags_to_install := user</p>
<p>&nbsp;&nbsp;ifeq ($(user_variant),userdebug)</p>
<p>&nbsp;&nbsp; &nbsp;# Pick up some extra useful tools</p>
<p>&nbsp;&nbsp; &nbsp;tags_to_install += debug</p>
<p>&nbsp;&nbsp;else</p>
<p>&nbsp;&nbsp; &nbsp;# Disable debugging in plain user builds.</p>
<p>&nbsp;&nbsp; &nbsp;enable_target_debugging :=</p>
<p>&nbsp;&nbsp;endif</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;# TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.</p>
<p>&nbsp;&nbsp;# Also, remove the corresponding block in config/product_config.make.</p>
<p>&nbsp;&nbsp;ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)</p>
<p>&nbsp;&nbsp; &nbsp;WITH_DEXPREOPT := true</p>
<p>&nbsp;&nbsp;endif</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;# Disallow mock locations by default for user builds</p>
<p>&nbsp;&nbsp;ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0</p>
<p>&nbsp;</p>
<p>else # !user_variant</p>
<p>&nbsp;&nbsp;# Turn on checkjni for non-user builds.</p>
<p>&nbsp;&nbsp;ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1</p>
<p>&nbsp;&nbsp;# Set device insecure for non-user builds.</p>
<p>&nbsp;&nbsp;ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0</p>
<p>&nbsp;&nbsp;# Allow mock locations by default for non user builds</p>
<p>&nbsp;&nbsp;ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1</p>
<p>endif # !user_variant</p>
<p>&nbsp;</p>
<p>ifeq (true,$(strip $(enable_target_debugging)))</p>
<p>&nbsp;&nbsp;# Target is more debuggable and adbd is on by default</p>
<p>&nbsp;&nbsp;ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1</p>
<p>&nbsp;&nbsp;# Include the debugging/testing OTA keys in this build.</p>
<p>&nbsp;&nbsp;INCLUDE_TEST_OTA_KEYS := true</p>
<p>else # !enable_target_debugging</p>
<p>&nbsp;&nbsp;# Target is less debuggable and adbd is off by default</p>
<p>&nbsp;&nbsp;ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0</p>
<p>endif # !enable_target_debugging</p>
<p>这段代码我大致解释一下：</p>
<p>主要通过判断当前的编译模式来给几个属性赋予不同的值，然后把属性存储在ADDITIONAL_DEFAULT_PROPERTIES这个变量中，这个变量在后面是要写到根目录下的/default.prop中去，在系统启动时被属性服务加载的。也就是说我们在/default.prop中看到的几个属性的值是在这里设置的。</p>
<p>只看两个属性ro.secure，persist.service.adb.enable。当前是user模式的话，编译系统会把ro.secure置为1，把persist.service.adb.enable置为0.也就是说，用user模式编译出来的系统运行在安全模式下，adbd默认关闭。即使通过设置属性的方式打开，adbd进程的用户也是shell，不具有root权限。这样，普通用户或者开发者拿到一个机器后，通过PC运行adb shell时，是以shell用户登录机器的。</p>
<p>好了，现在把ro.secure置为0，再重新编译，只要设置属性persist.service.adb.enable的值为1，adbd进程就会以root用户的身份启动。</p>
<p>http://blog.csdn.net/a345017062/article/details/6254402</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-551-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:11</pubDate>
		</item>
		<item>
			<guid>http://meisw.wdlinux.cn//show-550-1.html</guid>
			<title>Android源码的层次结构分析 .</title>
			<author>admin</author>
			<description><![CDATA[<p>bionic，整个系统的基础类库，Android系统就是基于这个类库开发的，</p>
<p>&nbsp;</p>
<p>system，Android系统类库，基于bionic类库开发，包含工具类库（libcutils），LOG类库（liblog），压缩类库（libzipfile）类。</p>
<p>主要功能有：</p>
<p>一、完成Android初始化（init）。</p>
<p>解析init.rc并开启系统初始化时需要加载的程序（parser.c），初始化设备（devices.c），开启属性服务（property_service.c）等。</p>
<p>二、开启Android系统的一些基础服务。</p>
<p>1、系统的设备服务（vold）。比如完成SD卡挂载、卸载管理，从内核处接收事件建立设备结点等。</p>
<p>三、SHELL程序及相应的toolbox。</p>
<p>四、ADB程序。</p>
<p>五、logcat系统。</p>
<p>&nbsp;</p>
<p>可以说，bionic和system两个文件里的东西完成了Android对Linux的封装，在这两个文件夹的基础上构建起了Android系统的两大核心模块：Dalvik和Framework。Dalvik是一个基础纯C的VM，这个网上有比较详细的说明。重点一层层地分析一下Framework。</p>
<p>最底层就是几大模块:</p>
<p>1、utils工具库（frameworks/base/libs/utils/目录下）</p>
<p>这个类库基于bionic编译写，提供了一些对bionic里面的基础C/C++类库中的高层次封装。Framework中的C++程序大量使用这里的类库来封装更高层的系统功能。</p>
<p>2、binder库（framewoks/base/libs/binder/目录下）</p>
<p>这个与OpenBinder开源项目相似，提供了一种进程通信机制。C++和Java层都大量使用了这种机制。它把通信双方分为服务提供者和使用者两种角色。提供者内部有注册的服务接口，使用者去查找调用。</p>
<p>3、ui库（frameworks/base/libs/ui/目录下）</p>
<p>这个库主要提供了UI绘制和视频输出两类接口，整个系统的输出框架都是以这个库为基础，通过它与FrameBuffer通信。</p>
<p>4、surfaceflinger库（frameworks/base/libs/surfaceflinger/目录下）</p>
<p>对ui库的更高层次的封装，通过binder机制对Android系统中的上层模块提供输出服务。</p>
<p>5、audioflinger库（frameworks/base/libs/audioflinger/目录下）</p>
<p>音频输出基础类库，上层模块通过这个库与驱动还有打交导输出声音。</p>
<p>6、大量开源库（external/目录下）</p>
<p>&nbsp;</p>
<p>这几大模块构成了整个Framework的基础。围绕这几大模块，就可以构建一个真正的操作系统的上层模块，创建应用程序运行环境了。比较典型的有：</p>
<p>多媒休服务，提供给音视频播放和录制服务。</p>
<p>服务管理，维护和管理系统中存在的大量服务提供程序，应用程序通过binder机制通过服务管理中心的servicemanager来访问和使用这些服务，比如电源、蓝牙、Wifi等模块都以服务的形式存在于系统中供应用程序调用。</p>
<p>运行时环境，初始化应用程序的运行环境，并加载第一个应用程序，Launcher。</p>
<p>&nbsp;</p>
<p>应用程序运行时环境创建完成后，系统就算正式启动起来了。当一个应用程序被加载到系统中时，它和系统打交导最多的就是系统提供的开发API了。主要集中在frameworks/base/core/目录下。</p>
<p>转</p>]]></description>
			<link>http://meisw.wdlinux.cn//show-550-1.html</link>
			<category domain="http://meisw.wdlinux.cn//category-35-1.html">android</category>
			<pubDate>2011-07-19 11:06</pubDate>
		</item>
	</channel>
</rss>
