use of android.content.pm.PackageItemInfo in project weex-example by KalicyZhou.
the class LoadPackagesAsyncTask method doInBackground.
@Override
protected List<AppInfo> doInBackground(Object... objects) {
List<AppInfo> labelsPackages = new ArrayList<>();
PackageManager packageManager = activity.getPackageManager();
Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
for (PackageItemInfo appInfo : appInfos) {
String packageName = appInfo.packageName;
if (!isHidden(packageName)) {
CharSequence label = appInfo.loadLabel(packageManager);
Drawable icon = appInfo.loadIcon(packageManager);
if (label != null) {
labelsPackages.add(new AppInfo(packageName, label.toString(), icon));
}
}
}
Collections.sort(labelsPackages);
return labelsPackages;
}
use of android.content.pm.PackageItemInfo in project android_packages_apps_Settings by LineageOS.
the class WebViewAppPickerTest method testWebViewVersionAddedAfterLabel.
/**
* Ensure that the version name of a WebView package is displayed after its name in the
* preference title.
*/
@Test
public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, mockPackageItemInfo, "");
PackageInfo packageInfo = new PackageInfo();
packageInfo.versionName = "myVersionName";
PackageManager pm = mock(PackageManager.class);
when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
when(mPackageManager.getPackageManager()).thenReturn(pm);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
mPicker.bindPreference(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
mPicker.bindPreferenceExtra(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
verify(mockPreference, times(1)).setTitle(eq("myPackage myVersionName"));
verify(mockPreference, times(1)).setTitle(any());
}
use of android.content.pm.PackageItemInfo in project incubator-weex by apache.
the class LoadPackagesAsyncTask method doInBackground.
@Override
protected List<AppInfo> doInBackground(Object... objects) {
List<AppInfo> labelsPackages = new ArrayList<>();
PackageManager packageManager = activity.getPackageManager();
Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
for (PackageItemInfo appInfo : appInfos) {
String packageName = appInfo.packageName;
if (!isHidden(packageName)) {
CharSequence label = appInfo.loadLabel(packageManager);
Drawable icon = appInfo.loadIcon(packageManager);
if (label != null) {
labelsPackages.add(new AppInfo(packageName, label.toString(), icon));
}
}
}
Collections.sort(labelsPackages);
return labelsPackages;
}
use of android.content.pm.PackageItemInfo in project platform_packages_apps_Settings by BlissRoms.
the class WebViewAppPickerTest method testWebViewVersionAddedAfterLabel.
/**
* Ensure that the version name of a WebView package is displayed after its name in the
* preference title.
*/
@Test
public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, mockPackageItemInfo, "");
PackageInfo packageInfo = new PackageInfo();
packageInfo.versionName = "myVersionName";
PackageManager pm = mock(PackageManager.class);
when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
when(mPackageManager.getPackageManager()).thenReturn(pm);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
mPicker.bindPreference(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
mPicker.bindPreferenceExtra(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
verify(mockPreference, times(1)).setTitle(eq("myPackage myVersionName"));
verify(mockPreference, times(1)).setTitle(any());
}
use of android.content.pm.PackageItemInfo in project android_packages_apps_Settings by omnirom.
the class WebViewAppPickerTest method testWebViewVersionAddedAfterLabel.
/**
* Ensure that the version name of a WebView package is displayed after its name in the
* preference title.
*/
@Test
public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, mockPackageItemInfo, "");
PackageInfo packageInfo = new PackageInfo();
packageInfo.versionName = "myVersionName";
PackageManager pm = mock(PackageManager.class);
when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
when(mPackageManager.getPackageManager()).thenReturn(pm);
RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
mPicker.bindPreference(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
mPicker.bindPreferenceExtra(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
verify(mockPreference, times(1)).setTitle(eq("myPackage myVersionName"));
verify(mockPreference, times(1)).setTitle(any());
}
Aggregations