diff --git a/app/src/main/java/org/mozilla/fenix/ext/Activity.kt b/app/src/main/java/org/mozilla/fenix/ext/Activity.kt index d142aee6ec..04f89784d7 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Activity.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Activity.kt @@ -15,6 +15,7 @@ import android.provider.Settings import androidx.annotation.DrawableRes import androidx.appcompat.app.AppCompatActivity import androidx.core.os.bundleOf +import mozilla.components.concept.engine.EngineSession import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R @@ -64,8 +65,15 @@ fun Activity.breadcrumb( /** * Opens Android's Manage Default Apps Settings if possible. + * Otherwise navigates to the Sumo article indicating why it couldn't open it. + * + * @param from fallback direction in case, couldn't open the setting. + * @param flags fallback flags for when opening the Sumo article page. */ -fun Activity.openSetDefaultBrowserOption() { +fun Activity.openSetDefaultBrowserOption( + from: BrowserDirection = BrowserDirection.FromSettings, + flags: EngineSession.LoadUrlFlags = EngineSession.LoadUrlFlags.none() +) { when { Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> { getSystemService(RoleManager::class.java).also { @@ -92,7 +100,8 @@ fun Activity.openSetDefaultBrowserOption() { SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER ), newTab = true, - from = BrowserDirection.FromSettings + from = from, + flags = flags ) } } diff --git a/app/src/main/java/org/mozilla/fenix/home/intent/HomeDeepLinkIntentProcessor.kt b/app/src/main/java/org/mozilla/fenix/home/intent/HomeDeepLinkIntentProcessor.kt index f608290f25..5214aed582 100644 --- a/app/src/main/java/org/mozilla/fenix/home/intent/HomeDeepLinkIntentProcessor.kt +++ b/app/src/main/java/org/mozilla/fenix/home/intent/HomeDeepLinkIntentProcessor.kt @@ -10,7 +10,6 @@ import android.net.Uri import android.os.Build import android.os.Build.VERSION.SDK_INT import android.provider.Settings -import androidx.core.os.bundleOf import androidx.navigation.NavController import mozilla.components.concept.engine.EngineSession import mozilla.components.support.base.log.logger.Logger @@ -20,7 +19,7 @@ import org.mozilla.fenix.GlobalDirections import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.ext.alreadyOnDestination -import org.mozilla.fenix.settings.SupportUtils +import org.mozilla.fenix.ext.openSetDefaultBrowserOption /** * Deep links in the form of `fenix://host` open different parts of the app. @@ -80,27 +79,10 @@ class HomeDeepLinkIntentProcessor( activity.browsingModeManager.mode = BrowsingMode.Private } "make_default_browser" -> { - if (SDK_INT >= Build.VERSION_CODES.N) { - val settingsIntent = Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS) - settingsIntent.putExtra(SETTINGS_SELECT_OPTION_KEY, DEFAULT_BROWSER_APP_OPTION) - settingsIntent.putExtra( - SETTINGS_SHOW_FRAGMENT_ARGS, - bundleOf(SETTINGS_SELECT_OPTION_KEY to DEFAULT_BROWSER_APP_OPTION) - ) - activity.startActivity( - settingsIntent - ) - } else { - activity.openToBrowserAndLoad( - searchTermOrURL = SupportUtils.getSumoURLForTopic( - activity, - SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER - ), - newTab = true, - from = BrowserDirection.FromGlobal, - flags = EngineSession.LoadUrlFlags.external() - ) - } + activity.openSetDefaultBrowserOption( + from = BrowserDirection.FromGlobal, + flags = EngineSession.LoadUrlFlags.external() + ) } "open" -> { val url = deepLink.getQueryParameter("url") @@ -140,10 +122,4 @@ class HomeDeepLinkIntentProcessor( } } } - - companion object { - private const val SETTINGS_SELECT_OPTION_KEY = ":settings:fragment_args_key" - private const val SETTINGS_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args" - private const val DEFAULT_BROWSER_APP_OPTION = "default_browser" - } }