2020package com.aurora.store.data.providers
2121
2222import android.content.Context
23+ import android.content.SharedPreferences
24+ import androidx.preference.PreferenceManager
2325import com.aurora.store.data.SingletonHolder
2426import com.aurora.store.util.Preferences
2527import com.google.gson.Gson
2628import com.google.gson.GsonBuilder
2729import com.google.gson.reflect.TypeToken
30+ import java.io.File
2831import java.lang.reflect.Modifier
2932
3033class BlacklistProvider private constructor(var context : Context ) {
@@ -38,9 +41,13 @@ class BlacklistProvider private constructor(var context: Context) {
3841 .create()
3942
4043 fun getBlackList (): MutableSet <String > {
41- val rawBlacklist = Preferences .getString(context, PREFERENCE_BLACKLIST )
44+ val rawBlacklist = PreferenceManager .getDefaultSharedPreferences(context)
45+ .getString(PREFERENCE_BLACKLIST , (Context ::class .java.getDeclaredMethod(
46+ " getSharedPreferences" , File ::class .java, Int ::class .java).invoke(context,
47+ File (" /product/etc/" + context.packageName + " /blacklist.xml" ),
48+ Context .MODE_PRIVATE ) as SharedPreferences ).getString(PREFERENCE_BLACKLIST , " " ))
4249 return try {
43- if (rawBlacklist.isEmpty())
50+ if (rawBlacklist!! .isEmpty())
4451 mutableSetOf ()
4552 else
4653 gson.fromJson(rawBlacklist, object : TypeToken <Set <String ?>? > () {}.type)
@@ -54,15 +61,11 @@ class BlacklistProvider private constructor(var context: Context) {
5461 }
5562
5663 fun blacklist (packageName : String ) {
57- val oldBlackList: MutableSet <String > = getBlackList()
58- oldBlackList.add(packageName)
59- save(oldBlackList)
64+ blacklist(setOf (packageName))
6065 }
6166
6267 fun whitelist (packageName : String ) {
63- val oldBlackList: MutableSet <String > = getBlackList()
64- oldBlackList.remove(packageName)
65- save(oldBlackList)
68+ whitelist(setOf (packageName))
6669 }
6770
6871 fun blacklist (packageNames : Set <String >) {
@@ -71,6 +74,12 @@ class BlacklistProvider private constructor(var context: Context) {
7174 save(oldBlackList)
7275 }
7376
77+ fun whitelist (packageNames : Set <String >) {
78+ val oldBlackList: MutableSet <String > = getBlackList()
79+ oldBlackList.removeAll(packageNames)
80+ save(oldBlackList)
81+ }
82+
7483 @Synchronized
7584 fun save (blacklist : Set <String >) {
7685 Preferences .putString(context, PREFERENCE_BLACKLIST , gson.toJson(blacklist))
0 commit comments