Merge branch 'default-blacklist' into 'master'
Read system xml blacklist as default See merge request AuroraOSS/AuroraStore!150
This commit is contained in:
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user