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