项目开发过程,为了排除电量导致的问题,或者不带电池的项目,有时候需要直接写死电量百分比去验证,可以通过以下办法:
frameworks/base/services/core/java/com/android/server/BatteryService.java
private void shutdownIfNoPowerLocked() {
// shut down gracefully if our battery is critically low and we are not powered.
// wait until the system has booted before attempting to display the shutdown dialog.
// add for bug#1021541
boolean checkPlugState = (mUpdatesStopped && mHealthInfo.batteryLevel == mSetBatteryLevel
&& mSetBatteryLevel != mRealBatteryLevel);
if (DEBUG) Slog.d(TAG, "shutdownIfNoPowerLocked: mUpdatesStopped: " + mUpdatesStopped
+ " mHealthInfo.batteryLevel:" + mHealthInfo.batteryLevel
+ " mSetBatteryLevel:" + mSetBatteryLevel + " mRealBatteryLevel:" + mRealBatteryLevel);
mHealthInfo.batteryLevel = 100;//add 固定写100%
if (mHealthInfo.batteryLevel == 0 && (!checkPlugState || !isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY))) {
/*SPRD : add power debug log start*/
Slog.d(TAG, "Low battery shutdown, batteryLevel : " + mHealthInfo.batteryLevel);
/*SPRD : add power debug log end*/
mHandler.post(new Runnable() {
@Override
public void run() {
if (mActivityManagerInternal.isSystemReady()) {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.putExtra(Intent.EXTRA_REASON,
PowerManager.SHUTDOWN_LOW_BATTERY);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
}
}
});
}
}