Search in sources :

Example 41 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class SmokeTestRunner method getAllTests.

/**
     * Returns a single testcase for each app to launch
     */
@Override
public TestSuite getAllTests() {
    final TestSuite suite = new TestSuite(SUITE_NAME);
    final PackageManager pm = getTargetContext().getPackageManager();
    final List<ResolveInfo> apps = ProcessErrorsTest.getLauncherActivities(pm);
    final TestCase setupTest = new ProcessErrorsTest() {

        @Override
        public void runTest() throws Exception {
            testSetUpConditions();
        }
    };
    setupTest.setName("testSetUpConditions");
    suite.addTest(setupTest);
    final TestCase postBootTest = new ProcessErrorsTest() {

        @Override
        public void runTest() throws Exception {
            testNoProcessErrorsAfterBoot();
        }
    };
    postBootTest.setName("testNoProcessErrorsAfterBoot");
    suite.addTest(postBootTest);
    for (final ResolveInfo app : apps) {
        final TestCase appTest = new ProcessErrorsTest() {

            @Override
            public void runTest() throws Exception {
                final Set<ProcessError> errSet = new HashSet<ProcessError>();
                final Collection<ProcessError> errProcs = runOneActivity(app);
                if (errProcs != null) {
                    errSet.addAll(errProcs);
                }
                if (!errSet.isEmpty()) {
                    fail(String.format("Got %d errors:\n%s", errSet.size(), reportWrappedListContents(errSet)));
                }
            }
        };
        appTest.setName(app.activityInfo.name);
        suite.addTest(appTest);
    }
    final TestCase asyncErrorTest = new ProcessErrorsTest() {

        @Override
        public void runTest() throws Exception {
            testZZReportAsyncErrors();
        }
    };
    asyncErrorTest.setName("testAsynchronousErrors");
    suite.addTest(asyncErrorTest);
    return suite;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) TestSuite(junit.framework.TestSuite) PackageManager(android.content.pm.PackageManager) TestCase(junit.framework.TestCase) HashSet(java.util.HashSet)

Example 42 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class VectorDrawableTest method getData.

protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(CATEGORY_HWUI_TEST);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
    if (null == list)
        return myData;
    String[] prefixPath;
    String prefixWithSlash = prefix;
    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }
    int len = list.size();
    Map<String, Boolean> entries = new HashMap<String, Boolean>();
    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
            String[] labelPath = label.split("/");
            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel, activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }
    Collections.sort(myData, sDisplayNameComparator);
    return myData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class MainActivity method getData.

protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<>();
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(CATEGORY_HWUI_TEST);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
    if (null == list)
        return myData;
    String[] prefixPath;
    String prefixWithSlash = prefix;
    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }
    int len = list.size();
    Map<String, Boolean> entries = new HashMap<>();
    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
            String[] labelPath = label.split("/");
            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel, activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }
    Collections.sort(myData, sDisplayNameComparator);
    return myData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with PackageManager

use of android.content.pm.PackageManager in project platform_packages_apps_launcher by android.

the class Launcher method infoFromShortcutIntent.

private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Drawable icon = null;
    boolean filtered = false;
    boolean customIcon = false;
    ShortcutIconResource iconResource = null;
    if (bitmap != null) {
        icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
        filtered = true;
        customIcon = true;
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra != null && extra instanceof ShortcutIconResource) {
            try {
                iconResource = (ShortcutIconResource) extra;
                final PackageManager packageManager = context.getPackageManager();
                Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
                final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                icon = resources.getDrawable(id);
            } catch (Exception e) {
                w(LOG_TAG, "Could not load shortcut icon: " + extra);
            }
        }
    }
    if (icon == null) {
        icon = context.getPackageManager().getDefaultActivityIcon();
    }
    final ApplicationInfo info = new ApplicationInfo();
    info.icon = icon;
    info.filtered = filtered;
    info.title = name;
    info.intent = intent;
    info.customIcon = customIcon;
    info.iconResource = iconResource;
    return info;
}
Also used : Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) Parcelable(android.os.Parcelable) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) Resources(android.content.res.Resources)

Example 45 with PackageManager

use of android.content.pm.PackageManager in project platform_packages_apps_launcher by android.

the class LauncherModel method getApplicationInfoShortcut.

/**
     * Make an ApplicationInfo object for a sortcut
     */
private ApplicationInfo getApplicationInfoShortcut(Cursor c, Context context, int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex) {
    final ApplicationInfo info = new ApplicationInfo();
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
    int iconType = c.getInt(iconTypeIndex);
    switch(iconType) {
        case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
            String packageName = c.getString(iconPackageIndex);
            String resourceName = c.getString(iconResourceIndex);
            PackageManager packageManager = context.getPackageManager();
            try {
                Resources resources = packageManager.getResourcesForApplication(packageName);
                final int id = resources.getIdentifier(resourceName, null, null);
                info.icon = Utilities.createIconThumbnail(resources.getDrawable(id), context);
            } catch (Exception e) {
                info.icon = packageManager.getDefaultActivityIcon();
            }
            info.iconResource = new Intent.ShortcutIconResource();
            info.iconResource.packageName = packageName;
            info.iconResource.resourceName = resourceName;
            info.customIcon = false;
            break;
        case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
            byte[] data = c.getBlob(iconIndex);
            try {
                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                info.icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
            } catch (Exception e) {
                packageManager = context.getPackageManager();
                info.icon = packageManager.getDefaultActivityIcon();
            }
            info.filtered = true;
            info.customIcon = true;
            break;
        default:
            info.icon = context.getPackageManager().getDefaultActivityIcon();
            info.customIcon = false;
            break;
    }
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) Resources(android.content.res.Resources) URISyntaxException(java.net.URISyntaxException)

Aggregations

PackageManager (android.content.pm.PackageManager)1475 Intent (android.content.Intent)499 ResolveInfo (android.content.pm.ResolveInfo)456 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)351 PackageInfo (android.content.pm.PackageInfo)268 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)48