• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.fuelgauge.batteryusage.db;
18 
19 import android.database.Cursor;
20 
21 import androidx.room.Dao;
22 import androidx.room.Insert;
23 import androidx.room.OnConflictStrategy;
24 import androidx.room.Query;
25 
26 import java.util.List;
27 
28 /** Data access object for accessing {@link BatteryEventEntity} in the database. */
29 @Dao
30 public interface BatteryEventDao {
31     /** Inserts a {@link BatteryEventEntity} data into the database. */
32     @Insert(onConflict = OnConflictStrategy.REPLACE)
insert(BatteryEventEntity event)33     void insert(BatteryEventEntity event);
34 
35     /** Gets all recorded data. */
36     @Query("SELECT * FROM BatteryEventEntity ORDER BY timestamp DESC")
getAll()37     List<BatteryEventEntity> getAll();
38 
39     /** Gets the {@link Cursor} of the last full charge time . */
40     @Query("SELECT MAX(timestamp) FROM BatteryEventEntity"
41             + " WHERE batteryEventType = 3")  // BatteryEventType.FULL_CHARGED = 3
getLastFullChargeTimestamp()42     Cursor getLastFullChargeTimestamp();
43 
44     /** Gets the {@link Cursor} of all recorded data after a specific timestamp. */
45     @Query("SELECT * FROM BatteryEventEntity"
46             + " WHERE timestamp > :timestamp AND batteryEventType IN (:batteryEventTypes)"
47             + " ORDER BY timestamp DESC")
getAllAfter(long timestamp, List<Integer> batteryEventTypes)48     Cursor getAllAfter(long timestamp, List<Integer> batteryEventTypes);
49 
50     /** Deletes all recorded data before a specific timestamp. */
51     @Query("DELETE FROM BatteryEventEntity WHERE timestamp <= :timestamp")
clearAllBefore(long timestamp)52     void clearAllBefore(long timestamp);
53 
54     /** Clears all recorded data in the database. */
55     @Query("DELETE FROM BatteryEventEntity")
clearAll()56     void clearAll();
57 }
58