Android系统启动篇
4,《Android SystemServer进程启动流程》
Android系统开发准备篇
3,《Android Framework代码IDE加载和调试》
Android系统开发实践篇
4,《android单独编译framework模块并push》
Android系统开发核心知识储备篇
1,《Android编译系统-envsetup和lunch代码篇》
6,《Android中Activity、View和Window关系详解》
11,《android中AMS进程通知Zygote进程fork新进程的通信方式》
Android核心功能详解篇
2,《Android 手势导航(从下往上滑动进入多任务页面)》
3,《android手势分析(应用界面左往右边滑动退出应用)》
———————————————————————————————————————————
目录
一,背景介绍
Android 系统属性主要有两种:SettingsProvider 和 SystemProperties 。
二,系统属性读取
2.1 在adb中进行属性读取和设置
2.1.1 Settings Provider设置和读取
//查看screen_off_timeout的值,可以使用下面的命令
$ adb shell settings get system screen_off_timeout
$ 60000
这里属性值是严格区分大小写的(全部都是小写),不存在的值或者写错就获取到null。
//修改休眠时间
$ adb shell settings put system screen_off_timeout 120000 //120秒,2分钟
2.1.2、SystemProperties属性读取和设置
$ adb shell getprop
[ro.boot.cdt_hwid]: [0x05020F00]
[ro.boot.cid]: [00000000]
[ro.boot.ddr_info]: [Samsung]
[ro.boot.ddr_size]: [4GB]
[ro.boot.dp_info_a]: [enabled(in-list)]
[ro.boot.dp_info_b]: [enabled(in-list)]
[ro.boot.dtb_idx]: [0]
[ro.boot.dtbo_idx]: [5]
[ro.boot.dynamic_partitions]: [true]
[ro.boot.dynamic_partitions_retrofit]: [true]
[ro.boot.flash.locked]: [0]
[ro.boot.force_normal_boot]: [1]
[ro.boot.hardware]: [blueline]
[ro.boot.hardware.ddr]: [4GB,Samsung,LPDDR4X]
[ro.boot.hardware.devcfg]: [Main8]
[ro.boot.hardware.dsds]: [0]
[ro.boot.hardware.majorid]: [0x02]
[ro.boot.hardware.pcbcfg]: [SMT8]
[ro.boot.hardware.platform]: [sdm845]
[ro.boot.hardware.revision]: [EVT2.0]
[ro.boot.hardware.sku]: [G013A]
[ro.boot.hardware.ufs]: [64GB,Samsung]
[ro.boot.keymaster]: [1]
[ro.boot.mode]: [normal]
[ro.boot.product.hardware.sku]: [G013A]
[ro.boot.revision]: [EVT2.0]
[ro.boot.secure_boot]: [NONE]
[ro.boot.serialno]: [84PX006FZ]
[ro.boot.slot_retry_count]: [2]
[ro.boot.slot_successful]: [no]
[ro.boot.slot_suffix]: [_b]
[ro.boot.super_partition]: [system]
[ro.boot.vbmeta.avb_version]: [1.1]
[ro.boot.vbmeta.device_state]: [unlocked]
[ro.boot.vbmeta.digest]: [6b77243998eb353bb432980bc832b3327f2c1d51cd73a81e4e23a3c62c990f57]
[ro.boot.vbmeta.hash_alg]: [sha256]
[ro.boot.vbmeta.size]: [4992]
[ro.boot.verifiedbootstate]: [orange]
[ro.boot.veritymode]: [enforcing]
[ro.boot.wificountrycode]: [00]
[ro.bootimage.build.date]: [Sat Aug 14 01:28:21 UTC 2021]
[ro.bootimage.build.date.utc]: [1628904501]
[ro.bootimage.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/7641976:userdebug/test-keys]
[ro.bootloader]: [b1c1-0.4-7617406]
[ro.bootmode]: [normal]
[ro.build.ab_update]: [true]
[ro.build.characteristics]: [nosdcard]
[ro.build.date]: [Fri Mar 31 09:12:46 CST 2023]
[ro.build.date.utc]: [1680225166]
[ro.build.description]: [aosp_blueline-userdebug 11 RQ3A.211001.001 eng.harry.20230331.091537 test-keys]
[ro.build.display.id]: [aosp_blueline-userdebug 11 RQ3A.211001.001 eng.harry.20230331.091537 test-keys]
[ro.build.expect.baseband]: [g845-00173-210331-B-7249945]
[ro.build.expect.bootloader]: [b1c1-0.3-7241706]
[ro.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/eng.harry.20230331.091537:userdebug/test-keys]
[ro.build.flavor]: [aosp_blueline-userdebug]
[ro.build.host]: [harry-P720]
[ro.build.id]: [RQ3A.211001.001]
[ro.build.product]: [blueline]
[ro.build.tags]: [test-keys]
[ro.build.type]: [userdebug]
[ro.build.user]: [harry]
[ro.build.version.all_codenames]: [REL]
[ro.build.version.base_os]: []
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [eng.harry.20230331.091537]
[ro.build.version.min_supported_target_sdk]: [23]
[ro.build.version.preview_sdk]: [0]
[ro.build.version.preview_sdk_fingerprint]: [REL]
[ro.build.version.release]: [11]
[ro.build.version.release_or_codename]: [11]
[ro.build.version.sdk]: [30]
[ro.build.version.security_patch]: [2021-10-01]
[ro.carrier]: [unknown]
[ro.com.android.dataroaming]: [true]
[ro.com.google.ime.height_ratio]: [1.2]
[ro.config.alarm_alert]: [Alarm_Classic.ogg]
[ro.config.media_vol_steps]: [25]
[ro.config.notification_sound]: [pixiedust.ogg]
[ro.config.ringtone]: [Ring_Synth_04.ogg]
[ro.config.vc_call_vol_steps]: [7]
[ro.control_privapp_permissions]: [enforce]
[ro.cp_system_other_odex]: [1]
[ro.crypto.metadata.enabled]: [true]
[ro.crypto.state]: [encrypted]
[ro.crypto.type]: [file]
[ro.crypto.volume.filenames_mode]: [aes-256-cts]
[ro.dalvik.vm.native.bridge]: [0]
[ro.debuggable]: [1]
[ro.frp.pst]: [/dev/block/bootdevice/by-name/frp]
[ro.hardware]: [blueline]
[ro.hardware.egl]: [adreno]
[ro.hardware.keystore_desede]: [true]
[ro.hardware.vulkan]: [adreno]
[ro.hwui.use_vulkan]: []
[ro.input.video_enabled]: [false]
[ro.iorapd.enable]: [false]
[ro.lmk.log_stats]: [true]
[ro.logd.size]: [1M]
[ro.logd.size.stats]: [64K]
[ro.minui.pixel_format]: [RGBX_8888]
[ro.odm.build.date]: [Sat Aug 14 01:28:21 UTC 2021]
[ro.odm.build.date.utc]: [1628904501]
[ro.odm.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/7641976:userdebug/test-keys]
[ro.odm.build.version.incremental]: [7641976]
[ro.oem.key1]: [G013A]
[ro.oem_unlock_supported]: [1]
[ro.opengles.version]: [196610]
[ro.organization_owned]: [false]
[ro.postinstall.fstab.prefix]: [/system]
[ro.product.board]: [blueline]
[ro.product.brand]: [Android]
[ro.product.build.date]: [Fri Mar 31 09:12:46 CST 2023]
[ro.product.build.date.utc]: [1680225166]
[ro.product.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/harry03310912:userdebug/test-keys]
[ro.product.build.id]: [RQ3A.211001.001]
[ro.product.build.tags]: [test-keys]
[ro.product.build.type]: [userdebug]
[ro.product.build.version.incremental]: [eng.harry.20230331.091537]
[ro.product.build.version.release]: [11]
[ro.product.build.version.release_or_codename]: [11]
[ro.product.build.version.sdk]: [30]
[ro.product.cpu.abi]: [arm64-v8a]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist64]: [arm64-v8a]
[ro.product.device]: [blueline]
[ro.product.first_api_level]: [28]
[ro.product.locale]: [en-US]
[ro.product.manufacturer]: [Google]
[ro.product.model]: [AOSP on blueline]
[ro.product.name]: [aosp_blueline]
[ro.product.odm.brand]: [Android]
[ro.product.odm.device]: [blueline]
[ro.product.odm.manufacturer]: [Google]
[ro.product.odm.model]: [AOSP on blueline]
[ro.product.odm.name]: [aosp_blueline]
[ro.product.product.brand]: [Android]
[ro.product.product.device]: [blueline]
[ro.product.product.manufacturer]: [Google]
[ro.product.product.model]: [AOSP on blueline]
[ro.product.product.name]: [aosp_blueline]
[ro.product.system.brand]: [Android]
[ro.product.system.device]: [generic]
[ro.product.system.manufacturer]: [Android]
[ro.product.system.model]: [mainline]
[ro.product.system.name]: [mainline]
[ro.product.system_ext.brand]: [Android]
[ro.product.system_ext.device]: [blueline]
[ro.product.system_ext.manufacturer]: [Google]
[ro.product.system_ext.model]: [AOSP on blueline]
[ro.product.system_ext.name]: [aosp_blueline]
[ro.product.vendor.brand]: [Android]
[ro.product.vendor.device]: [blueline]
[ro.product.vendor.manufacturer]: [Google]
[ro.product.vendor.model]: [AOSP on blueline]
[ro.product.vendor.name]: [aosp_blueline]
[ro.property_service.version]: [2]
[ro.qti.sdk.sensors.gestures]: [false]
[ro.qti.sensors.amd]: [false]
[ro.qti.sensors.cmc]: [false]
[ro.qti.sensors.dev_ori]: [true]
[ro.qti.sensors.facing]: [false]
[ro.qti.sensors.pedometer]: [false]
[ro.qti.sensors.rmd]: [false]
[ro.qti.sensors.scrn_ortn]: [false]
[ro.qti.sensors.step_counter]: [false]
[ro.qti.sensors.step_detector]: [false]
[ro.qti.sensors.wu]: [false]
[ro.radio.log_loc]: [/data/vendor/modem_dump]
[ro.radio.log_prefix]: [modem_log_]
[ro.revision]: [EVT2.0]
[ro.secure]: [1]
[ro.serialno]: [84PX006FZ]
[ro.sf.lcd_density]: [440]
[ro.surface_flinger.has_HDR_display]: [true]
[ro.surface_flinger.has_wide_color_display]: [true]
[ro.surface_flinger.protected_contents]: [true]
[ro.surface_flinger.use_color_management]: [true]
[ro.surface_flinger.vsync_event_phase_offset_ns]: [2000000]
[ro.surface_flinger.vsync_sf_event_phase_offset_ns]: [6000000]
[ro.surface_flinger.wcg_composition_dataspace]: [143261696]
[ro.sys.sdcardfs]: [1]
[ro.system.build.date]: [Fri Mar 31 09:12:46 CST 2023]
[ro.system.build.date.utc]: [1680225166]
[ro.system.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/harry03310912:userdebug/test-keys]
[ro.system.build.id]: [RQ3A.211001.001]
[ro.system.build.tags]: [test-keys]
[ro.system.build.type]: [userdebug]
[ro.system.build.version.incremental]: [eng.harry.20230331.091537]
[ro.system.build.version.release]: [11]
[ro.system.build.version.release_or_codename]: [11]
[ro.system.build.version.sdk]: [30]
[ro.system_ext.build.date]: [Fri Mar 31 09:12:46 CST 2023]
[ro.system_ext.build.date.utc]: [1680225166]
[ro.system_ext.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/harry03310912:userdebug/test-keys]
[ro.system_ext.build.id]: [RQ3A.211001.001]
[ro.system_ext.build.tags]: [test-keys]
[ro.system_ext.build.type]: [userdebug]
[ro.system_ext.build.version.incremental]: [eng.harry.20230331.091537]
[ro.system_ext.build.version.release]: [11]
[ro.system_ext.build.version.release_or_codename]: [11]
[ro.system_ext.build.version.sdk]: [30]
[ro.telephony.default_cdma_sub]: [0]
[ro.telephony.default_network]: [10]
[ro.thermal_warmreset]: [true]
[ro.treble.enabled]: [true]
[ro.vendor.build.date]: [Sat Aug 14 01:28:21 UTC 2021]
[ro.vendor.build.date.utc]: [1628904501]
[ro.vendor.build.fingerprint]: [Android/aosp_blueline/blueline:11/RQ3A.211001.001/7641976:userdebug/test-keys]
[ro.vendor.build.security_patch]: [2021-10-01]
[ro.vendor.build.version.incremental]: [7641976]
[ro.vendor.build.version.sdk]: [30]
[ro.vendor.camera.free_buf_early]: [true]
[ro.vendor.ril.svdo]: [false]
[ro.vendor.ril.svlte1x]: [false]
[ro.vndk.version]: [30]
[ro.wifi.channels]: []
[ro.zram.first_wb_delay_mins]: [1440]
[ro.zram.mark_idle_delay_mins]: [60]
[ro.zram.periodic_wb_delay_hours]: [24]
[ro.zygote]: [zygote64_32]
[security.perf_harden]: [1]
[selinux.restorecon_recursive]: [/data/misc_ce/0]
[service.bootanim.exit]: [1]
[service.sf.present_timestamp]: [1]
[sys.boot.reason]: [reboot,factory_reset]
[sys.boot.reason.last]: [reboot]
[sys.boot_completed]: [1]
[sys.bootstat.first_boot_completed]: [1]
[sys.cppreopt]: [finished]
[sys.init.perf_lsm_hooks]: [1]
[sys.isolated_storage_snapshot]: [true]
[sys.oem_unlock_allowed]: [1]
[sys.rescue_boot_count]: [1]
[sys.retaildemo.enabled]: [0]
[sys.sysctl.extra_free_kbytes]: [27337]
[sys.system_server.start_count]: [1]
[sys.system_server.start_elapsed]: [10684]
[sys.system_server.start_uptime]: [10684]
[sys.usb.config]: [adb]
[sys.usb.configfs]: [2]
[sys.usb.controller]: [a600000.dwc3]
[sys.usb.ffs.ready]: [1]
[sys.usb.mtp.device_type]: [3]
[sys.use_memfd]: [false]
[sys.user.0.ce_available]: [true]
[sys.wifitracing.started]: [1]
[telephony.lteOnCdmaDevice]: [1]
[tombstoned.max_tombstone_count]: [50]
[vidc.enc.dcvs.extra-buff-count]: [2]
[vidc.enc.disable.pq]: [1]
[vold.checkpoint_committed]: [1]
[vold.has_adoptable]: [0]
[vold.has_quota]: [1]
[vold.has_reserved]: [1]
[vold.post_fs_data_done]: [1]
[wifi.interface]: [wlan0]
读取特定属性值,
#读取系统sn
$ adb shell getprop ro.serialno
$ 84PX116FZ
2.2 Android代码中进行属性读取和设置
2.2.1 Settings Provider设置和读取
Settings Provider是指通过如下方式设置的系统变量数据库:
//读取
Settings.System.getInt(Context.getContentResolver(), "xxx", 1);
Settings.System.getString(Context.getContentResolver(), "xxx", "1");
Settings.System.getLong(Context.getContentResolver(), "xxx", 1);
Settings.System.getFloat(Context.getContentResolver(), "xxx", 1);
//设置
Settings.System.putInt(Context.getContentResolver(), "xxx", 1);
Settings.System.putString(Context.getContentResolver(), "xxx", "1");
Settings.System.putLong(Context.getContentResolver(), "xxx", 1);
Settings.System.putFloat(Context.getContentResolver(), "xxx", 1);
xxx表示属性,比如:screen_off_timeout
2.2.2 SystemProperties设置和读取
/**
* 设置属性值
*
* @param key 长度不能超过31,key.length <= 30
* @param value 长度不能超过91,value.length<=90
*/
public static void set(String key, String value) {
// android.os.SystemProperties
// public static void set(String key, String val)
try {
Class<?> cls = Class.forName("android.os.SystemProperties");
Method method = cls.getMethod("set", String.class, String.class);
method.invoke(null, key, value);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取属性值
*
* @param key 长度不能超过31,key.length <= 30
* @param defValue
* @return
*/
public static String get(String key, String defValue) {
// android.os.SystemProperties
// public static String get(String key, String def)
try {
Class<?> cls = Class.forName("android.os.SystemProperties");
Method method = cls.getMethod("get", String.class, String.class);
return (String) method.invoke(null, key, defValue);
} catch (Exception e) {
e.printStackTrace();
}
return defValue;
}
}
但反射对android11及以上,无法使用,android11接口定义如下,
@NonNull
@SystemApi
@TestApi
public static String get(@NonNull String key) {
if (TRACK_KEY_ACCESS) onKeyAccess(key);
return native_get(key);
}
可以看出,@SystemApi描述的为系统api,需要系统权限。解决思路授予应用系统权限。