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