Fix NullPointerException in BatteryUsageStats

Bug: 185287730
Test: Build and launch Settings on a crosshatch
Change-Id: Iccdd8a0f3839b98dbb5c09599f35ac15985daa4c
This commit is contained in:
Dmitri Plotnikov
2021-04-13 22:08:45 -07:00
parent 177de2ed55
commit 153f2acfee
2 changed files with 5 additions and 7 deletions

View File

@@ -24,7 +24,6 @@ import com.android.internal.os.BatteryStatsHistory;
import com.android.internal.os.BatteryStatsHistoryIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -233,8 +232,6 @@ public final class BatteryUsageStats implements Parcelable {
mHistoryBuffer = null;
mHistoryTagPool = null;
}
System.out.println("From Parcel = " + Arrays.toString(
mCustomPowerComponentNames));
}
@Override
@@ -293,6 +290,7 @@ public final class BatteryUsageStats implements Parcelable {
* Builder for BatteryUsageStats.
*/
public static final class Builder {
@NonNull
private final String[] mCustomPowerComponentNames;
private final int mCustomTimeComponentCount;
private final boolean mIncludePowerModels;
@@ -311,11 +309,11 @@ public final class BatteryUsageStats implements Parcelable {
private Parcel mHistoryBuffer;
private List<BatteryStats.HistoryTag> mHistoryTagPool;
public Builder(String[] customPowerComponentNames, int customTimeComponentCount) {
public Builder(@NonNull String[] customPowerComponentNames, int customTimeComponentCount) {
this(customPowerComponentNames, customTimeComponentCount, false);
}
public Builder(String[] customPowerComponentNames, int customTimeComponentCount,
public Builder(@NonNull String[] customPowerComponentNames, int customTimeComponentCount,
boolean includePowerModels) {
mCustomPowerComponentNames = customPowerComponentNames;
mCustomTimeComponentCount = customTimeComponentCount;

View File

@@ -6951,9 +6951,9 @@ public class BatteryStatsImpl extends BatteryStats {
/**
* Returns the names of custom power components.
*/
public @Nullable String[] getCustomPowerComponentNames() {
public @NonNull String[] getCustomPowerComponentNames() {
if (mGlobalMeasuredEnergyStats == null) {
return null;
return new String[0];
}
final String[] names = mGlobalMeasuredEnergyStats.getCustomBucketNames();
for (int i = 0; i < names.length; i++) {