Merge "Add method to calculate last full charge time" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-06-01 18:55:53 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ import android.util.Log;
import android.util.SparseLongArray;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.overlay.FeatureFactory;
import java.lang.annotation.Retention;
@@ -228,6 +229,19 @@ public class BatteryUtils {
});
}
/**
* Calculate the time since last full charge, including the device off time
*
* @param batteryStatsHelper utility class that contains the data
* @param currentTimeMs current wall time
* @return time in millis
*/
public long calculateLastFullChargeTime(BatteryStatsHelper batteryStatsHelper,
long currentTimeMs) {
return currentTimeMs - batteryStatsHelper.getStats().getStartClockTime();
}
private long convertUsToMs(long timeUs) {
return timeUs / 1000;
}

View File

@@ -41,7 +41,6 @@ import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BatterySipper;
@@ -415,11 +414,13 @@ public class PowerUsageSummary extends PowerUsageBase {
final int dischargeAmount = USE_FAKE_DATA ? 5000
: stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final long runningTime = calculateRunningTimeBasedOnStatsType();
final long lastFullChargeTime = mBatteryUtils.calculateLastFullChargeTime(mStatsHelper,
System.currentTimeMillis());
updateScreenPreference();
updateLastFullChargePreference(runningTime);
updateLastFullChargePreference(lastFullChargeTime);
final CharSequence timeSequence = Utils.formatElapsedTime(context, runningTime, false);
final CharSequence timeSequence = Utils.formatElapsedTime(context, lastFullChargeTime,
false);
final int resId = mShowAllApps ? R.string.power_usage_list_summary_device
: R.string.power_usage_list_summary;
mAppListGroup.setTitle(TextUtils.expandTemplate(getText(resId), timeSequence));