Add class BatteryLevelData used to parcel the battery timestamps and
levels. It behaves as an interface between UI and data. Bug: 236101687 Test: make RunSettingsRoboTests Change-Id: I4f79165125254ce1372abf1a207411a183aabb23
This commit is contained in:
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.fuelgauge.batteryusage;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** Wraps the battery timestamp and level data used for battery usage chart. */
|
||||||
|
public final class BatteryLevelData {
|
||||||
|
|
||||||
|
/** A container for the battery timestamp and level data. */
|
||||||
|
public static final class PeriodBatteryLevelData {
|
||||||
|
private static final String TAG = "PeriodBatteryLevelData";
|
||||||
|
|
||||||
|
private final ImmutableList<Long> mTimestamps;
|
||||||
|
private final ImmutableList<Integer> mLevels;
|
||||||
|
|
||||||
|
public PeriodBatteryLevelData(List<Long> timestamps, List<Integer> levels) {
|
||||||
|
if (timestamps.size() != levels.size()) {
|
||||||
|
Log.e(TAG, "Different sizes of timestamps and levels. Timestamp: "
|
||||||
|
+ timestamps.size() + ", Level: " + levels.size());
|
||||||
|
mTimestamps = ImmutableList.of();
|
||||||
|
mLevels = ImmutableList.of();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mTimestamps = ImmutableList.copyOf(timestamps);
|
||||||
|
mLevels = ImmutableList.copyOf(levels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableList<Long> getTimestamps() {
|
||||||
|
return mTimestamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableList<Integer> getLevels() {
|
||||||
|
return mLevels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final PeriodBatteryLevelData mDailyBatteryLevels;
|
||||||
|
private final ImmutableList<PeriodBatteryLevelData> mHourlyBatteryLevelsPerDay;
|
||||||
|
|
||||||
|
public BatteryLevelData(
|
||||||
|
PeriodBatteryLevelData dailyBatteryLevels,
|
||||||
|
List<PeriodBatteryLevelData> hourlyBatteryLevelsPerDay) {
|
||||||
|
mDailyBatteryLevels = dailyBatteryLevels;
|
||||||
|
mHourlyBatteryLevelsPerDay = ImmutableList.copyOf(hourlyBatteryLevelsPerDay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodBatteryLevelData getDailyBatteryLevels() {
|
||||||
|
return mDailyBatteryLevels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableList<PeriodBatteryLevelData> getHourlyBatteryLevelsPerDay() {
|
||||||
|
return mHourlyBatteryLevelsPerDay;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user