Loading src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.java→src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.kt +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,53 +13,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link AppUsageEventEntity} in the database. */ /** Data access object for accessing [AppUsageEventEntity] in the database. */ @Dao public interface AppUsageEventDao { /** Inserts a {@link AppUsageEventEntity} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(AppUsageEventEntity event); interface AppUsageEventDao { /** Inserts a [AppUsageEventEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: AppUsageEventEntity) /** Inserts {@link AppUsageEventEntity} data into the database. */ /** Inserts [AppUsageEventEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insertAll(List<AppUsageEventEntity> events); fun insertAll(events: List<AppUsageEventEntity>) /** Lists all recorded data after a specific timestamp. */ @Query("SELECT * FROM AppUsageEventEntity WHERE timestamp > :timestamp ORDER BY timestamp DESC") List<AppUsageEventEntity> getAllAfter(long timestamp); fun getAllAfter(timestamp: Long): List<AppUsageEventEntity> /** Gets the {@link Cursor} of all recorded data after a specific timestamp of the users. */ /** Gets the [Cursor] of all recorded data after a specific timestamp of the users. */ @Query( "SELECT * FROM AppUsageEventEntity WHERE timestamp >= :timestamp" + " AND userId IN (:userIds) ORDER BY timestamp ASC") Cursor getAllForUsersAfter(List<Long> userIds, long timestamp); "SELECT * FROM AppUsageEventEntity WHERE timestamp >= :timestamp" + " AND userId IN (:userIds) ORDER BY timestamp ASC" ) fun getAllForUsersAfter(userIds: List<Long>, timestamp: Long): Cursor /** Gets the {@link Cursor} of the latest timestamp of the specific user. */ /** Gets the [Cursor] of the latest timestamp of the specific user. */ @Query("SELECT MAX(timestamp) as timestamp FROM AppUsageEventEntity WHERE userId = :userId") Cursor getLatestTimestampOfUser(long userId); fun getLatestTimestampOfUser(userId: Long): Cursor /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM AppUsageEventEntity WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM AppUsageEventEntity WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM AppUsageEventEntity") void clearAll(); @Query("DELETE FROM AppUsageEventEntity") fun clearAll() } src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.java→src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.kt +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,63 +13,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link BatteryEventEntity} in the database. */ /** Data access object for accessing [BatteryEventEntity] in the database. */ @Dao public interface BatteryEventDao { /** Inserts a {@link BatteryEventEntity} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(BatteryEventEntity event); interface BatteryEventDao { /** Inserts a [BatteryEventEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: BatteryEventEntity) /** Gets all recorded data. */ @Query("SELECT * FROM BatteryEventEntity ORDER BY timestamp DESC") List<BatteryEventEntity> getAll(); fun getAll(): List<BatteryEventEntity> /** Gets the {@link Cursor} of the last full charge time . */ /** Gets the [Cursor] of the last full charge time. */ @Query( "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3") // BatteryEventType.FULL_CHARGED = 3 Cursor getLastFullChargeTimestamp(); "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3" // BatteryEventType.FULL_CHARGED = 3 ) fun getLastFullChargeTimestamp(): Cursor /** Gets the {@link Long} of the last full charge time . */ /** Gets the [Long] of the last full charge time. */ @Query( "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3") // BatteryEventType.FULL_CHARGED = 3 Long getLastFullChargeTimestampForLog(); "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3" // BatteryEventType.FULL_CHARGED = 3 ) fun getLastFullChargeTimestampForLog(): Long? /** Gets the {@link Cursor} of all recorded data after a specific timestamp. */ /** Gets the [Cursor] of all recorded data after a specific timestamp. */ @Query( "SELECT * FROM BatteryEventEntity" + " WHERE timestamp >= :timestamp AND batteryEventType IN (:batteryEventTypes)" + " ORDER BY timestamp DESC") Cursor getAllAfter(long timestamp, List<Integer> batteryEventTypes); "SELECT * FROM BatteryEventEntity" + " WHERE timestamp >= :timestamp AND batteryEventType IN (:batteryEventTypes)" + " ORDER BY timestamp DESC" ) fun getAllAfter(timestamp: Long, batteryEventTypes: List<Int>): Cursor /** Gets all recorded data after a specific timestamp for log. */ @Query( "SELECT * FROM BatteryEventEntity " + "WHERE timestamp >= :timestamp ORDER BY timestamp DESC") List<BatteryEventEntity> getAllAfterForLog(long timestamp); "SELECT * FROM BatteryEventEntity " + "WHERE timestamp >= :timestamp ORDER BY timestamp DESC" ) fun getAllAfterForLog(timestamp: Long): List<BatteryEventEntity> /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM BatteryEventEntity WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM BatteryEventEntity WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM BatteryEventEntity") void clearAll(); @Query("DELETE FROM BatteryEventEntity") fun clearAll() } src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.java→src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.kt +22 −30 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,59 +13,51 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link BatteryState} in the database. */ /** Data access object for accessing [BatteryState] in the database. */ @Dao public interface BatteryStateDao { /** Inserts a {@link BatteryState} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(BatteryState state); interface BatteryStateDao { /** Inserts a [BatteryState] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(state: BatteryState) /** Inserts {@link BatteryState} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insertAll(List<BatteryState> states); /** Inserts [BatteryState] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(states: List<BatteryState>) /** Gets the {@link Cursor} of the latest record timestamp no later than the given timestamp. */ /** Gets the [Cursor] of the latest record timestamp no later than the given timestamp. */ @Query("SELECT MAX(timestamp) FROM BatteryState WHERE timestamp <= :timestamp") Cursor getLatestTimestampBefore(long timestamp); fun getLatestTimestampBefore(timestamp: Long): Cursor /** Lists all recorded battery states after a specific timestamp. */ @Query("SELECT * FROM BatteryState WHERE timestamp >= :timestamp ORDER BY timestamp ASC") Cursor getBatteryStatesAfter(long timestamp); fun getBatteryStatesAfter(timestamp: Long): Cursor /** Lists all recorded data after a specific timestamp. */ @Query("SELECT * FROM BatteryState WHERE timestamp > :timestamp ORDER BY timestamp DESC") List<BatteryState> getAllAfter(long timestamp); fun getAllAfter(timestamp: Long): List<BatteryState> /** Get the count of distinct timestamp after a specific timestamp. */ @Query("SELECT COUNT(DISTINCT timestamp) FROM BatteryState WHERE timestamp > :timestamp") int getDistinctTimestampCount(long timestamp); fun getDistinctTimestampCount(timestamp: Long): Int /** Lists all distinct timestamps after a specific timestamp. */ @Query("SELECT DISTINCT timestamp FROM BatteryState WHERE timestamp > :timestamp") List<Long> getDistinctTimestamps(long timestamp); fun getDistinctTimestamps(timestamp: Long): List<Long> /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM BatteryState WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM BatteryState WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM BatteryState") void clearAll(); @Query("DELETE FROM BatteryState") fun clearAll() } src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.java→src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.kt +58 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,50 +13,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link BatteryUsageSlotEntity} in the database. */ /** Data access object for accessing [BatteryUsageSlotEntity] in the database. */ @Dao public interface BatteryUsageSlotDao { /** Inserts a {@link BatteryUsageSlotEntity} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(BatteryUsageSlotEntity event); interface BatteryUsageSlotDao { /** Inserts a [BatteryUsageSlotEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: BatteryUsageSlotEntity) /** Gets all recorded data. */ @Query("SELECT * FROM BatteryUsageSlotEntity ORDER BY timestamp ASC") List<BatteryUsageSlotEntity> getAll(); fun getAll(): List<BatteryUsageSlotEntity> /** Gets the {@link Cursor} of all recorded data after a specific timestamp. */ /** Gets the [Cursor] of all recorded data after a specific timestamp. */ @Query( "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp ASC") Cursor getAllAfter(long timestamp); "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp ASC" ) fun getAllAfter(timestamp: Long): Cursor /** Gets all recorded data after a specific timestamp for log. */ @Query( "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp DESC") List<BatteryUsageSlotEntity> getAllAfterForLog(long timestamp); "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp DESC" ) fun getAllAfterForLog(timestamp: Long): List<BatteryUsageSlotEntity> /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM BatteryUsageSlotEntity") void clearAll(); @Query("DELETE FROM BatteryUsageSlotEntity") fun clearAll() } Loading
src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.java→src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.kt +59 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,53 +13,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link AppUsageEventEntity} in the database. */ /** Data access object for accessing [AppUsageEventEntity] in the database. */ @Dao public interface AppUsageEventDao { /** Inserts a {@link AppUsageEventEntity} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(AppUsageEventEntity event); interface AppUsageEventDao { /** Inserts a [AppUsageEventEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: AppUsageEventEntity) /** Inserts {@link AppUsageEventEntity} data into the database. */ /** Inserts [AppUsageEventEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insertAll(List<AppUsageEventEntity> events); fun insertAll(events: List<AppUsageEventEntity>) /** Lists all recorded data after a specific timestamp. */ @Query("SELECT * FROM AppUsageEventEntity WHERE timestamp > :timestamp ORDER BY timestamp DESC") List<AppUsageEventEntity> getAllAfter(long timestamp); fun getAllAfter(timestamp: Long): List<AppUsageEventEntity> /** Gets the {@link Cursor} of all recorded data after a specific timestamp of the users. */ /** Gets the [Cursor] of all recorded data after a specific timestamp of the users. */ @Query( "SELECT * FROM AppUsageEventEntity WHERE timestamp >= :timestamp" + " AND userId IN (:userIds) ORDER BY timestamp ASC") Cursor getAllForUsersAfter(List<Long> userIds, long timestamp); "SELECT * FROM AppUsageEventEntity WHERE timestamp >= :timestamp" + " AND userId IN (:userIds) ORDER BY timestamp ASC" ) fun getAllForUsersAfter(userIds: List<Long>, timestamp: Long): Cursor /** Gets the {@link Cursor} of the latest timestamp of the specific user. */ /** Gets the [Cursor] of the latest timestamp of the specific user. */ @Query("SELECT MAX(timestamp) as timestamp FROM AppUsageEventEntity WHERE userId = :userId") Cursor getLatestTimestampOfUser(long userId); fun getLatestTimestampOfUser(userId: Long): Cursor /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM AppUsageEventEntity WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM AppUsageEventEntity WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM AppUsageEventEntity") void clearAll(); @Query("DELETE FROM AppUsageEventEntity") fun clearAll() }
src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.java→src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.kt +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,63 +13,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link BatteryEventEntity} in the database. */ /** Data access object for accessing [BatteryEventEntity] in the database. */ @Dao public interface BatteryEventDao { /** Inserts a {@link BatteryEventEntity} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(BatteryEventEntity event); interface BatteryEventDao { /** Inserts a [BatteryEventEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: BatteryEventEntity) /** Gets all recorded data. */ @Query("SELECT * FROM BatteryEventEntity ORDER BY timestamp DESC") List<BatteryEventEntity> getAll(); fun getAll(): List<BatteryEventEntity> /** Gets the {@link Cursor} of the last full charge time . */ /** Gets the [Cursor] of the last full charge time. */ @Query( "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3") // BatteryEventType.FULL_CHARGED = 3 Cursor getLastFullChargeTimestamp(); "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3" // BatteryEventType.FULL_CHARGED = 3 ) fun getLastFullChargeTimestamp(): Cursor /** Gets the {@link Long} of the last full charge time . */ /** Gets the [Long] of the last full charge time. */ @Query( "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3") // BatteryEventType.FULL_CHARGED = 3 Long getLastFullChargeTimestampForLog(); "SELECT MAX(timestamp) FROM BatteryEventEntity" + " WHERE batteryEventType = 3" // BatteryEventType.FULL_CHARGED = 3 ) fun getLastFullChargeTimestampForLog(): Long? /** Gets the {@link Cursor} of all recorded data after a specific timestamp. */ /** Gets the [Cursor] of all recorded data after a specific timestamp. */ @Query( "SELECT * FROM BatteryEventEntity" + " WHERE timestamp >= :timestamp AND batteryEventType IN (:batteryEventTypes)" + " ORDER BY timestamp DESC") Cursor getAllAfter(long timestamp, List<Integer> batteryEventTypes); "SELECT * FROM BatteryEventEntity" + " WHERE timestamp >= :timestamp AND batteryEventType IN (:batteryEventTypes)" + " ORDER BY timestamp DESC" ) fun getAllAfter(timestamp: Long, batteryEventTypes: List<Int>): Cursor /** Gets all recorded data after a specific timestamp for log. */ @Query( "SELECT * FROM BatteryEventEntity " + "WHERE timestamp >= :timestamp ORDER BY timestamp DESC") List<BatteryEventEntity> getAllAfterForLog(long timestamp); "SELECT * FROM BatteryEventEntity " + "WHERE timestamp >= :timestamp ORDER BY timestamp DESC" ) fun getAllAfterForLog(timestamp: Long): List<BatteryEventEntity> /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM BatteryEventEntity WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM BatteryEventEntity WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM BatteryEventEntity") void clearAll(); @Query("DELETE FROM BatteryEventEntity") fun clearAll() }
src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.java→src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.kt +22 −30 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,59 +13,51 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link BatteryState} in the database. */ /** Data access object for accessing [BatteryState] in the database. */ @Dao public interface BatteryStateDao { /** Inserts a {@link BatteryState} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(BatteryState state); interface BatteryStateDao { /** Inserts a [BatteryState] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(state: BatteryState) /** Inserts {@link BatteryState} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insertAll(List<BatteryState> states); /** Inserts [BatteryState] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(states: List<BatteryState>) /** Gets the {@link Cursor} of the latest record timestamp no later than the given timestamp. */ /** Gets the [Cursor] of the latest record timestamp no later than the given timestamp. */ @Query("SELECT MAX(timestamp) FROM BatteryState WHERE timestamp <= :timestamp") Cursor getLatestTimestampBefore(long timestamp); fun getLatestTimestampBefore(timestamp: Long): Cursor /** Lists all recorded battery states after a specific timestamp. */ @Query("SELECT * FROM BatteryState WHERE timestamp >= :timestamp ORDER BY timestamp ASC") Cursor getBatteryStatesAfter(long timestamp); fun getBatteryStatesAfter(timestamp: Long): Cursor /** Lists all recorded data after a specific timestamp. */ @Query("SELECT * FROM BatteryState WHERE timestamp > :timestamp ORDER BY timestamp DESC") List<BatteryState> getAllAfter(long timestamp); fun getAllAfter(timestamp: Long): List<BatteryState> /** Get the count of distinct timestamp after a specific timestamp. */ @Query("SELECT COUNT(DISTINCT timestamp) FROM BatteryState WHERE timestamp > :timestamp") int getDistinctTimestampCount(long timestamp); fun getDistinctTimestampCount(timestamp: Long): Int /** Lists all distinct timestamps after a specific timestamp. */ @Query("SELECT DISTINCT timestamp FROM BatteryState WHERE timestamp > :timestamp") List<Long> getDistinctTimestamps(long timestamp); fun getDistinctTimestamps(timestamp: Long): List<Long> /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM BatteryState WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM BatteryState WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM BatteryState") void clearAll(); @Query("DELETE FROM BatteryState") fun clearAll() }
src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.java→src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.kt +58 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * Copyright (C) 2024 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. Loading @@ -13,50 +13,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.fuelgauge.batteryusage.db package com.android.settings.fuelgauge.batteryusage.db; import android.database.Cursor import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query import android.database.Cursor; import androidx.room.Dao; import androidx.room.Insert; import androidx.room.OnConflictStrategy; import androidx.room.Query; import java.util.List; /** Data access object for accessing {@link BatteryUsageSlotEntity} in the database. */ /** Data access object for accessing [BatteryUsageSlotEntity] in the database. */ @Dao public interface BatteryUsageSlotDao { /** Inserts a {@link BatteryUsageSlotEntity} data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(BatteryUsageSlotEntity event); interface BatteryUsageSlotDao { /** Inserts a [BatteryUsageSlotEntity] data into the database. */ @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: BatteryUsageSlotEntity) /** Gets all recorded data. */ @Query("SELECT * FROM BatteryUsageSlotEntity ORDER BY timestamp ASC") List<BatteryUsageSlotEntity> getAll(); fun getAll(): List<BatteryUsageSlotEntity> /** Gets the {@link Cursor} of all recorded data after a specific timestamp. */ /** Gets the [Cursor] of all recorded data after a specific timestamp. */ @Query( "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp ASC") Cursor getAllAfter(long timestamp); "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp ASC" ) fun getAllAfter(timestamp: Long): Cursor /** Gets all recorded data after a specific timestamp for log. */ @Query( "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp DESC") List<BatteryUsageSlotEntity> getAllAfterForLog(long timestamp); "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp" + " ORDER BY timestamp DESC" ) fun getAllAfterForLog(timestamp: Long): List<BatteryUsageSlotEntity> /** Deletes all recorded data before a specific timestamp. */ @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp <= :timestamp") void clearAllBefore(long timestamp); fun clearAllBefore(timestamp: Long) /** Deletes all recorded data after a specific timestamp. */ @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp") void clearAllAfter(long timestamp); fun clearAllAfter(timestamp: Long) /** Clears all recorded data in the database. */ @Query("DELETE FROM BatteryUsageSlotEntity") void clearAll(); @Query("DELETE FROM BatteryUsageSlotEntity") fun clearAll() }