mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-25 07:32:46 +00:00
Fix, improvement, refactoring
This commit is contained in:
parent
94617dbe74
commit
e718655501
4 changed files with 15 additions and 18 deletions
|
@ -50,8 +50,8 @@ public class Receiver extends BroadcastReceiver {
|
|||
if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
|
||||
// Show notification
|
||||
if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context)) {
|
||||
int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
|
||||
notifyApplication(uid, context);
|
||||
int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
|
||||
notifyNewApplication(uid, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class Receiver extends BroadcastReceiver {
|
|||
}
|
||||
}
|
||||
|
||||
public static void notifyApplication(int uid, Context context) {
|
||||
public static void notifyNewApplication(int uid, Context context) {
|
||||
if (uid < 0)
|
||||
return;
|
||||
|
||||
|
@ -113,12 +113,6 @@ public class Receiver extends BroadcastReceiver {
|
|||
ApplicationInfo info = pm.getApplicationInfo(packages[0], 0);
|
||||
String name = (String) pm.getApplicationLabel(info);
|
||||
|
||||
// Check system application
|
||||
boolean system = ((info.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0);
|
||||
boolean manage_system = prefs.getBoolean("manage_system", false);
|
||||
if (system && !manage_system)
|
||||
return;
|
||||
|
||||
// Build notification
|
||||
Intent main = new Intent(context, ActivityMain.class);
|
||||
main.putExtra(ActivityMain.EXTRA_SEARCH, name);
|
||||
|
@ -213,12 +207,12 @@ public class Receiver extends BroadcastReceiver {
|
|||
|
||||
// TODO: delete unused
|
||||
} else if (oldVersion < 2016010307) {
|
||||
notifyApplication(Util.getSystemUid("com.facebook.katana", context), context);
|
||||
notifyApplication(Util.getSystemUid("com.facebook.orca", context), context);
|
||||
notifyApplication(Util.getSystemUid("com.google.android.youtube", context), context);
|
||||
notifyApplication(Util.getSystemUid("com.skype.raider", context), context);
|
||||
notifyApplication(Util.getSystemUid("com.twitter.android", context), context);
|
||||
notifyApplication(Util.getSystemUid("com.whatsapp", context), context);
|
||||
notifyNewApplication(Util.getSystemUid("com.facebook.katana", context), context);
|
||||
notifyNewApplication(Util.getSystemUid("com.facebook.orca", context), context);
|
||||
notifyNewApplication(Util.getSystemUid("com.google.android.youtube", context), context);
|
||||
notifyNewApplication(Util.getSystemUid("com.skype.raider", context), context);
|
||||
notifyNewApplication(Util.getSystemUid("com.twitter.android", context), context);
|
||||
notifyNewApplication(Util.getSystemUid("com.whatsapp", context), context);
|
||||
}
|
||||
} else {
|
||||
editor.putBoolean("whitelist_wifi", false);
|
||||
|
|
|
@ -79,7 +79,7 @@ public class Rule {
|
|||
|
||||
this.info = info;
|
||||
this.name = info.applicationInfo.loadLabel(pm).toString();
|
||||
this.system = ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
|
||||
this.system = ((info.applicationInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0);
|
||||
this.internet = (pm.checkPermission("android.permission.INTERNET", info.packageName) == PackageManager.PERMISSION_GRANTED);
|
||||
|
||||
int setting;
|
||||
|
|
|
@ -500,7 +500,7 @@ public class SinkholeService extends VpnService {
|
|||
prefs.edit().putBoolean(pkg, blocked).apply();
|
||||
|
||||
// Update notification
|
||||
Receiver.notifyApplication(uid, SinkholeService.this);
|
||||
Receiver.notifyNewApplication(uid, SinkholeService.this);
|
||||
|
||||
// Update UI
|
||||
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
|
||||
|
|
|
@ -87,7 +87,10 @@ public class Util {
|
|||
public static int getSystemUid(String packageName, Context context) {
|
||||
try {
|
||||
PackageInfo pInfo = context.getPackageManager().getPackageInfo(packageName, 0);
|
||||
return ((pInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ? -1 : pInfo.applicationInfo.uid);
|
||||
if ((pInfo.applicationInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0)
|
||||
return pInfo.applicationInfo.uid;
|
||||
else
|
||||
return -1;
|
||||
} catch (PackageManager.NameNotFoundException ex) {
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue