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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations