给android添加系统属性:Settings.system和SystemProperties

本文介绍了如何在Android系统中自定义全局标志或变量。通过Settings.system和SystemProperties两种方式,可以轻松实现系统属性的添加与修改。

android源码开发中,常常要用到一些全局标志或者说变量,这时候我们可以给android系统添加自己想要的属性。

1.Settings.system

这种系统属性我们经常用到,例如飞行模式的开启和关闭,我们就是去改变Settings.system.AIRPLANE_MODE_ON 的值。

下面就介绍下我们怎样去定义一个系统属性。例如要添加一个属性名为“SILVAN_LIU”

路径:frameworks/base/core/java/android/provider/Settings.java

  1. public static final String SILVAN_LIU = "silvan_liu";  
  2.  public static final String[] SETTINGS_TO_BACKUP ={  
  3.             ~  
  4.        +SILVAN_LIU  
  5.               ~     
  6. }  
	 public static final String SILVAN_LIU = "silvan_liu";
 	 public static final String[] SETTINGS_TO_BACKUP ={
   	    	~
	        +SILVAN_LIU
                ~   
		}
这样添加后,你就是可以通过Settings.System.getInt(getContentResolver(), Settings.System.SILVAN_LIU,0) 和Settings.System.getInt(getContentResolver(), Settings.System.SILVAN_LIU,0)去得到和设定SILVAN_LIU的属性值。

2.SystemProperties

创建与修改android属性用Systemproperties.set(name, value),获取android属性用Systemproperties.get(name),需要注意的是android属性的名称是有一定的格式要求的,如下: 前缀必须用system\core\init\property_service.c中定义的前缀 ,进行系统属性设置的程序也必须有system或root权限

如果我们要添加一个property:例如:silvan_liu

路径:system/core/rootdir/int.rc

在on post-fs-data 目录下

 setprop persist.sys.silvan_liu 1//persist.sys 前缀名; 1为初始值

PS:不同前缀名权限不同,这里就不一一说明;还有为什么要加载on post-fs-data目录下,这和int.rc的语法有关。


以上是我实际项目中运用到的地方,可能认识的不够深刻,还需继续摸索。

