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);
}
}
}
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;
}
}
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");
}
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);
}
}
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;
}
Aggregations