Bug: 344438848 Bug: 346706894 Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage Flag: EXEMPT bug fix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:164e2be9380ef0df6afe7616fb0bedc8eea6f899) Merged-In: Ifb18c2d156d11fcfdc67cff575ba800c4a6cc0fe Change-Id: Ifb18c2d156d11fcfdc67cff575ba800c4a6cc0fe
78 lines
2.8 KiB
Java
78 lines
2.8 KiB
Java
/*
|
|
* 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.content.Context;
|
|
import android.util.Log;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.room.Database;
|
|
import androidx.room.Room;
|
|
import androidx.room.RoomDatabase;
|
|
|
|
/** A {@link RoomDatabase} for battery usage states history. */
|
|
@Database(
|
|
entities = {
|
|
AppUsageEventEntity.class,
|
|
BatteryEventEntity.class,
|
|
BatteryState.class,
|
|
BatteryUsageSlotEntity.class,
|
|
BatteryReattributeEntity.class
|
|
},
|
|
version = 2)
|
|
public abstract class BatteryStateDatabase extends RoomDatabase {
|
|
private static final String TAG = "BatteryStateDatabase";
|
|
private static final String DB_FILE_NAME = "battery-usage-db-v10";
|
|
|
|
private static BatteryStateDatabase sBatteryStateDatabase;
|
|
|
|
/** Provides DAO for app usage event table. */
|
|
public abstract AppUsageEventDao appUsageEventDao();
|
|
|
|
/** Provides DAO for battery event table. */
|
|
public abstract BatteryEventDao batteryEventDao();
|
|
|
|
/** Provides DAO for battery state table. */
|
|
public abstract BatteryStateDao batteryStateDao();
|
|
|
|
/** Provides DAO for battery usage slot table. */
|
|
public abstract BatteryUsageSlotDao batteryUsageSlotDao();
|
|
|
|
/** Provides DAO for battery reattribution table. */
|
|
@NonNull
|
|
public abstract BatteryReattributeDao batteryReattributeDao();
|
|
|
|
/** Gets or creates an instance of {@link RoomDatabase}. */
|
|
public static BatteryStateDatabase getInstance(Context context) {
|
|
if (sBatteryStateDatabase == null) {
|
|
sBatteryStateDatabase =
|
|
Room.databaseBuilder(context, BatteryStateDatabase.class, DB_FILE_NAME)
|
|
// Allows accessing data in the main thread for dumping bugreport.
|
|
.allowMainThreadQueries()
|
|
.fallbackToDestructiveMigration()
|
|
.build();
|
|
Log.d(TAG, "initialize battery states database");
|
|
}
|
|
return sBatteryStateDatabase;
|
|
}
|
|
|
|
/** Sets the instance of {@link RoomDatabase}. */
|
|
public static void setBatteryStateDatabase(BatteryStateDatabase database) {
|
|
BatteryStateDatabase.sBatteryStateDatabase = database;
|
|
}
|
|
}
|