use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class RankingHelper method readXml.
public void readXml(XmlPullParser parser, boolean forRestore) throws XmlPullParserException, IOException {
final PackageManager pm = mContext.getPackageManager();
int type = parser.getEventType();
if (type != XmlPullParser.START_TAG)
return;
String tag = parser.getName();
if (!TAG_RANKING.equals(tag))
return;
mRecords.clear();
mRestoredWithoutUids.clear();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
tag = parser.getName();
if (type == XmlPullParser.END_TAG && TAG_RANKING.equals(tag)) {
return;
}
if (type == XmlPullParser.START_TAG) {
if (TAG_PACKAGE.equals(tag)) {
int uid = safeInt(parser, ATT_UID, Record.UNKNOWN_UID);
String name = parser.getAttributeValue(null, ATT_NAME);
if (!TextUtils.isEmpty(name)) {
if (forRestore) {
try {
//TODO: http://b/22388012
uid = pm.getPackageUidAsUser(name, UserHandle.USER_SYSTEM);
} catch (NameNotFoundException e) {
// noop
}
}
Record r = null;
if (uid == Record.UNKNOWN_UID) {
r = mRestoredWithoutUids.get(name);
if (r == null) {
r = new Record();
mRestoredWithoutUids.put(name, r);
}
} else {
r = getOrCreateRecord(name, uid);
}
r.importance = safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
r.priority = safeInt(parser, ATT_PRIORITY, DEFAULT_PRIORITY);
r.visibility = safeInt(parser, ATT_VISIBILITY, DEFAULT_VISIBILITY);
}
}
}
}
throw new IllegalStateException("Failed to reach END_DOCUMENT");
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class RankingHelper method onPackagesChanged.
public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
if (!removingPackage || pkgList == null || pkgList.length == 0 || mRestoredWithoutUids.isEmpty()) {
// nothing to do
return;
}
final PackageManager pm = mContext.getPackageManager();
boolean updated = false;
for (String pkg : pkgList) {
final Record r = mRestoredWithoutUids.get(pkg);
if (r != null) {
try {
//TODO: http://b/22388012
r.uid = pm.getPackageUidAsUser(r.pkg, UserHandle.USER_SYSTEM);
mRestoredWithoutUids.remove(pkg);
mRecords.put(recordKey(r.pkg, r.uid), r);
updated = true;
} catch (NameNotFoundException e) {
// noop
}
}
}
if (updated) {
updateConfig();
}
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class TrustManagerService method getSettingsComponentName.
private ComponentName getSettingsComponentName(PackageManager pm, ResolveInfo resolveInfo) {
if (resolveInfo == null || resolveInfo.serviceInfo == null || resolveInfo.serviceInfo.metaData == null)
return null;
String cn = null;
XmlResourceParser parser = null;
Exception caughtException = null;
try {
parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TrustAgentService.TRUST_AGENT_META_DATA);
if (parser == null) {
Slog.w(TAG, "Can't find " + TrustAgentService.TRUST_AGENT_META_DATA + " meta-data");
return null;
}
Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Drain preamble.
}
String nodeName = parser.getName();
if (!"trust-agent".equals(nodeName)) {
Slog.w(TAG, "Meta-data does not start with trust-agent tag");
return null;
}
TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
sa.recycle();
} catch (PackageManager.NameNotFoundException e) {
caughtException = e;
} catch (IOException e) {
caughtException = e;
} catch (XmlPullParserException e) {
caughtException = e;
} finally {
if (parser != null)
parser.close();
}
if (caughtException != null) {
Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
return null;
}
if (cn == null) {
return null;
}
if (cn.indexOf('/') < 0) {
cn = resolveInfo.serviceInfo.packageName + "/" + cn;
}
return ComponentName.unflattenFromString(cn);
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class TrustManagerService method maybeEnableFactoryTrustAgents.
private void maybeEnableFactoryTrustAgents(LockPatternUtils utils, int userId) {
if (0 != Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.TRUST_AGENTS_INITIALIZED, 0, userId)) {
return;
}
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> resolveInfos = resolveAllowedTrustAgents(pm, userId);
ArraySet<ComponentName> discoveredAgents = new ArraySet<>();
for (ResolveInfo resolveInfo : resolveInfos) {
ComponentName componentName = getComponentName(resolveInfo);
int applicationInfoFlags = resolveInfo.serviceInfo.applicationInfo.flags;
if ((applicationInfoFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
Log.i(TAG, "Leaving agent " + componentName + " disabled because package " + "is not a system package.");
continue;
}
discoveredAgents.add(componentName);
}
List<ComponentName> previouslyEnabledAgents = utils.getEnabledTrustAgents(userId);
if (previouslyEnabledAgents != null) {
discoveredAgents.addAll(previouslyEnabledAgents);
}
utils.setEnabledTrustAgents(discoveredAgents, userId);
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.TRUST_AGENTS_INITIALIZED, 1, userId);
}
use of android.content.pm.PackageManager in project platform_frameworks_base by android.
the class TvInputManagerService method buildTvContentRatingSystemListLocked.
private void buildTvContentRatingSystemListLocked(int userId) {
UserState userState = getOrCreateUserStateLocked(userId);
userState.contentRatingSystemList.clear();
final PackageManager pm = mContext.getPackageManager();
Intent intent = new Intent(TvInputManager.ACTION_QUERY_CONTENT_RATING_SYSTEMS);
for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA)) {
ActivityInfo receiver = resolveInfo.activityInfo;
Bundle metaData = receiver.metaData;
if (metaData == null) {
continue;
}
int xmlResId = metaData.getInt(TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS);
if (xmlResId == 0) {
Slog.w(TAG, "Missing meta-data '" + TvInputManager.META_DATA_CONTENT_RATING_SYSTEMS + "' on receiver " + receiver.packageName + "/" + receiver.name);
continue;
}
userState.contentRatingSystemList.add(TvContentRatingSystemInfo.createTvContentRatingSystemInfo(xmlResId, receiver.applicationInfo));
}
}
Aggregations