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

Commit 7f064a62 authored by Fynn Godau's avatar Fynn Godau
Browse files

Merge branch 'epic71-profile-provider' into 'master'

Expose device profile as content provider

See merge request !92
parents 080b149d 2257a3fb
Loading
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023 microG Project Team
 * SPDX-FileCopyrightText: 2023 e Foundation
 * SPDX-License-Identifier: Apache-2.0
 */

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

dependencies {
    implementation project(':play-services-base-core')
}

android {
    namespace "org.microg.gms.core.pkg"

    compileSdkVersion androidCompileSdk
    buildToolsVersion "$androidBuildVersionTools"

    defaultConfig {
        versionName version
        minSdkVersion androidMinSdk
        targetSdkVersion androidTargetSdk
    }

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

    lintOptions {
        disable 'MissingTranslation'
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    kotlinOptions {
        jvmTarget = 1.8
    }
}
+15 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ SPDX-FileCopyrightText: 2023 microG Project Team
  ~ SPDX-License-Identifier: Apache-2.0
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application>
        <provider
            android:name="org.microg.gms.profile.ProfileProvider"
            android:authorities="${applicationId}.microg.profile"
            android:exported="true"
            tools:ignore="ExportedContentProvider" />
    </application>
</manifest>
+52 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2023 e Foundation
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.profile

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import org.microg.gms.settings.SettingsContract

class ProfileProvider : ContentProvider() {

    val COLUMN_ID = "profile_id"
    val COLUMN_VALUE = "profile_value"

    override fun onCreate(): Boolean {
        ProfileManager.ensureInitialized(context!!)
        return true
    }

    override fun query(
        uri: Uri,
        projection: Array<out String>?,
        selection: String?,
        selectionArgs: Array<out String>?,
        sortOrder: String?
    ): Cursor =
        MatrixCursor(arrayOf(COLUMN_ID, COLUMN_VALUE)).apply {
            ProfileManager.getActiveProfileData(context!!).entries
                .forEach {
                    addRow(arrayOf(it.key, it.value))
                }
        }

    override fun getType(uri: Uri): String {
        return "vnd.android.cursor.item/vnd.${SettingsContract.getAuthority(context!!)}.${uri.path}"
    }

    override fun insert(uri: Uri, values: ContentValues?): Nothing = throw UnsupportedOperationException()

    override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Nothing =
        throw UnsupportedOperationException()

    override fun update(
        uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?
    ): Nothing = throw UnsupportedOperationException()

}
+4 −1
Original line number Diff line number Diff line
@@ -93,6 +93,9 @@ object ProfileManager {
        }
    }.getOrDefault(false)

    fun getActiveProfileData(context: Context): Map<String, String> =
        getProfileData(context, getProfile(context), getRealData())

    private fun getProfileData(context: Context, profile: String, realData: Map<String, String>): Map<String, String> {
        try {
            if (profile in listOf(PROFILE_REAL, PROFILE_NATIVE)) return realData
@@ -243,7 +246,7 @@ object ProfileManager {
        }
    }

    private fun applyProfileData(profileData: Map<String, String>) {
    fun applyProfileData(profileData: Map<String, String>) {
        fun applyStringField(key: String, valueSetter: (String) -> Unit) = profileData[key]?.let { valueSetter(it) }
        fun applyIntField(key: String, valueSetter: (Int) -> Unit) = profileData[key]?.toIntOrNull()?.let { valueSetter(it) }
        fun applyLongField(key: String, valueSetter: (Long) -> Unit) = profileData[key]?.toLongOrNull()?.let { valueSetter(it) }
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ dependencies {
    implementation project(':play-services-core-proto')

    implementation project(':play-services-core:microg-ui-tools') // deprecated
    implementation project(':play-services-base-core-package')
    implementation project(':play-services-api')

    implementation project(':play-services-appinvite')
Loading