Search in sources :

Example 96 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.

the class NotificationRecord method idDebugString.

static String idDebugString(Context baseContext, String packageName, int id) {
    Context c;
    if (packageName != null) {
        try {
            c = baseContext.createPackageContext(packageName, 0);
        } catch (NameNotFoundException e) {
            c = baseContext;
        }
    } else {
        c = baseContext;
    }
    Resources r = c.getResources();
    try {
        return r.getResourceName(id);
    } catch (Resources.NotFoundException e) {
        return "<name unknown>";
    }
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources)

Example 97 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerTests method deleteFromRawResource.

public void deleteFromRawResource(int iFlags, int dFlags) throws Exception {
    InstallParams ip = sampleInstallFromRawResource(iFlags, false);
    boolean retainData = ((dFlags & PackageManager.DELETE_KEEP_DATA) != 0);
    GenericReceiver receiver = new DeleteReceiver(ip.pkg.packageName);
    try {
        assertTrue(invokeDeletePackage(ip.pkg.packageName, dFlags, receiver));
        ApplicationInfo info = null;
        Log.i(TAG, "okay4");
        try {
            info = getPm().getApplicationInfo(ip.pkg.packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (NameNotFoundException e) {
            info = null;
        }
        if (retainData) {
            assertNotNull(info);
            assertEquals(info.packageName, ip.pkg.packageName);
            File file = new File(info.dataDir);
            assertTrue(file.exists());
        } else {
            assertNull(info);
        }
    } catch (Exception e) {
        failStr(e);
    } finally {
        cleanUpInstall(ip);
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) File(java.io.File) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) ErrnoException(android.system.ErrnoException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) PackageParserException(android.content.pm.PackageParser.PackageParserException)

Example 98 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerTests method cleanUpInstall.

void cleanUpInstall(InstallParams ip) throws Exception {
    if (ip == null) {
        return;
    }
    Runtime.getRuntime().gc();
    final String packageName = ip.pkg.packageName;
    Log.i(TAG, "Deleting package : " + packageName);
    ApplicationInfo info = null;
    try {
        info = getPm().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (NameNotFoundException ignored) {
    }
    DeleteObserver observer = new DeleteObserver(packageName);
    getPm().deletePackage(packageName, observer, PackageManager.DELETE_ALL_USERS);
    observer.waitForCompletion(MAX_WAIT_TIME);
    try {
        if (info != null) {
            assertUninstalled(info);
        }
    } finally {
        File outFile = new File(ip.pkg.codePath);
        if (outFile != null && outFile.exists()) {
            outFile.delete();
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) File(java.io.File)

Example 99 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.

the class UidDetailProvider method buildUidDetail.

/**
     * Build {@link UidDetail} object, blocking until all {@link Drawable}
     * lookup is finished.
     */
private UidDetail buildUidDetail(int uid) {
    final Resources res = mContext.getResources();
    final PackageManager pm = mContext.getPackageManager();
    final UidDetail detail = new UidDetail();
    detail.label = pm.getNameForUid(uid);
    detail.icon = pm.getDefaultActivityIcon();
    // handle special case labels
    switch(uid) {
        case android.os.Process.SYSTEM_UID:
            detail.label = res.getString(R.string.process_kernel_label);
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
        case TrafficStats.UID_REMOVED:
            detail.label = res.getString(UserManager.supportsMultipleUsers() ? R.string.data_usage_uninstalled_apps_users : R.string.data_usage_uninstalled_apps);
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
        case TrafficStats.UID_TETHERING:
            final ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
            detail.label = res.getString(Utils.getTetheringLabel(cm));
            detail.icon = pm.getDefaultActivityIcon();
            return detail;
    }
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    // Handle keys that are actually user handles
    if (isKeyForUser(uid)) {
        final int userHandle = getUserIdForKey(uid);
        final UserInfo info = um.getUserInfo(userHandle);
        if (info != null) {
            detail.label = Utils.getUserLabel(mContext, info);
            detail.icon = Utils.getUserIcon(mContext, um, info);
            return detail;
        }
    }
    // otherwise fall back to using packagemanager labels
    final String[] packageNames = pm.getPackagesForUid(uid);
    final int length = packageNames != null ? packageNames.length : 0;
    try {
        final int userId = UserHandle.getUserId(uid);
        UserHandle userHandle = new UserHandle(userId);
        IPackageManager ipm = AppGlobals.getPackageManager();
        if (length == 1) {
            final ApplicationInfo info = ipm.getApplicationInfo(packageNames[0], 0, /* no flags */
            userId);
            if (info != null) {
                detail.label = info.loadLabel(pm).toString();
                detail.icon = um.getBadgedIconForUser(info.loadIcon(pm), new UserHandle(userId));
            }
        } else if (length > 1) {
            detail.detailLabels = new CharSequence[length];
            detail.detailContentDescriptions = new CharSequence[length];
            for (int i = 0; i < length; i++) {
                final String packageName = packageNames[i];
                final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0);
                final ApplicationInfo appInfo = ipm.getApplicationInfo(packageName, 0, /* no flags */
                userId);
                if (appInfo != null) {
                    detail.detailLabels[i] = appInfo.loadLabel(pm).toString();
                    detail.detailContentDescriptions[i] = um.getBadgedLabelForUser(detail.detailLabels[i], userHandle);
                    if (packageInfo.sharedUserLabel != 0) {
                        detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, packageInfo.applicationInfo).toString();
                        detail.icon = um.getBadgedIconForUser(appInfo.loadIcon(pm), userHandle);
                    }
                }
            }
        }
        detail.contentDescription = um.getBadgedLabelForUser(detail.label, userHandle);
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Error while building UI detail for uid " + uid, e);
    } catch (RemoteException e) {
        Log.w(TAG, "Error while building UI detail for uid " + uid, e);
    }
    if (TextUtils.isEmpty(detail.label)) {
        detail.label = Integer.toString(uid);
    }
    return detail;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ConnectivityManager(android.net.ConnectivityManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) Resources(android.content.res.Resources) RemoteException(android.os.RemoteException)

Example 100 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.

the class SearchableInfo method getActivityMetaData.

/**
     * Gets search information for the given activity.
     *
     * @param context Context to use for reading activity resources.
     * @param activityInfo Activity to get search information from.
     * @return Search information about the given activity, or {@code null} if
     *         the activity has no or invalid searchability meta-data.
     *
     * @hide For use by SearchManagerService.
     */
public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo, int userId) {
    Context userContext = null;
    try {
        userContext = context.createPackageContextAsUser("system", 0, new UserHandle(userId));
    } catch (NameNotFoundException nnfe) {
        Log.e(LOG_TAG, "Couldn't create package context for user " + userId);
        return null;
    }
    // for each component, try to find metadata
    XmlResourceParser xml = activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE);
    if (xml == null) {
        return null;
    }
    ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
    SearchableInfo searchable = getActivityMetaData(userContext, xml, cName);
    xml.close();
    if (DBG) {
        if (searchable != null) {
            Log.d(LOG_TAG, "Checked " + activityInfo.name + ",label=" + searchable.getLabelId() + ",icon=" + searchable.getIconId() + ",suggestAuthority=" + searchable.getSuggestAuthority() + ",target=" + searchable.getSearchActivity().getClassName() + ",global=" + searchable.shouldIncludeInGlobalSearch() + ",settingsDescription=" + searchable.getSettingsDescriptionId() + ",threshold=" + searchable.getSuggestThreshold());
        } else {
            Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
        }
    }
    return searchable;
}
Also used : Context(android.content.Context) XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName)

Aggregations

NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1012 PackageManager (android.content.pm.PackageManager)358 PackageInfo (android.content.pm.PackageInfo)291 ApplicationInfo (android.content.pm.ApplicationInfo)235 Intent (android.content.Intent)141 ComponentName (android.content.ComponentName)133 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)103 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)90 UserHandle (android.os.UserHandle)79 ResolveInfo (android.content.pm.ResolveInfo)72 ArrayList (java.util.ArrayList)68 RemoteException (android.os.RemoteException)63 File (java.io.File)57 TextView (android.widget.TextView)52 View (android.view.View)47 FileNotFoundException (java.io.FileNotFoundException)44