1.添加 system property
在/device/<vendor>/<project>/system.prop 文件中添加需要的属性。
如在XXX中添加"persist.sys.touch_mode"属性,在system.prop文件中新增一行如下内容:
cpp
# Property for touch panel mode
persist.sys.touch_mode=glove
2**.添加Settings system, secure或者Global属性并监听**
下面以XXX为例添加Settings.system.BATTERY_SHIPPING_MODE.
添加BATTERY_SHIPPING_MODE Key
在frameworks/base/core/java/android/provider/Settings.java文件中添加"BATTERY_SHIPPING_MODE" key.
注册监听code
在frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java 文件的SettingsObserver中注册监听:
java
class SettingsObserver extends ContentObserver {
void observe() {
// Observe all users' changes
......
resolver.registerContentObserver(Settings.System.getUriFor(
Settings.System.BATTERY_SHIPPING_MODE),false,this,
UserHandle.USER_ALL);
}
@Override public void onChange(boolean selfChange) {
......
updateBatteryShippingMode();
......
}
}
添加功能
java
private void updateBatteryShippingMode(){
int shippingMode = Settings.System.getInt(mContext.getContentResolver(), Settings.System.BATTERY_SHIPPING_MODE, 0);
if(shippingMode == 1){
......
}
}
功能测试
测试功能的时候需要添加下面的权限
XML
android:sharedUserId="android.uid.system"
......
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>