For #25145: Unify behavior for opening systems setting for updating the default browser preference
This commit is contained in:
parent
fc76300325
commit
073f3ecc30
|
@ -15,6 +15,7 @@ import android.provider.Settings
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
|
import mozilla.components.concept.engine.EngineSession
|
||||||
import org.mozilla.fenix.BrowserDirection
|
import org.mozilla.fenix.BrowserDirection
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
@ -64,8 +65,15 @@ fun Activity.breadcrumb(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens Android's Manage Default Apps Settings if possible.
|
* 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 {
|
when {
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> {
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> {
|
||||||
getSystemService(RoleManager::class.java).also {
|
getSystemService(RoleManager::class.java).also {
|
||||||
|
@ -92,7 +100,8 @@ fun Activity.openSetDefaultBrowserOption() {
|
||||||
SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER
|
SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER
|
||||||
),
|
),
|
||||||
newTab = true,
|
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
|
||||||
import android.os.Build.VERSION.SDK_INT
|
import android.os.Build.VERSION.SDK_INT
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.core.os.bundleOf
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import mozilla.components.concept.engine.EngineSession
|
import mozilla.components.concept.engine.EngineSession
|
||||||
import mozilla.components.support.base.log.logger.Logger
|
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.HomeActivity
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||||
import org.mozilla.fenix.ext.alreadyOnDestination
|
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.
|
* Deep links in the form of `fenix://host` open different parts of the app.
|
||||||
|
@ -80,28 +79,11 @@ class HomeDeepLinkIntentProcessor(
|
||||||
activity.browsingModeManager.mode = BrowsingMode.Private
|
activity.browsingModeManager.mode = BrowsingMode.Private
|
||||||
}
|
}
|
||||||
"make_default_browser" -> {
|
"make_default_browser" -> {
|
||||||
if (SDK_INT >= Build.VERSION_CODES.N) {
|
activity.openSetDefaultBrowserOption(
|
||||||
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,
|
from = BrowserDirection.FromGlobal,
|
||||||
flags = EngineSession.LoadUrlFlags.external()
|
flags = EngineSession.LoadUrlFlags.external()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
"open" -> {
|
"open" -> {
|
||||||
val url = deepLink.getQueryParameter("url")
|
val url = deepLink.getQueryParameter("url")
|
||||||
if (url == null || !url.startsWith("https://")) {
|
if (url == null || !url.startsWith("https://")) {
|
||||||
|
@ -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