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.data.v33 18 19 import android.os.Build 20 import androidx.annotation.RequiresApi 21 import androidx.annotation.VisibleForTesting 22 import com.android.permissioncontroller.permission.data.SmartAsyncMediatorLiveData 23 import com.android.permissioncontroller.permission.service.PermissionEventStorage 24 import com.android.permissioncontroller.permission.service.v33.PermissionDecisionStorageImpl 25 import kotlinx.coroutines.Job 26 27 /** Gets all recent permission decisions made by the user. */ 28 @RequiresApi(Build.VERSION_CODES.TIRAMISU) 29 class RecentPermissionDecisionsLiveData( 30 @get:VisibleForTesting 31 val recentDecisionsStorage: PermissionEventStorage<PermissionDecision> = 32 PermissionDecisionStorageImpl.getInstance() 33 ) : SmartAsyncMediatorLiveData<List<PermissionDecision>>() { 34 loadDataAndPostValuenull35 override suspend fun loadDataAndPostValue(job: Job) { 36 if (job.isCancelled) { 37 return 38 } 39 40 // no need to subscribe to decision changes, since those will also be bubbled up through 41 // package info changes 42 recentDecisionsStorage.loadEvents().also { postValue(it) } 43 } 44 } 45