Merge "Reduce api calls when getDataSummary" into main
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.java b/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.java
deleted file mode 100644
index 2497801..0000000
--- a/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2022 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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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 java.util.List;
-
-/** Data access object for accessing {@link AppUsageEventEntity} in the database. */
-@Dao
-public interface AppUsageEventDao {
-
-    /** Inserts a {@link AppUsageEventEntity} data into the database. */
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
-    void insert(AppUsageEventEntity event);
-
-    /** Inserts {@link AppUsageEventEntity} data into the database. */
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
-    void insertAll(List<AppUsageEventEntity> events);
-
-    /** Lists all recorded data after a specific timestamp. */
-    @Query("SELECT * FROM AppUsageEventEntity WHERE timestamp > :timestamp ORDER BY timestamp DESC")
-    List<AppUsageEventEntity> getAllAfter(long timestamp);
-
-    /** Gets the {@link 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);
-
-    /** Gets the {@link Cursor} of the latest timestamp of the specific user. */
-    @Query("SELECT MAX(timestamp) as timestamp FROM AppUsageEventEntity WHERE userId = :userId")
-    Cursor getLatestTimestampOfUser(long userId);
-
-    /** Deletes all recorded data before a specific timestamp. */
-    @Query("DELETE FROM AppUsageEventEntity WHERE timestamp <= :timestamp")
-    void clearAllBefore(long timestamp);
-
-    /** Deletes all recorded data after a specific timestamp. */
-    @Query("DELETE FROM AppUsageEventEntity WHERE timestamp >= :timestamp")
-    void clearAllAfter(long timestamp);
-
-    /** Clears all recorded data in the database. */
-    @Query("DELETE FROM AppUsageEventEntity")
-    void clearAll();
-}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.kt b/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.kt
new file mode 100644
index 0000000..fa5fbc7
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batteryusage/db/AppUsageEventDao.kt
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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
+
+/** Data access object for accessing [AppUsageEventEntity] in the database. */
+@Dao
+interface AppUsageEventDao {
+    /** Inserts a [AppUsageEventEntity] data into the database. */
+    @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(event: AppUsageEventEntity)
+
+    /** Inserts [AppUsageEventEntity] data into the database. */
+    @Insert(onConflict = OnConflictStrategy.REPLACE)
+    fun insertAll(events: List<AppUsageEventEntity>)
+
+    /** Lists all recorded data after a specific timestamp. */
+    @Query("SELECT * FROM AppUsageEventEntity WHERE timestamp > :timestamp ORDER BY timestamp DESC")
+    fun getAllAfter(timestamp: Long): List<AppUsageEventEntity>
+
+    /** 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"
+    )
+    fun getAllForUsersAfter(userIds: List<Long>, timestamp: Long): Cursor
+
+    /** Gets the [Cursor] of the latest timestamp of the specific user. */
+    @Query("SELECT MAX(timestamp) as timestamp FROM AppUsageEventEntity WHERE userId = :userId")
+    fun getLatestTimestampOfUser(userId: Long): Cursor
+
+    /** Deletes all recorded data before a specific timestamp. */
+    @Query("DELETE FROM AppUsageEventEntity WHERE timestamp <= :timestamp")
+    fun clearAllBefore(timestamp: Long)
+
+    /** Deletes all recorded data after a specific timestamp. */
+    @Query("DELETE FROM AppUsageEventEntity WHERE timestamp >= :timestamp")
+    fun clearAllAfter(timestamp: Long)
+
+    /** Clears all recorded data in the database. */
+    @Query("DELETE FROM AppUsageEventEntity") fun clearAll()
+}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.java b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.java
deleted file mode 100644
index 19d2043..0000000
--- a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2023 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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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 java.util.List;
-
-/** Data access object for accessing {@link BatteryEventEntity} in the database. */
-@Dao
-public interface BatteryEventDao {
-    /** Inserts a {@link BatteryEventEntity} data into the database. */
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
-    void insert(BatteryEventEntity event);
-
-    /** Gets all recorded data. */
-    @Query("SELECT * FROM BatteryEventEntity ORDER BY timestamp DESC")
-    List<BatteryEventEntity> getAll();
-
-    /** Gets the {@link Cursor} of the last full charge time . */
-    @Query(
-            "SELECT MAX(timestamp) FROM BatteryEventEntity"
-                    + " WHERE batteryEventType = 3") // BatteryEventType.FULL_CHARGED = 3
-    Cursor getLastFullChargeTimestamp();
-
-    /** Gets the {@link Long} of the last full charge time . */
-    @Query(
-            "SELECT MAX(timestamp) FROM BatteryEventEntity"
-                    + " WHERE batteryEventType = 3") // BatteryEventType.FULL_CHARGED = 3
-    Long getLastFullChargeTimestampForLog();
-
-    /** Gets the {@link 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);
-
-    /** 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);
-
-    /** Deletes all recorded data before a specific timestamp. */
-    @Query("DELETE FROM BatteryEventEntity WHERE timestamp <= :timestamp")
-    void clearAllBefore(long timestamp);
-
-    /** Deletes all recorded data after a specific timestamp. */
-    @Query("DELETE FROM BatteryEventEntity WHERE timestamp >= :timestamp")
-    void clearAllAfter(long timestamp);
-
-    /** Clears all recorded data in the database. */
-    @Query("DELETE FROM BatteryEventEntity")
-    void clearAll();
-}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.kt b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.kt
new file mode 100644
index 0000000..bac97d0
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryEventDao.kt
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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
+
+/** 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)
+
+    /** Gets all recorded data. */
+    @Query("SELECT * FROM BatteryEventEntity ORDER BY timestamp DESC")
+    fun getAll(): List<BatteryEventEntity>
+
+    /** Gets the [Cursor] of the last full charge time. */
+    @Query(
+        "SELECT MAX(timestamp) FROM BatteryEventEntity" +
+            " WHERE batteryEventType = 3" // BatteryEventType.FULL_CHARGED = 3
+    )
+    fun getLastFullChargeTimestamp(): Cursor
+
+    /** Gets the [Long] of the last full charge time. */
+    @Query(
+        "SELECT MAX(timestamp) FROM BatteryEventEntity" +
+            " WHERE batteryEventType = 3" // BatteryEventType.FULL_CHARGED = 3
+    )
+    fun getLastFullChargeTimestampForLog(): Long?
+
+    /** 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"
+    )
+    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"
+    )
+    fun getAllAfterForLog(timestamp: Long): List<BatteryEventEntity>
+
+    /** Deletes all recorded data before a specific timestamp. */
+    @Query("DELETE FROM BatteryEventEntity WHERE timestamp <= :timestamp")
+    fun clearAllBefore(timestamp: Long)
+
+    /** Deletes all recorded data after a specific timestamp. */
+    @Query("DELETE FROM BatteryEventEntity WHERE timestamp >= :timestamp")
+    fun clearAllAfter(timestamp: Long)
+
+    /** Clears all recorded data in the database. */
+    @Query("DELETE FROM BatteryEventEntity") fun clearAll()
+}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.java b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.java
deleted file mode 100644
index 049251e..0000000
--- a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2022 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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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 java.util.List;
-
-/** Data access object for accessing {@link BatteryState} in the database. */
-@Dao
-public interface BatteryStateDao {
-
-    /** Inserts a {@link BatteryState} data into the database. */
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
-    void insert(BatteryState state);
-
-    /** Inserts {@link BatteryState} data into the database. */
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
-    void insertAll(List<BatteryState> states);
-
-    /** Gets the {@link 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);
-
-    /** Lists all recorded battery states after a specific timestamp. */
-    @Query("SELECT * FROM BatteryState WHERE timestamp >= :timestamp ORDER BY timestamp ASC")
-    Cursor getBatteryStatesAfter(long timestamp);
-
-    /** Lists all recorded data after a specific timestamp. */
-    @Query("SELECT * FROM BatteryState WHERE timestamp > :timestamp ORDER BY timestamp DESC")
-    List<BatteryState> getAllAfter(long timestamp);
-
-    /** Get the count of distinct timestamp after a specific timestamp. */
-    @Query("SELECT COUNT(DISTINCT timestamp) FROM BatteryState WHERE timestamp > :timestamp")
-    int getDistinctTimestampCount(long timestamp);
-
-    /** Lists all distinct timestamps after a specific timestamp. */
-    @Query("SELECT DISTINCT timestamp FROM BatteryState WHERE timestamp > :timestamp")
-    List<Long> getDistinctTimestamps(long timestamp);
-
-    /** Deletes all recorded data before a specific timestamp. */
-    @Query("DELETE FROM BatteryState WHERE timestamp <= :timestamp")
-    void clearAllBefore(long timestamp);
-
-    /** Deletes all recorded data after a specific timestamp. */
-    @Query("DELETE FROM BatteryState WHERE timestamp >= :timestamp")
-    void clearAllAfter(long timestamp);
-
-    /** Clears all recorded data in the database. */
-    @Query("DELETE FROM BatteryState")
-    void clearAll();
-}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.kt b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.kt
new file mode 100644
index 0000000..6d31e07
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryStateDao.kt
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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
+
+/** Data access object for accessing [BatteryState] in the database. */
+@Dao
+interface BatteryStateDao {
+    /** Inserts a [BatteryState] data into the database. */
+    @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(state: BatteryState)
+
+    /** Inserts [BatteryState] data into the database. */
+    @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(states: List<BatteryState>)
+
+    /** Gets the [Cursor] of the latest record timestamp no later than the given timestamp. */
+    @Query("SELECT MAX(timestamp) FROM BatteryState WHERE timestamp <= :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")
+    fun getBatteryStatesAfter(timestamp: Long): Cursor
+
+    /** Lists all recorded data after a specific timestamp. */
+    @Query("SELECT * FROM BatteryState WHERE timestamp > :timestamp ORDER BY timestamp DESC")
+    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")
+    fun getDistinctTimestampCount(timestamp: Long): Int
+
+    /** Lists all distinct timestamps after a specific timestamp. */
+    @Query("SELECT DISTINCT timestamp FROM BatteryState WHERE timestamp > :timestamp")
+    fun getDistinctTimestamps(timestamp: Long): List<Long>
+
+    /** Deletes all recorded data before a specific timestamp. */
+    @Query("DELETE FROM BatteryState WHERE timestamp <= :timestamp")
+    fun clearAllBefore(timestamp: Long)
+
+    /** Deletes all recorded data after a specific timestamp. */
+    @Query("DELETE FROM BatteryState WHERE timestamp >= :timestamp")
+    fun clearAllAfter(timestamp: Long)
+
+    /** Clears all recorded data in the database. */
+    @Query("DELETE FROM BatteryState") fun clearAll()
+}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.java b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.java
deleted file mode 100644
index d53b0cf..0000000
--- a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2023 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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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 java.util.List;
-
-/** Data access object for accessing {@link BatteryUsageSlotEntity} in the database. */
-@Dao
-public interface BatteryUsageSlotDao {
-    /** Inserts a {@link BatteryUsageSlotEntity} data into the database. */
-    @Insert(onConflict = OnConflictStrategy.REPLACE)
-    void insert(BatteryUsageSlotEntity event);
-
-    /** Gets all recorded data. */
-    @Query("SELECT * FROM BatteryUsageSlotEntity ORDER BY timestamp ASC")
-    List<BatteryUsageSlotEntity> getAll();
-
-    /** Gets the {@link Cursor} of all recorded data after a specific timestamp. */
-    @Query(
-            "SELECT * FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp"
-                    + " ORDER BY timestamp ASC")
-    Cursor getAllAfter(long timestamp);
-
-    /** 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);
-
-    /** Deletes all recorded data before a specific timestamp. */
-    @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp <= :timestamp")
-    void clearAllBefore(long timestamp);
-
-    /** Deletes all recorded data after a specific timestamp. */
-    @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp")
-    void clearAllAfter(long timestamp);
-
-    /** Clears all recorded data in the database. */
-    @Query("DELETE FROM BatteryUsageSlotEntity")
-    void clearAll();
-}
diff --git a/src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.kt b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.kt
new file mode 100644
index 0000000..434c61a
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batteryusage/db/BatteryUsageSlotDao.kt
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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
+
+/** Data access object for accessing [BatteryUsageSlotEntity] in the database. */
+@Dao
+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")
+    fun getAll(): List<BatteryUsageSlotEntity>
+
+    /** Gets the [Cursor] of all recorded data after a specific timestamp. */
+    @Query(
+        "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"
+    )
+    fun getAllAfterForLog(timestamp: Long): List<BatteryUsageSlotEntity>
+
+    /** Deletes all recorded data before a specific timestamp. */
+    @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp <= :timestamp")
+    fun clearAllBefore(timestamp: Long)
+
+    /** Deletes all recorded data after a specific timestamp. */
+    @Query("DELETE FROM BatteryUsageSlotEntity WHERE timestamp >= :timestamp")
+    fun clearAllAfter(timestamp: Long)
+
+    /** Clears all recorded data in the database. */
+    @Query("DELETE FROM BatteryUsageSlotEntity") fun clearAll()
+}