Expose device profile as content 9d5a99710f

This commit is contained in:
inotia00 2023-12-27 06:29:46 +09:00 • committed by Cuynu
commit 77cef2fec3
2 changed files with 64 additions and 0 deletions

View file

@ -3,11 +3,23 @@
~ SPDX-FileCopyrightText: 2020, microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->
<<<<<<< HEAD
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
=======
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.microg.gms.base.core">
>>>>>>> 0f8fb823 (Expose device profile as content https://github.com/microg/GmsCore/commit/9d5a99710f0cbe9055a43df371eaae77610583f3)
<application>
<provider
android:name="org.microg.gms.settings.SettingsProvider"
android:authorities="${applicationId}.microg.settings"
android:exported="false" />
<provider
android:name="org.microg.gms.profile.ProfileProvider"
android:authorities="${applicationId}.microg.profile"
android:exported="true"
tools:ignore="ExportedContentProvider" />
</application>
</manifest>

View file

@ -0,0 +1,52 @@
/*
* 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()
}