mirror of https://github.com/M66B/NetGuard.git
Refactoring
This commit is contained in:
parent
8e66f863d0
commit
5c6559c514
|
@ -107,7 +107,7 @@ public class Receiver extends BroadcastReceiver {
|
|||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
try {
|
||||
// Get application name
|
||||
// Get application info
|
||||
String name = TextUtils.join(", ", Util.getApplicationNames(uid, context));
|
||||
|
||||
// Get application info
|
||||
|
@ -115,12 +115,11 @@ public class Receiver extends BroadcastReceiver {
|
|||
String[] packages = pm.getPackagesForUid(uid);
|
||||
if (packages.length < 1)
|
||||
throw new PackageManager.NameNotFoundException(Integer.toString(uid));
|
||||
ApplicationInfo info = pm.getApplicationInfo(packages[0], 0);
|
||||
boolean internet = (pm.checkPermission("android.permission.INTERNET", info.packageName) == PackageManager.PERMISSION_GRANTED);
|
||||
boolean internet = Util.hasInternet(uid, context);
|
||||
|
||||
// Build notification
|
||||
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);
|
||||
|
||||
Util.setTheme(context);
|
||||
|
|
|
@ -81,7 +81,7 @@ public class Rule {
|
|||
this.info = info;
|
||||
this.name = info.applicationInfo.loadLabel(pm).toString();
|
||||
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;
|
||||
try {
|
||||
|
|
|
@ -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) {
|
||||
List<String> listResult = new ArrayList<>();
|
||||
if (uid == 0)
|
||||
|
|
Loading…
Reference in New Issue