Android 中build.prop 文件与 getprop 命令
在android系统中,它的根文件系统下有几个用于启动系统时需要的配置文件:
- /init.rc
- /default.prop
- /system/build.prop
我们先看看 build.prop 里面到底有些什么东西:
E:\AndroidProject\NowaMagic>adb shell shell@android:/ $ su su root@android:/ # cd system cd system root@android:/system # cat build.prop cat build.prop # begin build properties # autogenerated by buildinfo.sh ro.build.id=JRO03L ro.build.display.id=JRO03L ro.build.version.incremental=JLB21.0 ro.build.version.sdk=16 ro.build.version.codename=REL ro.build.version.release=4.1.1 ro.build.date=Thu Aug 1 17:50:59 CST 2013 ro.build.date.utc=1375350659 ro.build.type=user ro.build.user=builder ro.build.host=taishan ro.build.tags=release-keys ro.product.model=MI 2 ro.product.brand=Xiaomi ro.product.name=aries ro.product.device=aries ro.product.board=MSM8960 ro.product.cpu.abi=armeabi-v7a ro.product.cpu.abi2=armeabi ro.product.manufacturer=Xiaomi ro.product.locale.language=zh ro.product.locale.region=CN ro.wifi.channels= ro.board.platform=msm8960 # ro.build.product is obsolete; use ro.product.device ro.build.product=aries # Do not try to parse ro.build.description or .fingerprint ro.build.description=aries-user 4.1.1 JRO03L JLB21.0 release-keys ro.build.fingerprint=Xiaomi/aries/aries:4.1.1/JRO03L/JLB21.0:user/release-keys ro.build.characteristics=nosdcard # end build properties # # system.prop for surf # rild.libpath=/system/lib/libril-qc-qmi-1.so rild.libargs=-d /dev/smd0 persist.rild.nitz_plmn= persist.rild.nitz_long_ons_0= persist.rild.nitz_long_ons_1= persist.rild.nitz_long_ons_2= persist.rild.nitz_long_ons_3= persist.rild.nitz_short_ons_0= persist.rild.nitz_short_ons_1= persist.rild.nitz_short_ons_2= persist.rild.nitz_short_ons_3= ril.subscription.types=RUIM DEVICE_PROVISIONED=1 debug.sf.hw=1 debug.egl.hw=1 debug.composition.type=dyn debug.mdpcomp.maxlayer=3 debug.mdpcomp.logs=0 ro.sf.lcd_density=320 # save modem ramdump to sdcard persist.radio.parsedump=1 persist.radio.ramdump_sdcard=0 persist.radio.ramdump_num=3 # # system props for the cne module # #persist.cne.bat.range.low.med=30 #persist.cne.bat.range.med.high=60 #persist.cne.loc.policy.op=/system/etc/OperatorPolicy.xml #persist.cne.loc.policy.user=/system/etc/UserPolicy.xml #persist.cne.bwbased.rat.sel=false #persist.cne.snsr.based.rat.mgt=false #persist.cne.bat.based.rat.mgt=false #persist.cne.rat.acq.time.out=30000 #persist.cne.rat.acq.retry.tout=0 #persist.cne.feature=1 ro.hdmi.enable=true lpa.decode=false lpa.use-stagefright=true #system props for the MM modules media.stagefright.enable-player=true media.stagefright.enable-http=true media.stagefright.enable-aac=true media.stagefright.enable-qcp=true media.stagefright.enable-fma2dp=true media.stagefright.enable-scan=true mmp.enable.3g2=true # # system props for the data modules # ro.use_data_netmgrd=true #system props for time-services #persist.timed.enable=true # System props for audio persist.audio.fluence.mode=endfire persist.audio.vr.enable=false persist.audio.handset.mic=digital # System prop to select audio resampler quality af.resampler.quality=255 # System prop to select MPQAudioPlayer by default on mpq8064 mpq.audio.decode=true # # system prop for opengles version # # 131072 is decimal for 0x20000 to report version 2 ro.opengles.version=131072 # # system property for Bluetooth Handsfree Profile version # ro.bluetooth.hfp.ver=1.6 # #system prop for Bluetooth hci transport ro.qualcomm.bt.hci_transport=smd # # system prop for requesting Master role in incoming Bluetooth connection. # ro.bluetooth.request.master=true # # system prop for Bluetooth Auto connect for remote initated connections # ro.bluetooth.remote.autoconnect=true # system property for Bluetooth discoverability time out in seconds # 0: Always discoverable #debug.bt.discoverable_time=0 #system prop for switching gps driver to qmi persist.gps.qmienabled=true # System property for cabl ro.qualcomm.cabl=0 # System property for csc debug.csc.poll=0 # System props for telephony # System prop to turn on CdmaLTEPhone always # telephony.lteOnCdmaDevice=1 # # System prop for sending transmit power request to RIL during WiFi hotspot on/off # ro.ril.transmitpower=true # #Simulate sdcard on /data/media # persist.fuse_sdcard=true ro.hwui.text_cache_width=2048 ro.hwui.texture_cache_size=48 # # Supports warmboot capabilities # ro.warmboot.capability=1 #snapdragon value add features ro.qcom.audio.ssr=true persist.sys.strictmode.disable=true power.webview.DM=false #enable cdrom installer persist.service.cdrom.enable=1 # # Haptic # ro.haptic.vibrate_ex.enabled=1 sys.haptic.long.weak=0,127,10,50,20,-50,10,0,10 sys.haptic.long.normal=0,127,10,80,20,-80,10,0,10 sys.haptic.long.strong=0,127,10,100,20,-100,10,0,10 sys.haptic.down.weak=0,120,10,-50,10,0,10 sys.haptic.down.normal=0,127,10,-80,10,0,10 sys.haptic.down.strong=0,127,20,-80,10,0,10 sys.haptic.up.weak=0,80,30,-50,10,0,10 sys.haptic.up.normal=0,100,30,-100,10,0,10 sys.haptic.up.strong=0,120,30,-120,10,0,10 sys.haptic.tap.weak=0,80,40,-5,5,0,10 sys.haptic.tap.normal=0,100,40,-5,5,0,10 sys.haptic.tap.strong=0,120,40,-5,5,0,10 # power mode persist.sys.aries.power_profile=middle # button jack mode and switch persist.sys.button_jack_profile=volume persist.sys.button_jack_switch=0 # suspend mode capability ro.warmboot.capability=true # display preference persist.sys.display_prefer=0 persist.sys.display_ce=0 debug.enabletr=false # # ADDITIONAL_BUILD_PROPERTIES # ro.miui.ui.version.code=3 ro.miui.ui.version.name=V5 keyguard.no_require_sim=true ro.com.android.dataroaming=false ro.com.android.dateformat=MM-dd-yyyy ro.config.ringtone=MI.ogg ro.config.notification_sound=FadeIn.ogg ro.config.alarm_alert=GoodMorning.ogg ro.config.sms_received_sound=FadeIn.ogg ro.config.sms_delivered_sound=MessageComplete.ogg ro.carrier=unknown persist.sys.mitalk.enable=true ro.vendor.extension_library=/system/lib/libqc-opt.so ro.com.google.clientidbase=android-xiaomi dalvik.vm.heapstartsize=8m dalvik.vm.heapgrowthlimit=96m dalvik.vm.heapsize=384m dalvik.vm.heaputilization=0.25 dalvik.vm.heapidealfree=8388608 dalvik.vm.heapconcurrentstart=2097152 ro.setupwizard.mode=OPTIONAL ro.com.google.gmsversion=4.1_r5 net.bt.name=Android dalvik.vm.stack-trace-file=/data/anr/traces.txt
该文件存放的数据是以这种等号形式存放的,而且它们是键值对成对出现的。
留意最后几行,我们试下用 getprop 命令:
root@android:/ # getprop net.bt.name getprop net.bt.name Android root@android:/ # getprop dalvik.vm.stack-trace-file getprop dalvik.vm.stack-trace-file /data/anr/traces.txt root@android:/ #
很明显,getprop 就是将配置文件 build.prop 里的信息读取出来并经过整理后,并以字典的形式展示给用户的。
它的格式如下:
- getprop 列出所有配置属性值
- getprop [key] 取得对应的key的属性值
如果要修改属性的话,很简单,只需修改字典值就可以了,如:
setprop [key] [value] 设置指定key的属性值。
而 watchprops 监听系统属性的变化,如果期间系统的属性发生变化则把变化的值显示出来。
其实这三个命令都是toolbox的子命令,如果有兴趣的可以看在android源码中看到其对应的源码:system/core/toolbox/
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!