Search in sources :

Example 1 with PackageItemInfo

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;
}
Also used : PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) PackageItemInfo(android.content.pm.PackageItemInfo) Drawable(android.graphics.drawable.Drawable)

Example 2 with PackageItemInfo

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());
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) PackageItemInfo(android.content.pm.PackageItemInfo) DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 3 with PackageItemInfo

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;
}
Also used : PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) PackageItemInfo(android.content.pm.PackageItemInfo) Drawable(android.graphics.drawable.Drawable)

Example 4 with PackageItemInfo

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());
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) PackageItemInfo(android.content.pm.PackageItemInfo) DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 5 with PackageItemInfo

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());
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) PackageItemInfo(android.content.pm.PackageItemInfo) DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Aggregations

PackageItemInfo (android.content.pm.PackageItemInfo)14 PackageManager (android.content.pm.PackageManager)14 ApplicationInfo (android.content.pm.ApplicationInfo)6 PackageInfo (android.content.pm.PackageInfo)6 Drawable (android.graphics.drawable.Drawable)6 DefaultAppInfo (com.android.settings.applications.defaultapps.DefaultAppInfo)6 RadioButtonPreference (com.android.settings.widget.RadioButtonPreference)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ComponentName (android.content.ComponentName)2