Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit d707288e authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Settings: Make provider package dependent and move to core

parent a0558a5f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 */

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
apply plugin: 'signing'

@@ -12,6 +13,7 @@ dependencies {
    api "androidx.lifecycle:lifecycle-service:$lifecycleVersion"

    implementation "androidx.annotation:annotation:$annotationVersion"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
}

android {
@@ -24,6 +26,10 @@ android {
        targetSdkVersion androidTargetSdk
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
+7 −2
Original line number Diff line number Diff line
@@ -3,7 +3,12 @@
  ~ SPDX-FileCopyrightText: 2020, microG Project Team
  ~ 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>
+17 −12
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2021, microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.settings

import android.content.ContentValues
@@ -7,13 +12,13 @@ import android.net.Uri
import android.os.Binder

object SettingsContract {
    const val AUTHORITY = "org.microg.gms.settings"
    val AUTHORITY_URI: Uri = Uri.parse("content://$AUTHORITY")
    fun getAuthority(context: Context) = "${context.packageName}.microg.settings"
    fun getAuthorityUri(context: Context): Uri = Uri.parse("content://${getAuthority(context)}")

    object CheckIn {
        private const val id = "check-in"
        val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
        const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
        fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
        fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"

        const val ENABLED = "checkin_enable_service"
        const val ANDROID_ID = "androidId"
@@ -38,8 +43,8 @@ object SettingsContract {

    object Gcm {
        private const val id = "gcm"
        val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
        const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
        fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
        fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"

        const val FULL_LOG = "gcm_full_log"
        const val LAST_PERSISTENT_ID = "gcm_last_persistent_id"
@@ -72,8 +77,8 @@ object SettingsContract {

    object Auth {
        private const val id = "auth"
        val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
        const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
        fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
        fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"

        const val TRUST_GOOGLE = "auth_manager_trust_google"
        const val VISIBLE = "auth_manager_visible"
@@ -86,8 +91,8 @@ object SettingsContract {

    object Exposure {
        private const val id = "exposureNotification"
        val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
        const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
        fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
        fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"

        const val SCANNER_ENABLED = "exposure_scanner_enabled"
        const val LAST_CLEANUP = "exposure_last_cleanup"
@@ -100,8 +105,8 @@ object SettingsContract {

    object SafetyNet {
        private const val id = "safety-net"
        val CONTENT_URI: Uri = Uri.withAppendedPath(AUTHORITY_URI, id)
        const val CONTENT_TYPE = "vnd.android.cursor.item/vnd.$AUTHORITY.$id"
        fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id)
        fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id"
    }

    private fun <T> withoutCallingIdentity(f: () -> T): T {
+16 −11
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2021, microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.settings

import android.content.ContentProvider
@@ -8,13 +13,13 @@ import android.content.SharedPreferences
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import androidx.preference.PreferenceManager
import android.preference.PreferenceManager
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.CheckIn
import org.microg.gms.settings.SettingsContract.Exposure
import org.microg.gms.settings.SettingsContract.Gcm
import org.microg.gms.settings.SettingsContract.getAuthority
import java.io.File

/**
@@ -52,10 +57,10 @@ class SettingsProvider : ContentProvider() {
        selectionArgs: Array<out String>?,
        sortOrder: String?
    ): Cursor? = when (uri) {
        CheckIn.CONTENT_URI -> queryCheckIn(projection ?: CheckIn.PROJECTION)
        Gcm.CONTENT_URI -> queryGcm(projection ?: Gcm.PROJECTION)
        Auth.CONTENT_URI -> queryAuth(projection ?: Auth.PROJECTION)
        Exposure.CONTENT_URI -> queryExposure(projection ?: Exposure.PROJECTION)
        CheckIn.getContentUri(context!!) -> queryCheckIn(projection ?: CheckIn.PROJECTION)
        Gcm.getContentUri(context!!) -> queryGcm(projection ?: Gcm.PROJECTION)
        Auth.getContentUri(context!!) -> queryAuth(projection ?: Auth.PROJECTION)
        Exposure.getContentUri(context!!) -> queryExposure(projection ?: Exposure.PROJECTION)
        else -> null
    }

@@ -68,10 +73,10 @@ class SettingsProvider : ContentProvider() {
        warnIfNotMainProcess(context, this.javaClass)
        if (values == null) return 0
        when (uri) {
            CheckIn.CONTENT_URI -> updateCheckIn(values)
            Gcm.CONTENT_URI -> updateGcm(values)
            Auth.CONTENT_URI -> updateAuth(values)
            Exposure.CONTENT_URI -> updateExposure(values)
            CheckIn.getContentUri(context!!) -> updateCheckIn(values)
            Gcm.getContentUri(context!!) -> updateGcm(values)
            Auth.getContentUri(context!!) -> updateAuth(values)
            Exposure.getContentUri(context!!) -> updateExposure(values)
            else -> return 0
        }
        return 1
@@ -221,7 +226,7 @@ class SettingsProvider : ContentProvider() {
    }

    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? {
+0 −7
Original line number Diff line number Diff line
@@ -128,13 +128,6 @@
            android:exported="true"
            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 -->

        <activity
Loading