Remove redundant methods and refactor
Remove the summary method and write the code in AOSP directly instead to force string consistency. Also refactor a bit after the modification. Fixes: 276399056 Test: robotests Change-Id: I76ad740b694363a3cdfb3748e41c840fb678b93d
This commit is contained in:
@@ -20,15 +20,8 @@ package com.android.settings.fuelgauge;
|
||||
public interface BatterySettingsFeatureProvider {
|
||||
|
||||
/** Returns true if manufacture date should be shown */
|
||||
boolean isManufactureDateAvailable();
|
||||
boolean isManufactureDateAvailable(long manufactureDateMs);
|
||||
|
||||
/** Returns true if first use date should be shown */
|
||||
boolean isFirstUseDateAvailable();
|
||||
|
||||
/** Returns the summary of battery manufacture date */
|
||||
CharSequence getManufactureDateSummary();
|
||||
|
||||
/** Returns the summary of battery first use date */
|
||||
CharSequence getFirstUseDateSummary();
|
||||
|
||||
boolean isFirstUseDateAvailable(long firstUseDateMs);
|
||||
}
|
||||
|
||||
@@ -16,77 +16,16 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.BatteryManager;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** Feature provider implementation for battery settings usage. */
|
||||
public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatureProvider {
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
private BatteryManager mBatteryManager;
|
||||
private long mManufactureDateInMs;
|
||||
private long mFirstUseDateInMs;
|
||||
|
||||
public BatterySettingsFeatureProviderImpl(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
mBatteryManager = mContext.getSystemService(BatteryManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isManufactureDateAvailable() {
|
||||
public boolean isManufactureDateAvailable(long manufactureDateMs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirstUseDateAvailable() {
|
||||
public boolean isFirstUseDateAvailable(long firstUseDateMs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getManufactureDateSummary() {
|
||||
return isManufactureDateAvailable()
|
||||
? getFormattedDate(getManufactureDate())
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getFirstUseDateSummary() {
|
||||
return isFirstUseDateAvailable()
|
||||
? getFormattedDate(getFirstUseDate())
|
||||
: null;
|
||||
}
|
||||
|
||||
protected long getManufactureDate() {
|
||||
if (mManufactureDateInMs == 0L) {
|
||||
final long manufactureDateInSec = mBatteryManager.getLongProperty(
|
||||
BatteryManager.BATTERY_PROPERTY_MANUFACTURING_DATE);
|
||||
mManufactureDateInMs = TimeUnit.MILLISECONDS.convert(manufactureDateInSec,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
return mManufactureDateInMs;
|
||||
}
|
||||
|
||||
protected long getFirstUseDate() {
|
||||
if (mFirstUseDateInMs == 0L) {
|
||||
final long firstUseDateInSec = mBatteryManager.getLongProperty(
|
||||
BatteryManager.BATTERY_PROPERTY_FIRST_USAGE_DATE);
|
||||
mFirstUseDateInMs = TimeUnit.MILLISECONDS.convert(firstUseDateInSec, TimeUnit.SECONDS);
|
||||
}
|
||||
return mFirstUseDateInMs;
|
||||
}
|
||||
|
||||
private CharSequence getFormattedDate(long dateInMs) {
|
||||
final Instant instant = Instant.ofEpochMilli(dateInMs);
|
||||
final String localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate().format(
|
||||
DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG));
|
||||
|
||||
return localDate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +64,10 @@ import com.google.protobuf.MessageLite;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -671,6 +673,14 @@ public class BatteryUtils {
|
||||
}
|
||||
return summary.toString();
|
||||
}
|
||||
/** Format the date of battery related info */
|
||||
public static CharSequence getBatteryInfoFormattedDate(long dateInMs) {
|
||||
final Instant instant = Instant.ofEpochMilli(dateInMs);
|
||||
final String localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate().format(
|
||||
DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG));
|
||||
|
||||
return localDate;
|
||||
}
|
||||
|
||||
/** Builds the battery usage time information for one timestamp. */
|
||||
private static String buildBatteryUsageTimeInfo(final Context context, long timeInMs,
|
||||
|
||||
Reference in New Issue
Block a user