Merge "Don't call setLastChosen if it's a chooser activity instance" into klp-dev

This commit is contained in:
Amith Yamasani
2013-09-03 20:22:15 +00:00
committed by Android (Google) Code Review

View File

@@ -287,102 +287,104 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
} }
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) { protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
// Build a reasonable intent filter, based on what matched. if (mAlwaysUseOption) {
IntentFilter filter = new IntentFilter(); // Build a reasonable intent filter, based on what matched.
IntentFilter filter = new IntentFilter();
if (intent.getAction() != null) { if (intent.getAction() != null) {
filter.addAction(intent.getAction()); filter.addAction(intent.getAction());
}
Set<String> categories = intent.getCategories();
if (categories != null) {
for (String cat : categories) {
filter.addCategory(cat);
} }
} Set<String> categories = intent.getCategories();
filter.addCategory(Intent.CATEGORY_DEFAULT); if (categories != null) {
for (String cat : categories) {
int cat = ri.match&IntentFilter.MATCH_CATEGORY_MASK; filter.addCategory(cat);
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;
} }
} }
} filter.addCategory(Intent.CATEGORY_DEFAULT);
if (data != null && data.getScheme() != null) {
// We need the data specification if there was no type,
// OR if the scheme is not one of our magical "file:"
// 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 int cat = ri.match&IntentFilter.MATCH_CATEGORY_MASK;
// of it matched the original Intent. Uri data = intent.getData();
Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator(); if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
if (pIt != null) { String mimeType = intent.resolveType(this);
String ssp = data.getSchemeSpecificPart(); if (mimeType != null) {
while (ssp != null && pIt.hasNext()) { try {
PatternMatcher p = pIt.next(); filter.addDataType(mimeType);
if (p.match(ssp)) { } catch (IntentFilter.MalformedMimeTypeException e) {
filter.addDataSchemeSpecificPart(p.getPath(), p.getType()); Log.w("ResolverActivity", e);
break; filter = null;
}
} }
} }
Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); }
if (aIt != null) { if (data != null && data.getScheme() != null) {
while (aIt.hasNext()) { // We need the data specification if there was no type,
IntentFilter.AuthorityEntry a = aIt.next(); // OR if the scheme is not one of our magical "file:"
if (a.match(data) >= 0) { // or "content:" schemes (see IntentFilter for the reason).
int port = a.getPort(); if (cat != IntentFilter.MATCH_CATEGORY_TYPE
filter.addDataAuthority(a.getHost(), || (!"file".equals(data.getScheme())
port >= 0 ? Integer.toString(port) : null); && !"content".equals(data.getScheme()))) {
break; 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();
pIt = ri.filter.pathsIterator(); if (aIt != null) {
if (pIt != null) { while (aIt.hasNext()) {
String path = data.getPath(); IntentFilter.AuthorityEntry a = aIt.next();
while (path != null && pIt.hasNext()) { if (a.match(data) >= 0) {
PatternMatcher p = pIt.next(); int port = a.getPort();
if (p.match(path)) { filter.addDataAuthority(a.getHost(),
filter.addDataPath(p.getPath(), p.getType()); port >= 0 ? Integer.toString(port) : null);
break; 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) { if (filter != null) {
final int N = mAdapter.mList.size(); final int N = mAdapter.mList.size();
ComponentName[] set = new ComponentName[N]; ComponentName[] set = new ComponentName[N];
int bestMatch = 0; int bestMatch = 0;
for (int i=0; i<N; i++) { for (int i=0; i<N; i++) {
ResolveInfo r = mAdapter.mList.get(i).ri; ResolveInfo r = mAdapter.mList.get(i).ri;
set[i] = new ComponentName(r.activityInfo.packageName, set[i] = new ComponentName(r.activityInfo.packageName,
r.activityInfo.name); r.activityInfo.name);
if (r.match > bestMatch) bestMatch = r.match; if (r.match > bestMatch) bestMatch = r.match;
} }
if (alwaysCheck) { if (alwaysCheck) {
getPackageManager().addPreferredActivity(filter, bestMatch, set, getPackageManager().addPreferredActivity(filter, bestMatch, set,
intent.getComponent()); intent.getComponent());
} else { } else {
try { try {
AppGlobals.getPackageManager().setLastChosenActivity(intent, AppGlobals.getPackageManager().setLastChosenActivity(intent,
intent.resolveTypeIfNeeded(getContentResolver()), intent.resolveTypeIfNeeded(getContentResolver()),
PackageManager.MATCH_DEFAULT_ONLY, PackageManager.MATCH_DEFAULT_ONLY,
filter, bestMatch, intent.getComponent()); filter, bestMatch, intent.getComponent());
} catch (RemoteException re) { } catch (RemoteException re) {
Log.d(TAG, "Error calling setLastChosenActivity\n" + re); Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
}
} }
} }
} }