原生代码的位置
首先直接给出代码位置:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java
第507行
// Battery
final QuickSettingsTileView batteryTile = (QuickSettingsTileView)
inflater.inflate(R.layout.quick_settings_tile, parent, false);
batteryTile.setContent(R.layout.quick_settings_tile_battery, inflater);
batteryTile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
}
});
mModel.addBatteryTile(batteryTile, new QuickSettingsModel.RefreshCallback() {
@Override
public void refreshView(QuickSettingsTileView unused, State state) {
QuickSettingsModel.BatteryState batteryState =
(QuickSettingsModel.BatteryState) state;
String t;
if (batteryState.batteryLevel == 100) {
t = mContext.getString(R.string.quick_settings_battery_charged_label);
} else {
t = batteryState.pluggedIn
? mContext.getString(R.string.quick_settings_battery_charging_label,
batteryState.batteryLevel)
: mContext.getString(R.string.status_bar_settings_battery_meter_format,
batteryState.batteryLevel);
}
((TextView)batteryTile.findViewById(R.id.text)).setText(t);
batteryTile.setContentDescription(
mContext.getString(R.string.accessibility_quick_settings_battery, t));
}
});
parent.addView(batteryTile);
直接注释掉parent.addView(batteryTile); 就好了。
非原厂代码
我现在手上这部分是非原厂代码,它的大体代码如下:
private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
...
if(!hasNoBattery){
final QuickSettingsTileView batteryTile = (QuickSettingsTileView)
inflater.inflate(R.layout.quick_settings_tile, parent, false);
batteryTile.setContent(R.layout.quick_settings_tile_battery, inflater);
batteryTile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
}
});
mModel.addBatteryTile(batteryTile, new QuickSettingsModel.RefreshCallback() {
@Override
public void refreshView(QuickSettingsTileView unused, State state) {
QuickSettingsModel.BatteryState batteryState =
(QuickSettingsModel.BatteryState) state;
String t;
if (batteryState.batteryLevel == 100) {
t = mContext.getString(R.string.quick_settings_battery_charged_label);
} else {
t = batteryState.pluggedIn
? mContext.getString(R.string.quick_settings_battery_charging_label,
batteryState.batteryLevel)
: mContext.getString(R.string.status_bar_settings_battery_meter_format,
batteryState.batteryLevel);
}
((TextView)batteryTile.findViewById(R.id.text)).setText(t);
batteryTile.setContentDescription(
mContext.getString(R.string.accessibility_quick_settings_battery, t));
}
});
parent.addView(batteryTile);
}
增加了ro.factory.without_battery这个属性,那都有谁会对这个属性感兴趣呢?
./base/packages/Keyguard/src/com/android/keyguard/KeyguardMessageArea.java:59: private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:72: private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java:64: private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java:2906: private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java:39: private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java:110: private final boolean hasNoBattery = "true".equals(SystemProperties.get("ro.factory.without_battery", "false"));
可以看到全部都是对 hasNoBattery 做判断的,再找找hasNoBattery这个关键字的用法。
./base/packages/Keyguard/src/com/android/keyguard/KeyguardMessageArea.java:227: if(!hasNoBattery) setText(status);
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java:607: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java:613: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java:2929: if(!hasNoBattery)
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarTransitions.java:107: if(!hasNoBattery) mBattery.setAlpha(newAlphaBC);
./base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java:509: if(!hasNoBattery){
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:91: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:153: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:167: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:248: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:267: if(hasNoBattery) return;
./base/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java:373: if(hasNoBattery) return;
现在你知道如果你的机器没有电池的话都应该改AOSP的哪些地方了,具体的方式我就不多说了,直接修改就好了。