use of android.content.pm.PackageManager.NameNotFoundException in project UltimateAndroid by cymcsg.
the class CrashHandler method collectDeviceInfo.
/**
* Collect Device info
*
* @param ctx
*/
public void collectDeviceInfo(Context ctx) {
try {
PackageManager pm = ctx.getPackageManager();
PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);
if (pi != null) {
String versionName = pi.versionName == null ? "null" : pi.versionName;
String versionCode = pi.versionCode + "";
infos.put("versionName", versionName);
infos.put("versionCode", versionCode);
}
} catch (NameNotFoundException e) {
Logs.e("an error occured when collect package info", e);
}
Field[] fields = Build.class.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
infos.put(field.getName(), field.get(null).toString());
Logs.d(field.getName() + " : " + field.get(null));
} catch (Exception e) {
Logs.e("an error occured when collect crash info", e);
}
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
the class RegisteredServicesCache method updateServices.
public void updateServices(int userId) {
if (DEBUG) {
Slog.d(TAG, "updateServices u" + userId);
}
List<ServiceInfo<V>> allServices;
synchronized (mServicesLock) {
final UserServices<V> user = findOrCreateUserLocked(userId);
// If services haven't been initialized yet - no updates required
if (user.services == null) {
return;
}
allServices = new ArrayList<>(user.services.values());
}
IntArray updatedUids = null;
for (ServiceInfo<V> service : allServices) {
int versionCode = service.componentInfo.applicationInfo.versionCode;
String pkg = service.componentInfo.packageName;
ApplicationInfo newAppInfo = null;
try {
newAppInfo = mContext.getPackageManager().getApplicationInfoAsUser(pkg, 0, userId);
} catch (NameNotFoundException e) {
// Package uninstalled - treat as null app info
}
// If package updated or removed
if ((newAppInfo == null) || (newAppInfo.versionCode != versionCode)) {
if (DEBUG) {
Slog.d(TAG, "Package " + pkg + " uid=" + service.uid + " updated. New appInfo: " + newAppInfo);
}
if (updatedUids == null) {
updatedUids = new IntArray();
}
updatedUids.add(service.uid);
}
}
if (updatedUids != null && updatedUids.size() > 0) {
int[] updatedUidsArray = updatedUids.toArray();
generateServicesMap(updatedUidsArray, userId);
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
the class LauncherActivityInfo method getIcon.
/**
* Returns the icon for this activity, without any badging for the profile.
* @param density The preferred density of the icon, zero for default density. Use
* density DPI values from {@link DisplayMetrics}.
* @see #getBadgedIcon(int)
* @see DisplayMetrics
* @return The drawable associated with the activity.
*/
public Drawable getIcon(int density) {
final int iconRes = mActivityInfo.getIconResource();
Drawable icon = null;
// Get the preferred density icon from the app's resources
if (density != 0 && iconRes != 0) {
try {
final Resources resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo);
icon = resources.getDrawableForDensity(iconRes, density);
} catch (NameNotFoundException | Resources.NotFoundException exc) {
}
}
// Get the default density icon
if (icon == null) {
icon = mActivityInfo.loadIcon(mPm);
}
return icon;
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
the class ChooserActivity method queryTargetServices.
void queryTargetServices(ChooserListAdapter adapter) {
final PackageManager pm = getPackageManager();
int targetsToQuery = 0;
for (int i = 0, N = adapter.getDisplayResolveInfoCount(); i < N; i++) {
final DisplayResolveInfo dri = adapter.getDisplayResolveInfo(i);
if (adapter.getScore(dri) == 0) {
// don't query it as it's not likely to be relevant.
continue;
}
final ActivityInfo ai = dri.getResolveInfo().activityInfo;
final Bundle md = ai.metaData;
final String serviceName = md != null ? convertServiceName(ai.packageName, md.getString(ChooserTargetService.META_DATA_NAME)) : null;
if (serviceName != null) {
final ComponentName serviceComponent = new ComponentName(ai.packageName, serviceName);
final Intent serviceIntent = new Intent(ChooserTargetService.SERVICE_INTERFACE).setComponent(serviceComponent);
if (DEBUG) {
Log.d(TAG, "queryTargets found target with service " + serviceComponent);
}
try {
final String perm = pm.getServiceInfo(serviceComponent, 0).permission;
if (!ChooserTargetService.BIND_PERMISSION.equals(perm)) {
Log.w(TAG, "ChooserTargetService " + serviceComponent + " does not require" + " permission " + ChooserTargetService.BIND_PERMISSION + " - this service will not be queried for ChooserTargets." + " add android:permission=\"" + ChooserTargetService.BIND_PERMISSION + "\"" + " to the <service> tag for " + serviceComponent + " in the manifest.");
continue;
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Could not look up service " + serviceComponent + "; component name not found");
continue;
}
final ChooserTargetServiceConnection conn = new ChooserTargetServiceConnection(this, dri);
// user handle
if (bindServiceAsUser(serviceIntent, conn, BIND_AUTO_CREATE | BIND_NOT_FOREGROUND, Process.myUserHandle())) {
if (DEBUG) {
Log.d(TAG, "Binding service connection for target " + dri + " intent " + serviceIntent);
}
mServiceConnections.add(conn);
targetsToQuery++;
}
}
if (targetsToQuery >= QUERY_TARGET_SERVICE_LIMIT) {
if (DEBUG)
Log.d(TAG, "queryTargets hit query target limit " + QUERY_TARGET_SERVICE_LIMIT);
break;
}
}
if (!mServiceConnections.isEmpty()) {
if (DEBUG)
Log.d(TAG, "queryTargets setting watchdog timer for " + WATCHDOG_TIMEOUT_MILLIS + "ms");
mChooserHandler.sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_TIMEOUT, WATCHDOG_TIMEOUT_MILLIS);
} else {
sendVoiceChoicesIfNeeded();
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
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);
}
}
}
Aggregations