From 5b84fde6af6ffb2b7ab79b40bed77a46cd81f837 Mon Sep 17 00:00:00 2001 From: Salvador Martinez Date: Fri, 17 May 2019 15:43:16 -0700 Subject: [PATCH] Add function to query last estimate time to Estimate This just adds a centralized place to query for the last update time so that people don't implement it with different defaults or something like that. Test: in sister CL Bug: 132751712 Change-Id: I10769eaa2e4c2ec613397988a264228a9474d1d6 --- .../com/android/settingslib/fuelgauge/Estimate.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt index 786139ffc7903..b2e75ea6867fc 100644 --- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt +++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/Estimate.kt @@ -77,5 +77,17 @@ class Estimate( Settings.Global.putLong(resolver, Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME, System.currentTimeMillis()) } + + /** + * Returns when the estimate was last updated as an Instant + */ + @JvmStatic + fun getLastCacheUpdateTime(context: Context): Instant { + return Instant.ofEpochMilli( + Settings.Global.getLong( + context.contentResolver, + Settings.Global.BATTERY_ESTIMATES_LAST_UPDATE_TIME, + -1)) + } } }