Clear cache data to recalculate usage slot after receiving timezone change intent.
- Clear usage slot & even hour calculate event. Bug: 355084572 Test: atest BootBroadcastReceiverTest Test: atest BatteryEventDaoTest Flag: EXEMPT bug fix Change-Id: I0bc8b71219ce8cea3987a7bfc39b69e0c6047e3d
This commit is contained in:
@@ -455,6 +455,21 @@ public final class DatabaseUtils {
|
||||
});
|
||||
}
|
||||
|
||||
/** Clears generated cache data in the battery usage database. */
|
||||
public static void clearEvenHourCacheData(Context context) {
|
||||
AsyncTask.execute(
|
||||
() -> {
|
||||
try {
|
||||
final BatteryStateDatabase database =
|
||||
BatteryStateDatabase.getInstance(context.getApplicationContext());
|
||||
database.batteryEventDao().clearEvenHourEvent();
|
||||
database.batteryUsageSlotDao().clearAll();
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "clearEvenHourCacheData() failed", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Clears all out-of-date data in the battery usage database. */
|
||||
public static void clearExpiredDataIfNeeded(Context context) {
|
||||
AsyncTask.execute(
|
||||
@@ -923,14 +938,12 @@ public final class DatabaseUtils {
|
||||
final String logInfo =
|
||||
String.format(
|
||||
Locale.ENGLISH,
|
||||
"clear database for new time zone = %s",
|
||||
"clear database cache for new time zone = %s",
|
||||
TimeZone.getDefault().toString());
|
||||
BatteryUsageLogUtils.writeLog(context, Action.TIMEZONE_UPDATED, logInfo);
|
||||
Log.d(TAG, logInfo);
|
||||
DatabaseUtils.clearAll(context);
|
||||
DatabaseUtils.clearEvenHourCacheData(context);
|
||||
PeriodicJobManager.getInstance(context).refreshJob(/* fromBoot= */ false);
|
||||
// Take a snapshot of battery usage data immediately
|
||||
BatteryUsageDataLoader.enqueueWork(context, /* isFullChargeStart= */ true);
|
||||
}
|
||||
|
||||
private static long loadLongFromContentProvider(
|
||||
|
||||
@@ -20,12 +20,14 @@ import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.android.settings.fuelgauge.batteryusage.BatteryEventType
|
||||
|
||||
/** Data access object for accessing [BatteryEventEntity] in the database. */
|
||||
@Dao
|
||||
interface BatteryEventDao {
|
||||
/** Inserts a [BatteryEventEntity] data into the database. */
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: BatteryEventEntity)
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(event: BatteryEventEntity)
|
||||
|
||||
/** Gets all recorded data. */
|
||||
@Query("SELECT * FROM BatteryEventEntity ORDER BY timestamp DESC")
|
||||
@@ -68,6 +70,14 @@ interface BatteryEventDao {
|
||||
@Query("DELETE FROM BatteryEventEntity WHERE timestamp >= :timestamp")
|
||||
fun clearAllAfter(timestamp: Long)
|
||||
|
||||
/** Deletes even_hour event data in the database. */
|
||||
@Query(
|
||||
"DELETE FROM BatteryEventEntity " +
|
||||
"WHERE batteryEventType = 4" // BatteryEventType.EVEN_HOUR = 4
|
||||
)
|
||||
fun clearEvenHourEvent()
|
||||
|
||||
/** Clears all recorded data in the database. */
|
||||
@Query("DELETE FROM BatteryEventEntity") fun clearAll()
|
||||
@Query("DELETE FROM BatteryEventEntity")
|
||||
fun clearAll()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user