From db3fe819902f2bea08746c3e3ea55a9a55e3bac5 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 24 Jun 2015 16:15:48 -0700 Subject: [PATCH] Use a framework resource to name a factory-default browser app If there is no resource-named default but there is a single factory- installed browser app, that app is made the titular default. This also introduces a permission guard on attempts to set the default browser or the app-link state. These operations are now contingent on the existing SET_PREFERRED_APPLICATIONS permission. Bug 21778406 Change-Id: Id099bb9c4141f28917546492657cd2fba472e6b6 --- core/res/res/values/config.xml | 8 ++ core/res/res/values/symbols.xml | 1 + .../server/pm/PackageManagerService.java | 91 ++++++++++++++++--- .../java/com/android/server/pm/Settings.java | 6 +- 4 files changed, 91 insertions(+), 15 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index f6cefba7b77cc..9d7995205e042 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1268,6 +1268,14 @@ application is desired. --> com.android.mms + + + true diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 5c42d04c78c0d..8bf1aac836b21 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -903,6 +903,7 @@ + diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 40ff3f42ea975..d771085831fcd 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -2191,7 +2191,8 @@ public class PackageManagerService extends IPackageManager.Stub { // If this is the first boot, and it is a normal boot, then // we need to initialize the default preferred apps. if (!mRestoredSettings && !onlyCore) { - mSettings.readDefaultPreferredAppsLPw(this, 0); + mSettings.applyDefaultPreferredAppsLPw(this, UserHandle.USER_OWNER); + applyFactoryDefaultBrowserLPw(UserHandle.USER_OWNER); } // If this is first boot after an OTA, and a normal boot, then @@ -2375,13 +2376,72 @@ public class PackageManagerService extends IPackageManager.Stub { if (DEBUG_DOMAIN_VERIFICATION) Slog.d(TAG, "End priming domain verifications"); } + private void applyFactoryDefaultBrowserLPw(int userId) { + // The default browser app's package name is stored in a string resource, + // with a product-specific overlay used for vendor customization. + String browserPkg = mContext.getResources().getString( + com.android.internal.R.string.default_browser); + if (browserPkg != null) { + // non-empty string => required to be a known package + PackageSetting ps = mSettings.mPackages.get(browserPkg); + if (ps == null) { + Slog.e(TAG, "Product default browser app does not exist: " + browserPkg); + browserPkg = null; + } else { + mSettings.setDefaultBrowserPackageNameLPw(browserPkg, userId); + } + } + + // Nothing valid explicitly set? Make the factory-installed browser the explicit + // default. If there's more than one, just leave everything alone. + if (browserPkg == null) { + calculateDefaultBrowserLPw(userId); + } + } + + private void calculateDefaultBrowserLPw(int userId) { + List allBrowsers = resolveAllBrowserApps(userId); + final String browserPkg = (allBrowsers.size() == 1) ? allBrowsers.get(0) : null; + mSettings.setDefaultBrowserPackageNameLPw(browserPkg, userId); + } + + private List resolveAllBrowserApps(int userId) { + // Match all generic http: browser apps + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.setData(Uri.parse("http:")); + + // Resolve that intent and check that the handleAllWebDataURI boolean is set + List list = queryIntentActivities(intent, null, 0, userId); + + final int count = list.size(); + List result = new ArrayList(count); + for (int i=0; i 1 + } + } } } @@ -4443,7 +4503,7 @@ public class PackageManagerService extends IPackageManager.Stub { synchronized (mPackages) { final int count = candidates.size(); - // First, try to use the domain prefered App. Partition the candidates into four lists: + // First, try to use the domain preferred app. Partition the candidates into four lists: // one for the final results, one for the "do not use ever", one for "undefined status" // and finally one for "Browser App type". for (int n=0; n