Settings: deviceinfo: Try read designed capacity from PowerProfile if unavailable

Signed-off-by: cjh1249131356 <cjh1249131356@gmail.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
cjh1249131356
2024-06-11 15:57:21 +08:00
committed by Joey
parent 6cb2fd35e5
commit 6e94d6b041
2 changed files with 14 additions and 2 deletions

View File

@@ -20,6 +20,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import com.android.internal.os.PowerProfile;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.fuelgauge.BatteryUtils;
@@ -42,8 +44,12 @@ public class BatteryDesignCapacityPreferenceController extends BasePreferenceCon
@Override
public CharSequence getSummary() {
Intent batteryIntent = BatteryUtils.getBatteryIntent(mContext);
final int designCapacityUah =
int designCapacityUah =
batteryIntent.getIntExtra(BatteryManager.EXTRA_DESIGN_CAPACITY, -1);
if (designCapacityUah <= 0) {
final PowerProfile profile = new PowerProfile(mContext);
designCapacityUah = (int) profile.getBatteryCapacity() * 1000;
}
if (designCapacityUah > 0) {
int designCapacity = designCapacityUah / 1_000;

View File

@@ -20,6 +20,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.BatteryManager;
import com.android.internal.os.PowerProfile;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.fuelgauge.BatteryUtils;
@@ -44,8 +46,12 @@ public class BatteryMaximumCapacityPreferenceController extends BasePreferenceCo
Intent batteryIntent = BatteryUtils.getBatteryIntent(mContext);
final int maxCapacityUah =
batteryIntent.getIntExtra(BatteryManager.EXTRA_MAXIMUM_CAPACITY, -1);
final int designCapacityUah =
int designCapacityUah =
batteryIntent.getIntExtra(BatteryManager.EXTRA_DESIGN_CAPACITY, -1);
if (designCapacityUah <= 0) {
final PowerProfile profile = new PowerProfile(mContext);
designCapacityUah = (int) profile.getBatteryCapacity() * 1000;
}
if (maxCapacityUah > 0 && designCapacityUah > 0) {
int maxCapacity = maxCapacityUah / 1_000;