mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
Bug 1829619 - Fix external ActivityNotFoundException for default browser settings
This commit is contained in:
parent
990886fc6c
commit
3fcc8890b0
@ -12,6 +12,7 @@ import android.provider.Settings
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import mozilla.components.concept.base.crash.Breadcrumb
|
import mozilla.components.concept.base.crash.Breadcrumb
|
||||||
@ -88,14 +89,53 @@ fun Activity.openSetDefaultBrowserOption(
|
|||||||
REQUEST_CODE_BROWSER_ROLE,
|
REQUEST_CODE_BROWSER_ROLE,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
navigateToDefaultBrowserAppsSettings()
|
navigateToDefaultBrowserAppsSettings(
|
||||||
|
useCustomTab = useCustomTab,
|
||||||
|
from = from,
|
||||||
|
flags = flags,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
|
||||||
navigateToDefaultBrowserAppsSettings()
|
navigateToDefaultBrowserAppsSettings(
|
||||||
|
useCustomTab = useCustomTab,
|
||||||
|
from = from,
|
||||||
|
flags = flags,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
openDefaultBrowserSumoPage(useCustomTab, from, flags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
|
private fun Activity.navigateToDefaultBrowserAppsSettings(
|
||||||
|
from: BrowserDirection,
|
||||||
|
flags: EngineSession.LoadUrlFlags,
|
||||||
|
useCustomTab: Boolean,
|
||||||
|
) {
|
||||||
|
val intent = Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS).apply {
|
||||||
|
putExtra(SETTINGS_SELECT_OPTION_KEY, DEFAULT_BROWSER_APP_OPTION)
|
||||||
|
putExtra(
|
||||||
|
SETTINGS_SHOW_FRAGMENT_ARGS,
|
||||||
|
bundleOf(SETTINGS_SELECT_OPTION_KEY to DEFAULT_BROWSER_APP_OPTION),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
startExternalActivitySafe(
|
||||||
|
intent = intent,
|
||||||
|
onActivityNotPresent = {
|
||||||
|
openDefaultBrowserSumoPage(useCustomTab = useCustomTab, from = from, flags = flags)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Activity.openDefaultBrowserSumoPage(
|
||||||
|
useCustomTab: Boolean,
|
||||||
|
from: BrowserDirection,
|
||||||
|
flags: EngineSession.LoadUrlFlags,
|
||||||
|
) {
|
||||||
val sumoDefaultBrowserUrl = SupportUtils.getGenericSumoURLForTopic(
|
val sumoDefaultBrowserUrl = SupportUtils.getGenericSumoURLForTopic(
|
||||||
topic = SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER,
|
topic = SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER,
|
||||||
)
|
)
|
||||||
@ -114,22 +154,22 @@ fun Activity.openSetDefaultBrowserOption(
|
|||||||
flags = flags,
|
flags = flags,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Activity.navigateToDefaultBrowserAppsSettings() {
|
/**
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
* Checks for the presence of an activity before starting it. In case it's not present,
|
||||||
val intent = Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
|
* [onActivityNotPresent] is invoked, preventing ActivityNotFoundException from being thrown.
|
||||||
intent.putExtra(
|
* This is useful when navigating to external activities like device permission settings,
|
||||||
SETTINGS_SELECT_OPTION_KEY,
|
* notification settings, default app settings, etc.
|
||||||
DEFAULT_BROWSER_APP_OPTION,
|
*
|
||||||
)
|
* @param intent The Intent of the activity to resolve and start.
|
||||||
intent.putExtra(
|
* @param onActivityNotPresent Invoked when the activity to handle the intent is not present.
|
||||||
SETTINGS_SHOW_FRAGMENT_ARGS,
|
*/
|
||||||
bundleOf(SETTINGS_SELECT_OPTION_KEY to DEFAULT_BROWSER_APP_OPTION),
|
inline fun Activity.startExternalActivitySafe(intent: Intent, onActivityNotPresent: () -> Unit) {
|
||||||
)
|
if (intent.resolveActivity(packageManager) != null) {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
|
} else {
|
||||||
|
onActivityNotPresent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ import android.content.Intent
|
|||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build.VERSION_CODES.M
|
import android.os.Build.VERSION_CODES.M
|
||||||
import android.os.Build.VERSION_CODES.N
|
|
||||||
import android.os.Build.VERSION_CODES.P
|
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import io.mockk.Called
|
import io.mockk.Called
|
||||||
@ -238,16 +236,6 @@ class HomeDeepLinkIntentProcessorTest {
|
|||||||
verify { out wasNot Called }
|
verify { out wasNot Called }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(minSdk = N, maxSdk = P)
|
|
||||||
fun `process make_default_browser deep link for above API 23`() {
|
|
||||||
assertTrue(processorHome.process(testIntent("make_default_browser"), navController, out))
|
|
||||||
|
|
||||||
verify { activity.startActivity(any()) }
|
|
||||||
verify { navController wasNot Called }
|
|
||||||
verify { out wasNot Called }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(maxSdk = M)
|
@Config(maxSdk = M)
|
||||||
fun `process make_default_browser deep link for API 23 and below`() {
|
fun `process make_default_browser deep link for API 23 and below`() {
|
||||||
|
Loading…
Reference in New Issue
Block a user