forked from ReVanced/revanced-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5838550
commit 2a89ef7
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
android/app/src/main/kotlin/app/revanced/manager/flutter/utils/share/ShareProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |