Search in sources :

Example 21 with PatternMatcher

use of android.os.PatternMatcher in project platform_frameworks_base by android.

the class IntentFilter method writeToXml.

/**
     * Write the contents of the IntentFilter as an XML stream.
     */
public void writeToXml(XmlSerializer serializer) throws IOException {
    if (getAutoVerify()) {
        serializer.attribute(null, AUTO_VERIFY_STR, Boolean.toString(true));
    }
    int N = countActions();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, ACTION_STR);
        serializer.attribute(null, NAME_STR, mActions.get(i));
        serializer.endTag(null, ACTION_STR);
    }
    N = countCategories();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, CAT_STR);
        serializer.attribute(null, NAME_STR, mCategories.get(i));
        serializer.endTag(null, CAT_STR);
    }
    N = countDataTypes();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, TYPE_STR);
        String type = mDataTypes.get(i);
        if (type.indexOf('/') < 0)
            type = type + "/*";
        serializer.attribute(null, NAME_STR, type);
        serializer.endTag(null, TYPE_STR);
    }
    N = countDataSchemes();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, SCHEME_STR);
        serializer.attribute(null, NAME_STR, mDataSchemes.get(i));
        serializer.endTag(null, SCHEME_STR);
    }
    N = countDataSchemeSpecificParts();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, SSP_STR);
        PatternMatcher pe = mDataSchemeSpecificParts.get(i);
        switch(pe.getType()) {
            case PatternMatcher.PATTERN_LITERAL:
                serializer.attribute(null, LITERAL_STR, pe.getPath());
                break;
            case PatternMatcher.PATTERN_PREFIX:
                serializer.attribute(null, PREFIX_STR, pe.getPath());
                break;
            case PatternMatcher.PATTERN_SIMPLE_GLOB:
                serializer.attribute(null, SGLOB_STR, pe.getPath());
                break;
        }
        serializer.endTag(null, SSP_STR);
    }
    N = countDataAuthorities();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, AUTH_STR);
        AuthorityEntry ae = mDataAuthorities.get(i);
        serializer.attribute(null, HOST_STR, ae.getHost());
        if (ae.getPort() >= 0) {
            serializer.attribute(null, PORT_STR, Integer.toString(ae.getPort()));
        }
        serializer.endTag(null, AUTH_STR);
    }
    N = countDataPaths();
    for (int i = 0; i < N; i++) {
        serializer.startTag(null, PATH_STR);
        PatternMatcher pe = mDataPaths.get(i);
        switch(pe.getType()) {
            case PatternMatcher.PATTERN_LITERAL:
                serializer.attribute(null, LITERAL_STR, pe.getPath());
                break;
            case PatternMatcher.PATTERN_PREFIX:
                serializer.attribute(null, PREFIX_STR, pe.getPath());
                break;
            case PatternMatcher.PATTERN_SIMPLE_GLOB:
                serializer.attribute(null, SGLOB_STR, pe.getPath());
                break;
        }
        serializer.endTag(null, PATH_STR);
    }
}
Also used : PatternMatcher(android.os.PatternMatcher)

Example 22 with PatternMatcher

use of android.os.PatternMatcher in project platform_frameworks_base by android.

the class PackageParser method parseProviderTags.

private boolean parseProviderTags(Resources res, XmlResourceParser parser, Provider outInfo, String[] outError) throws XmlPullParserException, IOException {
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        if (parser.getName().equals("intent-filter")) {
            ProviderIntentInfo intent = new ProviderIntentInfo(outInfo);
            if (!parseIntent(res, parser, true, false, intent, outError)) {
                return false;
            }
            outInfo.intents.add(intent);
        } else if (parser.getName().equals("meta-data")) {
            if ((outInfo.metaData = parseMetaData(res, parser, outInfo.metaData, outError)) == null) {
                return false;
            }
        } else if (parser.getName().equals("grant-uri-permission")) {
            TypedArray sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestGrantUriPermission);
            PatternMatcher pa = null;
            String str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestGrantUriPermission_path, 0);
            if (str != null) {
                pa = new PatternMatcher(str, PatternMatcher.PATTERN_LITERAL);
            }
            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPrefix, 0);
            if (str != null) {
                pa = new PatternMatcher(str, PatternMatcher.PATTERN_PREFIX);
            }
            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestGrantUriPermission_pathPattern, 0);
            if (str != null) {
                pa = new PatternMatcher(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }
            sa.recycle();
            if (pa != null) {
                if (outInfo.info.uriPermissionPatterns == null) {
                    outInfo.info.uriPermissionPatterns = new PatternMatcher[1];
                    outInfo.info.uriPermissionPatterns[0] = pa;
                } else {
                    final int N = outInfo.info.uriPermissionPatterns.length;
                    PatternMatcher[] newp = new PatternMatcher[N + 1];
                    System.arraycopy(outInfo.info.uriPermissionPatterns, 0, newp, 0, N);
                    newp[N] = pa;
                    outInfo.info.uriPermissionPatterns = newp;
                }
                outInfo.info.grantUriPermissions = true;
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG, "Unknown element under <path-permission>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                } else {
                    outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
                    return false;
                }
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (parser.getName().equals("path-permission")) {
            TypedArray sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestPathPermission);
            PathPermission pa = null;
            String permission = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestPathPermission_permission, 0);
            String readPermission = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestPathPermission_readPermission, 0);
            if (readPermission == null) {
                readPermission = permission;
            }
            String writePermission = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestPathPermission_writePermission, 0);
            if (writePermission == null) {
                writePermission = permission;
            }
            boolean havePerm = false;
            if (readPermission != null) {
                readPermission = readPermission.intern();
                havePerm = true;
            }
            if (writePermission != null) {
                writePermission = writePermission.intern();
                havePerm = true;
            }
            if (!havePerm) {
                if (!RIGID_PARSER) {
                    Slog.w(TAG, "No readPermission or writePermssion for <path-permission>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                } else {
                    outError[0] = "No readPermission or writePermssion for <path-permission>";
                    return false;
                }
            }
            String path = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestPathPermission_path, 0);
            if (path != null) {
                pa = new PathPermission(path, PatternMatcher.PATTERN_LITERAL, readPermission, writePermission);
            }
            path = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestPathPermission_pathPrefix, 0);
            if (path != null) {
                pa = new PathPermission(path, PatternMatcher.PATTERN_PREFIX, readPermission, writePermission);
            }
            path = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestPathPermission_pathPattern, 0);
            if (path != null) {
                pa = new PathPermission(path, PatternMatcher.PATTERN_SIMPLE_GLOB, readPermission, writePermission);
            }
            sa.recycle();
            if (pa != null) {
                if (outInfo.info.pathPermissions == null) {
                    outInfo.info.pathPermissions = new PathPermission[1];
                    outInfo.info.pathPermissions[0] = pa;
                } else {
                    final int N = outInfo.info.pathPermissions.length;
                    PathPermission[] newp = new PathPermission[N + 1];
                    System.arraycopy(outInfo.info.pathPermissions, 0, newp, 0, N);
                    newp[N] = pa;
                    outInfo.info.pathPermissions = newp;
                }
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG, "No path, pathPrefix, or pathPattern for <path-permission>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                }
                outError[0] = "No path, pathPrefix, or pathPattern for <path-permission>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);
        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Unknown element under <provider>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                outError[0] = "Bad element under <provider>: " + parser.getName();
                return false;
            }
        }
    }
    return true;
}
Also used : TypedArray(android.content.res.TypedArray) PatternMatcher(android.os.PatternMatcher)

Example 23 with PatternMatcher

