Refactoring

This commit is contained in:
M66B 2016-01-31 09:46:15 +01:00
parent 8e66f863d0
commit 5c6559c514
3 changed files with 19 additions and 5 deletions

View File

@ -107,7 +107,7 @@ public class Receiver extends BroadcastReceiver {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try { try {
// Get application name // Get application info
String name = TextUtils.join(", ", Util.getApplicationNames(uid, context)); String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));
// Get application info // Get application info
@ -115,12 +115,11 @@ public class Receiver extends BroadcastReceiver {
String[] packages = pm.getPackagesForUid(uid); String[] packages = pm.getPackagesForUid(uid);
if (packages.length < 1) if (packages.length < 1)
throw new PackageManager.NameNotFoundException(Integer.toString(uid)); throw new PackageManager.NameNotFoundException(Integer.toString(uid));
ApplicationInfo info = pm.getApplicationInfo(packages[0], 0); boolean internet = Util.hasInternet(uid, context);
boolean internet = (pm.checkPermission("android.permission.INTERNET", info.packageName) == PackageManager.PERMISSION_GRANTED);
// Build notification // Build notification
Intent main = new Intent(context, ActivityMain.class); Intent main = new Intent(context, ActivityMain.class);
main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(info.uid)); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pi = PendingIntent.getActivity(context, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);
Util.setTheme(context); Util.setTheme(context);

View File

@ -81,7 +81,7 @@ public class Rule {
this.info = info; this.info = info;
this.name = info.applicationInfo.loadLabel(pm).toString(); this.name = info.applicationInfo.loadLabel(pm).toString();
this.system = Util.isSystem(info.packageName, context); this.system = Util.isSystem(info.packageName, context);
this.internet = (pm.checkPermission("android.permission.INTERNET", info.packageName) == PackageManager.PERMISSION_GRANTED); this.internet = Util.hasInternet(info.packageName, context);
int setting; int setting;
try { try {

View File

@ -325,6 +325,21 @@ public class Util {
} }
} }
public static boolean hasInternet(String packageName, Context context) {
PackageManager pm = context.getPackageManager();
return (pm.checkPermission("android.permission.INTERNET", packageName) == PackageManager.PERMISSION_GRANTED);
}
public static boolean hasInternet(int uid, Context context) {
PackageManager pm = context.getPackageManager();
String[] pkgs = pm.getPackagesForUid(uid);
if (pkgs != null)
for (String pkg : pkgs)
if (hasInternet(pkg, context))
return true;
return false;
}
public static List<String> getApplicationNames(int uid, Context context) { public static List<String> getApplicationNames(int uid, Context context) {
List<String> listResult = new ArrayList<>(); List<String> listResult = new ArrayList<>();
if (uid == 0) if (uid == 0)