偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.
全部博文(1748)
分类: Android平台
2014-05-16 08:33:41
1、通过build.prop实现产品定制的方法:
1)以编译模拟器的Generic版本为例,system.prop文件处
于以下位置(相对于工程根目录):
./build/target/board/generic/system.prop
里面的内容如下:
#
# system.prop for generic sdk
#
rild.libpath=/system/lib/libreference-ril.so
rild.libargs=-d /dev/ttyS0
system.prop文件中的内容最终会被编译到build.prop文
件中,路径如下(相对于工程根目录):
./out/target/product/generic/system/build.prop
2)Android中提供了一个android.os.SystemProperties类来
负责读取其中的内容,并且提供几个Static的方法,可以让
应用很方便地使用。内容简略如下:
//SystemProperties.java
package android.os;
public class SystemProperties{
public static final int PROP_NAME_MAX = 31;//Key字符串最大长度31
public static final int PROP_VALUE_MAX = 91;//Value字符串最大长度91
public static String get(String key, String def);
public static int getInt(String key, int def);//获取整型值
public static boolean getBoolean(String key, boolean def);//获取布尔值
public static void set(String key, String val);//设置Key值
}
3)
import android.os.SystemProperties
private static final bSupportBluetoosh =
SystemProperties.getBoolean("ro.Gallery.bSupportBluetooth",false);
4)注:有时会显示无法import android.os.SystemProperties
修改方法如下:
注释掉相应Android.mk文件中的以下内容:1. android现在好像只有/ default.prop,/system/build.prop两个文件,别的两个文件找不到
2. /data/property下有4个prop文件:persist.sys.timezone,persist.sys.language,persist.sys.country,persist.sys.localevar,里面保存着属性名称以“persist.”开头的属性值。
3. libcutils的源码位于system/core/libcutils/下面,获取和设置属性的代码在properties.c里面,读取属性通过读共享内存得到,设置属性通过发送请求到property_service进行设置。
4. 相关的函数有property_set,property_get,property_list。
5. 属性系统的初始化通过__system_properties_init函数完成,__system_properties_init函数代码如下:
int __system_properties_init(void) { prop_area *pa; int s, fd; unsigned sz; char *env; if(__system_property_area__ != ((void*) &dummy_props)) { return 0; } env = getenv("ANDROID_PROPERTY_WORKSPACE"); if (!env) { return -1; } fd = atoi(env); env = strchr(env, ','); if (!env) { return -1; } sz = atoi(env + 1); pa = mmap(0, sz, PROT_READ, MAP_SHARED, fd, 0); if(pa == MAP_FAILED) { return -1; } if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION)) { munmap(pa, sz); return -1; } __system_property_area__ = pa; return 0; }
可以看到首先从环境变量里面获取ANDROID_PROPERTY_WORKSPACE,ANDROID_PROPERTY_WORKSPACE的值为如下形式:ANDROID_PROPERTY_WORKSPACE=9,32768。 然后获取共享内存的文件句柄和长度,最后对共享内存进行检查并设置全局变量__system_property_area__的 值,property_get就是从__system_property_area__里面读取的属性值。环境变量的初始化在init.c的 service_start函数里面。
6. /init.rc里面有设置属性的代码,例如:
# Define the oom_adj values for the classes of processes that can be
# killed by the kernel. These are used in ActivityManagerService.
setprop ro.FOREGROUND_APP_ADJ 0
setprop ro.VISIBLE_APP_ADJ 1
setprop ro.SECONDARY_SERVER_ADJ 2
setprop ro.HOME_APP_ADJ 4
setprop ro.HIDDEN_APP_MIN_ADJ 7
setprop ro.CONTENT_PROVIDER_ADJ 14
setprop ro.EMPTY_APP_ADJ 15
7. 通过property_list可以枚举所有的属性,下面是一段打印所有属性的代码。
#include
Android.mk文件:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= /
list_property.cpp /
LOCAL_SHARED_LIBRARIES := /
libcutils /
libutils /
LOCAL_MODULE:= list_prop
include $(BUILD_EXECUTABLE)
include $(call all-makefiles-under,$(LOCAL_PATH))
所有的属性如下:
key=ro.secure,value=0
key=ro.allow.mock.location,value=1
key=ro.debuggable,value=1
key=persist.service.adb.enable,value=1
key=ro.kernel.qemu,value=1
key=ro.kernel.console,value=ttyS0
key=ro.kernel.android.checkjni,value=1
key=ro.kernel.android.qemud,value=ttyS1
key=ro.factorytest,value=0
key=ro.serialno,value=
key=ro.bootmode,value=unknown
key=ro.baseband,value=unknown
key=ro.carrier,value=unknown
key=ro.bootloader,value=unknown
key=ro.hardware,value=goldfish
key=ro.revision,value=0
key=ro.build.id,value=CUPCAKE
key=ro.build.display.id,value=sdk-eng 1.5 CUPCAKE 148875 test-keys
key=ro.build.version.incremental,value=148875
key=ro.build.version.sdk,value=3
key=ro.build.version.release,value=1.5
key=ro.build.date,value=Thu May 14 17:29:49 PDT 2009
key=ro.build.date.utc,value=1242347389
key=ro.build.type,value=eng
key=ro.build.user,value=android-build
key=ro.build.host,value=e-honda.mtv.corp.google.com
key=ro.build.tags,value=test-keys
key=ro.product.model,value=sdk
key=ro.product.brand,value=generic
key=ro.product.name,value=sdk
key=ro.product.device,value=generic
key=ro.product.board,value=
key=ro.product.manufacturer,value=unknown
key=ro.product.locale.language,value=en
key=ro.product.locale.region,value=US
key=ro.board.platform,value=
key=ro.build.product,value=generic
key=ro.build.description,value=sdk-eng 1.5 CUPCAKE 148875 test-keys
key=ro.build.fingerprint,value=generic/sdk/generic/:1.5/CUPCAKE/148875:eng/test-keys
key=rild.libpath,value=/system/lib/libreference-ril.so
key=rild.libargs,value=-d /dev/ttyS0
key=ro.config.notification_sound,value=F1_New_SMS.ogg
key=xmpp.auto-presence,value=true
key=ro.config.nocheckin,value=yes
key=net.bt.name,value=Android
key=net.change,value=net.gprs.local-ip
key=dalvik.vm.stack-trace-file,value=/data/anr/traces.txt
key=persist.sys.timezone,value=GMT
key=persist.sys.language,value=en
key=persist.sys.country,value=US
key=persist.sys.localevar,value=
key=ro.FOREGROUND_APP_ADJ,value=0
key=ro.VISIBLE_APP_ADJ,value=1
key=ro.SECONDARY_SERVER_ADJ,value=2
key=ro.HOME_APP_ADJ,value=4
key=ro.HIDDEN_APP_MIN_ADJ,value=7
key=ro.CONTENT_PROVIDER_ADJ,value=14
key=ro.EMPTY_APP_ADJ,value=15
key=ro.FOREGROUND_APP_MEM,value=1536
key=ro.VISIBLE_APP_MEM,value=2048
key=ro.SECONDARY_SERVER_MEM,value=4096
key=ro.HOME_APP_MEM,value=4096
key=ro.HIDDEN_APP_MEM,value=5120
key=ro.CONTENT_PROVIDER_MEM,value=5632
key=ro.EMPTY_APP_MEM,value=6144
key=net.tcp.buffersize.default,value=4096,87380,110208,4096,16384,110208
key=net.tcp.buffersize.wifi,value=4095,87380,110208,4096,16384,110208
key=net.tcp.buffersize.umts,value=4094,87380,110208,4096,16384,110208
key=net.tcp.buffersize.edge,value=4093,26280,35040,4096,16384,35040
key=net.tcp.buffersize.gprs,value=4092,8760,11680,4096,8760,11680
key=init.svc.console,value=running
key=init.svc.servicemanager,value=running
key=init.svc.vold,value=running
key=init.svc.debuggerd,value=running
key=init.svc.ril-daemon,value=running
key=init.svc.zygote,value=running
key=init.svc.media,value=running
key=init.svc.installd,value=running
key=init.svc.flash_recovery,value=stopped
key=init.svc.goldfish-setup,value=stopped
key=init.svc.qemud,value=stopped
key=init.svc.goldfish-logcat,value=stopped
key=ARGH,value=ARGH
key=net.eth0.dns1,value=10.0.2.3
key=net.gprs.local-ip,value=10.0.2.15
key=ro.radio.use-ppp,value=no
key=status.battery.state,value=Slow
key=status.battery.level,value=5
key=status.battery.level_raw,value=50
key=status.battery.level_scale,value=9
key=ro.setupwizard.mode,value=EMULATOR
key=ro.com.google.locationfeatures,value=1
key=init.svc.adbd,value=running
key=ro.qemu.init.completed,value=1
key=hw.keyboards.65536.devname,value=qwerty2
key=sys.settings_secure_version,value=2
key=dev.bootcomplete,value=1
key=sys.settings_system_version,value=6
key=gsm.sim.operator.numeric,value=
key=gsm.sim.operator.alpha,value=
key=gsm.sim.operator.iso-country,value=
key=gsm.sim.state,value=UNKNOWN
key=adb.connected,value=1