原生代碼的位置
首先直接給出代碼位置:
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); 就好了诵叁。
非原廠代碼
我現(xiàn)在手上這部分是非原廠代碼,它的大體代碼如下:
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這個(gè)屬性舶赔,那都有誰會對這個(gè)屬性感興趣呢臀叙?
./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這個(gè)關(guān)鍵字的用法。
./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;
現(xiàn)在你知道如果你的機(jī)器沒有電池的話都應(yīng)該改AOSP的哪些地方了逮光,具體的方式我就不多說了话瞧,直接修改就好了。