Example usage for android.os PatternMatcher PatternMatcher

List of usage examples for android.os PatternMatcher PatternMatcher

Introduction

In this page you can find the example usage for android.os PatternMatcher PatternMatcher.

Prototype

public PatternMatcher(String pattern, int type) 

Source Link

Usage

From source file:android.content.pm.PackageParser.java

private boolean parseProviderTags(Resources res, XmlPullParser parser, AttributeSet attrs, Provider outInfo,
        String[] outError) throws XmlPullParserException, IOException {
    int outerDepth = parser.getDepth();
    int type;//from  www  .  j  a  v  a  2  s  .c  o  m
    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, attrs, true, false, intent, outError)) {
                return false;
            }
            outInfo.intents.add(intent);

        } else if (parser.getName().equals("meta-data")) {
            if ((outInfo.metaData = parseMetaData(res, parser, attrs, outInfo.metaData, outError)) == null) {
                return false;
            }

        } else if (parser.getName().equals("grant-uri-permission")) {
            TypedArray sa = res.obtainAttributes(attrs,
                    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(attrs,
                    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;
}