mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/25145: Unify behavior for opening systems setting for updating the default browser preference
This commit is contained in:
parent
4befb1746f
commit
994fdaec0f
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user