1 /* 2 * Copyright (C) 2021 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.permissioncontroller.permission.service.v33 18 19 import android.os.Build 20 import androidx.annotation.RequiresApi 21 import com.android.permissioncontroller.permission.data.v33.PermissionEvent 22 23 /** 24 * Persistent storage for retrieving persisted permission event data. 25 */ 26 @RequiresApi(Build.VERSION_CODES.TIRAMISU) 27 interface PermissionEventStorage<T : PermissionEvent> { 28 /** 29 * Persist a permission event for retrieval later. 30 * 31 * @param event the event to store 32 * @return whether the storage was successful 33 */ storeEventnull34 suspend fun storeEvent(event: T): Boolean 35 36 /** 37 * Returns all events, sorted from newest to oldest. This returns directly what is in storage 38 * and does not do any additional validation checking. 39 */ 40 suspend fun loadEvents(): List<T> 41 42 /** 43 * Clear all events. 44 */ 45 suspend fun clearEvents() 46 47 /** 48 * Remove data older than a certain threshold defined by the implementing class. 49 * 50 * @return whether the storage was successful 51 */ 52 suspend fun removeOldData(): Boolean 53 54 /** 55 * Remove all the event data for a particular package. 56 * 57 * @param packageName of the package to remove 58 * @return whether the storage was successful 59 */ 60 suspend fun removeEventsForPackage(packageName: String): Boolean 61 62 /** 63 * Update event timestamps based on the delta in system time. 64 * 65 * @param diffSystemTimeMillis the difference between the current and old system times. Positive 66 * values mean that the time has changed in the future and negative means the time was changed 67 * into the past. 68 * @return whether the storage was successful 69 */ 70 suspend fun updateEventsBySystemTimeDelta(diffSystemTimeMillis: Long): Boolean 71 }