Search in sources :

Example 1 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ParanoidAndroid.

the class LoadedApk method initializeJavaContextClassLoader.

/**
     * Setup value for Thread.getContextClassLoader(). If the
     * package will not run in in a VM with other packages, we set
     * the Java context ClassLoader to the
     * PackageInfo.getClassLoader value. However, if this VM can
     * contain multiple packages, we intead set the Java context
     * ClassLoader to a proxy that will warn about the use of Java
     * context ClassLoaders and then fall through to use the
     * system ClassLoader.
     *
     * <p> Note that this is similar to but not the same as the
     * android.content.Context.getClassLoader(). While both
     * context class loaders are typically set to the
     * PathClassLoader used to load the package archive in the
     * single application per VM case, a single Android process
     * may contain several Contexts executing on one thread with
     * their own logical ClassLoaders while the Java context
     * ClassLoader is a thread local. This is why in the case when
     * we have multiple packages per VM we do not set the Java
     * context ClassLoader to an arbitrary but instead warn the
     * user to set their own if we detect that they are using a
     * Java library that expects it to be set.
     */
private void initializeJavaContextClassLoader() {
    IPackageManager pm = ActivityThread.getPackageManager();
    android.content.pm.PackageInfo pi;
    try {
        pi = pm.getPackageInfo(mPackageName, 0, UserHandle.myUserId());
    } catch (RemoteException e) {
        throw new IllegalStateException("Unable to get package info for " + mPackageName + "; is system dying?", e);
    }
    if (pi == null) {
        throw new IllegalStateException("Unable to get package info for " + mPackageName + "; is package not installed?");
    }
    /*
         * Two possible indications that this package could be
         * sharing its virtual machine with other packages:
         *
         * 1.) the sharedUserId attribute is set in the manifest,
         *     indicating a request to share a VM with other
         *     packages with the same sharedUserId.
         *
         * 2.) the application element of the manifest has an
         *     attribute specifying a non-default process name,
         *     indicating the desire to run in another packages VM.
         */
    boolean sharedUserIdSet = (pi.sharedUserId != null);
    boolean processNameNotDefault = (pi.applicationInfo != null && !mPackageName.equals(pi.applicationInfo.processName));
    boolean sharable = (sharedUserIdSet || processNameNotDefault);
    ClassLoader contextClassLoader = (sharable) ? new WarningContextClassLoader() : mClassLoader;
    Thread.currentThread().setContextClassLoader(contextClassLoader);
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 2 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ParanoidAndroid.

the class GLImpl method allowIndirectBuffers.

private static boolean allowIndirectBuffers(String appName) {
    boolean result = false;
    int version = 0;
    IPackageManager pm = AppGlobals.getPackageManager();
    try {
        ApplicationInfo applicationInfo = pm.getApplicationInfo(appName, 0, UserHandle.myUserId());
        if (applicationInfo != null) {
            version = applicationInfo.targetSdkVersion;
        }
    } catch (android.os.RemoteException e) {
    // ignore
    }
    Log.e("OpenGLES", String.format("Application %s (SDK target %d) called a GL11 Pointer method with an indirect Buffer.", appName, version));
    if (version <= Build.VERSION_CODES.CUPCAKE) {
        result = true;
    }
    return result;
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 3 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ParanoidAndroid.

the class DevicePolicyManagerService method enableIfNecessary.

private void enableIfNecessary(String packageName, int userId) {
    try {
        IPackageManager ipm = AppGlobals.getPackageManager();
        ApplicationInfo ai = ipm.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
        if (ai.enabledSetting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
            ipm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP, userId, "DevicePolicyManager");
        }
    } catch (RemoteException e) {
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 4 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ParanoidAndroid.

the class DevicePolicyManagerService method handlePackagesChanged.

private void handlePackagesChanged(int userHandle) {
    boolean removed = false;
    if (DBG)
        Slog.d(TAG, "Handling package changes for user " + userHandle);
    DevicePolicyData policy = getUserData(userHandle);
    IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = policy.mAdminList.size() - 1; i >= 0; i--) {
        ActiveAdmin aa = policy.mAdminList.get(i);
        try {
            if (pm.getPackageInfo(aa.info.getPackageName(), 0, userHandle) == null || pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle) == null) {
                removed = true;
                policy.mAdminList.remove(i);
            }
        } catch (RemoteException re) {
        // Shouldn't happen
        }
    }
    if (removed) {
        validatePasswordOwnerLocked(policy);
        syncDeviceCapabilitiesLocked(policy);
        saveSettingsLocked(policy.mUserHandle);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Example 5 with IPackageManager

use of android.content.pm.IPackageManager in project android_frameworks_base by ParanoidAndroid.

the class ActivityManagerService method forceStopPackage.

public void forceStopPackage(final String packageName, int userId) {
    if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES) != PackageManager.PERMISSION_GRANTED) {
        String msg = "Permission Denial: forceStopPackage() from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
        Slog.w(TAG, msg);
        throw new SecurityException(msg);
    }
    userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, true, "forceStopPackage", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        synchronized (this) {
            int[] users = userId == UserHandle.USER_ALL ? getUsersLocked() : new int[] { userId };
            for (int user : users) {
                int pkgUid = -1;
                try {
                    pkgUid = pm.getPackageUid(packageName, user);
                } catch (RemoteException e) {
                }
                if (pkgUid == -1) {
                    Slog.w(TAG, "Invalid packageName: " + packageName);
                    continue;
                }
                try {
                    pm.setPackageStoppedState(packageName, true, user);
                } catch (RemoteException e) {
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Failed trying to unstop package " + packageName + ": " + e);
                }
                if (isUserRunningLocked(user, false)) {
                    forceStopPackageLocked(packageName, pkgUid);
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) RemoteException(android.os.RemoteException)

Aggregations

IPackageManager (android.content.pm.IPackageManager)192 RemoteException (android.os.RemoteException)182 ApplicationInfo (android.content.pm.ApplicationInfo)58 Point (android.graphics.Point)33 PackageInfo (android.content.pm.PackageInfo)32 ComponentName (android.content.ComponentName)29 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)20 PackageManager (android.content.pm.PackageManager)18 UserHandle (android.os.UserHandle)13 Context (android.content.Context)12 HashMap (java.util.HashMap)12 ProviderInfo (android.content.pm.ProviderInfo)10 PendingIntent (android.app.PendingIntent)9 HashSet (java.util.HashSet)9 UserManager (android.os.UserManager)8 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 ResolveInfo (android.content.pm.ResolveInfo)7 ActivityManager (android.app.ActivityManager)6 SpannableString (android.text.SpannableString)6