diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 08e9e77c..8ae06734 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -54,5 +54,10 @@ android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> + + diff --git a/android/app/src/main/kotlin/app/revanced/manager/flutter/MainActivity.kt b/android/app/src/main/kotlin/app/revanced/manager/flutter/MainActivity.kt index 22463f8c..444fa970 100644 --- a/android/app/src/main/kotlin/app/revanced/manager/flutter/MainActivity.kt +++ b/android/app/src/main/kotlin/app/revanced/manager/flutter/MainActivity.kt @@ -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 @@ -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) diff --git a/android/app/src/main/kotlin/app/revanced/manager/flutter/utils/share/ShareProvider.kt b/android/app/src/main/kotlin/app/revanced/manager/flutter/utils/share/ShareProvider.kt new file mode 100644 index 00000000..9460b335 --- /dev/null +++ b/android/app/src/main/kotlin/app/revanced/manager/flutter/utils/share/ShareProvider.kt @@ -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 = 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?, + selection: String?, + selectionArgs: Array?, + 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?): Int { + throw UnsupportedOperationException("Update operation is not supported") + } + + override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int { + throw UnsupportedOperationException("Delete operation is not supported") + } + + override fun getType(uri: Uri): String? { + throw UnsupportedOperationException("Get type operation is not supported") + } +}