use of android.os.PatternMatcher in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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);
}
}
use of android.os.PatternMatcher in project android_frameworks_base by AOSPA.
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 platform_frameworks_base by android.
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 ParanoidAndroid.
the class Settings method readDefaultPreferredActivitiesLPw.
private void readDefaultPreferredActivitiesLPw(PackageManagerService service, XmlPullParser parser, int userId) 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;
}
String tagName = parser.getName();
if (tagName.equals(TAG_ITEM)) {
PreferredActivity tmpPa = new PreferredActivity(parser);
if (tmpPa.mPref.getParseError() == null) {
// preferred activity entry.
if (PackageManagerService.DEBUG_PREFERRED) {
Log.d(TAG, "Processing preferred:");
tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), " ");
}
final ComponentName cn = tmpPa.mPref.mComponent;
Intent intent = new Intent();
int flags = 0;
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 |= PackageManager.MATCH_DEFAULT_ONLY;
} else {
intent.addCategory(cat);
}
}
if (tmpPa.countDataSchemes() > 0) {
Uri.Builder builder = new Uri.Builder();
builder.scheme(tmpPa.getDataScheme(0));
if (tmpPa.countDataAuthorities() > 0) {
IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(0);
if (auth.getHost() != null) {
builder.authority(auth.getHost());
}
}
if (tmpPa.countDataPaths() > 0) {
PatternMatcher path = tmpPa.getDataPath(0);
builder.path(path.getPath());
}
intent.setData(builder.build());
} else if (tmpPa.countDataTypes() > 0) {
intent.setType(tmpPa.getDataType(0));
}
List<ResolveInfo> ri = service.mActivities.queryIntent(intent, intent.getType(), flags, 0);
if (PackageManagerService.DEBUG_PREFERRED)
Log.d(TAG, "Queried " + intent + " results: " + ri);
int match = 0;
if (ri != null && ri.size() > 1) {
boolean haveAct = false;
boolean haveNonSys = false;
ComponentName[] set = new ComponentName[ri.size()];
for (int i = 0; i < ri.size(); i++) {
ActivityInfo ai = ri.get(i).activityInfo;
set[i] = new ComponentName(ai.packageName, ai.name);
if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
// so don't set a default since we don't want to hide it.
if (PackageManagerService.DEBUG_PREFERRED)
Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": non-system!");
haveNonSys = true;
break;
} else if (cn.getPackageName().equals(ai.packageName) && cn.getClassName().equals(ai.name)) {
if (PackageManagerService.DEBUG_PREFERRED)
Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": default!");
haveAct = true;
match = ri.get(i).match;
} else {
if (PackageManagerService.DEBUG_PREFERRED)
Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": skipped");
}
}
if (haveAct && !haveNonSys) {
PreferredActivity pa = new PreferredActivity(tmpPa, match, set, tmpPa.mPref.mComponent);
editPreferredActivitiesLPw(userId).addFilter(pa);
} else if (!haveNonSys) {
Slog.w(TAG, "No component found for default preferred activity " + tmpPa.mPref.mComponent);
}
}
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <preferred-activity> " + tmpPa.mPref.getParseError() + " at " + parser.getPositionDescription());
}
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Unknown element under <preferred-activities>: " + parser.getName());
XmlUtils.skipCurrentTag(parser);
}
}
}
Aggregations