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 */
}
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations