use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
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;
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project KISS by Neamar.
the class IconsHandler method getDefaultAppDrawable.
public Drawable getDefaultAppDrawable(ComponentName componentName, UserHandle userHandle) {
try {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
LauncherApps launcher = (LauncherApps) ctx.getSystemService(Context.LAUNCHER_APPS_SERVICE);
LauncherActivityInfo info = launcher.getActivityList(componentName.getPackageName(), userHandle.getRealHandle()).get(0);
return info.getBadgedIcon(0);
} else {
return pm.getActivityIcon(componentName);
}
} catch (NameNotFoundException | IndexOutOfBoundsException e) {
Log.e(TAG, "Unable to found component " + componentName.toString() + e);
return null;
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerService method notifyPendingSystemUpdate.
@Override
public void notifyPendingSystemUpdate(long updateReceivedTime) {
mContext.enforceCallingOrSelfPermission(permission.NOTIFY_PENDING_SYSTEM_UPDATE, "Only the system update service can broadcast update information");
if (UserHandle.getCallingUserId() != UserHandle.USER_SYSTEM) {
Slog.w(LOG_TAG, "Only the system update service in the system user " + "can broadcast update information.");
return;
}
Intent intent = new Intent(DeviceAdminReceiver.ACTION_NOTIFY_PENDING_SYSTEM_UPDATE);
intent.putExtra(DeviceAdminReceiver.EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, updateReceivedTime);
synchronized (this) {
final String deviceOwnerPackage = mOwners.hasDeviceOwner() ? mOwners.getDeviceOwnerComponent().getPackageName() : null;
if (deviceOwnerPackage == null) {
return;
}
final UserHandle deviceOwnerUser = new UserHandle(mOwners.getDeviceOwnerUserId());
ActivityInfo[] receivers = null;
try {
receivers = mContext.getPackageManager().getPackageInfo(deviceOwnerPackage, PackageManager.GET_RECEIVERS).receivers;
} catch (NameNotFoundException e) {
Log.e(LOG_TAG, "Cannot find device owner package", e);
}
if (receivers != null) {
long ident = mInjector.binderClearCallingIdentity();
try {
for (int i = 0; i < receivers.length; i++) {
if (permission.BIND_DEVICE_ADMIN.equals(receivers[i].permission)) {
intent.setComponent(new ComponentName(deviceOwnerPackage, receivers[i].name));
mContext.sendBroadcastAsUser(intent, deviceOwnerUser);
}
}
} finally {
mInjector.binderRestoreCallingIdentity(ident);
}
}
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
the class MemoryUsageTest method testMemory.
public void testMemory() {
MemoryUsageInstrumentation instrumentation = (MemoryUsageInstrumentation) getInstrumentation();
Bundle args = instrumentation.getBundle();
mAm = ActivityManagerNative.getDefault();
createMappings();
parseArgs(args);
Bundle results = new Bundle();
for (String app : mNameToResultKey.keySet()) {
if (!mPersistentProcesses.contains(app)) {
String processName;
try {
processName = startApp(app);
measureMemory(app, processName, results);
closeApp();
} catch (NameNotFoundException e) {
Log.i(TAG, "Application " + app + " not found");
}
} else {
measureMemory(app, app, results);
}
}
instrumentation.sendStatus(0, results);
}
use of android.content.pm.PackageManager.NameNotFoundException in project android_frameworks_base by DirtyUnicorns.
the class CallerInfoAsyncQuery method getCurrentProfileContentResolver.
/**
* @return {@link ContentResolver} for the "current" user.
*/
static ContentResolver getCurrentProfileContentResolver(Context context) {
if (DBG)
Rlog.d(LOG_TAG, "Trying to get current content resolver...");
final int currentUser = ActivityManager.getCurrentUser();
final int myUser = UserManager.get(context).getUserHandle();
if (DBG)
Rlog.d(LOG_TAG, "myUser=" + myUser + "currentUser=" + currentUser);
if (myUser != currentUser) {
final Context otherContext;
try {
otherContext = context.createPackageContextAsUser(context.getPackageName(), /* flags =*/
0, new UserHandle(currentUser));
return otherContext.getContentResolver();
} catch (NameNotFoundException e) {
Rlog.e(LOG_TAG, "Can't find self package", e);
// Fall back to the primary user.
}
}
return context.getContentResolver();
}
Aggregations