Search in sources :

Example 91 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method getTargetSdk.

/**
     * Returns the target sdk version number that the given packageName was built for
     * in the given user.
     */
private int getTargetSdk(String packageName, int userId) {
    final ApplicationInfo ai;
    try {
        ai = mIPackageManager.getApplicationInfo(packageName, 0, userId);
        final int targetSdkVersion = ai == null ? 0 : ai.targetSdkVersion;
        return targetSdkVersion;
    } catch (RemoteException e) {
        // Shouldn't happen
        return 0;
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 92 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method getStorageEncryptionStatus.

/**
     * Get the current encryption status of the device.
     */
@Override
public int getStorageEncryptionStatus(@Nullable String callerPackage, int userHandle) {
    if (!mHasFeature) {
    // Ok to return current status.
    }
    enforceFullCrossUsersPermission(userHandle);
    // It's not critical here, but let's make sure the package name is correct, in case
    // we start using it for different purposes.
    ensureCallerPackage(callerPackage);
    final ApplicationInfo ai;
    try {
        ai = mIPackageManager.getApplicationInfo(callerPackage, 0, userHandle);
    } catch (RemoteException e) {
        throw new SecurityException(e);
    }
    boolean legacyApp = false;
    if (ai != null) {
        if (ai.targetSdkVersion <= Build.VERSION_CODES.M) {
            legacyApp = true;
        }
    }
    final int rawStatus = getEncryptionStatus();
    if ((rawStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER) && legacyApp) {
        return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
    }
    return rawStatus;
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Example 93 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method getApplicationLabel.

/**
     * Canonical name for a given package.
     */
private String getApplicationLabel(String packageName, int userHandle) {
    long token = mInjector.binderClearCallingIdentity();
    try {
        final Context userContext;
        try {
            UserHandle handle = new UserHandle(userHandle);
            userContext = mContext.createPackageContextAsUser(packageName, 0, handle);
        } catch (PackageManager.NameNotFoundException nnfe) {
            Log.w(LOG_TAG, packageName + " is not installed for user " + userHandle, nnfe);
            return null;
        }
        ApplicationInfo appInfo = userContext.getApplicationInfo();
        CharSequence result = null;
        if (appInfo != null) {
            PackageManager pm = userContext.getPackageManager();
            result = pm.getApplicationLabel(appInfo);
        }
        return result != null ? result.toString() : null;
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) UserHandle(android.os.UserHandle) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 94 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method getPermittedInputMethodsForCurrentUser.

@Override
public List getPermittedInputMethodsForCurrentUser() {
    UserInfo currentUser;
    try {
        currentUser = mInjector.getIActivityManager().getCurrentUser();
    } catch (RemoteException e) {
        Slog.e(LOG_TAG, "Failed to make remote calls to get current user", e);
        // Activity managed is dead, just allow all IMEs
        return null;
    }
    int userId = currentUser.id;
    synchronized (this) {
        List<String> result = null;
        // If we have multiple profiles we return the intersection of the
        // permitted lists. This can happen in cases where we have a device
        // and profile owner.
        int[] profileIds = mUserManager.getProfileIdsWithDisabled(userId);
        for (int profileId : profileIds) {
            // Just loop though all admins, only device or profiles
            // owners can have permitted lists set.
            DevicePolicyData policy = getUserDataUnchecked(profileId);
            final int N = policy.mAdminList.size();
            for (int j = 0; j < N; j++) {
                ActiveAdmin admin = policy.mAdminList.get(j);
                List<String> fromAdmin = admin.permittedInputMethods;
                if (fromAdmin != null) {
                    if (result == null) {
                        result = new ArrayList<String>(fromAdmin);
                    } else {
                        result.retainAll(fromAdmin);
                    }
                }
            }
        }
        // If we have a permitted list add all system input methods.
        if (result != null) {
            InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class);
            List<InputMethodInfo> imes = inputMethodManager.getInputMethodList();
            long id = mInjector.binderClearCallingIdentity();
            try {
                if (imes != null) {
                    for (InputMethodInfo ime : imes) {
                        ServiceInfo serviceInfo = ime.getServiceInfo();
                        ApplicationInfo applicationInfo = serviceInfo.applicationInfo;
                        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                            result.add(serviceInfo.packageName);
                        }
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(id);
            }
        }
        return result;
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) UserInfo(android.content.pm.UserInfo) InputMethodManager(android.view.inputmethod.InputMethodManager) ParcelableString(com.android.internal.util.ParcelableString) InputMethodInfo(android.view.inputmethod.InputMethodInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) RemoteException(android.os.RemoteException)

Example 95 with ApplicationInfo

use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.

the class MidiService method addPackageDeviceServer.

private void addPackageDeviceServer(ServiceInfo serviceInfo) {
    XmlResourceParser parser = null;
    try {
        parser = serviceInfo.loadXmlMetaData(mPackageManager, MidiDeviceService.SERVICE_INTERFACE);
        if (parser == null)
            return;
        // ignore virtual device servers that do not require the correct permission
        if (!android.Manifest.permission.BIND_MIDI_DEVICE_SERVICE.equals(serviceInfo.permission)) {
            Log.w(TAG, "Skipping MIDI device service " + serviceInfo.packageName + ": it does not require the permission " + android.Manifest.permission.BIND_MIDI_DEVICE_SERVICE);
            return;
        }
        Bundle properties = null;
        int numInputPorts = 0;
        int numOutputPorts = 0;
        boolean isPrivate = false;
        ArrayList<String> inputPortNames = new ArrayList<String>();
        ArrayList<String> outputPortNames = new ArrayList<String>();
        while (true) {
            int eventType = parser.next();
            if (eventType == XmlPullParser.END_DOCUMENT) {
                break;
            } else if (eventType == XmlPullParser.START_TAG) {
                String tagName = parser.getName();
                if ("device".equals(tagName)) {
                    if (properties != null) {
                        Log.w(TAG, "nested <device> elements in metadata for " + serviceInfo.packageName);
                        continue;
                    }
                    properties = new Bundle();
                    properties.putParcelable(MidiDeviceInfo.PROPERTY_SERVICE_INFO, serviceInfo);
                    numInputPorts = 0;
                    numOutputPorts = 0;
                    isPrivate = false;
                    int count = parser.getAttributeCount();
                    for (int i = 0; i < count; i++) {
                        String name = parser.getAttributeName(i);
                        String value = parser.getAttributeValue(i);
                        if ("private".equals(name)) {
                            isPrivate = "true".equals(value);
                        } else {
                            properties.putString(name, value);
                        }
                    }
                } else if ("input-port".equals(tagName)) {
                    if (properties == null) {
                        Log.w(TAG, "<input-port> outside of <device> in metadata for " + serviceInfo.packageName);
                        continue;
                    }
                    numInputPorts++;
                    String portName = null;
                    int count = parser.getAttributeCount();
                    for (int i = 0; i < count; i++) {
                        String name = parser.getAttributeName(i);
                        String value = parser.getAttributeValue(i);
                        if ("name".equals(name)) {
                            portName = value;
                            break;
                        }
                    }
                    inputPortNames.add(portName);
                } else if ("output-port".equals(tagName)) {
                    if (properties == null) {
                        Log.w(TAG, "<output-port> outside of <device> in metadata for " + serviceInfo.packageName);
                        continue;
                    }
                    numOutputPorts++;
                    String portName = null;
                    int count = parser.getAttributeCount();
                    for (int i = 0; i < count; i++) {
                        String name = parser.getAttributeName(i);
                        String value = parser.getAttributeValue(i);
                        if ("name".equals(name)) {
                            portName = value;
                            break;
                        }
                    }
                    outputPortNames.add(portName);
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                String tagName = parser.getName();
                if ("device".equals(tagName)) {
                    if (properties != null) {
                        if (numInputPorts == 0 && numOutputPorts == 0) {
                            Log.w(TAG, "<device> with no ports in metadata for " + serviceInfo.packageName);
                            continue;
                        }
                        int uid;
                        try {
                            ApplicationInfo appInfo = mPackageManager.getApplicationInfo(serviceInfo.packageName, 0);
                            uid = appInfo.uid;
                        } catch (PackageManager.NameNotFoundException e) {
                            Log.e(TAG, "could not fetch ApplicationInfo for " + serviceInfo.packageName);
                            continue;
                        }
                        synchronized (mDevicesByInfo) {
                            addDeviceLocked(MidiDeviceInfo.TYPE_VIRTUAL, numInputPorts, numOutputPorts, inputPortNames.toArray(EMPTY_STRING_ARRAY), outputPortNames.toArray(EMPTY_STRING_ARRAY), properties, null, serviceInfo, isPrivate, uid);
                        }
                        // setting properties to null signals that we are no longer
                        // processing a <device>
                        properties = null;
                        inputPortNames.clear();
                        outputPortNames.clear();
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to load component info " + serviceInfo.toString(), e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException)

Aggregations

ApplicationInfo (android.content.pm.ApplicationInfo)1914 PackageManager (android.content.pm.PackageManager)682 Test (org.junit.Test)366 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)363 ArrayList (java.util.ArrayList)258 Intent (android.content.Intent)231 RemoteException (android.os.RemoteException)229 PackageInfo (android.content.pm.PackageInfo)214 ResolveInfo (android.content.pm.ResolveInfo)177 IOException (java.io.IOException)122 ActivityInfo (android.content.pm.ActivityInfo)114 IPackageManager (android.content.pm.IPackageManager)109 UserHandle (android.os.UserHandle)108 Context (android.content.Context)103 Bundle (android.os.Bundle)103 File (java.io.File)100 Drawable (android.graphics.drawable.Drawable)91 UserInfo (android.content.pm.UserInfo)89 ComponentName (android.content.ComponentName)69 SmallTest (android.support.test.filters.SmallTest)66