mirror of https://github.com/YTVanced/VancedMicroG
Settings: Make provider package dependent and move to core
This commit is contained in:
parent
a0558a5f38
commit
d707288ec9
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'signing'
|
apply plugin: 'signing'
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ dependencies {
|
||||||
api "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
|
api "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
|
||||||
|
|
||||||
implementation "androidx.annotation:annotation:$annotationVersion"
|
implementation "androidx.annotation:annotation:$annotationVersion"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
@ -24,6 +26,10 @@ android {
|
||||||
targetSdkVersion androidTargetSdk
|
targetSdkVersion androidTargetSdk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
|
|
|
@ -3,7 +3,12 @@
|
||||||
~ SPDX-FileCopyrightText: 2020, microG Project Team
|
~ SPDX-FileCopyrightText: 2020, microG Project Team
|
||||||
~ SPDX-License-Identifier: Apache-2.0
|
~ SPDX-License-Identifier: Apache-2.0
|
||||||
-->
|
-->
|
||||||
<manifest package="org.microg.gms.base.core">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.microg.gms.base.core">
|
||||||
|
|
||||||
<application />
|
<application>
|
||||||
|
<provider
|
||||||
|
android:name="org.microg.gms.settings.SettingsProvider"
|
||||||
|
android:authorities="${applicationId}.microg.settings"
|
||||||
|
android:exported="false" />
|
||||||
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021, microG Project Team
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
package org.microg.gms.settings
|
package org.microg.gms.settings
|
||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
|
@ -7,13 +12,13 @@ import android.net.Uri
|
||||||
import android.os.Binder
|
import android.os.Binder
|
||||||
|
|
||||||
object SettingsContract {
|
object SettingsContract {
|
||||||
const val AUTHORITY = "org.microg.gms.settings"
|
fun getAuthority(context: Context) = "${context.packageName}.microg.settings"
|
||||||
val AUTHORITY_URI: Uri = Uri.parse("content://$AUTHORITY")
|
fun getAuthorityUri(context: Context): Uri = Uri.parse("content://${getAuthority(context)}")
|
||||||
|
|
||||||
object CheckIn {
|
object CheckIn {
|
||||||
private const val id = "check-in"
|
private const val id = "check-in"
|
||||||
val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
|
fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
|
||||||
const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
|
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"
|
||||||
|
|
||||||
const val ENABLED = "checkin_enable_service"
|
const val ENABLED = "checkin_enable_service"
|
||||||
const val ANDROID_ID = "androidId"
|
const val ANDROID_ID = "androidId"
|
||||||
|
@ -38,8 +43,8 @@ object SettingsContract {
|
||||||
|
|
||||||
object Gcm {
|
object Gcm {
|
||||||
private const val id = "gcm"
|
private const val id = "gcm"
|
||||||
val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
|
fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
|
||||||
const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
|
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"
|
||||||
|
|
||||||
const val FULL_LOG = "gcm_full_log"
|
const val FULL_LOG = "gcm_full_log"
|
||||||
const val LAST_PERSISTENT_ID = "gcm_last_persistent_id"
|
const val LAST_PERSISTENT_ID = "gcm_last_persistent_id"
|
||||||
|
@ -72,8 +77,8 @@ object SettingsContract {
|
||||||
|
|
||||||
object Auth {
|
object Auth {
|
||||||
private const val id = "auth"
|
private const val id = "auth"
|
||||||
val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
|
fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
|
||||||
const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
|
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"
|
||||||
|
|
||||||
const val TRUST_GOOGLE = "auth_manager_trust_google"
|
const val TRUST_GOOGLE = "auth_manager_trust_google"
|
||||||
const val VISIBLE = "auth_manager_visible"
|
const val VISIBLE = "auth_manager_visible"
|
||||||
|
@ -86,8 +91,8 @@ object SettingsContract {
|
||||||
|
|
||||||
object Exposure {
|
object Exposure {
|
||||||
private const val id = "exposureNotification"
|
private const val id = "exposureNotification"
|
||||||
val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
|
fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
|
||||||
const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
|
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"
|
||||||
|
|
||||||
const val SCANNER_ENABLED = "exposure_scanner_enabled"
|
const val SCANNER_ENABLED = "exposure_scanner_enabled"
|
||||||
const val LAST_CLEANUP = "exposure_last_cleanup"
|
const val LAST_CLEANUP = "exposure_last_cleanup"
|
||||||
|
@ -100,8 +105,8 @@ object SettingsContract {
|
||||||
|
|
||||||
object SafetyNet {
|
object SafetyNet {
|
||||||
private const val id = "safety-net"
|
private const val id = "safety-net"
|
||||||
val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
|
fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
|
||||||
const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
|
fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> withoutCallingIdentity(f: () -> T): T {
|
private fun <T> withoutCallingIdentity(f: () -> T): T {
|
|
@ -1,3 +1,8 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021, microG Project Team
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
package org.microg.gms.settings
|
package org.microg.gms.settings
|
||||||
|
|
||||||
import android.content.ContentProvider
|
import android.content.ContentProvider
|
||||||
|
@ -8,13 +13,13 @@ import android.content.SharedPreferences
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.database.MatrixCursor
|
import android.database.MatrixCursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import org.microg.gms.common.PackageUtils.warnIfNotMainProcess
|
import org.microg.gms.common.PackageUtils.warnIfNotMainProcess
|
||||||
import org.microg.gms.settings.SettingsContract.AUTHORITY
|
|
||||||
import org.microg.gms.settings.SettingsContract.Auth
|
import org.microg.gms.settings.SettingsContract.Auth
|
||||||
import org.microg.gms.settings.SettingsContract.CheckIn
|
import org.microg.gms.settings.SettingsContract.CheckIn
|
||||||
import org.microg.gms.settings.SettingsContract.Exposure
|
import org.microg.gms.settings.SettingsContract.Exposure
|
||||||
import org.microg.gms.settings.SettingsContract.Gcm
|
import org.microg.gms.settings.SettingsContract.Gcm
|
||||||
|
import org.microg.gms.settings.SettingsContract.getAuthority
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,10 +57,10 @@ class SettingsProvider : ContentProvider() {
|
||||||
selectionArgs: Array<out String>?,
|
selectionArgs: Array<out String>?,
|
||||||
sortOrder: String?
|
sortOrder: String?
|
||||||
): Cursor? = when (uri) {
|
): Cursor? = when (uri) {
|
||||||
CheckIn.CONTENT_URI -> queryCheckIn(projection ?: CheckIn.PROJECTION)
|
CheckIn.getContentUri(context!!) -> queryCheckIn(projection ?: CheckIn.PROJECTION)
|
||||||
Gcm.CONTENT_URI -> queryGcm(projection ?: Gcm.PROJECTION)
|
Gcm.getContentUri(context!!) -> queryGcm(projection ?: Gcm.PROJECTION)
|
||||||
Auth.CONTENT_URI -> queryAuth(projection ?: Auth.PROJECTION)
|
Auth.getContentUri(context!!) -> queryAuth(projection ?: Auth.PROJECTION)
|
||||||
Exposure.CONTENT_URI -> queryExposure(projection ?: Exposure.PROJECTION)
|
Exposure.getContentUri(context!!) -> queryExposure(projection ?: Exposure.PROJECTION)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,10 +73,10 @@ class SettingsProvider : ContentProvider() {
|
||||||
warnIfNotMainProcess(context, this.javaClass)
|
warnIfNotMainProcess(context, this.javaClass)
|
||||||
if (values == null) return 0
|
if (values == null) return 0
|
||||||
when (uri) {
|
when (uri) {
|
||||||
CheckIn.CONTENT_URI -> updateCheckIn(values)
|
CheckIn.getContentUri(context!!) -> updateCheckIn(values)
|
||||||
Gcm.CONTENT_URI -> updateGcm(values)
|
Gcm.getContentUri(context!!) -> updateGcm(values)
|
||||||
Auth.CONTENT_URI -> updateAuth(values)
|
Auth.getContentUri(context!!) -> updateAuth(values)
|
||||||
Exposure.CONTENT_URI -> updateExposure(values)
|
Exposure.getContentUri(context!!) -> updateExposure(values)
|
||||||
else -> return 0
|
else -> return 0
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
|
@ -221,7 +226,7 @@ class SettingsProvider : ContentProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getType(uri: Uri): String {
|
override fun getType(uri: Uri): String {
|
||||||
return "vnd.android.cursor.item/vnd.$AUTHORITY.${uri.path}"
|
return "vnd.android.cursor.item/vnd.${getAuthority(context!!)}.${uri.path}"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun insert(uri: Uri, values: ContentValues?): Uri? {
|
override fun insert(uri: Uri, values: ContentValues?): Uri? {
|
|
@ -128,13 +128,6 @@
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:permission="org.microg.gms.PROVISION" />
|
android:permission="org.microg.gms.PROVISION" />
|
||||||
|
|
||||||
<!-- Internal Settings -->
|
|
||||||
|
|
||||||
<provider
|
|
||||||
android:name="org.microg.gms.settings.SettingsProvider"
|
|
||||||
android:authorities="org.microg.gms.settings"
|
|
||||||
android:exported="false" />
|
|
||||||
|
|
||||||
<!-- Location -->
|
<!-- Location -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
|
|
|
@ -8,14 +8,14 @@ object AuthPrefs {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun isTrustGooglePermitted(context: Context): Boolean {
|
fun isTrustGooglePermitted(context: Context): Boolean {
|
||||||
return SettingsContract.getSettings(context, Auth.CONTENT_URI, arrayOf(Auth.TRUST_GOOGLE)) { c ->
|
return SettingsContract.getSettings(context, Auth.getContentUri(context), arrayOf(Auth.TRUST_GOOGLE)) { c ->
|
||||||
c.getInt(0) != 0
|
c.getInt(0) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun isAuthVisible(context: Context): Boolean {
|
fun isAuthVisible(context: Context): Boolean {
|
||||||
return SettingsContract.getSettings(context, Auth.CONTENT_URI, arrayOf(Auth.VISIBLE)) { c ->
|
return SettingsContract.getSettings(context, Auth.getContentUri(context), arrayOf(Auth.VISIBLE)) { c ->
|
||||||
c.getInt(0) != 0
|
c.getInt(0) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ object CheckinPrefs {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun isEnabled(context: Context): Boolean {
|
fun isEnabled(context: Context): Boolean {
|
||||||
val projection = arrayOf(CheckIn.ENABLED)
|
val projection = arrayOf(CheckIn.ENABLED)
|
||||||
return SettingsContract.getSettings(context, CheckIn.CONTENT_URI, projection) { c ->
|
return SettingsContract.getSettings(context, CheckIn.getContentUri(context), projection) { c ->
|
||||||
c.getInt(0) != 0
|
c.getInt(0) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ data class LastCheckinInfo(
|
||||||
CheckIn.VERSION_INFO,
|
CheckIn.VERSION_INFO,
|
||||||
CheckIn.DEVICE_DATA_VERSION_INFO,
|
CheckIn.DEVICE_DATA_VERSION_INFO,
|
||||||
)
|
)
|
||||||
return SettingsContract.getSettings(context, CheckIn.CONTENT_URI, projection) { c ->
|
return SettingsContract.getSettings(context, CheckIn.getContentUri(context), projection) { c ->
|
||||||
LastCheckinInfo(
|
LastCheckinInfo(
|
||||||
androidId = c.getLong(0),
|
androidId = c.getLong(0),
|
||||||
digest = c.getString(1),
|
digest = c.getString(1),
|
||||||
|
@ -61,7 +61,7 @@ data class LastCheckinInfo(
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun clear(context: Context) = SettingsContract.setSettings(context, CheckIn.CONTENT_URI) {
|
fun clear(context: Context) = SettingsContract.setSettings(context, CheckIn.getContentUri(context)) {
|
||||||
put(CheckIn.ANDROID_ID, 0L)
|
put(CheckIn.ANDROID_ID, 0L)
|
||||||
put(CheckIn.DIGEST, CheckIn.INITIAL_DIGEST)
|
put(CheckIn.DIGEST, CheckIn.INITIAL_DIGEST)
|
||||||
put(CheckIn.LAST_CHECK_IN, 0L)
|
put(CheckIn.LAST_CHECK_IN, 0L)
|
||||||
|
@ -71,7 +71,7 @@ data class LastCheckinInfo(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun write(context: Context) = SettingsContract.setSettings(context, CheckIn.CONTENT_URI) {
|
fun write(context: Context) = SettingsContract.setSettings(context, CheckIn.getContentUri(context)) {
|
||||||
put(CheckIn.ANDROID_ID, androidId)
|
put(CheckIn.ANDROID_ID, androidId)
|
||||||
put(CheckIn.DIGEST, digest)
|
put(CheckIn.DIGEST, digest)
|
||||||
put(CheckIn.LAST_CHECK_IN, lastCheckin)
|
put(CheckIn.LAST_CHECK_IN, lastCheckin)
|
||||||
|
|
|
@ -20,7 +20,7 @@ data class ServiceConfiguration(val enabled: Boolean) : Serializable
|
||||||
|
|
||||||
suspend fun getCheckinServiceInfo(context: Context): ServiceInfo = withContext(Dispatchers.IO) {
|
suspend fun getCheckinServiceInfo(context: Context): ServiceInfo = withContext(Dispatchers.IO) {
|
||||||
val projection = arrayOf(CheckIn.ENABLED, CheckIn.LAST_CHECK_IN, CheckIn.ANDROID_ID)
|
val projection = arrayOf(CheckIn.ENABLED, CheckIn.LAST_CHECK_IN, CheckIn.ANDROID_ID)
|
||||||
getSettings(context, CheckIn.CONTENT_URI, projection) { c ->
|
getSettings(context, CheckIn.getContentUri(context), projection) { c ->
|
||||||
ServiceInfo(
|
ServiceInfo(
|
||||||
configuration = ServiceConfiguration(c.getInt(0) != 0),
|
configuration = ServiceConfiguration(c.getInt(0) != 0),
|
||||||
lastCheckin = c.getLong(1),
|
lastCheckin = c.getLong(1),
|
||||||
|
@ -33,7 +33,7 @@ suspend fun setCheckinServiceConfiguration(context: Context, configuration: Serv
|
||||||
val serviceInfo = getCheckinServiceInfo(context)
|
val serviceInfo = getCheckinServiceInfo(context)
|
||||||
if (serviceInfo.configuration == configuration) return@withContext
|
if (serviceInfo.configuration == configuration) return@withContext
|
||||||
// enabled state is not already set, setting it now
|
// enabled state is not already set, setting it now
|
||||||
setSettings(context, CheckIn.CONTENT_URI) {
|
setSettings(context, CheckIn.getContentUri(context)) {
|
||||||
put(CheckIn.ENABLED, configuration.enabled)
|
put(CheckIn.ENABLED, configuration.enabled)
|
||||||
}
|
}
|
||||||
if (configuration.enabled) {
|
if (configuration.enabled) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ data class GcmPrefs(
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun get(context: Context): GcmPrefs {
|
fun get(context: Context): GcmPrefs {
|
||||||
return SettingsContract.getSettings(context, Gcm.CONTENT_URI, Gcm.PROJECTION) { c ->
|
return SettingsContract.getSettings(context, Gcm.getContentUri(context), Gcm.PROJECTION) { c ->
|
||||||
GcmPrefs(
|
GcmPrefs(
|
||||||
isGcmLogEnabled = c.getInt(0) != 0,
|
isGcmLogEnabled = c.getInt(0) != 0,
|
||||||
lastPersistedId = c.getString(1),
|
lastPersistedId = c.getString(1),
|
||||||
|
@ -62,7 +62,7 @@ data class GcmPrefs(
|
||||||
|
|
||||||
fun write(context: Context, config: ServiceConfiguration) {
|
fun write(context: Context, config: ServiceConfiguration) {
|
||||||
val gcmPrefs = get(context)
|
val gcmPrefs = get(context)
|
||||||
setSettings(context, Gcm.CONTENT_URI) {
|
setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.ENABLE_GCM, config.enabled)
|
put(Gcm.ENABLE_GCM, config.enabled)
|
||||||
put(Gcm.CONFIRM_NEW_APPS, config.confirmNewApps)
|
put(Gcm.CONFIRM_NEW_APPS, config.confirmNewApps)
|
||||||
put(Gcm.NETWORK_MOBILE, config.mobile)
|
put(Gcm.NETWORK_MOBILE, config.mobile)
|
||||||
|
@ -75,7 +75,7 @@ data class GcmPrefs(
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun clearLastPersistedId(context: Context) {
|
fun clearLastPersistedId(context: Context) {
|
||||||
setSettings(context, Gcm.CONTENT_URI) {
|
setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LAST_PERSISTENT_ID, "")
|
put(Gcm.LAST_PERSISTENT_ID, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,13 +124,13 @@ data class GcmPrefs(
|
||||||
fun learnTimeout(context: Context, pref: String) {
|
fun learnTimeout(context: Context, pref: String) {
|
||||||
Log.d("GmsGcmPrefs", "learnTimeout: $pref")
|
Log.d("GmsGcmPrefs", "learnTimeout: $pref")
|
||||||
when (pref) {
|
when (pref) {
|
||||||
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> setSettings(context, Gcm.CONTENT_URI) {
|
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LEARNT_MOBILE, (learntMobileInterval * 0.95).toInt())
|
put(Gcm.LEARNT_MOBILE, (learntMobileInterval * 0.95).toInt())
|
||||||
}
|
}
|
||||||
PREF_NETWORK_WIFI -> setSettings(context, Gcm.CONTENT_URI) {
|
PREF_NETWORK_WIFI -> setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LEARNT_WIFI, (learntWifiInterval * 0.95).toInt())
|
put(Gcm.LEARNT_WIFI, (learntWifiInterval * 0.95).toInt())
|
||||||
}
|
}
|
||||||
else -> setSettings(context, Gcm.CONTENT_URI) {
|
else -> setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LEARNT_OTHER, (learntOtherInterval * 0.95).toInt())
|
put(Gcm.LEARNT_OTHER, (learntOtherInterval * 0.95).toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ data class GcmPrefs(
|
||||||
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> {
|
PREF_NETWORK_MOBILE, PREF_NETWORK_ROAMING -> {
|
||||||
if (time > learntMobileInterval / 4 * 3) {
|
if (time > learntMobileInterval / 4 * 3) {
|
||||||
val newInterval = (learntMobileInterval * 1.02).toInt()
|
val newInterval = (learntMobileInterval * 1.02).toInt()
|
||||||
setSettings(context, Gcm.CONTENT_URI) {
|
setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LEARNT_MOBILE, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
put(Gcm.LEARNT_MOBILE, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ data class GcmPrefs(
|
||||||
PREF_NETWORK_WIFI -> {
|
PREF_NETWORK_WIFI -> {
|
||||||
if (time > learntWifiInterval / 4 * 3) {
|
if (time > learntWifiInterval / 4 * 3) {
|
||||||
val newInterval = (learntWifiInterval * 1.02).toInt()
|
val newInterval = (learntWifiInterval * 1.02).toInt()
|
||||||
setSettings(context, Gcm.CONTENT_URI) {
|
setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LEARNT_WIFI, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
put(Gcm.LEARNT_WIFI, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ data class GcmPrefs(
|
||||||
else -> {
|
else -> {
|
||||||
if (time > learntOtherInterval / 4 * 3) {
|
if (time > learntOtherInterval / 4 * 3) {
|
||||||
val newInterval = (learntOtherInterval * 1.02).toInt()
|
val newInterval = (learntOtherInterval * 1.02).toInt()
|
||||||
setSettings(context, Gcm.CONTENT_URI) {
|
setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LEARNT_OTHER, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
put(Gcm.LEARNT_OTHER, max(MIN_INTERVAL, min(newInterval, MAX_INTERVAL)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ data class GcmPrefs(
|
||||||
|
|
||||||
fun extendLastPersistedId(context: Context, id: String) {
|
fun extendLastPersistedId(context: Context, id: String) {
|
||||||
val newId = if (lastPersistedId.isNullOrEmpty()) id else "$lastPersistedId|$id"
|
val newId = if (lastPersistedId.isNullOrEmpty()) id else "$lastPersistedId|$id"
|
||||||
setSettings(context, Gcm.CONTENT_URI) {
|
setSettings(context, Gcm.getContentUri(context)) {
|
||||||
put(Gcm.LAST_PERSISTENT_ID, newId)
|
put(Gcm.LAST_PERSISTENT_ID, newId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ package org.microg.gms.nearby.exposurenotification
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import org.microg.gms.settings.SettingsContract.Exposure.CONTENT_URI
|
import org.microg.gms.settings.SettingsContract.Exposure.getContentUri
|
||||||
import org.microg.gms.settings.SettingsContract.Exposure.LAST_CLEANUP
|
import org.microg.gms.settings.SettingsContract.Exposure.LAST_CLEANUP
|
||||||
import org.microg.gms.settings.SettingsContract.Exposure.SCANNER_ENABLED
|
import org.microg.gms.settings.SettingsContract.Exposure.SCANNER_ENABLED
|
||||||
import org.microg.gms.settings.SettingsContract.getSettings
|
import org.microg.gms.settings.SettingsContract.getSettings
|
||||||
|
@ -16,12 +16,12 @@ import org.microg.gms.settings.SettingsContract.setSettings
|
||||||
class ExposurePreferences(private val context: Context) {
|
class ExposurePreferences(private val context: Context) {
|
||||||
|
|
||||||
var enabled
|
var enabled
|
||||||
get() = getSettings(context, CONTENT_URI, arrayOf(SCANNER_ENABLED)) { c ->
|
get() = getSettings(context, getContentUri(context), arrayOf(SCANNER_ENABLED)) { c ->
|
||||||
c.getInt(0) != 0
|
c.getInt(0) != 0
|
||||||
}
|
}
|
||||||
set(newStatus) {
|
set(newStatus) {
|
||||||
val changed = enabled != newStatus
|
val changed = enabled != newStatus
|
||||||
setSettings(context, CONTENT_URI) {
|
setSettings(context, getContentUri(context)) {
|
||||||
put(SCANNER_ENABLED, newStatus)
|
put(SCANNER_ENABLED, newStatus)
|
||||||
}
|
}
|
||||||
if (!changed) return
|
if (!changed) return
|
||||||
|
@ -34,10 +34,10 @@ class ExposurePreferences(private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastCleanup
|
var lastCleanup
|
||||||
get() = getSettings(context, CONTENT_URI, arrayOf(LAST_CLEANUP)) { c ->
|
get() = getSettings(context, getContentUri(context), arrayOf(LAST_CLEANUP)) { c ->
|
||||||
c.getLong(0)
|
c.getLong(0)
|
||||||
}
|
}
|
||||||
set(value) = setSettings(context, CONTENT_URI) {
|
set(value) = setSettings(context, getContentUri(context)) {
|
||||||
put(LAST_CLEANUP, value)
|
put(LAST_CLEANUP, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue