Search in sources :

Example 21 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class PackageManagerService method getInstalledPackages.

@Override
public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, int userId) {
    final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
    enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "get installed packages");
    // writer
    synchronized (mPackages) {
        ArrayList<PackageInfo> list;
        if (listUninstalled) {
            list = new ArrayList<PackageInfo>(mSettings.mPackages.size());
            for (PackageSetting ps : mSettings.mPackages.values()) {
                PackageInfo pi;
                if (ps.pkg != null) {
                    pi = generatePackageInfo(ps.pkg, flags, userId);
                } else {
                    pi = generatePackageInfoFromSettingsLPw(ps.name, flags, userId);
                }
                if (pi != null) {
                    list.add(pi);
                }
            }
        } else {
            list = new ArrayList<PackageInfo>(mPackages.size());
            for (PackageParser.Package p : mPackages.values()) {
                PackageInfo pi = generatePackageInfo(p, flags, userId);
                if (pi != null) {
                    list.add(pi);
                }
            }
        }
        return new ParceledListSlice<PackageInfo>(list);
    }
}
Also used : PackageParser(android.content.pm.PackageParser) PackageInfo(android.content.pm.PackageInfo) ParceledListSlice(android.content.pm.ParceledListSlice)

Example 22 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class UsbSettingsManager method handlePackageUpdate.

