Search in sources :

Example 41 with NameNotFoundException

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

the class BackupManagerService method clearApplicationDataSynchronous.

// clear an application's data, blocking until the operation completes or times out
void clearApplicationDataSynchronous(String packageName) {
    // Don't wipe packages marked allowClearUserData=false
    try {
        PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
        if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) == 0) {
            if (MORE_DEBUG)
                Slog.i(TAG, "allowClearUserData=false so not wiping " + packageName);
            return;
        }
    } catch (NameNotFoundException e) {
        Slog.w(TAG, "Tried to clear data for " + packageName + " but not found");
        return;
    }
    ClearDataObserver observer = new ClearDataObserver();
    synchronized (mClearDataLock) {
        mClearingData = true;
        try {
            mActivityManager.clearApplicationUserData(packageName, observer, 0);
        } catch (RemoteException e) {
        // can't happen because the activity manager is in this process
        }
        // only wait 10 seconds for the clear data to happen
        long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
        while (mClearingData && (System.currentTimeMillis() < timeoutMark)) {
            try {
                mClearDataLock.wait(5000);
            } catch (InterruptedException e) {
                // won't happen, but still.
                mClearingData = false;
            }
        }
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) RemoteException(android.os.RemoteException)

Example 42 with NameNotFoundException

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

the class PermissionDialog method getAppName.

private String getAppName(String packageName) {
    ApplicationInfo appInfo = null;
    PackageManager pm = mContext.getPackageManager();
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES);
    } catch (final NameNotFoundException e) {
        return null;
    }
    if (appInfo != null) {
        return (String) pm.getApplicationLabel(appInfo);
    }
    return null;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 43 with NameNotFoundException

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

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Example 44 with NameNotFoundException

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

the class ChooserActivity method filterServiceTargets.

void filterServiceTargets(String packageName, List<ChooserTarget> targets) {
    if (targets == null) {
        return;
    }
    final PackageManager pm = getPackageManager();
    for (int i = targets.size() - 1; i >= 0; i--) {
        final ChooserTarget target = targets.get(i);
        final ComponentName targetName = target.getComponentName();
        if (packageName != null && packageName.equals(targetName.getPackageName())) {
            // Anything from the original target's package is fine.
            continue;
        }
        boolean remove;
        try {
            final ActivityInfo ai = pm.getActivityInfo(targetName, 0);
            remove = !ai.exported || ai.permission != null;
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Target " + target + " returned by " + packageName + " component not found");
            remove = true;
        }
        if (remove) {
            targets.remove(i);
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName)

Example 45 with NameNotFoundException

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

the class OmniJawsClient method isAvailableApp.

private boolean isAvailableApp(String packageName) {
    final PackageManager pm = mContext.getPackageManager();
    try {
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        int enabled = pm.getApplicationEnabledSetting(packageName);
        return enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED && enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
    } catch (NameNotFoundException e) {
        return false;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

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)143 ComponentName (android.content.ComponentName)134 ActivityInfo (android.content.pm.ActivityInfo)125 Resources (android.content.res.Resources)112 Context (android.content.Context)105 Drawable (android.graphics.drawable.Drawable)93 Bundle (android.os.Bundle)93 IOException (java.io.IOException)91 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