Merge remote-tracking branch 'origin/fenix/113.1.0' into iceraven

pull/636/head
akliuxingyuan 1 year ago
commit 31a7442660

@ -17,7 +17,6 @@ import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import androidx.annotation.VisibleForTesting
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.children
import androidx.viewbinding.ViewBinding
@ -25,8 +24,6 @@ import mozilla.components.feature.downloads.databinding.MozacDownloaderChooserPr
import mozilla.components.feature.downloads.toMegabyteOrKilobyteString
import mozilla.components.feature.downloads.ui.DownloaderApp
import mozilla.components.feature.downloads.ui.DownloaderAppAdapter
import mozilla.components.support.ktx.android.view.setNavigationBarTheme
import mozilla.components.support.ktx.android.view.setStatusBarTheme
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.DialogScrimBinding
import org.mozilla.fenix.databinding.StartDownloadDialogLayoutBinding
@ -51,12 +48,6 @@ abstract class StartDownloadDialog(
@VisibleForTesting
internal var onDismiss: () -> Unit = {}
@VisibleForTesting
internal var initialNavigationBarColor = activity.window.navigationBarColor
@VisibleForTesting
internal var initialStatusBarColor = activity.window.statusBarColor
/**
* Show the download view.
*
@ -89,10 +80,6 @@ abstract class StartDownloadDialog(
elevation = activity.resources.getDimension(R.dimen.browser_fragment_download_dialog_elevation)
visibility = View.VISIBLE
}
activity.window.setNavigationBarTheme(ContextCompat.getColor(activity, R.color.material_scrim_color))
activity.window.setStatusBarTheme(ContextCompat.getColor(activity, R.color.material_scrim_color))
return this
}
@ -121,9 +108,6 @@ abstract class StartDownloadDialog(
container?.visibility = View.GONE
activity.window.setNavigationBarTheme(initialNavigationBarColor)
activity.window.setStatusBarTheme(initialStatusBarColor)
onDismiss()
}

@ -12,6 +12,7 @@ import android.provider.Settings
import android.view.View
import android.view.WindowManager
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import mozilla.components.concept.base.crash.Breadcrumb
@ -88,48 +89,87 @@ fun Activity.openSetDefaultBrowserOption(
REQUEST_CODE_BROWSER_ROLE,
)
} else {
navigateToDefaultBrowserAppsSettings()
navigateToDefaultBrowserAppsSettings(
useCustomTab = useCustomTab,
from = from,
flags = flags,
)
}
}
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
navigateToDefaultBrowserAppsSettings()
navigateToDefaultBrowserAppsSettings(
useCustomTab = useCustomTab,
from = from,
flags = flags,
)
}
else -> {
val sumoDefaultBrowserUrl = SupportUtils.getGenericSumoURLForTopic(
topic = SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER,
)
if (useCustomTab) {
startActivity(
SupportUtils.createSandboxCustomTabIntent(
context = this,
url = sumoDefaultBrowserUrl,
),
)
} else {
(this as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = sumoDefaultBrowserUrl,
newTab = true,
from = from,
flags = flags,
)
}
openDefaultBrowserSumoPage(useCustomTab, from, flags)
}
}
}
private fun Activity.navigateToDefaultBrowserAppsSettings() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val intent = Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS)
intent.putExtra(
SETTINGS_SELECT_OPTION_KEY,
DEFAULT_BROWSER_APP_OPTION,
)
intent.putExtra(
@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(
topic = SupportUtils.SumoTopic.SET_AS_DEFAULT_BROWSER,
)
if (useCustomTab) {
startActivity(
SupportUtils.createSandboxCustomTabIntent(
context = this,
url = sumoDefaultBrowserUrl,
),
)
} else {
(this as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = sumoDefaultBrowserUrl,
newTab = true,
from = from,
flags = flags,
)
}
}
/**
* Checks for the presence of an activity before starting it. In case it's not present,
* [onActivityNotPresent] is invoked, preventing ActivityNotFoundException from being thrown.
* This is useful when navigating to external activities like device permission settings,
* notification settings, default app settings, etc.
*
* @param intent The Intent of the activity to resolve and start.
* @param onActivityNotPresent Invoked when the activity to handle the intent is not present.
*/
inline fun Activity.startExternalActivitySafe(intent: Intent, onActivityNotPresent: () -> Unit) {
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
} else {
onActivityNotPresent()
}
}

@ -6,21 +6,16 @@ package org.mozilla.fenix.downloads
import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.view.isVisible
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import mozilla.components.support.ktx.android.view.setNavigationBarTheme
import mozilla.components.support.ktx.android.view.setStatusBarTheme
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@ -37,20 +32,6 @@ import org.robolectric.Robolectric
@RunWith(FenixRobolectricTestRunner::class)
class StartDownloadDialogTest {
@Test
fun `WHEN the dialog is instantiated THEN cache the navigation and status bar colors`() {
val navigationBarColor = Color.RED
val statusBarColor = Color.BLUE
val activity: Activity = mockk {
every { window.navigationBarColor } returns navigationBarColor
every { window.statusBarColor } returns statusBarColor
}
val dialog = TestDownloadDialog(activity)
assertEquals(navigationBarColor, dialog.initialNavigationBarColor)
assertEquals(statusBarColor, dialog.initialStatusBarColor)
}
@Test
fun `WHEN the view is to be shown THEN set the scrim and other window customization bind the download values`() {
val activity = Robolectric.buildActivity(Activity::class.java).create().get()
@ -78,10 +59,6 @@ class StartDownloadDialogTest {
dialogContainer.elevation,
)
assertTrue(dialogContainer.isVisible)
verify {
activity.window.setNavigationBarTheme(ContextCompat.getColor(activity, R.color.material_scrim_color))
activity.window.setStatusBarTheme(ContextCompat.getColor(activity, R.color.material_scrim_color))
}
assertEquals(dialog, fluentDialog)
}
}
@ -119,10 +96,6 @@ class StartDownloadDialogTest {
assertTrue(dialogParent.childCount == 1)
assertTrue(dialogContainer.childCount == 0)
assertFalse(dialogContainer.isVisible)
verify {
activity.window.setNavigationBarTheme(dialog.initialNavigationBarColor)
activity.window.setStatusBarTheme(dialog.initialStatusBarColor)
}
}
}

@ -8,8 +8,6 @@ import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
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.navigation.NavController
import io.mockk.Called
@ -238,16 +236,6 @@ class HomeDeepLinkIntentProcessorTest {
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
@Config(maxSdk = M)
fun `process make_default_browser deep link for API 23 and below`() {

Loading…
Cancel
Save