Search in sources :

Example 76 with PackageInfo

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

the class BackupUtilsTest method genPackage.

private PackageInfo genPackage(String... signatures) {
    final PackageInfo pi = new PackageInfo();
    pi.packageName = "package";
    pi.applicationInfo = new ApplicationInfo();
    pi.signatures = genSignatures(signatures);
    return pi;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 77 with PackageInfo

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

the class BackupUtilsTest method testSignaturesMatch.

public void testSignaturesMatch() {
    final ArrayList<byte[]> stored1 = BackupUtils.hashSignatureArray(Arrays.asList("abc".getBytes()));
    final ArrayList<byte[]> stored2 = BackupUtils.hashSignatureArray(Arrays.asList("abc".getBytes(), "def".getBytes()));
    PackageInfo pi;
    // False for null package.
    assertFalse(BackupUtils.signaturesMatch(stored1, null));
    // If it's a system app, signatures don't matter.
    pi = genPackage("xyz");
    pi.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
    assertTrue(BackupUtils.signaturesMatch(stored1, pi));
    // Non system apps.
    assertTrue(BackupUtils.signaturesMatch(stored1, genPackage("abc")));
    // Superset is okay.
    assertTrue(BackupUtils.signaturesMatch(stored1, genPackage("abc", "xyz")));
    assertTrue(BackupUtils.signaturesMatch(stored1, genPackage("xyz", "abc")));
    assertFalse(BackupUtils.signaturesMatch(stored1, genPackage("xyz")));
    assertFalse(BackupUtils.signaturesMatch(stored1, genPackage("xyz", "def")));
    assertTrue(BackupUtils.signaturesMatch(stored2, genPackage("def", "abc")));
    assertTrue(BackupUtils.signaturesMatch(stored2, genPackage("x", "def", "abc", "y")));
    // Subset is not okay.
    assertFalse(BackupUtils.signaturesMatch(stored2, genPackage("abc")));
    assertFalse(BackupUtils.signaturesMatch(stored2, genPackage("def")));
}
Also used : PackageInfo(android.content.pm.PackageInfo)

Example 78 with PackageInfo

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

the class AndroidPackageInfoFetcher method getStatements.

/**
     * Returns all statements that the specified package makes in its AndroidManifest.xml.
     *
     * @throws NameNotFoundException if the app is not installed on the device.
     */
public List<String> getStatements(String packageName) throws NameNotFoundException {
    PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
    ApplicationInfo appInfo = packageInfo.applicationInfo;
    if (appInfo.metaData == null) {
        return Collections.<String>emptyList();
    }
    int tokenResourceId = appInfo.metaData.getInt(ASSOCIATED_ASSETS_KEY);
    if (tokenResourceId == 0) {
        return Collections.<String>emptyList();
    }
    try {
        return Arrays.asList(mContext.getPackageManager().getResourcesForApplication(packageName).getStringArray(tokenResourceId));
    } catch (NotFoundException e) {
        return Collections.<String>emptyList();
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 79 with PackageInfo

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

the class KeyboardShortcuts method getIconForIntentCategory.

private Icon getIconForIntentCategory(String intentCategory, int userId) {
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(intentCategory);
    final PackageInfo packageInfo = getPackageInfoForIntent(intent, userId);
    if (packageInfo != null && packageInfo.applicationInfo.icon != 0) {
        return Icon.createWithResource(packageInfo.applicationInfo.packageName, packageInfo.applicationInfo.icon);
    }
    return null;
}
Also used : PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent)

Example 80 with PackageInfo

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

the class KeyboardShortcuts method getDefaultApplicationShortcuts.

private KeyboardShortcutGroup getDefaultApplicationShortcuts() {
    final int userId = mContext.getUserId();
    List<KeyboardShortcutInfo> keyboardShortcutInfoAppItems = new ArrayList<>();
    // Assist.
    final AssistUtils assistUtils = new AssistUtils(mContext);
    final ComponentName assistComponent = assistUtils.getAssistComponentForUser(userId);
    PackageInfo assistPackageInfo = null;
    try {
        assistPackageInfo = mPackageManager.getPackageInfo(assistComponent.getPackageName(), 0, userId);
    } catch (RemoteException e) {
        Log.e(TAG, "PackageManagerService is dead");
    }
    if (assistPackageInfo != null) {
        final Icon assistIcon = Icon.createWithResource(assistPackageInfo.applicationInfo.packageName, assistPackageInfo.applicationInfo.icon);
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_assist), assistIcon, KeyEvent.KEYCODE_UNKNOWN, KeyEvent.META_META_ON));
    }
    // Browser.
    final Icon browserIcon = getIconForIntentCategory(Intent.CATEGORY_APP_BROWSER, userId);
    if (browserIcon != null) {
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_browser), browserIcon, KeyEvent.KEYCODE_B, KeyEvent.META_META_ON));
    }
    // Contacts.
    final Icon contactsIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CONTACTS, userId);
    if (contactsIcon != null) {
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_contacts), contactsIcon, KeyEvent.KEYCODE_C, KeyEvent.META_META_ON));
    }
    // Email.
    final Icon emailIcon = getIconForIntentCategory(Intent.CATEGORY_APP_EMAIL, userId);
    if (emailIcon != null) {
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_email), emailIcon, KeyEvent.KEYCODE_E, KeyEvent.META_META_ON));
    }
    // Messaging.
    final Icon messagingIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MESSAGING, userId);
    if (messagingIcon != null) {
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_im), messagingIcon, KeyEvent.KEYCODE_T, KeyEvent.META_META_ON));
    }
    // Music.
    final Icon musicIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MUSIC, userId);
    if (musicIcon != null) {
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_music), musicIcon, KeyEvent.KEYCODE_P, KeyEvent.META_META_ON));
    }
    // Calendar.
    final Icon calendarIcon = getIconForIntentCategory(Intent.CATEGORY_APP_CALENDAR, userId);
    if (calendarIcon != null) {
        keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(mContext.getString(R.string.keyboard_shortcut_group_applications_calendar), calendarIcon, KeyEvent.KEYCODE_L, KeyEvent.META_META_ON));
    }
    final int itemsSize = keyboardShortcutInfoAppItems.size();
    if (itemsSize == 0) {
        return null;
    }
    // Sorts by label, case insensitive with nulls and/or empty labels last.
    Collections.sort(keyboardShortcutInfoAppItems, mApplicationItemsComparator);
    return new KeyboardShortcutGroup(mContext.getString(R.string.keyboard_shortcut_group_applications), keyboardShortcutInfoAppItems, true);
}
Also used : KeyboardShortcutGroup(android.view.KeyboardShortcutGroup) AssistUtils(com.android.internal.app.AssistUtils) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) KeyboardShortcutInfo(android.view.KeyboardShortcutInfo) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon) RemoteException(android.os.RemoteException)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1567 PackageManager (android.content.pm.PackageManager)703 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