2019-04-08 02:24:22 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-04-08 02:24:22 +02:00
|
|
|
|
|
|
|
package org.mozilla.fenix.components
|
|
|
|
|
|
|
|
import android.content.Context
|
2019-04-11 22:04:51 +02:00
|
|
|
import androidx.paging.DataSource
|
2019-04-08 02:24:22 +02:00
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissions
|
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissions.Status
|
|
|
|
import mozilla.components.feature.sitepermissions.SitePermissionsStorage
|
2019-05-07 23:36:37 +02:00
|
|
|
import org.mozilla.fenix.test.Mockable
|
2019-04-08 02:24:22 +02:00
|
|
|
|
2019-05-07 23:36:37 +02:00
|
|
|
@Mockable
|
2019-05-16 23:02:24 +02:00
|
|
|
class PermissionStorage(private val context: Context) {
|
2019-04-08 02:24:22 +02:00
|
|
|
|
|
|
|
private val permissionsStorage by lazy {
|
|
|
|
SitePermissionsStorage(context)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun addSitePermissionException(
|
|
|
|
origin: String,
|
|
|
|
location: Status,
|
|
|
|
notification: Status,
|
|
|
|
microphone: Status,
|
|
|
|
camera: Status
|
|
|
|
): SitePermissions {
|
|
|
|
val sitePermissions = SitePermissions(
|
|
|
|
origin = origin,
|
|
|
|
location = location,
|
|
|
|
camera = camera,
|
|
|
|
microphone = microphone,
|
|
|
|
notification = notification,
|
|
|
|
savedAt = System.currentTimeMillis()
|
|
|
|
)
|
|
|
|
permissionsStorage.save(sitePermissions)
|
|
|
|
return sitePermissions
|
|
|
|
}
|
|
|
|
|
|
|
|
fun findSitePermissionsBy(origin: String): SitePermissions? {
|
|
|
|
return permissionsStorage.findSitePermissionsBy(origin)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun updateSitePermissions(sitePermissions: SitePermissions) {
|
|
|
|
permissionsStorage.update(sitePermissions)
|
|
|
|
}
|
2019-04-11 22:04:51 +02:00
|
|
|
|
|
|
|
fun getSitePermissionsPaged(): DataSource.Factory<Int, SitePermissions> {
|
|
|
|
return permissionsStorage.getSitePermissionsPaged()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun deleteSitePermissions(sitePermissions: SitePermissions) {
|
|
|
|
permissionsStorage.remove(sitePermissions)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun deleteAllSitePermissions() {
|
|
|
|
permissionsStorage.removeAll()
|
|
|
|
}
|
2019-04-08 02:24:22 +02:00
|
|
|
}
|