From dfa282ebd1ccc33a6a201c1e9120e31e76bfee3e Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Wed, 11 Oct 2023 21:40:25 +0200 Subject: [PATCH 1/4] Expose device profile as content provider For use in fakestore. --- .../core/src/main/AndroidManifest.xml | 9 +++- .../org/microg/gms/profile/ProfileManager.kt | 5 +- .../org/microg/gms/profile/ProfileProvider.kt | 47 +++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt diff --git a/play-services-base/core/src/main/AndroidManifest.xml b/play-services-base/core/src/main/AndroidManifest.xml index aebc21a46..5c321135e 100644 --- a/play-services-base/core/src/main/AndroidManifest.xml +++ b/play-services-base/core/src/main/AndroidManifest.xml @@ -3,12 +3,19 @@ ~ SPDX-FileCopyrightText: 2020, microG Project Team ~ SPDX-License-Identifier: Apache-2.0 --> - + + + diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt b/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt index d367cb34d..4620abe15 100644 --- a/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt +++ b/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt @@ -93,6 +93,9 @@ object ProfileManager { } }.getOrDefault(false) + internal fun getActiveProfileData(context: Context): Map = + getProfileData(context, getProfile(context), getRealData()) + private fun getProfileData(context: Context, profile: String, realData: Map): Map { try { if (profile in listOf(PROFILE_REAL, PROFILE_NATIVE)) return realData @@ -243,7 +246,7 @@ object ProfileManager { } } - private fun applyProfileData(profileData: Map) { + fun applyProfileData(profileData: Map) { 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) } diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt b/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt new file mode 100644 index 000000000..c6472e80f --- /dev/null +++ b/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt @@ -0,0 +1,47 @@ +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?, + selection: String?, + selectionArgs: Array?, + 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?): Nothing = + throw UnsupportedOperationException() + + override fun update( + uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array? + ): Nothing = throw UnsupportedOperationException() + +} -- GitLab From f855b3ab1a42a652456a50c4d1e097f6fb1f9d33 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Thu, 12 Oct 2023 13:16:47 +0200 Subject: [PATCH 2/4] Move profile provider to `play-services-core-package` --- .../core/src/main/AndroidManifest.xml | 9 +--- .../org/microg/gms/profile/ProfileManager.kt | 2 +- play-services-core/build.gradle | 1 + play-services-core/package/build.gradle | 43 +++++++++++++++++++ .../package/src/main/AndroidManifest.xml | 15 +++++++ .../org/microg/gms/profile/ProfileProvider.kt | 0 settings.gradle | 1 + 7 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 play-services-core/package/build.gradle create mode 100644 play-services-core/package/src/main/AndroidManifest.xml rename {play-services-base/core => play-services-core/package}/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt (100%) diff --git a/play-services-base/core/src/main/AndroidManifest.xml b/play-services-base/core/src/main/AndroidManifest.xml index 5c321135e..aebc21a46 100644 --- a/play-services-base/core/src/main/AndroidManifest.xml +++ b/play-services-base/core/src/main/AndroidManifest.xml @@ -3,19 +3,12 @@ ~ SPDX-FileCopyrightText: 2020, microG Project Team ~ SPDX-License-Identifier: Apache-2.0 --> - + - - diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt b/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt index 4620abe15..69b26894b 100644 --- a/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt +++ b/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileManager.kt @@ -93,7 +93,7 @@ object ProfileManager { } }.getOrDefault(false) - internal fun getActiveProfileData(context: Context): Map = + fun getActiveProfileData(context: Context): Map = getProfileData(context, getProfile(context), getRealData()) private fun getProfileData(context: Context, profile: String, realData: Map): Map { diff --git a/play-services-core/build.gradle b/play-services-core/build.gradle index 4b99a557d..744c7836e 100644 --- a/play-services-core/build.gradle +++ b/play-services-core/build.gradle @@ -46,6 +46,7 @@ dependencies { implementation project(':play-services-core-proto') implementation project(':play-services-core:microg-ui-tools') // deprecated + implementation project(':play-services-core-package') implementation project(':play-services-api') implementation project(':play-services-appinvite') diff --git a/play-services-core/package/build.gradle b/play-services-core/package/build.gradle new file mode 100644 index 000000000..ebcafbb3f --- /dev/null +++ b/play-services-core/package/build.gradle @@ -0,0 +1,43 @@ +/* + * SPDX-FileCopyrightText: 2023 microG Project Team + * 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 + } +} diff --git a/play-services-core/package/src/main/AndroidManifest.xml b/play-services-core/package/src/main/AndroidManifest.xml new file mode 100644 index 000000000..9a7aa8fb7 --- /dev/null +++ b/play-services-core/package/src/main/AndroidManifest.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt b/play-services-core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt similarity index 100% rename from play-services-base/core/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt rename to play-services-core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt diff --git a/settings.gradle b/settings.gradle index aceae3a68..4b5d16486 100644 --- a/settings.gradle +++ b/settings.gradle @@ -106,3 +106,4 @@ sublude ':firebase-auth:core' include ':play-services-core:microg-ui-tools' // Legacy include ':play-services-core' +sublude ':play-services-core:package' -- GitLab From 500f418dc2d55b7d7da1449fc73dfba3df4b9cf6 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 24 Oct 2023 07:51:15 +0200 Subject: [PATCH 3/4] Move profile provider to `play-services-base-core-package` --- .../core}/package/build.gradle | 0 .../core}/package/src/main/AndroidManifest.xml | 0 .../src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt | 0 play-services-core/build.gradle | 2 +- settings.gradle | 4 +++- 5 files changed, 4 insertions(+), 2 deletions(-) rename {play-services-core => play-services-base/core}/package/build.gradle (100%) rename {play-services-core => play-services-base/core}/package/src/main/AndroidManifest.xml (100%) rename {play-services-core => play-services-base/core}/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt (100%) diff --git a/play-services-core/package/build.gradle b/play-services-base/core/package/build.gradle similarity index 100% rename from play-services-core/package/build.gradle rename to play-services-base/core/package/build.gradle diff --git a/play-services-core/package/src/main/AndroidManifest.xml b/play-services-base/core/package/src/main/AndroidManifest.xml similarity index 100% rename from play-services-core/package/src/main/AndroidManifest.xml rename to play-services-base/core/package/src/main/AndroidManifest.xml diff --git a/play-services-core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt b/play-services-base/core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt similarity index 100% rename from play-services-core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt rename to play-services-base/core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt diff --git a/play-services-core/build.gradle b/play-services-core/build.gradle index 744c7836e..eb6454a5c 100644 --- a/play-services-core/build.gradle +++ b/play-services-core/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation project(':play-services-core-proto') implementation project(':play-services-core:microg-ui-tools') // deprecated - implementation project(':play-services-core-package') + implementation project(':play-services-base-core-package') implementation project(':play-services-api') implementation project(':play-services-appinvite') diff --git a/settings.gradle b/settings.gradle index 4b5d16486..63a1e400b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -106,4 +106,6 @@ sublude ':firebase-auth:core' include ':play-services-core:microg-ui-tools' // Legacy include ':play-services-core' -sublude ':play-services-core:package' + +include ':play-services-base-core-package' +project(':play-services-base-core-package').projectDir = file('play-services-base/core/package') -- GitLab From 2257a3fb5dc5b630bd52756ecea34eba99983fe3 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Sat, 11 Nov 2023 16:10:57 +0100 Subject: [PATCH 4/4] Add missing license information --- play-services-base/core/package/build.gradle | 1 + .../main/kotlin/org/microg/gms/profile/ProfileProvider.kt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/play-services-base/core/package/build.gradle b/play-services-base/core/package/build.gradle index ebcafbb3f..02142c68b 100644 --- a/play-services-base/core/package/build.gradle +++ b/play-services-base/core/package/build.gradle @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 microG Project Team + * SPDX-FileCopyrightText: 2023 e Foundation * SPDX-License-Identifier: Apache-2.0 */ diff --git a/play-services-base/core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt b/play-services-base/core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt index c6472e80f..53e4149f4 100644 --- a/play-services-base/core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt +++ b/play-services-base/core/package/src/main/kotlin/org/microg/gms/profile/ProfileProvider.kt @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2023 e Foundation + * SPDX-License-Identifier: Apache-2.0 + */ + package org.microg.gms.profile import android.content.ContentProvider -- GitLab