Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecurityException crash opening link in external browser, when MX Player is installed

Steps to reproduce:

  • Disable or uninstall all browsers on the device
  • Install MX Player
  • Launch MX Player and accept any popups
  • Open a link from your app as follows (assume the code is in an Activity):
val url = "https://mylink.com"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
val resolveInfo = context.packageManager.resolveActivity(intent, 0)
if (resolveInfo != null) {
    startActivity(intent)
} else {
    // error handling because no browser is installed
}

My app crashes with:

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=https://mylink.com.... cmp=com.mxtech.videoplayer.ad/com.mxtech.videoplayer.ActivityWebBrowser } from ProcessRecord{64f9702 20760:com.myapp/u0a65} (pid=20760, uid=10065) not exported from uid 10139
       at android.os.Parcel.createException + 1966(Parcel.java:1966)
       at android.os.Parcel.readException + 1934(Parcel.java:1934)
       at android.os.Parcel.readException + 1884(Parcel.java:1884)
       at android.app.IActivityManager$Stub$Proxy.startActivity + 3618(IActivityManager.java:3618)
       at android.app.Instrumentation.execStartActivity + 1673(Instrumentation.java:1673)
       at android.app.Activity.startActivityForResult + 4689(Activity.java:4689)
       at androidx.fragment.app.FragmentActivity.startActivityForResult + 767(FragmentActivity.java:767)
       at android.app.Activity.startActivityForResult + 4647(Activity.java:4647)
       at androidx.fragment.app.FragmentActivity.startActivityForResult + 754(FragmentActivity.java:754)
       at android.app.Activity.startActivity + 5008(Activity.java:5008)
       at android.app.Activity.startActivity + 4976(Activity.java:4976)
       at com.myapp.MyActivity.someFunction

I only see this issue if all browsers are uninstalled/disabled. It appears that MX Player installs itself as a browser in this situation, but can't handle opening links from my app.

like image 976
Carmen Avatar asked Jul 26 '19 15:07

Carmen


1 Answers

You can check the Activity to view the URL is resolved and exported with something like this:

private fun openUrl(url: String?) {
    if (url == null) return
    val intent = Intent(Intent.ACTION_VIEW)
    intent.addCategory(Intent.CATEGORY_DEFAULT)
    intent.data = Uri.parse(url)
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    activity?.let {
        val activityInfo = intent.resolveActivityInfo(it.packageManager, intent.flags)
        if (activityInfo != null && activityInfo.exported) {
            ActivityCompat.startActivity(it, intent, null)
        }
    }
}
like image 142
riot Avatar answered Sep 19 '22 06:09

riot