use of android.os.PatternMatcher in project XobotOS by xamarin.
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 (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());
}
}
use of android.os.PatternMatcher in project XobotOS by xamarin.
the class PackageParser method parseProviderTags.
private boolean parseProviderTags(Resources res, XmlPullParser parser, AttributeSet attrs, 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("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;
}
use of android.os.PatternMatcher in project android_frameworks_base by ParanoidAndroid.
the class ResolverActivity method onIntentSelected.
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
if (alwaysCheck) {
// Build a reasonable intent filter, based on what matched.
IntentFilter filter = new IntentFilter();
if (intent.getAction() != null) {
filter.addAction(intent.getAction());
}
Set<String> categories = intent.getCategories();
if (categories != null) {
for (String cat : categories) {
filter.addCategory(cat);
}
}
filter.addCategory(Intent.CATEGORY_DEFAULT);
int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
Uri data = intent.getData();
if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
String mimeType = intent.resolveType(this);
if (mimeType != null) {
try {
filter.addDataType(mimeType);
} catch (IntentFilter.MalformedMimeTypeException e) {
Log.w("ResolverActivity", e);
filter = null;
}
}
}
if (data != null && data.getScheme() != null) {
// or "content:" schemes (see IntentFilter for the reason).
if (cat != IntentFilter.MATCH_CATEGORY_TYPE || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) {
filter.addDataScheme(data.getScheme());
// Look through the resolved filter to determine which part
// of it matched the original Intent.
Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
if (aIt != null) {
while (aIt.hasNext()) {
IntentFilter.AuthorityEntry a = aIt.next();
if (a.match(data) >= 0) {
int port = a.getPort();
filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
break;
}
}
}
Iterator<PatternMatcher> pIt = ri.filter.pathsIterator();
if (pIt != null) {
String path = data.getPath();
while (path != null && pIt.hasNext()) {
PatternMatcher p = pIt.next();
if (p.match(path)) {
filter.addDataPath(p.getPath(), p.getType());
break;
}
}
}
}
}
if (filter != null) {
final int N = mAdapter.mList.size();
ComponentName[] set = new ComponentName[N];
int bestMatch = 0;
for (int i = 0; i < N; i++) {
ResolveInfo r = mAdapter.mList.get(i).ri;
set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
if (r.match > bestMatch)
bestMatch = r.match;
}
getPackageManager().addPreferredActivity(filter, bestMatch, set, intent.getComponent());
}
}
if (intent != null) {
startActivity(intent);
}
}
use of android.os.PatternMatcher in project android_frameworks_base by AOSPA.
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);
}
}
use of android.os.PatternMatcher in project android_frameworks_base by AOSPA.
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());
}
}
Aggregations