From 8f6a9399a57b33203a277db238658e4f77f36b7f Mon Sep 17 00:00:00 2001 From: Yi-Ling Chuang Date: Wed, 3 Jun 2020 16:02:32 +0800 Subject: [PATCH] Create an API for browser app checking. Add this new API into AppUtils so we can check if a certain app is a browser. Bug: 129162570 Test: Build with Settings app and see "Open by default" is hidden if it's a browser. Change-Id: I8179481434dce59a7a82d26d7ec63445b1659a10 --- .../settingslib/applications/AppUtils.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java index a6202956efa51..38eeda245616d 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/AppUtils.java @@ -19,10 +19,13 @@ package com.android.settingslib.applications; import android.app.Application; import android.content.ComponentName; import android.content.Context; +import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.hardware.usb.IUsbManager; +import android.net.Uri; import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; @@ -44,6 +47,15 @@ public class AppUtils { */ private static InstantAppDataProvider sInstantAppDataProvider = null; + private static final Intent sBrowserIntent; + + static { + sBrowserIntent = new Intent() + .setAction(Intent.ACTION_VIEW) + .addCategory(Intent.CATEGORY_BROWSABLE) + .setData(Uri.parse("http:")); + } + public static CharSequence getLaunchByDefaultSummary(ApplicationsState.AppEntry appEntry, IUsbManager usbManager, PackageManager pm, Context context) { String packageName = appEntry.info.packageName; @@ -153,4 +165,22 @@ public class AppUtils { return com.android.settingslib.utils.applications.AppUtils.getAppContentDescription(context, packageName, userId); } + + /** + * Returns a boolean indicating whether a given package is a browser app. + * + * An app is a "browser" if it has an activity resolution that wound up + * marked with the 'handleAllWebDataURI' flag. + */ + public static boolean isBrowserApp(Context context, String packageName, int userId) { + sBrowserIntent.setPackage(packageName); + final List list = context.getPackageManager().queryIntentActivitiesAsUser( + sBrowserIntent, PackageManager.MATCH_ALL, userId); + for (ResolveInfo info : list) { + if (info.activityInfo != null && info.handleAllWebDataURI) { + return true; + } + } + return false; + } }