// Check to see if the package supports any USB devices or accessories.
// If so, clear any non-matching preferences for matching devices/accessories.
private void handlePackageUpdate(String packageName) {
    synchronized (mLock) {
        PackageInfo info;
        boolean changed = false;
        try {
            info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
        } catch (NameNotFoundException e) {
            Slog.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
            return;
        }
        ActivityInfo[] activities = info.activities;
        if (activities == null)
            return;
        for (int i = 0; i < activities.length; i++) {
            // check for meta-data, both for devices and accessories
            if (handlePackageUpdateLocked(packageName, activities[i], UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                changed = true;
            }
            if (handlePackageUpdateLocked(packageName, activities[i], UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
                changed = true;
            }
        }
        if (changed) {
            writeSettingsLocked();
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 23 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class Pm method displayPackageFilePath.

/**
     * Displays the package file for a package.
     * @param pckg
     */
private void displayPackageFilePath(String pckg) {
    try {
        PackageInfo info = mPm.getPackageInfo(pckg, 0, 0);
        if (info != null && info.applicationInfo != null) {
            System.out.print("package:");
            System.out.println(info.applicationInfo.sourceDir);
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 24 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class Pm method runListPackages.

/**
     * Lists all the installed packages.
     */
private void runListPackages(boolean showApplicationPackage) {
    int getFlags = 0;
    boolean listDisabled = false, listEnabled = false;
    boolean listSystem = false, listThirdParty = false;
    boolean listInstaller = false;
    int userId = UserHandle.USER_OWNER;
    try {
        String opt;
        while ((opt = nextOption()) != null) {
            if (opt.equals("-l")) {
            // old compat
            } else if (opt.equals("-lf")) {
                showApplicationPackage = true;
            } else if (opt.equals("-f")) {
                showApplicationPackage = true;
            } else if (opt.equals("-d")) {
                listDisabled = true;
            } else if (opt.equals("-e")) {
                listEnabled = true;
            } else if (opt.equals("-s")) {
                listSystem = true;
            } else if (opt.equals("-3")) {
                listThirdParty = true;
            } else if (opt.equals("-i")) {
                listInstaller = true;
            } else if (opt.equals("--user")) {
                userId = Integer.parseInt(nextArg());
            } else if (opt.equals("-u")) {
                getFlags |= PackageManager.GET_UNINSTALLED_PACKAGES;
            } else {
                System.err.println("Error: Unknown option: " + opt);
                return;
            }
        }
    } catch (RuntimeException ex) {
        System.err.println("Error: " + ex.toString());
        return;
    }
    String filter = nextArg();
    try {
        final List<PackageInfo> packages = getInstalledPackages(mPm, getFlags, userId);
        int count = packages.size();
        for (int p = 0; p < count; p++) {
            PackageInfo info = packages.get(p);
            if (filter != null && !info.packageName.contains(filter)) {
                continue;
            }
            final boolean isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
            if ((!listDisabled || !info.applicationInfo.enabled) && (!listEnabled || info.applicationInfo.enabled) && (!listSystem || isSystem) && (!listThirdParty || !isSystem)) {
                System.out.print("package:");
                if (showApplicationPackage) {
                    System.out.print(info.applicationInfo.sourceDir);
                    System.out.print("=");
                }
                System.out.print(info.packageName);
                if (listInstaller) {
                    System.out.print("  installer=");
                    System.out.print(mPm.getInstallerPackageName(info.packageName));
                }
                System.out.println();
            }
        }
    } catch (RemoteException e) {
        System.err.println(e.toString());
        System.err.println(PM_NOT_RUNNING_ERR);
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 25 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method attachThemeAssets.

/**
     * Attach the necessary theme asset paths and meta information to convert an
     * AssetManager to being globally "theme-aware".
     *
     * @param assets
     * @param theme
     * @return true if the AssetManager is now theme-aware; false otherwise.
     *         This can fail, for example, if the theme package has been been
     *         removed and the theme manager has yet to revert formally back to
     *         the framework default.
     */
private boolean attachThemeAssets(AssetManager assets, CustomTheme theme) {
    IAssetRedirectionManager rm = getAssetRedirectionManager();
    if (rm == null) {
        return false;
    }
    PackageInfo pi = null;
    try {
        pi = getPackageManager().getPackageInfo(theme.getThemePackageName(), 0, UserHandle.myUserId());
    } catch (RemoteException e) {
    }
    if (pi != null && pi.applicationInfo != null && pi.themeInfos != null) {
        String themeResDir = pi.applicationInfo.publicSourceDir;
        int cookie = assets.attachThemePath(themeResDir);
        if (cookie != 0) {
            String themePackageName = theme.getThemePackageName();
            String themeId = theme.getThemeId();
            int N = assets.getBasePackageCount();
            for (int i = 0; i < N; i++) {
                String packageName = assets.getBasePackageName(i);
                int packageId = assets.getBasePackageId(i);
                /*
                     * For now, we only consider redirections coming from the
                     * framework or regular android packages. This excludes
                     * themes and other specialty APKs we are not aware of.
                     */
                if (packageId != 0x01 && packageId != 0x7f) {
                    continue;
                }
                try {
                    PackageRedirectionMap map = rm.getPackageRedirectionMap(themePackageName, themeId, packageName);
                    if (map != null) {
                        assets.addRedirections(map);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Failure accessing package redirection map, removing theme support.");
                    assets.detachThemePath(themePackageName, cookie);
                    return false;
                }
            }
            assets.setThemePackageName(theme.getThemePackageName());
            assets.setThemeCookie(cookie);
            return true;
        } else {
            Log.e(TAG, "Unable to attach theme assets at " + themeResDir);
        }
    }
    return false;
}
Also used : PackageInfo(android.content.pm.PackageInfo) PackageRedirectionMap(android.content.res.PackageRedirectionMap) IAssetRedirectionManager(com.android.internal.app.IAssetRedirectionManager) RemoteException(android.os.RemoteException)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1566 PackageManager (android.content.pm.PackageManager)702 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)327 ApplicationInfo (android.content.pm.ApplicationInfo)217 Test (org.junit.Test)193 RemoteException (android.os.RemoteException)179 ArrayList (java.util.ArrayList)166 Intent (android.content.Intent)126 IOException (java.io.IOException)121 Context (android.content.Context)81 IPackageManager (android.content.pm.IPackageManager)65 ResolveInfo (android.content.pm.ResolveInfo)65 File (java.io.File)62 SuppressLint (android.annotation.SuppressLint)58 ComponentName (android.content.ComponentName)57 ActivityInfo (android.content.pm.ActivityInfo)57 View (android.view.View)57 TextView (android.widget.TextView)54 Signature (android.content.pm.Signature)51 OverlayInfo (android.content.om.OverlayInfo)42