D OplusAppHeapManager: java.lang.NoSuchMethodException: dalvik.system.VMRuntime.updateProcessValue [int, int, int] 行 131373: 10-16 06:36:39.245 24380 24380 D callGcSupression: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])' on a null object reference 行 131373: 10-16 06:36:39.245 24380 24380 D callGcSupression: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])' on a null object reference 行 131388: 10-16 06:36:39.293 24380 24380 D CompactWindowAppManager: initCompactApplicationInfo CompactMode: , NormalMode: 行 131388: 10-16 06:36:39.293 24380 24380 D CompactWindowAppManager: initCompactApplicationInfo CompactMode: , NormalMode: 行 131403: 10-16 06:36:39.347 24380 24380 D OplusScrollToTopManager: setIsInWhiteList false 行 131403: 10-16 06:36:39.347 24380 24380 D OplusScrollToTopManager: setIsInWhiteList false 行 131408: 10-16 06:36:39.380 24380 24380 D OplusViewDebugManager: OplusViewDebugManager Constructor android.view.debug.OplusViewDebugManager@39a6ce5 [mHasViewDebugProperty true] [mHasMsgDebugProperty false] [DEBUG false] [EXTRAINFOENABLE false] [LIGHT_OS true] 行 131408: 10-16 06:36:39.380 24380 24380 D OplusViewDebugManager: OplusViewDebugManager Constructor android.view.debug.OplusViewDebugManager@39a6ce5 [mHasViewDebugProperty true] [mHasMsgDebugProperty false] [DEBUG false] [EXTRAINFOENABLE false] [LIGHT_OS true] 行 131478: 10-16 06:36:39.504 24380 24380 W libc : Access denied finding property "ro.odm.prev.product.name" 行 131478: 10-16 06:36:39.504 24380 24380 W libc : Access denied finding property "ro.odm.prev.product.name" 行 131486: 10-16 06:36:39.522 24380 24380 D ApplicationLoaders: Returning zygote-cached class loader: /system/framework/org.apache.http.legacy.jar 行 131486: 10-16 06:36:39.522 24380 24380 D ApplicationLoaders: Returning zygote-cached class loader: /system/framework/org.apache.http.legacy.jar 行 131520: 10-16 06:36:39.523 04269 04747 I RunningProcessManager: onProcessAdded: pid = 24380 行 131580: 10-16 06:36:39.603 24380 24380 D nativeloader: Configuring clns-shared-7 for other apk /system/system_ext/framework/vendor.oplus.hardware.charger-V1-java.jar. target_sdk_version=35, uses_libraries=ALL, library_path=/system_ext/priv-app/Settings/lib/arm64:/system_ext/priv-app/Settings/ ... 行 131580: 10-16 06:36:39.603 24380 24380 D nativeloader: Configuring clns-shared-7 for other apk /system/system_ext/framework/vendor.oplus.hardware.charger-V1-java.jar. target_sdk_version=35, uses_libraries=ALL, library_path=/system_ext/priv-app/Settings/lib/arm64:/system_ext/priv-app/Settings/Setting ... 行 131581: 10-16 06:36:39.603 24380 24380 D nativeloader: Extending system_exposed_libraries: libbinauralrenderer_wrapper.qti.so:libhoaeffects.qti.so:libSloganJni.oplus.so:libsuperNight.oplus.so:libAPSClient-cmd-jni-extension.oplus.so:libsatellite_audio_jni.oplus.so:libortc_so.oplus.so:libsoundt ... 行 131581: 10-16 06:36:39.603 24380 24380 D nativeloader: Extending system_exposed_libraries: libbinauralrenderer_wrapper.qti.so:libhoaeffects.qti.so:libSloganJni.oplus.so:libsuperNight.oplus.so:libAPSClient-cmd-jni-extension.oplus.so:libsatellite_audio_jni.oplus.so:libortc_so.oplus.so:libsoundtouch.op ... 行 131584: 10-16 06:36:39.632 24380 24380 D nativeloader: Configuring clns-shared-8 for other apk /system_ext/framework/nfcvendorlib.jar. target_sdk_version=35, uses_libraries=ALL, library_path=/system_ext/priv-app/Settings/lib/arm64:/system_ext/priv-app/Settings/Settings.apk!/lib/arm64-v8a:/sys ... 行 131584: 10-16 06:36:39.632 24380 24380 D nativeloader: Configuring clns-shared-8 for other apk /system_ext/framework/nfcvendorlib.jar. target_sdk_version=35, uses_libraries=ALL, library_path=/system_ext/priv-app/Settings/lib/arm64:/system_ext/priv-app/Settings/Settings.apk!/lib/arm64-v8a:/system/lib ... 行 131585: 10-16 06:36:39.646 24380 24380 D nativeloader: Extending system_exposed_libraries: libbinauralrenderer_wrapper.qti.so:libhoaeffects.qti.so:libSloganJni.oplus.so:libsuperNight.oplus.so:libAPSClient-cmd-jni-extension.oplus.so:libsatellite_audio_jni.oplus.so:libortc_so.oplus.so:libsoundt ... 行 131585: 10-16 06:36:39.646 24380 24380 D nativeloader: Extending system_exposed_libraries: libbinauralrenderer_wrapper.qti.so:libhoaeffects.qti.so:libSloganJni.oplus.so:libsuperNight.oplus.so:libAPSClient-cmd-jni-extension.oplus.so:libsatellite_audio_jni.oplus.so:libortc_so.oplus.so:libsoundtouch.op ... 行 131586: 10-16 06:36:39.649 24380 24380 D ApplicationLoaders: Returning zygote-cached class loader: /system_ext/framework/androidx.window.extensions.jar 行 131586: 10-16 06:36:39.649 24380 24380 D ApplicationLoaders: Returning zygote-cached class loader: /system_ext/framework/androidx.window.extensions.jar 行 131587: 10-16 06:36:39.655 24380 24380 D ApplicationLoaders: Returning zygote-cached class loader: /system_ext/framework/androidx.window.sidecar.jar 行 131587: 10-16 06:36:39.655 24380 24380 D ApplicationLoaders: Returning zygote-cached class loader: /system_ext/framework/androidx.window.sidecar.jar 行 131622: 10-16 06:36:39.828 24380 24380 D nativeloader: Configuring clns-shared-9 for other apk /system_ext/priv-app/Settings/Settings.apk. target_sdk_version=35, uses_libraries=, library_path=/system_ext/priv-app/Settings/lib/arm64:/system_ext/priv-app/Settings/Settings.apk!/lib/arm64-v8a:/sy ... 行 131622: 10-16 06:36:39.828 24380 24380 D nativeloader: Configuring clns-shared-9 for other apk /system_ext/priv-app/Settings/Settings.apk. target_sdk_version=35, uses_libraries=, library_path=/system_ext/priv-app/Settings/lib/arm64:/system_ext/priv-app/Settings/Settings.apk!/lib/arm64-v8a:/system/li ... 行 131623: 10-16 06:36:39.832 24380 24380 D CompatChangeReporter: Compat change id reported: 202956589; UID 1000; state: ENABLED 行 131623: 10-16 06:36:39.832 24380 24380 D CompatChangeReporter: Compat change id reported: 202956589; UID 1000; state: ENABLED 行 131637: 10-16 06:36:39.986 24380 24380 V GraphicsEnvironment: Currently set values for: 行 131637: 10-16 06:36:39.986 24380 24380 V GraphicsEnvironment: Currently set values for: 行 131645: 10-16 06:36:39.997 24380 24380 V GraphicsEnvironment: angle_gl_driver_selection_pkgs=[] 行 131645: 10-16 06:36:39.997 24380 24380 V GraphicsEnvironment: angle_gl_driver_selection_pkgs=[] 行 131647: 10-16 06:36:39.999 24380 24380 V GraphicsEnvironment: angle_gl_driver_selection_values=[] 行 131647: 10-16 06:36:39.999 24380 24380 V GraphicsEnvironment: angle_gl_driver_selection_values=[] 行 131654: 10-16 06:36:40.001 24380 24380 V GraphicsEnvironment: Global.Settings values are invalid: number of packages: 0, number of values: 0 行 131654: 10-16 06:36:40.001 24380 24380 V GraphicsEnvironment: Global.Settings values are invalid: number of packages: 0, number of values: 0 行 131655: 10-16 06:36:40.002 24380 24380 V GraphicsEnvironment: Neither updatable production driver nor prerelease driver is supported. 行 131655: 10-16 06:36:40.002 24380 24380 V GraphicsEnvironment: Neither updatable production driver nor prerelease driver is supported. 行 131667: 10-16 06:36:40.129 24380 24380 I Settings_common: LogMsg: qeOff: false, mtk: false 行 131667: 10-16 06:36:40.129 24380 24380 I Settings_common: LogMsg: qeOff: false, mtk: false 行 131668: 10-16 06:36:40.131 24380 24380 I Settings_common: LogMsg: log level: 5, DEBUGG_THREAD: false 行 131668: 10-16 06:36:40.131 24380 24380 I Settings_common: LogMsg: log level: 5, DEBUGG_THREAD: false 行 131681: 10-16 06:36:40.190 24380 24384 W ings:background: Suspending all threads took: 8.249ms 行 131711: 10-16 06:36:40.298 24380 24380 D SpaEnvironment: reset 行 131711: 10-16 06:36:40.298 24380 24380 D SpaEnvironment: reset 行 131738: 10-16 06:36:40.419 03095 04519 I ActivityManager: Flag disabled. Ignoring finishAttachApplication from uid: 1000. pid: 24380 行 131739: 10-16 06:36:40.421 24380 24380 W ServiceManagerCppClient: Failed to get isDeclared for vendor.qti.hardware.perf2.IPerf/default: Status(-1, EX_SECURITY): 'SELinux denied.' 行 131739: 10-16 06:36:40.421 24380 24380 W ServiceManagerCppClient: Failed to get isDeclared for vendor.qti.hardware.perf2.IPerf/default: Status(-1, EX_SECURITY): 'SELinux denied.' 行 131749: 10-16 06:36:40.455 24380 24380 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1978 android.content.ContextWrapper.startService:837 android.content.ContextWrapper.startService:837 com.oplus.settings.background.Settin ... 行 131749: 10-16 06:36:40.455 24380 24380 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1978 android.content.ContextWrapper.startService:837 android.content.ContextWrapper.startService:837 com.oplus.settings.background.SettingsBackg ... 行 131771: 10-16 06:36:40.563 24380 24463 E AppFeatureProviderUtils: getBoolean: getStringForFeature return null 行 131813: 10-16 06:36:40.677 24470 24470 E crash_dump64: failed to get the guest state header for thread 24380: Bad address 行 131905: 10-16 06:36:40.901 24470 24470 I crash_dump64: performing dump of process 24380 (target tid = 24384)
最新发布
10-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值