Skip to content

Commit

Permalink
feat: share settings
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminHalko committed Sep 24, 2023
1 parent 5838550 commit 2a89ef7
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
5 changes: 5 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<provider
android:name=".utils.share.ShareProvider"
android:authorities="app.revanced.manager.flutter.provider"
android:exported="true">
</provider>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import java.io.StringWriter
import java.util.logging.LogRecord
import java.util.logging.Logger

import android.content.ContentResolver
import android.content.Context
import android.database.Cursor
import android.net.Uri

import android.util.Log

class MainActivity : FlutterActivity() {
private val handler = Handler(Looper.getMainLooper())
private lateinit var installerChannel: MethodChannel
Expand All @@ -39,6 +46,21 @@ class MainActivity : FlutterActivity() {
val patcherChannel = "app.revanced.manager.flutter/patcher"
val installerChannel = "app.revanced.manager.flutter/installer"

val contentProviderUri = Uri.parse("content://app.revanced.manager.flutter.provider/settings")
val contentResolver: ContentResolver = context.contentResolver
val cursor: Cursor? = contentResolver.query(contentProviderUri, null, null, null, null)

Log.d("app.revanced.manager.flutter.debug", "byhithere")
if (cursor != null) {
Log.d("app.revanced.manager.flutter.debug", "test2")
if (cursor.moveToFirst()) {
val helloValue = cursor.getString(cursor.getColumnIndex("settings"))
// Process the retrieved "hello" value
Log.d("testing2", helloValue)
}
cursor.close()
}

val mainChannel =
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, patcherChannel)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package app.revanced.manager.flutter.utils.share

import android.content.ContentProvider
import android.content.ContentValues
import android.content.Context
import android.content.UriMatcher
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import org.json.JSONObject

import android.util.Log

class ShareProvider : ContentProvider() {
private val authority = "app.revanced.manager.flutter.provider"
private val URI_CODE_SETTINGS = 1

private val uriMatcher = UriMatcher(UriMatcher.NO_MATCH).apply {
addURI(authority, "settings", URI_CODE_SETTINGS)
}

override fun onCreate(): Boolean {
return true
}

fun getSettings(): String {
val json = JSONObject()

// Default Data

// TODO: load default data

// Load Shared Preferences
val sharedPreferences = context!!.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
val allEntries: Map<String, *> = sharedPreferences.getAll()
for ((key, value) in allEntries.entries) {
Log.d("map values", key + ": " + value.toString())
json.put(key.replace("flutter.", ""), value)
}

// TODO: Load keystore

return json.toString()
}

override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
):Cursor? {
when (uriMatcher.match(uri)) {
URI_CODE_SETTINGS -> {
val cursor = MatrixCursor(arrayOf("settings"))
val row = arrayOf(getSettings())
cursor.addRow(row)
return cursor
}
else -> throw IllegalArgumentException("Unknown URI: $uri")
}
return null
}

override fun insert(uri: Uri, values: ContentValues?): Uri? {
throw UnsupportedOperationException("Insert operation is not supported")
}

override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int {
throw UnsupportedOperationException("Update operation is not supported")
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
throw UnsupportedOperationException("Delete operation is not supported")
}

override fun getType(uri: Uri): String? {
throw UnsupportedOperationException("Get type operation is not supported")
}
}

0 comments on commit 2a89ef7

Please sign in to comment.