Search in sources :

Example 76 with NameNotFoundException

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

the class DevelopmentSettings method writeMockLocation.

private void writeMockLocation() {
    AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
    // Disable the app op of the previous mock location app if such.
    List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
    if (packageOps != null) {
        // Should be one but in case we are in a bad state due to use of command line tools.
        for (PackageOps packageOp : packageOps) {
            if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
                String oldMockLocationApp = packageOp.getPackageName();
                try {
                    ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
                    appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, oldMockLocationApp, AppOpsManager.MODE_ERRORED);
                } catch (NameNotFoundException e) {
                /* ignore */
                }
            }
        }
    }
    // Enable the app op of the new mock location app if such.
    if (!TextUtils.isEmpty(mMockLocationApp)) {
        try {
            ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
            appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, mMockLocationApp, AppOpsManager.MODE_ALLOWED);
        } catch (NameNotFoundException e) {
        /* ignore */
        }
    }
}
Also used : AppOpsManager(android.app.AppOpsManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) PackageOps(android.app.AppOpsManager.PackageOps)

Example 77 with NameNotFoundException

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

the class InstalledAppDetails method refreshUi.

@Override
protected boolean refreshUi() {
    retrieveAppEntry();
    if (mAppEntry == null) {
        // onCreate must have failed, make sure to exit
        return false;
    }
    if (mPackageInfo == null) {
        // onCreate must have failed, make sure to exit
        return false;
    }
    // Get list of "home" apps and trace through any meta-data references
    List<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
    mPm.getHomeActivities(homeActivities);
    mHomePackages.clear();
    for (int i = 0; i < homeActivities.size(); i++) {
        ResolveInfo ri = homeActivities.get(i);
        final String activityPkg = ri.activityInfo.packageName;
        mHomePackages.add(activityPkg);
        // Also make sure to include anything proxying for the home app
        final Bundle metadata = ri.activityInfo.metaData;
        if (metadata != null) {
            final String metaPkg = metadata.getString(ActivityManager.META_HOME_ALTERNATE);
            if (signaturesMatch(metaPkg, activityPkg)) {
                mHomePackages.add(metaPkg);
            }
        }
    }
    checkForceStop();
    setAppLabelAndIcon(mPackageInfo);
    initUninstallButtons();
    // Update the preference summaries.
    Activity context = getActivity();
    mStoragePreference.setSummary(AppStorageSettings.getSummary(mAppEntry, context));
    PermissionsSummaryHelper.getPermissionSummary(getContext(), mPackageName, mPermissionCallback);
    mLaunchPreference.setSummary(AppUtils.getLaunchByDefaultSummary(mAppEntry, mUsbManager, mPm, context));
    mNotificationPreference.setSummary(getNotificationSummary(mAppEntry, context, mBackend));
    if (mDataPreference != null) {
        mDataPreference.setSummary(getDataSummary());
    }
    updateBattery();
    if (!mInitialized) {
        // First time init: are we displaying an uninstalled app?
        mInitialized = true;
        mShowUninstalled = (mAppEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) == 0;
    } else {
        // to go away.
        try {
            ApplicationInfo ainfo = context.getPackageManager().getApplicationInfo(mAppEntry.info.packageName, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
            if (!mShowUninstalled) {
                // user means we should go away as well.
                return (ainfo.flags & ApplicationInfo.FLAG_INSTALLED) != 0;
            }
        } catch (NameNotFoundException e) {
            return false;
        }
    }
    return true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) SettingsActivity(com.android.settings.SettingsActivity) Activity(android.app.Activity)

Example 78 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android-app-common-tasks by multidots.

the class Common method getAppIcon.

// ----------------------------------------------
/**
     * use for getting application Icon.
     *
     * @param mContext
     * @return Icon as drawable from the application
     */
public static Drawable getAppIcon(Context mContext) {
    Drawable icon;
    final PackageManager pm = mContext.getPackageManager();
    String packageName = mContext.getPackageName();
    try {
        icon = pm.getApplicationIcon(packageName);
        return icon;
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }
    return null;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 79 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherTransitionable method getExternalPackageToolbarIcon.

private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
    try {
        PackageManager packageManager = getPackageManager();
        // Look for the toolbar icon specified in the activity meta-data
        Bundle metaData = packageManager.getActivityInfo(activityName, PackageManager.GET_META_DATA).metaData;
        if (metaData != null) {
            int iconResId = metaData.getInt(resourceName);
            if (iconResId != 0) {
                Resources res = packageManager.getResourcesForActivity(activityName);
                return res.getDrawable(iconResId);
            }
        }
    } catch (NameNotFoundException e) {
        // This can happen if the activity defines an invalid drawable
        Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + " not found", e);
    } catch (Resources.NotFoundException nfe) {
        // This can happen if the activity defines an invalid drawable
        Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), nfe);
    }
    return null;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle) Resources(android.content.res.Resources)

Example 80 with NameNotFoundException

use of android.content.pm.PackageManager.NameNotFoundException in project AndroidChromium by JackyAndroid.

the class ShareDialogAdapter method loadIconForResolveInfo.

private Drawable loadIconForResolveInfo(ResolveInfo info) {
    try {
        final int iconRes = info.getIconResource();
        if (iconRes != 0) {
            Resources res = mManager.getResourcesForApplication(info.activityInfo.packageName);
            Drawable icon = ApiCompatibilityUtils.getDrawable(res, iconRes);
            return icon;
        }
    } catch (NameNotFoundException | NotFoundException e) {
    // Could not find the icon. loadIcon call below will return the default app icon.
    }
    return info.loadIcon(mManager);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

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