use of android.os.PatternMatcher in project platform_frameworks_base by android.

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, IntentFilter tmpPa, ComponentName cn, int userId) {
    // preferred activity entry.
    if (PackageManagerService.DEBUG_PREFERRED) {
        Log.d(TAG, "Processing preferred:");
        tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), "  ");
    }
    Intent intent = new Intent();
    int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
    intent.setAction(tmpPa.getAction(0));
    for (int i = 0; i < tmpPa.countCategories(); i++) {
        String cat = tmpPa.getCategory(i);
        if (cat.equals(Intent.CATEGORY_DEFAULT)) {
            flags |= MATCH_DEFAULT_ONLY;
        } else {
            intent.addCategory(cat);
        }
    }
    boolean doNonData = true;
    boolean hasSchemes = false;
    for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
        boolean doScheme = true;
        String scheme = tmpPa.getDataScheme(ischeme);
        if (scheme != null && !scheme.isEmpty()) {
            hasSchemes = true;
        }
        for (int issp = 0; issp < tmpPa.countDataSchemeSpecificParts(); issp++) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp);
            builder.opaquePart(ssp.getPath());
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, ssp, null, null, userId);
            doScheme = false;
        }
        for (int iauth = 0; iauth < tmpPa.countDataAuthorities(); iauth++) {
            boolean doAuth = true;
            IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth);
            for (int ipath = 0; ipath < tmpPa.countDataPaths(); ipath++) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                PatternMatcher path = tmpPa.getDataPath(ipath);
                builder.path(path.getPath());
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, path, userId);
                doAuth = doScheme = false;
            }
            if (doAuth) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, null, userId);
                doScheme = false;
            }
        }
        if (doScheme) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
        }
        doNonData = false;
    }
    for (int idata = 0; idata < tmpPa.countDataTypes(); idata++) {
        String mimeType = tmpPa.getDataType(idata);
        if (hasSchemes) {
            Uri.Builder builder = new Uri.Builder();
            for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
                String scheme = tmpPa.getDataScheme(ischeme);
                if (scheme != null && !scheme.isEmpty()) {
                    Intent finalIntent = new Intent(intent);
                    builder.scheme(scheme);
                    finalIntent.setDataAndType(builder.build(), mimeType);
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
                }
            }
        } else {
            Intent finalIntent = new Intent(intent);
            finalIntent.setType(mimeType);
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, null, null, null, null, userId);
        }
        doNonData = false;
    }
    if (doNonData) {
        applyDefaultPreferredActivityLPw(service, intent, flags, cn, null, null, null, null, userId);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Uri(android.net.Uri) PatternMatcher(android.os.PatternMatcher) LogPrinter(android.util.LogPrinter)

Example 24 with PatternMatcher

use of android.os.PatternMatcher in project android_frameworks_base by DirtyUnicorns.

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, IntentFilter tmpPa, ComponentName cn, int userId) {
    // preferred activity entry.
    if (PackageManagerService.DEBUG_PREFERRED) {
        Log.d(TAG, "Processing preferred:");
        tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), "  ");
    }
    Intent intent = new Intent();
    int flags = PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
    intent.setAction(tmpPa.getAction(0));
    for (int i = 0; i < tmpPa.countCategories(); i++) {
        String cat = tmpPa.getCategory(i);
        if (cat.equals(Intent.CATEGORY_DEFAULT)) {
            flags |= MATCH_DEFAULT_ONLY;
        } else {
            intent.addCategory(cat);
        }
    }
    boolean doNonData = true;
    boolean hasSchemes = false;
    for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
        boolean doScheme = true;
        String scheme = tmpPa.getDataScheme(ischeme);
        if (scheme != null && !scheme.isEmpty()) {
            hasSchemes = true;
        }
        for (int issp = 0; issp < tmpPa.countDataSchemeSpecificParts(); issp++) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp);
            builder.opaquePart(ssp.getPath());
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, ssp, null, null, userId);
            doScheme = false;
        }
        for (int iauth = 0; iauth < tmpPa.countDataAuthorities(); iauth++) {
            boolean doAuth = true;
            IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth);
            for (int ipath = 0; ipath < tmpPa.countDataPaths(); ipath++) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                PatternMatcher path = tmpPa.getDataPath(ipath);
                builder.path(path.getPath());
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, path, userId);
                doAuth = doScheme = false;
            }
            if (doAuth) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme(scheme);
                if (auth.getHost() != null) {
                    builder.authority(auth.getHost());
                }
                Intent finalIntent = new Intent(intent);
                finalIntent.setData(builder.build());
                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, auth, null, userId);
                doScheme = false;
            }
        }
        if (doScheme) {
            Uri.Builder builder = new Uri.Builder();
            builder.scheme(scheme);
            Intent finalIntent = new Intent(intent);
            finalIntent.setData(builder.build());
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
        }
        doNonData = false;
    }
    for (int idata = 0; idata < tmpPa.countDataTypes(); idata++) {
        String mimeType = tmpPa.getDataType(idata);
        if (hasSchemes) {
            Uri.Builder builder = new Uri.Builder();
            for (int ischeme = 0; ischeme < tmpPa.countDataSchemes(); ischeme++) {
                String scheme = tmpPa.getDataScheme(ischeme);
                if (scheme != null && !scheme.isEmpty()) {
                    Intent finalIntent = new Intent(intent);
                    builder.scheme(scheme);
                    finalIntent.setDataAndType(builder.build(), mimeType);
                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, scheme, null, null, null, userId);
                }
            }
        } else {
            Intent finalIntent = new Intent(intent);
            finalIntent.setType(mimeType);
            applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn, null, null, null, null, userId);
        }
        doNonData = false;
    }
    if (doNonData) {
        applyDefaultPreferredActivityLPw(service, intent, flags, cn, null, null, null, null, userId);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Uri(android.net.Uri) PatternMatcher(android.os.PatternMatcher) LogPrinter(android.util.LogPrinter)

Example 25 with PatternMatcher

use of android.os.PatternMatcher in project android_frameworks_base by DirtyUnicorns.

the class IntentFilter method dump.

public void dump(Printer du, String prefix) {
    StringBuilder sb = new StringBuilder(256);
    if (mActions.size() > 0) {
        Iterator<String> it = mActions.iterator();
        while (it.hasNext()) {
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Action: \"");
            sb.append(it.next());
            sb.append("\"");
            du.println(sb.toString());
        }
    }
    if (mCategories != null) {
        Iterator<String> it = mCategories.iterator();
        while (it.hasNext()) {
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Category: \"");
            sb.append(it.next());
            sb.append("\"");
            du.println(sb.toString());
        }
    }
    if (mDataSchemes != null) {
        Iterator<String> it = mDataSchemes.iterator();
        while (it.hasNext()) {
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Scheme: \"");
            sb.append(it.next());
            sb.append("\"");
            du.println(sb.toString());
        }
    }
    if (mDataSchemeSpecificParts != null) {
        Iterator<PatternMatcher> it = mDataSchemeSpecificParts.iterator();
        while (it.hasNext()) {
            PatternMatcher pe = it.next();
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Ssp: \"");
            sb.append(pe);
            sb.append("\"");
            du.println(sb.toString());
        }
    }
    if (mDataAuthorities != null) {
        Iterator<AuthorityEntry> it = mDataAuthorities.iterator();
        while (it.hasNext()) {
            AuthorityEntry ae = it.next();
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Authority: \"");
            sb.append(ae.mHost);
            sb.append("\": ");
            sb.append(ae.mPort);
            if (ae.mWild)
                sb.append(" WILD");
            du.println(sb.toString());
        }
    }
    if (mDataPaths != null) {
        Iterator<PatternMatcher> it = mDataPaths.iterator();
        while (it.hasNext()) {
            PatternMatcher pe = it.next();
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Path: \"");
            sb.append(pe);
            sb.append("\"");
            du.println(sb.toString());
        }
    }
    if (mDataTypes != null) {
        Iterator<String> it = mDataTypes.iterator();
        while (it.hasNext()) {
            sb.setLength(0);
            sb.append(prefix);
            sb.append("Type: \"");
            sb.append(it.next());
            sb.append("\"");
            du.println(sb.toString());
        }
    }
    if (mPriority != 0 || mHasPartialTypes) {
        sb.setLength(0);
        sb.append(prefix);
        sb.append("mPriority=");
        sb.append(mPriority);
        sb.append(", mHasPartialTypes=");
        sb.append(mHasPartialTypes);
        du.println(sb.toString());
    }
    {
        sb.setLength(0);
        sb.append(prefix);
        sb.append("AutoVerify=");
        sb.append(getAutoVerify());
        du.println(sb.toString());
    }
}
Also used : PatternMatcher(android.os.PatternMatcher)

Aggregations

PatternMatcher (android.os.PatternMatcher)35 IntentFilter (android.content.IntentFilter)14 Uri (android.net.Uri)14 ComponentName (android.content.ComponentName)10 Intent (android.content.Intent)10 ResolveInfo (android.content.pm.ResolveInfo)10 TypedArray (android.content.res.TypedArray)7 LabeledIntent (android.content.pm.LabeledIntent)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 LogPrinter (android.util.LogPrinter)5 ActivityInfo (android.content.pm.ActivityInfo)2 SuppressLint (android.annotation.SuppressLint)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1