1 /* 2 * Copyright (C) 2022 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 android.annotation.SuppressLint 20 import com.android.permissioncontroller.PermissionControllerApplication 21 import com.android.permissioncontroller.permission.data.PermissionEvent 22 import com.android.permissioncontroller.permission.service.v33.PermissionDecisionStorageImpl 23 24 /** Singleton of all supported [PermissionEventStorage] on the device. */ 25 class PermissionEventStorageImpls { 26 companion object { 27 @Volatile private var INSTANCE: List<PermissionEventStorage<out PermissionEvent>>? = null 28 getInstancenull29 fun getInstance(): List<PermissionEventStorage<out PermissionEvent>> = 30 INSTANCE ?: synchronized(this) { INSTANCE ?: createInstance().also { INSTANCE = it } } 31 32 @SuppressLint("NewApi") createInstancenull33 private fun createInstance(): List<PermissionEventStorage<out PermissionEvent>> { 34 val list = mutableListOf<PermissionEventStorage<out PermissionEvent>>() 35 list.add(PermissionChangeStorageImpl.getInstance()) 36 val context = PermissionControllerApplication.get().applicationContext 37 if (PermissionDecisionStorageImpl.isRecordPermissionsSupported(context)) { 38 list.add(PermissionDecisionStorageImpl.getInstance()) 39 } 40 return list 41 } 42 } 43 } 44