Android系统默认显示电池电量百分比
整理一下修该需求时候遇到的问题以及进行修改的思路:
需求:Android 11 让系统默认显示电池电量百分比
首先想到的是系统设置中的电池设置选项,就是让设备第一次开机或者恢复出厂之后默认打开显示电池电量百分比这个选项:
首先进入adb shell:
然后settings list system 可以看到:
status_bar_show_battery_percent=1
这个数值就是用来控制是否默认显示电池百分比的(0不显示 1显示)
我们也可以通过adb sehll 来修改这个数值:
settings put system status_bar_show_battery_percent 0(不显示电池电量百分比)
settings put system status_bar_show_battery_percent 0(显示电池电量百分比)
那么如果说是想让系统默认显示电池电量百分比其实就是让这个数值默认为1就好了
通过查找status_bar_show_battery_percent可以发现对应的String 名字为SHOW_BATTERY_PERCENT
然后查找SHOW_BATTERY_PERCENT
最后发现许多数值都是在/packages/apps/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java中设置的默认值:
通过如下方法设置的默认值:
private void loadSystemSettings(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
R.bool.def_dim_screen);
loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
R.integer.def_screen_off_timeout);
// Set default cdma DTMF type
loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
// Set default hearing aid
loadSetting(stmt, Settings.System.HEARING_AID, 0);
// Set default tty mode
loadSetting(stmt, Settings.System.TTY_MODE, 0);
//Default display battery percentage
loadSetting(stmt, Settings.System.SHOW_BATTERY_PERCENT, 1);//设置默认显示电池百分比
loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
R.integer.def_screen_brightness);
loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
R.bool.def_screen_brightness_automatic_mode);
loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
R.bool.def_accelerometer_rotation);
loadDefaultHapticSettings(stmt);
loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
R.bool.def_notification_pulse);
loadUISoundEffectsSettings(stmt);
loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
R.integer.def_pointer_speed);
/// M: Load MTK added System providers before Android M.
mUtils.loadCustomSystemSettings(stmt);
/*
* IMPORTANT: Do not add any more upgrade steps here as the global,
* secure, and system settings are no longer stored in a database
* but are kept in memory and persisted to XML.
*
* See: SettingsProvider.UpgradeController#onUpgradeLocked
*/
} finally {
if (stmt != null) stmt.close();
}
}
通过loadSetting(stmt, Settings.System.SHOW_BATTERY_PERCENT, 1);来给SHOW_BATTERY_PERCENT设置默认值为1,编译后刷机,开机后默认显示电池百分比。
问题解决~ '(>﹏<)′