mirror of https://github.com/M66B/NetGuard.git
Get application names
This commit is contained in:
parent
f60b3e5b6b
commit
4560925d6d
|
@ -21,7 +21,6 @@ package eu.faircode.netguard;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
@ -31,6 +30,7 @@ import android.preference.PreferenceManager;
|
|||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
|
@ -128,19 +128,8 @@ public class ActivityLog extends AppCompatActivity {
|
|||
final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport")));
|
||||
final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid")));
|
||||
|
||||
// Get package name
|
||||
String name = null;
|
||||
if (uid == 0)
|
||||
name = "root";
|
||||
else {
|
||||
String[] pkg = pm.getPackagesForUid(uid);
|
||||
if (pkg != null && pkg.length > 0)
|
||||
try {
|
||||
ApplicationInfo info = pm.getApplicationInfo(pkg[0], 0);
|
||||
name = pm.getApplicationLabel(info).toString();
|
||||
} catch (PackageManager.NameNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
// Get application name(s)
|
||||
String name = (uid == 0 ? "root" : TextUtils.join(",", Util.getApplicationNames(uid, ActivityLog.this)));
|
||||
|
||||
// Get external address
|
||||
InetAddress addr = null;
|
||||
|
|
|
@ -27,12 +27,12 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.VpnService;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
|
@ -107,13 +107,15 @@ public class Receiver extends BroadcastReceiver {
|
|||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
try {
|
||||
// Get application name(s)
|
||||
String name = TextUtils.join(",", Util.getApplicationNames(uid, context));
|
||||
|
||||
// Get application info
|
||||
PackageManager pm = context.getPackageManager();
|
||||
String[] packages = pm.getPackagesForUid(uid);
|
||||
if (packages.length < 1)
|
||||
throw new PackageManager.NameNotFoundException(Integer.toString(uid));
|
||||
ApplicationInfo info = pm.getApplicationInfo(packages[0], 0);
|
||||
String name = (String) pm.getApplicationLabel(info);
|
||||
boolean internet = (pm.checkPermission("android.permission.INTERNET", info.packageName) == PackageManager.PERMISSION_GRANTED);
|
||||
|
||||
// Build notification
|
||||
|
|
|
@ -57,6 +57,8 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.lang.reflect.Method;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -305,6 +307,20 @@ public class Util {
|
|||
}
|
||||
}
|
||||
|
||||
public static List<String> getApplicationNames(int uid, Context context) {
|
||||
List<String> listResult = new ArrayList<>();
|
||||
PackageManager pm = context.getPackageManager();
|
||||
String[] pkg = pm.getPackagesForUid(uid);
|
||||
if (pkg != null && pkg.length > 0)
|
||||
try {
|
||||
ApplicationInfo info = pm.getApplicationInfo(pkg[0], 0);
|
||||
listResult.add(pm.getApplicationLabel(info).toString());
|
||||
} catch (PackageManager.NameNotFoundException ignored) {
|
||||
}
|
||||
Collections.sort(listResult);
|
||||
return listResult;
|
||||
}
|
||||
|
||||
public static boolean isDebuggable(Context context) {
|
||||
return ((context.getApplicationContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue