Search in sources :

Example 26 with ResolveInfo

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

the class InputMethodManagerService method buildInputMethodListLocked.

void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
    if (DEBUG) {
        Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme + " \n ------ \n" + getStackTrace());
    }
    list.clear();
    map.clear();
    // Use for queryIntentServicesAsUser
    final PackageManager pm = mContext.getPackageManager();
    String disabledSysImes = mSettings.getDisabledSystemInputMethods();
    if (disabledSysImes == null)
        disabledSysImes = "";
    final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(InputMethod.SERVICE_INTERFACE), PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId());
    final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = mFileManager.getAllAdditionalInputMethodSubtypes();
    for (int i = 0; i < services.size(); ++i) {
        ResolveInfo ri = services.get(i);
        ServiceInfo si = ri.serviceInfo;
        ComponentName compName = new ComponentName(si.packageName, si.name);
        if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
            Slog.w(TAG, "Skipping input method " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_INPUT_METHOD);
            continue;
        }
        if (DEBUG)
            Slog.d(TAG, "Checking " + compName);
        try {
            InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
            list.add(p);
            final String id = p.getId();
            map.put(id, p);
            if (DEBUG) {
                Slog.d(TAG, "Found an input method " + p);
            }
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Unable to load input method " + compName, e);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to load input method " + compName, e);
        }
    }
    if (resetDefaultEnabledIme) {
        final ArrayList<InputMethodInfo> defaultEnabledIme = InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
        for (int i = 0; i < defaultEnabledIme.size(); ++i) {
            final InputMethodInfo imi = defaultEnabledIme.get(i);
            if (DEBUG) {
                Slog.d(TAG, "--- enable ime = " + imi);
            }
            setInputMethodEnabledLocked(imi.getId(), true);
        }
    }
    final String defaultImiId = mSettings.getSelectedInputMethod();
    if (!TextUtils.isEmpty(defaultImiId)) {
        if (!map.containsKey(defaultImiId)) {
            Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
            if (chooseNewDefaultIMELocked()) {
                updateFromSettingsLocked(true);
            }
        } else {
            // Double check that the default IME is certainly enabled.
            setInputMethodEnabledLocked(defaultImiId, true);
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) ArrayList(java.util.ArrayList) List(java.util.List) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 27 with ResolveInfo

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

the class DevicePolicyManagerService method findAdmin.

public DeviceAdminInfo findAdmin(ComponentName adminName, int userHandle) {
    enforceCrossUserPermission(userHandle);
    Intent resolveIntent = new Intent();
    resolveIntent.setComponent(adminName);
    List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers(resolveIntent, PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userHandle);
    if (infos == null || infos.size() <= 0) {
        throw new IllegalArgumentException("Unknown admin: " + adminName);
    }
    try {
        return new DeviceAdminInfo(mContext, infos.get(0));
    } catch (XmlPullParserException e) {
        Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e);
        return null;
    } catch (IOException e) {
        Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e);
        return null;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) DeviceAdminInfo(android.app.admin.DeviceAdminInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 28 with ResolveInfo

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

the class LocationManagerService method ensureFallbackFusedProviderPresentLocked.

private void ensureFallbackFusedProviderPresentLocked(ArrayList<String> pkgs) {
    PackageManager pm = mContext.getPackageManager();
    String systemPackageName = mContext.getPackageName();
    ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs);
    List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser(new Intent(FUSED_LOCATION_SERVICE_ACTION), PackageManager.GET_META_DATA, mCurrentUserId);
    for (ResolveInfo rInfo : rInfos) {
        String packageName = rInfo.serviceInfo.packageName;
        // this list the standard provider binding logic won't bind to it.
        try {
            PackageInfo pInfo;
            pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) {
                Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION + ", but has wrong signature, ignoring");
                continue;
            }
        } catch (NameNotFoundException e) {
            Log.e(TAG, "missing package: " + packageName);
            continue;
        }
        // Get the version info
        if (rInfo.serviceInfo.metaData == null) {
            Log.w(TAG, "Found fused provider without metadata: " + packageName);
            continue;
        }
        int version = rInfo.serviceInfo.metaData.getInt(ServiceWatcher.EXTRA_SERVICE_VERSION, -1);
        if (version == 0) {
            // Make sure it's in the system partition.
            if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                if (D)
                    Log.d(TAG, "Fallback candidate not in /system: " + packageName);
                continue;
            }
            // as a proxy for coreApp="true"
            if (pm.checkSignatures(systemPackageName, packageName) != PackageManager.SIGNATURE_MATCH) {
                if (D)
                    Log.d(TAG, "Fallback candidate not signed the same as system: " + packageName);
                continue;
            }
            // Found a valid fallback.
            if (D)
                Log.d(TAG, "Found fallback provider: " + packageName);
            return;
        } else {
            if (D)
                Log.d(TAG, "Fallback candidate not version 0: " + packageName);
        }
    }
    throw new IllegalStateException("Unable to find a fused location provider that is in the " + "system partition with version 0 and signed with the platform certificate. " + "Such a package is needed to provide a default fused location provider in the " + "event that no other fused location provider has been installed or is currently " + "available. For example, coreOnly boot mode when decrypting the data " + "partition. The fallback must also be marked coreApp=\"true\" in the manifest");
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) HashSet(java.util.HashSet)

