use of android.os.PatternMatcher in project android_frameworks_base by DirtyUnicorns.
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 ResolverActivity method onTargetSelected.
protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) {
final ResolveInfo ri = target.getResolveInfo();
final Intent intent = target != null ? target.getResolvedIntent() : null;
if (intent != null && (mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) {
// Build a reasonable intent filter, based on what matched.
IntentFilter filter = new IntentFilter();
Intent filterIntent;
if (intent.getSelector() != null) {
filterIntent = intent.getSelector();
} else {
filterIntent = intent;
}
String action = filterIntent.getAction();
if (action != null) {
filter.addAction(action);
}
Set<String> categories = filterIntent.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 = filterIntent.getData();
if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
String mimeType = filterIntent.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<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();
if (pIt != null) {
String ssp = data.getSchemeSpecificPart();
while (ssp != null && pIt.hasNext()) {
PatternMatcher p = pIt.next();
if (p.match(ssp)) {
filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
break;
}
}
}
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;
}
}
}
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.mOrigResolveList.size();
ComponentName[] set = new ComponentName[N];
int bestMatch = 0;
for (int i = 0; i < N; i++) {
ResolveInfo r = mAdapter.mOrigResolveList.get(i).getResolveInfoAt(0);
set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
if (r.match > bestMatch)
bestMatch = r.match;
}
if (alwaysCheck) {
final int userId = getUserId();
final PackageManager pm = getPackageManager();
// Set the preferred Activity
pm.addPreferredActivity(filter, bestMatch, set, intent.getComponent());
if (ri.handleAllWebDataURI) {
// Set default Browser if needed
final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId);
if (TextUtils.isEmpty(packageName)) {
pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId);
}
} else {
// Update Domain Verification status
ComponentName cn = intent.getComponent();
String packageName = cn.getPackageName();
String dataScheme = (data != null) ? data.getScheme() : null;
boolean isHttpOrHttps = (dataScheme != null) && (dataScheme.equals(IntentFilter.SCHEME_HTTP) || dataScheme.equals(IntentFilter.SCHEME_HTTPS));
boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW);
boolean hasCategoryBrowsable = (categories != null) && categories.contains(Intent.CATEGORY_BROWSABLE);
if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) {
pm.updateIntentVerificationStatusAsUser(packageName, PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS, userId);
}
}
} else {
try {
AppGlobals.getPackageManager().setLastChosenActivity(intent, intent.resolveType(getContentResolver()), PackageManager.MATCH_DEFAULT_ONLY, filter, bestMatch, intent.getComponent());
} catch (RemoteException re) {
Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
}
}
}
}
if (target != null) {
safelyStartActivity(target);
}
return true;
}
use of android.os.PatternMatcher in project android_frameworks_base by ResurrectionRemix.
the class ResolverActivity method onTargetSelected.
protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) {
final ResolveInfo ri = target.getResolveInfo();
final Intent intent = target != null ? target.getResolvedIntent() : null;
if (intent != null && (mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) {
// Build a reasonable intent filter, based on what matched.
IntentFilter filter = new IntentFilter();
Intent filterIntent;
if (intent.getSelector() != null) {
filterIntent = intent.getSelector();
} else {
filterIntent = intent;
}
String action = filterIntent.getAction();
if (action != null) {
filter.addAction(action);
}
Set<String> categories = filterIntent.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 = filterIntent.getData();
if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
String mimeType = filterIntent.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<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();
if (pIt != null) {
String ssp = data.getSchemeSpecificPart();
while (ssp != null && pIt.hasNext()) {
PatternMatcher p = pIt.next();
if (p.match(ssp)) {
filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
break;
}
}
}
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;
}
}
}
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.mOrigResolveList.size();
ComponentName[] set = new ComponentName[N];
int bestMatch = 0;
for (int i = 0; i < N; i++) {
ResolveInfo r = mAdapter.mOrigResolveList.get(i).getResolveInfoAt(0);
set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
if (r.match > bestMatch)
bestMatch = r.match;
}
if (alwaysCheck) {
final int userId = getUserId();
final PackageManager pm = getPackageManager();
// Set the preferred Activity
pm.addPreferredActivity(filter, bestMatch, set, intent.getComponent());
if (ri.handleAllWebDataURI) {
// Set default Browser if needed
final String packageName = pm.getDefaultBrowserPackageNameAsUser(userId);
if (TextUtils.isEmpty(packageName)) {
pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId);
}
} else {
// Update Domain Verification status
ComponentName cn = intent.getComponent();
String packageName = cn.getPackageName();
String dataScheme = (data != null) ? data.getScheme() : null;
boolean isHttpOrHttps = (dataScheme != null) && (dataScheme.equals(IntentFilter.SCHEME_HTTP) || dataScheme.equals(IntentFilter.SCHEME_HTTPS));
boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW);
boolean hasCategoryBrowsable = (categories != null) && categories.contains(Intent.CATEGORY_BROWSABLE);
if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) {
pm.updateIntentVerificationStatusAsUser(packageName, PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS, userId);
}
}
} else {
try {
AppGlobals.getPackageManager().setLastChosenActivity(intent, intent.resolveType(getContentResolver()), PackageManager.MATCH_DEFAULT_ONLY, filter, bestMatch, intent.getComponent());
} catch (RemoteException re) {
Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
}
}
}
}
if (target != null) {
safelyStartActivity(target);
}
return true;
}
use of android.os.PatternMatcher in project android_frameworks_base by ResurrectionRemix.
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;
}
use of android.os.PatternMatcher in project android_frameworks_base by ResurrectionRemix.
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