Java Code Examples for android.content.pm.PackageManager.getPackagesForUid()

The following are Jave code examples for showing how to use getPackagesForUid() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lineagex86   File: AppNotificationSettings.java   View Source Code Vote up 6 votes
private static PackageInfo findPackageInfo(PackageManager pm, String pkg, int uid) {
    final String[] packages = pm.getPackagesForUid(uid);
    if (packages != null && pkg != null) {
        final int N = packages.length;
        for (int i = 0; i < N; i++) {
            final String p = packages[i];
            if (pkg.equals(p)) {
                try {
                    return pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
                } catch (NameNotFoundException e) {
                    Log.w(TAG, "Failed to load package " + pkg, e);
                }
            }
        }
    }
    return null;
}
 
Example 2
Project: MKAPP   File: Util.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: MKAPP   File: Util.java   View Source Code Vote up 6 votes
public static List<String> getApplicationNames(int uid, Context context) {
    List<String> listResult = new ArrayList<>();
    if (uid == 0)
        listResult.add(context.getString(R.string.title_root));
    else if (uid == 1013)
        listResult.add(context.getString(R.string.title_mediaserver));
    else if (uid == 9999)
        listResult.add(context.getString(R.string.title_nobody));
    else {
        PackageManager pm = context.getPackageManager();
        String[] pkgs = pm.getPackagesForUid(uid);
        if (pkgs == null)
            listResult.add(Integer.toString(uid));
        else
            for (String pkg : pkgs)
                try {
                    ApplicationInfo info = pm.getApplicationInfo(pkg, 0);
                    listResult.add(pm.getApplicationLabel(info).toString());
                } catch (PackageManager.NameNotFoundException ignored) {
                }
        Collections.sort(listResult);
    }
    return listResult;
}
 
Example 4
Project: MKAPP   File: Util.java   View Source Code Vote up 5 votes
public static boolean isSystem(int uid, Context context) {
    PackageManager pm = context.getPackageManager();
    String[] pkgs = pm.getPackagesForUid(uid);
    if (pkgs != null)
        for (String pkg : pkgs)
            if (isSystem(pkg, context))
                return true;
    return false;
}
 
Example 5
Project: prevent   File: GmsUtils.java   View Source Code Vote up 5 votes
private static boolean isGapps(PackageManager pm, int callingUid) {
    String[] packageNames = pm.getPackagesForUid(callingUid);
    if (packageNames == null) {
        return false;
    }
    for (String packageName : packageNames) {
        if (isGapps(packageName)) {
            return true;
        }
    }
    return false;
}
 
Example 6
Project: XPrivacy   File: ApplicationInfoEx.java   View Source Code Vote up 5 votes
public ApplicationInfoEx(Context context, int uid) {
	mUid = uid;
	mMapAppInfo = new TreeMap<String, ApplicationInfo>();
	PackageManager pm = context.getPackageManager();
	String[] packages = pm.getPackagesForUid(uid);
	if (packages != null)
		for (String packageName : packages)
			try {
				ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
				mMapAppInfo.put(pm.getApplicationLabel(appInfo).toString(), appInfo);
			} catch (NameNotFoundException ignored) {
			}
}
 
Example 7
Project: chromium-for-android-56-debug-video   File: ExternalAuthUtils.java   View Source Code Vote up 4 votes
/**
 * Gets the calling package names for the current transaction.
 * @param context The context to use for accessing the package manager.
 * @return The calling package names.
 */
private static String[] getCallingPackages(Context context) {
    int callingUid = Binder.getCallingUid();
    PackageManager pm = context.getApplicationContext().getPackageManager();
    return pm.getPackagesForUid(callingUid);
}
 
Example 8
Project: chromium-for-android-56-debug-video   File: ClientManager.java   View Source Code Vote up 4 votes
private static String getPackageName(Context context, int uid) {
    PackageManager packageManager = context.getPackageManager();
    String[] packageList = packageManager.getPackagesForUid(uid);
    if (packageList.length != 1 || TextUtils.isEmpty(packageList[0])) return null;
    return packageList[0];
}