Example 29 with ResolveInfo

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

the class RecognitionManagerService method findAvailRecognizer.

ComponentName findAvailRecognizer(String prefPackage, int userHandle) {
    List<ResolveInfo> available = mContext.getPackageManager().queryIntentServicesAsUser(new Intent(RecognitionService.SERVICE_INTERFACE), 0, userHandle);
    int numAvailable = available.size();
    if (numAvailable == 0) {
        Slog.w(TAG, "no available voice recognition services found for user " + userHandle);
        return null;
    } else {
        if (prefPackage != null) {
            for (int i = 0; i < numAvailable; i++) {
                ServiceInfo serviceInfo = available.get(i).serviceInfo;
                if (prefPackage.equals(serviceInfo.packageName)) {
                    return new ComponentName(serviceInfo.packageName, serviceInfo.name);
                }
            }
        }
        if (numAvailable > 1) {
            Slog.w(TAG, "more than one voice recognition service found, picking first");
        }
        ServiceInfo serviceInfo = available.get(0).serviceInfo;
        return new ComponentName(serviceInfo.packageName, serviceInfo.name);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 30 with ResolveInfo

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

the class ServiceWatcher method bindBestPackageLocked.

/**
     * Searches and binds to the best package, or do nothing
     * if the best package is already bound.
     * Only checks the named package, or checks all packages if it
     * is null.
     * Return true if a new package was found to bind to.
     */
private boolean bindBestPackageLocked(String justCheckThisPackage) {
    Intent intent = new Intent(mAction);
    if (justCheckThisPackage != null) {
        intent.setPackage(justCheckThisPackage);
    }
    List<ResolveInfo> rInfos = mPm.queryIntentServicesAsUser(intent, PackageManager.GET_META_DATA, UserHandle.USER_OWNER);
    int bestVersion = Integer.MIN_VALUE;
    String bestPackage = null;
    boolean bestIsMultiuser = false;
    if (rInfos != null) {
        for (ResolveInfo rInfo : rInfos) {
            String packageName = rInfo.serviceInfo.packageName;
            // check signature
            try {
                PackageInfo pInfo;
                pInfo = mPm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
                if (!isSignatureMatch(pInfo.signatures)) {
                    Log.w(mTag, packageName + " resolves service " + mAction + ", but has wrong signature, ignoring");
                    continue;
                }
            } catch (NameNotFoundException e) {
                Log.wtf(mTag, e);
                continue;
            }
            // check metadata
            int version = Integer.MIN_VALUE;
            boolean isMultiuser = false;
            if (rInfo.serviceInfo.metaData != null) {
                version = rInfo.serviceInfo.metaData.getInt(EXTRA_SERVICE_VERSION, Integer.MIN_VALUE);
                isMultiuser = rInfo.serviceInfo.metaData.getBoolean(EXTRA_SERVICE_IS_MULTIUSER);
            }
            if (version > mVersion) {
                bestVersion = version;
                bestPackage = packageName;
                bestIsMultiuser = isMultiuser;
            }
        }
        if (D) {
            Log.d(mTag, String.format("bindBestPackage for %s : %s found %d, %s", mAction, (justCheckThisPackage == null ? "" : "(" + justCheckThisPackage + ") "), rInfos.size(), (bestPackage == null ? "no new best package" : "new best package: " + bestPackage)));
        }
    } else {
        if (D)
            Log.d(mTag, "Unable to query intent services for action: " + mAction);
    }
    if (bestPackage != null) {
        bindToPackageLocked(bestPackage, bestVersion, bestIsMultiuser);
        return true;
    }
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)2316 Intent (android.content.Intent)1476 PackageManager (android.content.pm.PackageManager)875 ComponentName (android.content.ComponentName)637 ArrayList (java.util.ArrayList)515 ActivityInfo (android.content.pm.ActivityInfo)360 Test (org.junit.Test)282 ServiceInfo (android.content.pm.ServiceInfo)203 PendingIntent (android.app.PendingIntent)183 ApplicationInfo (android.content.pm.ApplicationInfo)178 RemoteException (android.os.RemoteException)170 Context (android.content.Context)101 Bundle (android.os.Bundle)97 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)81 IOException (java.io.IOException)78 PackageInfo (android.content.pm.PackageInfo)68 HashSet (java.util.HashSet)65 HashMap (java.util.HashMap)63 ActivityNotFoundException (android.content.ActivityNotFoundException)59 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)58