Search in sources :

Example 86 with NameNotFoundException

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;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 87 with NameNotFoundException

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;
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps)

Example 88 with NameNotFoundException

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);
            }
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ParcelableString(com.android.internal.util.ParcelableString)

Example 89 with NameNotFoundException

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);
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Bundle(android.os.Bundle)

Example 90 with NameNotFoundException

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();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle)

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