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