Search in sources :

Example 41 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ResurrectionRemix.

the class Bmgr method backupNowAllPackages.

private void backupNowAllPackages() {
    int userId = UserHandle.USER_SYSTEM;
    IPackageManager mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
    if (mPm == null) {
        System.err.println(PM_NOT_RUNNING_ERR);
        return;
    }
    List<PackageInfo> installedPackages = null;
    try {
        installedPackages = mPm.getInstalledPackages(0, userId).getList();
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
    if (installedPackages != null) {
        List<String> packages = new ArrayList<>();
        for (PackageInfo pi : installedPackages) {
            try {
                if (mBmgr.isAppEligibleForBackup(pi.packageName)) {
                    packages.add(pi.packageName);
                }
            } catch (RemoteException e) {
                System.err.println(e.toString());
                System.err.println(BMGR_NOT_RUNNING_ERR);
            }
        }
        backupNowPackages(packages);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException)

Example 42 with IPackageManager

use of android.content.pm.IPackageManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminSettings method addActiveAdminsForProfile.

/**
     * Add a {@link DeviceAdminInfo} object to the internal collection of available admins for all
     * active admin components associated with a profile.
     *
     * @param profileId a profile identifier.
     */
private void addActiveAdminsForProfile(final List<ComponentName> activeAdmins, final int profileId) {
    if (activeAdmins != null) {
        final PackageManager packageManager = getActivity().getPackageManager();
        final IPackageManager iPackageManager = AppGlobals.getPackageManager();
        final int n = activeAdmins.size();
        for (int i = 0; i < n; ++i) {
            final ComponentName activeAdmin = activeAdmins.get(i);
            final ActivityInfo ai;
            try {
                ai = iPackageManager.getReceiverInfo(activeAdmin, PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE, profileId);
            } catch (RemoteException e) {
                Log.w(TAG, "Unable to load component: " + activeAdmin);
                continue;
            }
            final DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(ai);
            if (deviceAdminInfo == null) {
                continue;
            }
            // Don't do the applicationInfo.isInternal() check here; if an active
            // admin is already on SD card, just show it.
            final DeviceAdminListItem item = new DeviceAdminListItem();
            item.info = deviceAdminInfo;
            item.name = deviceAdminInfo.loadLabel(packageManager).toString();
            item.active = true;
            mAdmins.add(item);
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) DeviceAdminInfo(android.app.admin.DeviceAdminInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 43 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ResurrectionRemix.

the class ClipboardService method addActiveOwnerLocked.

private final void addActiveOwnerLocked(int uid, String pkg) {
    final IPackageManager pm = AppGlobals.getPackageManager();
    final int targetUserHandle = UserHandle.getCallingUserId();
    final long oldIdentity = Binder.clearCallingIdentity();
    try {
        PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle);
        if (pi == null) {
            throw new IllegalArgumentException("Unknown package " + pkg);
        }
        if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) {
            throw new SecurityException("Calling uid " + uid + " does not own package " + pkg);
        }
    } catch (RemoteException e) {
    // Can't happen; the package manager is in the same process
    } finally {
        Binder.restoreCallingIdentity(oldIdentity);
    }
    PerUserClipboard clipboard = getClipboard();
    if (clipboard.primaryClip != null && !clipboard.activePermissionOwners.contains(pkg)) {
        final int N = clipboard.primaryClip.getItemCount();
        for (int i = 0; i < N; i++) {
            grantItemLocked(clipboard.primaryClip.getItemAt(i), pkg, UserHandle.getUserId(uid));
        }
        clipboard.activePermissionOwners.add(pkg);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 44 with IPackageManager

use of android.content.pm.IPackageManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryEntry method loadNameAndIcon.

/**
     * Loads the app label and icon image and stores into the cache.
     */
public void loadNameAndIcon() {
    // Bail out if the current sipper is not an App sipper.
    if (sipper.uidObj == null) {
        return;
    }
    PackageManager pm = context.getPackageManager();
    final int uid = sipper.uidObj.getUid();
    sipper.mPackages = pm.getPackagesForUid(uid);
    if (sipper.mPackages != null) {
        String[] packageLabels = new String[sipper.mPackages.length];
        System.arraycopy(sipper.mPackages, 0, packageLabels, 0, sipper.mPackages.length);
        // Convert package names to user-facing labels where possible
        IPackageManager ipm = AppGlobals.getPackageManager();
        final int userId = UserHandle.getUserId(uid);
        for (int i = 0; i < packageLabels.length; i++) {
            try {
                final ApplicationInfo ai = ipm.getApplicationInfo(packageLabels[i], 0, /* no flags */
                userId);
                if (ai == null) {
                    Log.d(PowerUsageSummary.TAG, "Retrieving null app info for package " + packageLabels[i] + ", user " + userId);
                    continue;
                }
                CharSequence label = ai.loadLabel(pm);
                if (label != null) {
                    packageLabels[i] = label.toString();
                }
                if (ai.icon != 0) {
                    defaultPackageName = sipper.mPackages[i];
                    icon = ai.loadIcon(pm);
                    break;
                }
            } catch (RemoteException e) {
                Log.d(PowerUsageSummary.TAG, "Error while retrieving app info for package " + packageLabels[i] + ", user " + userId, e);
            }
        }
        if (packageLabels.length == 1) {
            name = packageLabels[0];
        } else {
            // Look for an official name for this UID.
            for (String pkgName : sipper.mPackages) {
                try {
                    final PackageInfo pi = ipm.getPackageInfo(pkgName, 0, /* no flags */
                    userId);
                    if (pi == null) {
                        Log.d(PowerUsageSummary.TAG, "Retrieving null package info for package " + pkgName + ", user " + userId);
                        continue;
                    }
                    if (pi.sharedUserLabel != 0) {
                        final CharSequence nm = pm.getText(pkgName, pi.sharedUserLabel, pi.applicationInfo);
                        if (nm != null) {
                            name = nm.toString();
                            if (pi.applicationInfo.icon != 0) {
                                defaultPackageName = pkgName;
                                icon = pi.applicationInfo.loadIcon(pm);
                            }
                            break;
                        }
                    }
                } catch (RemoteException e) {
                    Log.d(PowerUsageSummary.TAG, "Error while retrieving package info for package " + pkgName + ", user " + userId, e);
                }
            }
        }
    }
    final String uidString = Integer.toString(uid);
    if (name == null) {
        name = uidString;
    }
    if (icon == null) {
        icon = pm.getDefaultActivityIcon();
    }
    UidToDetail utd = new UidToDetail();
    utd.name = name;
    utd.icon = icon;
    utd.packageName = defaultPackageName;
    sUidCache.put(uidString, utd);
    if (sHandler != null) {
        sHandler.sendMessage(sHandler.obtainMessage(MSG_UPDATE_NAME_ICON, this));
    }
}
Also used : PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 45 with IPackageManager

use of android.content.pm.IPackageManager in project XobotOS by xamarin.

the class GLImpl method allowIndirectBuffers.

private static boolean allowIndirectBuffers(String appName) {
    boolean result = false;
    int version = 0;
    IPackageManager pm = AppGlobals.getPackageManager();
    try {
        ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0);
        if (applicationInfo != null) {
            version = applicationInfo.targetSdkVersion;
        }
    } catch (android.os.RemoteException e) {
    // ignore
    }
    Log.e("OpenGLES", String.format("Application %s (SDK target %d) called a GL11 Pointer method with an indirect Buffer.", appName, version));
    if (version <= Build.VERSION_CODES.CUPCAKE) {
        result = true;
    }
    return result;
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

IPackageManager (android.content.pm.IPackageManager)192 RemoteException (android.os.RemoteException)182 ApplicationInfo (android.content.pm.ApplicationInfo)58 Point (android.graphics.Point)33 PackageInfo (android.content.pm.PackageInfo)32 ComponentName (android.content.ComponentName)29 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)20 PackageManager (android.content.pm.PackageManager)18 UserHandle (android.os.UserHandle)13 Context (android.content.Context)12 HashMap (java.util.HashMap)12 ProviderInfo (android.content.pm.ProviderInfo)10 PendingIntent (android.app.PendingIntent)9 HashSet (java.util.HashSet)9 UserManager (android.os.UserManager)8 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 ResolveInfo (android.content.pm.ResolveInfo)7 ActivityManager (android.app.ActivityManager)6 SpannableString (android.text.SpannableString)6