From eeb2c7e712dbae91de04ab2338c1fbccfbce7ba2 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 23 Sep 2014 16:45:39 -0700 Subject: [PATCH] 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 --- .../java/com/android/server/pm/Settings.java | 60 ++++++++++++------- tests/ActivityTests/AndroidManifest.xml | 14 +++++ 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 0dadee7f1fc4c..4e33ca88ba1bc 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 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= 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 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 3fb547dc4bf80..f31f4f280a829 100644 --- a/tests/ActivityTests/AndroidManifest.xml +++ b/tests/ActivityTests/AndroidManifest.xml @@ -30,6 +30,20 @@ + + + + + + + + + + + +