Dan Ballard pushed to branch tor-browser-153.1.0esr-16.0-1 at The Tor Project / Applications / Tor Browser

Commits:

2 changed files:

Changes:

  • mobile/android/android-components/components/support/utils/src/main/java/mozilla/components/support/utils/DefaultDownloadFileUtils.kt
    ... ... @@ -28,10 +28,11 @@ import mozilla.components.support.utils.DownloadUtils.findFileInMediaStore
    28 28
     import mozilla.components.support.utils.DownloadUtils.isDefaultDownloadDirectory
    
    29 29
     import mozilla.components.support.utils.DownloadUtils.sanitizeMimeType
    
    30 30
     import mozilla.components.support.utils.DownloadUtils.truncateFileName
    
    31
    -import mozilla.components.support.utils.TorUtils
    
    32 31
     import java.io.File
    
    33 32
     import java.io.FileNotFoundException
    
    34 33
     
    
    34
    +import android.content.pm.PackageManager
    
    35
    +
    
    35 36
     /**
    
    36 37
      * The default implementation of [DownloadFileUtils].
    
    37 38
      *
    
    ... ... @@ -62,6 +63,8 @@ class DefaultDownloadFileUtils(
    62 63
             private const val SCHEME_CONTENT = "content://"
    
    63 64
             private const val SCHEME_FILE = "file"
    
    64 65
             private const val FILE_PROVIDER_EXTENSION = ".feature.downloads.fileprovider"
    
    66
    +
    
    67
    +        const val EXTRA_IS_PDF = "mozilla.components.feature.downloads.extras.IS_PDF"
    
    65 68
         }
    
    66 69
         override val currentDownloadLocation: String
    
    67 70
             get() = downloadLocation()
    
    ... ... @@ -103,7 +106,15 @@ class DefaultDownloadFileUtils(
    103 106
             )
    
    104 107
     
    
    105 108
             return try {
    
    106
    -            TorUtils.startActivityPrompt(context, newIntent)
    
    109
    +            if (newIntent.getBooleanExtra(
    
    110
    +                    EXTRA_IS_PDF,
    
    111
    +                    false,
    
    112
    +                ) || newIntent.type == INTENT_TYPE_PDF
    
    113
    +            ) {
    
    114
    +                context.startActivity(newIntent)
    
    115
    +            } else {
    
    116
    +                TorUtils.startActivityPrompt(context, newIntent)
    
    117
    +            }
    
    107 118
                 true
    
    108 119
             } catch (_: ActivityNotFoundException) {
    
    109 120
                 false
    
    ... ... @@ -118,13 +129,23 @@ class DefaultDownloadFileUtils(
    118 129
             val shareableUri = findShareableDownloadFileUri(fileName, directoryPath)
    
    119 130
     
    
    120 131
             return if (shareableUri != null) {
    
    121
    -            Intent(Intent.ACTION_VIEW).apply {
    
    132
    +            val newIntent = Intent(Intent.ACTION_VIEW).apply {
    
    122 133
                     setDataAndType(
    
    123 134
                         shareableUri,
    
    124 135
                         getSafeContentType(fileName, downloadContentType, shareableUri),
    
    125 136
                     )
    
    126 137
                     flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
    
    127 138
                 }
    
    139
    +
    
    140
    +            val isPdf: Boolean = (downloadContentType == "application/pdf" ||
    
    141
    +                fileName?.let { File(it).extension } == "pdf")
    
    142
    +
    
    143
    +            if (isPdf) {
    
    144
    +                newIntent.setPackage(context.packageName) // Set it to open in TBA
    
    145
    +                newIntent.putExtra(EXTRA_IS_PDF, true)
    
    146
    +            }
    
    147
    +
    
    148
    +            newIntent
    
    128 149
             } else {
    
    129 150
                 // Fallback to opening the downloads manager if the file URI could not be determined.
    
    130 151
                 Intent(DownloadManager.ACTION_VIEW_DOWNLOADS).apply {
    

  • mobile/android/fenix/app/src/main/AndroidManifest.xml
    ... ... @@ -557,8 +557,9 @@
    557 557
                 android:theme="@style/Theme.Transparent"
    
    558 558
                 android:relinquishTaskIdentity="true"
    
    559 559
                 android:taskAffinity=""
    
    560
    -            android:exported="true"
    
    561
    -            android:excludeFromRecents="true" >
    
    560
    +            android:exported="false"
    
    561
    +            android:excludeFromRecents="true"
    
    562
    +            tools:ignore="AppLinkUrlError">
    
    562 563
     
    
    563 564
     
    
    564 565
                 <intent-filter>
    
    ... ... @@ -586,7 +587,7 @@
    586 587
                     <data android:scheme="https" />
    
    587 588
                 </intent-filter>
    
    588 589
     
    
    589
    -            <intent-filter>
    
    590
    +            <intent-filter tools:ignore="AppLinkUrlError">
    
    590 591
                     <action android:name="android.intent.action.VIEW" />
    
    591 592
                     <category android:name="android.intent.category.BROWSABLE" />
    
    592 593
                     <category android:name="android.intent.category.DEFAULT" />