Search in sources :

Example 71 with PackageManager

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");
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 72 with PackageManager

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();
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 73 with PackageManager

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);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) DeadObjectException(android.os.DeadObjectException)

Example 74 with PackageManager

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);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArraySet(android.util.ArraySet) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 75 with PackageManager

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));
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) Intent(android.content.Intent)

Aggregations

PackageManager (android.content.pm.PackageManager)1482 Intent (android.content.Intent)505 ResolveInfo (android.content.pm.ResolveInfo)460 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)353 PackageInfo (android.content.pm.PackageInfo)270 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)127 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)91 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)55 ServiceInfo (android.content.pm.ServiceInfo)48