summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2014-09-23 16:45:39 -0700
committerDianne Hackborn <hackbod@google.com>2014-09-23 16:45:39 -0700
commiteeb2c7e712dbae91de04ab2338c1fbccfbce7ba2 (patch)
tree02ff12fb190fc18e32f69f16438fb2f719a0ee4f
parent4c45b649c36d6c28d22a98d979fbda3b7c36677a (diff)
Work on issue #17628623: Need to update default preferred activities for YouTube
Improve the warning logs when setting up preferred activities to help identify when there are issues and what they are. Also improve the algorithm a little to still apply permissions when resetting them and there are additional third party apps, as long as the additional app is something like another browser and the preferred activity being set is more specific (has a better match). And add an example of using manifest-based preferred activities in to ActivityTest -- and yes it DOES work! :p Change-Id: I1ff39e03a5df6526206e0c3882085396b355d814
-rw-r--r--services/core/java/com/android/server/pm/Settings.java60
-rw-r--r--tests/ActivityTests/AndroidManifest.xml14
2 files changed, 54 insertions, 20 deletions
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 0dadee7f1fc4..4e33ca88ba1b 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -2285,7 +2285,7 @@ final class Settings {
Intent finalIntent = new Intent(intent);
finalIntent.setData(builder.build());
applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
- scheme, ssp, null, null, null, userId);
+ scheme, ssp, null, null, userId);
doScheme = false;
}
for (int iauth=0; iauth<tmpPa.countDataAuthorities(); iauth++) {
@@ -2302,7 +2302,7 @@ final class Settings {
Intent finalIntent = new Intent(intent);
finalIntent.setData(builder.build());
applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
- scheme, null, auth, path, null, userId);
+ scheme, null, auth, path, userId);
doAuth = doScheme = false;
}
if (doAuth) {
@@ -2314,7 +2314,7 @@ final class Settings {
Intent finalIntent = new Intent(intent);
finalIntent.setData(builder.build());
applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
- scheme, null, auth, null, null, userId);
+ scheme, null, auth, null, userId);
doScheme = false;
}
}
@@ -2324,7 +2324,7 @@ final class Settings {
Intent finalIntent = new Intent(intent);
finalIntent.setData(builder.build());
applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
- scheme, null, null, null, null, userId);
+ scheme, null, null, null, userId);
}
doNonData = false;
}
@@ -2340,28 +2340,27 @@ final class Settings {
builder.scheme(scheme);
finalIntent.setDataAndType(builder.build(), mimeType);
applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
- scheme, null, null, null, mimeType, userId);
+ scheme, null, null, null, userId);
}
}
} else {
Intent finalIntent = new Intent(intent);
finalIntent.setType(mimeType);
applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
- null, null, null, null, mimeType, userId);
+ null, null, null, null, userId);
}
doNonData = false;
}
if (doNonData) {
applyDefaultPreferredActivityLPw(service, intent, flags, cn,
- null, null, null, null, null, userId);
+ null, null, null, null, userId);
}
}
private void applyDefaultPreferredActivityLPw(PackageManagerService service,
Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp,
- IntentFilter.AuthorityEntry auth, PatternMatcher path, String mimeType,
- int userId) {
+ IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) {
List<ResolveInfo> ri = service.mActivities.queryIntent(intent,
intent.getType(), flags, 0);
if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
@@ -2369,19 +2368,24 @@ final class Settings {
int match = 0;
if (ri != null && ri.size() > 1) {
boolean haveAct = false;
- boolean haveNonSys = false;
+ ComponentName haveNonSys = null;
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) {
- // If any of the matches are not system apps, then
- // there is a third party app that is now an option...
- // 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;
+ if (ri.get(i).match >= match) {
+ // If any of the matches are not system apps, then
+ // there is a third party app that is now an option...
+ // so don't set a default since we don't want to hide it.
+ // Only do this if the match of this one is at least as good
+ // as what we have found as the built-in app; if it isn't
+ // as good, the user won't want it anyway, right?
+ if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
+ + ai.packageName + "/" + ai.name + ": non-system!");
+ haveNonSys = set[i];
+ break;
+ }
} else if (cn.getPackageName().equals(ai.packageName)
&& cn.getClassName().equals(ai.name)) {
if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
@@ -2393,7 +2397,7 @@ final class Settings {
+ ai.packageName + "/" + ai.name + ": skipped");
}
}
- if (haveAct && !haveNonSys) {
+ if (haveAct && haveNonSys == null) {
IntentFilter filter = new IntentFilter();
if (intent.getAction() != null) {
filter.addAction(intent.getAction());
@@ -2427,9 +2431,25 @@ final class Settings {
}
PreferredActivity pa = new PreferredActivity(filter, match, set, cn, true);
editPreferredActivitiesLPw(userId).addFilter(pa);
- } else if (!haveNonSys) {
- Slog.w(TAG, "No component found for default preferred activity " + cn);
+ } else if (haveNonSys == null) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("No component ");
+ sb.append(cn.flattenToShortString());
+ sb.append(" found setting preferred ");
+ sb.append(intent);
+ sb.append("; possible matches are ");
+ for (int i=0; i<set.length; i++) {
+ if (i > 0) sb.append(", ");
+ sb.append(set[i].flattenToShortString());
+ }
+ Slog.w(TAG, sb.toString());
+ } else {
+ Slog.i(TAG, "Not setting preferred " + intent + "; found third party match "
+ + haveNonSys.flattenToShortString());
}
+ } else {
+ Slog.w(TAG, "No potential matches found for " + intent + " while setting preferred "
+ + cn.flattenToShortString());
}
}
diff --git a/tests/ActivityTests/AndroidManifest.xml b/tests/ActivityTests/AndroidManifest.xml
index 3fb547dc4bf8..f31f4f280a82 100644
--- a/tests/ActivityTests/AndroidManifest.xml
+++ b/tests/ActivityTests/AndroidManifest.xml
@@ -30,6 +30,20 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="http" android:host="www.angryredplanet.com"
+ android:pathPrefix="" />
+ </intent-filter>
+ <preferred>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:scheme="http" android:host="www.angryredplanet.com"
+ android:pathPrefix="" />
+ </preferred>
</activity>
<activity android:name="SpamActivity" android:label="Spam!"
android:documentLaunchMode="always">