Read system xml blacklist as default

This commit is contained in:
Oliver Scott
2021-10-01 15:31:41 -04:00
parent 934a96fb11
commit a550a4dddc

View File

@@ -20,11 +20,14 @@
package com.aurora.store.data.providers package com.aurora.store.data.providers
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import com.aurora.store.data.SingletonHolder import com.aurora.store.data.SingletonHolder
import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.GsonBuilder import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import java.io.File
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
class BlacklistProvider private constructor(var context: Context) { class BlacklistProvider private constructor(var context: Context) {
@@ -38,9 +41,13 @@ class BlacklistProvider private constructor(var context: Context) {
.create() .create()
fun getBlackList(): MutableSet<String> { fun getBlackList(): MutableSet<String> {
val rawBlacklist = Preferences.getString(context, PREFERENCE_BLACKLIST) val rawBlacklist = PreferenceManager.getDefaultSharedPreferences(context)
.getString(PREFERENCE_BLACKLIST, (Context::class.java.getDeclaredMethod(
"getSharedPreferences", File::class.java, Int::class.java).invoke(context,
File("/product/etc/" + context.packageName + "/blacklist.xml"),
Context.MODE_PRIVATE) as SharedPreferences).getString(PREFERENCE_BLACKLIST, ""))
return try { return try {
if (rawBlacklist.isEmpty()) if (rawBlacklist!!.isEmpty())
mutableSetOf() mutableSetOf()
else else
gson.fromJson(rawBlacklist, object : TypeToken<Set<String?>?>() {}.type) gson.fromJson(rawBlacklist, object : TypeToken<Set<String?>?>() {}.type)
@@ -54,15 +61,11 @@ class BlacklistProvider private constructor(var context: Context) {
} }
fun blacklist(packageName: String) { fun blacklist(packageName: String) {
val oldBlackList: MutableSet<String> = getBlackList() blacklist(setOf(packageName))
oldBlackList.add(packageName)
save(oldBlackList)
} }
fun whitelist(packageName: String) { fun whitelist(packageName: String) {
val oldBlackList: MutableSet<String> = getBlackList() whitelist(setOf(packageName))
oldBlackList.remove(packageName)
save(oldBlackList)
} }
fun blacklist(packageNames: Set<String>) { fun blacklist(packageNames: Set<String>) {
@@ -71,6 +74,12 @@ class BlacklistProvider private constructor(var context: Context) {
save(oldBlackList) save(oldBlackList)
} }
fun whitelist(packageNames: Set<String>) {
val oldBlackList: MutableSet<String> = getBlackList()
oldBlackList.removeAll(packageNames)
save(oldBlackList)
}
@Synchronized @Synchronized
fun save(blacklist: Set<String>) { fun save(blacklist: Set<String>) {
Preferences.putString(context, PREFERENCE_BLACKLIST, gson.toJson(blacklist)) Preferences.putString(context, PREFERENCE_BLACKLIST, gson.toJson(blacklist))