mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
Cleanup package blacklist handling
Didn't find a cause for #664, though.
This commit is contained in:
parent
36c1b5a6f2
commit
2003d56190
@ -40,6 +40,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@ -313,10 +314,23 @@ public class GBApplication extends Application {
|
||||
return NotificationManager.INTERRUPTION_FILTER_ALL;
|
||||
}
|
||||
|
||||
public static HashSet<String> blacklist = null;
|
||||
private static HashSet<String> blacklist = null;
|
||||
|
||||
public static boolean isBlacklisted(String packageName) {
|
||||
return blacklist != null && blacklist.contains(packageName);
|
||||
}
|
||||
|
||||
public static void setBlackList(Set<String> packageNames) {
|
||||
if (packageNames == null) {
|
||||
blacklist = new HashSet<>();
|
||||
} else {
|
||||
blacklist = new HashSet<>(packageNames);
|
||||
}
|
||||
saveBlackList();
|
||||
}
|
||||
|
||||
private static void loadBlackList() {
|
||||
blacklist = (HashSet<String>) sharedPrefs.getStringSet("package_blacklist", null);
|
||||
blacklist = (HashSet<String>) sharedPrefs.getStringSet(GBPrefs.PACKAGE_BLACKLIST, null);
|
||||
if (blacklist == null) {
|
||||
blacklist = new HashSet<>();
|
||||
}
|
||||
@ -325,16 +339,15 @@ public class GBApplication extends Application {
|
||||
private static void saveBlackList() {
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
if (blacklist.isEmpty()) {
|
||||
editor.putStringSet("package_blacklist", null);
|
||||
editor.putStringSet(GBPrefs.PACKAGE_BLACKLIST, null);
|
||||
} else {
|
||||
editor.putStringSet("package_blacklist", blacklist);
|
||||
editor.putStringSet(GBPrefs.PACKAGE_BLACKLIST, blacklist);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void addToBlacklist(String packageName) {
|
||||
if (!blacklist.contains(packageName)) {
|
||||
blacklist.add(packageName);
|
||||
if (blacklist.add(packageName)) {
|
||||
saveBlackList();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
@ -33,8 +32,6 @@ import android.view.MenuItem;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.adapter.AppBlacklistAdapter;
|
||||
@ -55,8 +52,6 @@ public class AppBlacklistActivity extends GBActivity {
|
||||
}
|
||||
};
|
||||
|
||||
private IdentityHashMap<ApplicationInfo, String> nameMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -40,13 +40,13 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter<AppBlacklistAdapte
|
||||
applicationInfoList = mPm.getInstalledApplications(PackageManager.GET_META_DATA);
|
||||
|
||||
// sort the package list by label and blacklist status
|
||||
mNameMap = new IdentityHashMap<ApplicationInfo, String>(applicationInfoList.size());
|
||||
mNameMap = new IdentityHashMap<>(applicationInfoList.size());
|
||||
for (ApplicationInfo ai : applicationInfoList) {
|
||||
CharSequence name = mPm.getApplicationLabel(ai);
|
||||
if (name == null) {
|
||||
name = ai.packageName;
|
||||
}
|
||||
if (GBApplication.blacklist.contains(ai.packageName)) {
|
||||
if (GBApplication.isBlacklisted(ai.packageName)) {
|
||||
// sort blacklisted first by prefixing with a '!'
|
||||
name = "!" + name;
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter<AppBlacklistAdapte
|
||||
holder.deviceAppNameLabel.setText(mNameMap.get(appInfo));
|
||||
holder.deviceImageView.setImageDrawable(appInfo.loadIcon(mPm));
|
||||
|
||||
holder.checkbox.setChecked(GBApplication.blacklist.contains(appInfo.packageName));
|
||||
holder.checkbox.setChecked(GBApplication.isBlacklisted(appInfo.packageName));
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -242,7 +242,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
if (GBApplication.blacklist != null && GBApplication.blacklist.contains(source)) {
|
||||
if (GBApplication.isBlacklisted(source)) {
|
||||
LOG.info("Not forwarding notification, application is blacklisted");
|
||||
return;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
public class GBPrefs {
|
||||
|
||||
public static final String PACKAGE_BLACKLIST = "package_blacklist";
|
||||
public static final String AUTO_RECONNECT = "general_autocreconnect";
|
||||
private static final String AUTO_START = "general_autostartonboot";
|
||||
private static final boolean AUTO_START_DEFAULT = true;
|
||||
@ -61,7 +61,7 @@ public class GBPrefs {
|
||||
}
|
||||
}
|
||||
|
||||
public int getUserSex() {
|
||||
public int getUserGender() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import org.xmlpull.v1.XmlSerializer;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Xml;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.blacklist;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
|
||||
public class ImportExportSharedPreferences {
|
||||
|
||||
@ -26,7 +26,7 @@ public class ImportExportSharedPreferences {
|
||||
private static final String INTEGER = Integer.class.getSimpleName();
|
||||
private static final String LONG = Long.class.getSimpleName();
|
||||
private static final String STRING = String.class.getSimpleName();
|
||||
private static final String HASTSET = HashSet.class.getSimpleName();
|
||||
private static final String HASHSET = HashSet.class.getSimpleName();
|
||||
|
||||
private static final String NAME = "name";
|
||||
private static final String PREFERENCES = "preferences";
|
||||
@ -107,14 +107,14 @@ public class ImportExportSharedPreferences {
|
||||
editor.putLong(key, Long.parseLong(text));
|
||||
} else if (STRING.equals(name)) {
|
||||
editor.putString(key, text);
|
||||
} else if (HASTSET.equals(name)) {
|
||||
if (key.equals("package_blacklist")) {
|
||||
blacklist.clear();
|
||||
} else if (HASHSET.equals(name)) {
|
||||
if (key.equals(GBPrefs.PACKAGE_BLACKLIST)) {
|
||||
Set<String> blacklist = new HashSet<>();
|
||||
text=text.replace("[","").replace("]","");
|
||||
for (int z=0;z<text.split(",").length;z++){
|
||||
blacklist.add(text.split(",")[z].trim());
|
||||
}
|
||||
editor.putStringSet(key, blacklist);
|
||||
GBApplication.setBlackList(blacklist);
|
||||
}
|
||||
} else if (!PREFERENCES.equals(name)) {
|
||||
throw new Exception("Unkown type " + name);
|
||||
|
Loading…
Reference in New Issue
Block a user