Permalink
Browse files

Make application blacklist matching better.

Now matches exact package names. The old method could match substrings of
package names.
  • Loading branch information...
firetech committed Apr 15, 2012
1 parent 4682024 commit 0bf3ba0fbb3ea34a44c8780e8174fd784100a19b
@@ -1,6 +1,7 @@
package org.metawatch.manager;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -46,8 +47,10 @@ protected void onPreExecute() {
protected List<AppInfo> doInBackground(Void... params) {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(AppBlacklist.this);
- String blacklist = sharedPreferences.getString("appBlacklist",
- DEFAULT_BLACKLIST);
+ String[] blacklist = sharedPreferences.getString("appBlacklist",
+ DEFAULT_BLACKLIST).split(",");
+ Arrays.sort(blacklist);
+
PackageManager pm = getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(0);
List<AppInfo> appInfos = new ArrayList<AppInfo>();
@@ -64,7 +67,8 @@ protected void onPreExecute() {
appInfo.name = pi.applicationInfo.loadLabel(pm).toString();
appInfo.icon = pi.applicationInfo.loadIcon(pm);
appInfo.packageName = pi.packageName;
- appInfo.isBlacklisted = blacklist.contains(pi.packageName);
+ appInfo.isBlacklisted =
+ (Arrays.binarySearch(blacklist, pi.packageName) >= 0);
appInfos.add(appInfo);
}
Collections.sort(appInfos);
@@ -1,5 +1,7 @@
package org.metawatch.manager;
+import java.util.Arrays;
+
import org.metawatch.manager.MetaWatchService.Preferences;
import android.accessibilityservice.AccessibilityService;
@@ -129,11 +131,12 @@ public void onAccessibilityEvent(AccessibilityEvent event) {
/* Some other notification */
if (sharedPreferences.getBoolean("NotifyOtherNotification", true)) {
- String appBlacklist = sharedPreferences.getString("appBlacklist",
- AppBlacklist.DEFAULT_BLACKLIST);
+ String[] appBlacklist = sharedPreferences.getString("appBlacklist",
+ AppBlacklist.DEFAULT_BLACKLIST).split(",");
+ Arrays.sort(appBlacklist);
/* Ignore if on blacklist */
- if (appBlacklist.contains(packageName)) {
+ if (Arrays.binarySearch(appBlacklist, packageName) >= 0) {
if (Preferences.logging) Log.d(MetaWatch.TAG,
"onAccessibilityEvent(): App is blacklisted, ignoring.");
return;

0 comments on commit 0bf3ba0

Please sign in to comment.