diff options
Diffstat (limited to 'apk/src/com/android/healthconnect/controller/utils/DeviceInfoUtils.kt')
-rw-r--r-- | apk/src/com/android/healthconnect/controller/utils/DeviceInfoUtils.kt | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/apk/src/com/android/healthconnect/controller/utils/DeviceInfoUtils.kt b/apk/src/com/android/healthconnect/controller/utils/DeviceInfoUtils.kt index c710d9ec..20e5be0c 100644 --- a/apk/src/com/android/healthconnect/controller/utils/DeviceInfoUtils.kt +++ b/apk/src/com/android/healthconnect/controller/utils/DeviceInfoUtils.kt @@ -3,8 +3,6 @@ package com.android.healthconnect.controller.utils import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent -import android.content.pm.ApplicationInfo -import android.content.pm.PackageManager import android.net.Uri import android.text.TextUtils import android.util.Log @@ -23,66 +21,38 @@ import javax.inject.Inject interface DeviceInfoUtils { fun isSendFeedbackAvailable(context: Context): Boolean - fun getFeedbackReporterPackage(context: Context): String? - fun isPlayStoreAvailable(context: Context): Boolean fun openHCGetStartedLink(activity: FragmentActivity) fun openSendFeedbackActivity(activity: FragmentActivity) + + fun isIntentHandlerAvailable(context: Context, intent: Intent): Boolean } class DeviceInfoUtilsImpl @Inject constructor() : DeviceInfoUtils { companion object { private val TAG = "DeviceInfoUtils" - private val FEEDBACK_REPORTER = "com.google.android.gms" } override fun isSendFeedbackAvailable(context: Context): Boolean { - return !TextUtils.isEmpty(getFeedbackReporterPackage(context)) - } - - override fun getFeedbackReporterPackage(context: Context): String? { - // Check to ensure the feedback reporter is on system image, and feedback reporter is - // configured to listen to the intent. Otherwise, don't show the "send feedback" preference. - val intent = Intent(Intent.ACTION_BUG_REPORT) - val pm = context.packageManager - val resolvedPackages = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER) - for (info in resolvedPackages) { - if (info.activityInfo != null) { - if (!TextUtils.isEmpty(info.activityInfo.packageName)) { - try { - val ai = pm.getApplicationInfo(info.activityInfo.packageName, 0) - if (ai.flags and ApplicationInfo.FLAG_SYSTEM != 0) { - // Package is on the system image - if (TextUtils.equals( - info.activityInfo.packageName, FEEDBACK_REPORTER)) { - return FEEDBACK_REPORTER - } - } - } catch (e: PackageManager.NameNotFoundException) { - // No need to do anything here. - } - } - } - } - return null + return isIntentHandlerAvailable(context, Intent(Intent.ACTION_BUG_REPORT)) } override fun isPlayStoreAvailable(context: Context): Boolean { - val playStorePackageName = context.resources?.getString(R.string.playstore_package_name) + val playStorePackageName = context.resources?.getString(R.string.playstore_collection_url) + val vendingPackageName = context.resources?.getString(R.string.playstore_package_name) if (TextUtils.isEmpty(playStorePackageName) || playStorePackageName == null) { // Package name not configured. Return. return false } - val pm = context.packageManager - return try { - pm?.getApplicationInfo(playStorePackageName, 0) - true - } catch (e: PackageManager.NameNotFoundException) { - false - } + return isIntentHandlerAvailable( + context, + Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse(playStorePackageName) + setPackage(vendingPackageName) + }) } override fun openHCGetStartedLink(activity: FragmentActivity) { @@ -104,6 +74,14 @@ class DeviceInfoUtilsImpl @Inject constructor() : DeviceInfoUtils { intent.putExtra("category_tag", USER_INITIATED_FEEDBACK_BUCKET_ID) activity.startActivityForResult(intent, FEEDBACK_INTENT_RESULT_CODE) } + + override fun isIntentHandlerAvailable(context: Context, intent: Intent): Boolean { + val packageManager = context.packageManager + if (intent.resolveActivity(packageManager) != null) { + return true + } + return false + } } @EntryPoint |