Unverified Commit c99a8f5c authored by Tiger Oakes's avatar Tiger Oakes Committed by GitHub
Browse files

Fixes #9832 - Change targetSdkVersion to Android 10 (#11014)

parent 63eb7b3e
......@@ -20,7 +20,7 @@ import org.mozilla.fenix.gradle.tasks.LintUnitTestRunner
import static org.gradle.api.tasks.testing.TestResult.ResultType
android {
compileSdkVersion 28
compileSdkVersion Config.compileSdkVersion
defaultConfig {
applicationId "org.mozilla"
minSdkVersion Config.minSdkVersion
......
......@@ -9,7 +9,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.CoordinatesProvider
......
......@@ -6,35 +6,32 @@ package org.mozilla.fenix.syncintegration
import android.os.SystemClock.sleep
import android.widget.EditText
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.HomeActivityTestRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import okhttp3.mockwebserver.MockWebServer
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.ext.toUri
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.accountSettings
import org.mozilla.fenix.ui.robots.settingsSubMenuLoginsAndPassword
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.settingsSubMenuLoginsAndPassword
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
class SyncIntegrationTest {
......@@ -185,7 +182,7 @@ class SyncIntegrationTest {
.className(EditText::class.java))
emailInput.waitForExists(TestAssetHelper.waitingTime)
val emailAddress = javaClass.classLoader.getResource("email.txt").readText()
val emailAddress = javaClass.classLoader!!.getResource("email.txt").readText()
emailInput.setText(emailAddress)
}
......@@ -199,7 +196,7 @@ class SyncIntegrationTest {
.instance(0)
.className(EditText::class.java))
val passwordValue = javaClass.classLoader.getResource("password.txt").readText()
val passwordValue = javaClass.classLoader!!.getResource("password.txt").readText()
passwordInput.setText(passwordValue)
}
......
......@@ -55,6 +55,7 @@ class DownloadTest {
}
}
@Suppress("Deprecation")
@After
fun tearDown() {
mockWebServer.shutdown()
......
......@@ -34,8 +34,8 @@ import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.ChronoField
import java.util.Date
import java.util.Calendar
import java.util.Date
/**
* Implementation of Robot Pattern for the settings search sub menu.
......@@ -250,7 +250,9 @@ class BuildDateAssertion {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
val simpleDateFormat = SimpleDateFormat(DATE_PATTERN)
val date = simpleDateFormat.parse(dateText)
if (!date.isWithinRangeOf(hours)) throw AssertionError("The build date is not within Range.")
if (date == null || !date.isWithinRangeOf(hours)) {
throw AssertionError("The build date is not within Range.")
}
} else {
val textviewDate = getLocalDateTimeFromString(dateText)
val buildConfigDate = getLocalDateTimeFromString(BuildConfig.BUILD_DATE)
......
......@@ -6,9 +6,7 @@ package org.mozilla.fenix.library.bookmarks
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.res.Resources
import androidx.core.content.getSystemService
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import kotlinx.coroutines.CoroutineScope
......@@ -51,8 +49,9 @@ interface BookmarkController {
@SuppressWarnings("TooManyFunctions")
class DefaultBookmarkController(
private val context: Context,
private val activity: HomeActivity,
private val navController: NavController,
private val clipboardManager: ClipboardManager?,
private val scope: CoroutineScope,
private val store: BookmarkFragmentStore,
private val sharedViewModel: BookmarksSharedViewModel,
......@@ -63,8 +62,7 @@ class DefaultBookmarkController(
private val invokePendingDeletion: () -> Unit
) : BookmarkController {
private val activity: HomeActivity = context as HomeActivity
private val resources: Resources = context.resources
private val resources: Resources = activity.resources
override fun handleBookmarkChanged(item: BookmarkNode) {
sharedViewModel.selectedFolder = item
......@@ -115,7 +113,7 @@ class DefaultBookmarkController(
override fun handleCopyUrl(item: BookmarkNode) {
val urlClipData = ClipData.newPlainText(item.url, item.url)
context.getSystemService<ClipboardManager>()?.primaryClip = urlClipData
clipboardManager?.setPrimaryClip(urlClipData)
showSnackbar(resources.getString(R.string.url_copied))
}
......@@ -143,14 +141,14 @@ class DefaultBookmarkController(
scope.launch {
store.dispatch(BookmarkFragmentAction.StartSync)
invokePendingDeletion()
context.components.backgroundServices.accountManager.syncNowAsync(SyncReason.User).await()
activity.components.backgroundServices.accountManager.syncNowAsync(SyncReason.User).await()
// The current bookmark node we are viewing may be made invalid after syncing so we
// check if the current node is valid and if it isn't we find the nearest valid ancestor
// and open it
val validAncestorGuid = store.state.guidBackstack.findLast { guid ->
context.bookmarkStorage.getBookmark(guid) != null
activity.bookmarkStorage.getBookmark(guid) != null
} ?: BookmarkRoot.Mobile.id
val node = context.bookmarkStorage.getBookmark(validAncestorGuid)!!
val node = activity.bookmarkStorage.getBookmark(validAncestorGuid)!!
handleBookmarkExpand(node)
store.dispatch(BookmarkFragmentAction.FinishSync)
}
......@@ -160,12 +158,12 @@ class DefaultBookmarkController(
invokePendingDeletion.invoke()
scope.launch {
val parentGuid = store.state.guidBackstack.findLast { guid ->
store.state.tree?.guid != guid && context.bookmarkStorage.getBookmark(guid) != null
store.state.tree?.guid != guid && activity.bookmarkStorage.getBookmark(guid) != null
}
if (parentGuid == null) {
navController.popBackStack()
} else {
val parent = context.bookmarkStorage.getBookmark(parentGuid)!!
val parent = activity.bookmarkStorage.getBookmark(parentGuid)!!
handleBookmarkExpand(parent)
}
}
......
......@@ -13,6 +13,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.content.getSystemService
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
......@@ -37,6 +38,7 @@ import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.UserInteractionHandler
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavHostActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
......@@ -85,8 +87,9 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), UserInteractionHan
_bookmarkInteractor = BookmarkFragmentInteractor(
bookmarksController = DefaultBookmarkController(
context = requireContext(),
activity = requireActivity() as HomeActivity,
navController = findNavController(),
clipboardManager = requireContext().getSystemService(),
scope = viewLifecycleOwner.lifecycleScope,
store = bookmarkStore,
sharedViewModel = sharedViewModel,
......
......@@ -81,7 +81,7 @@ class DefaultHistoryController(
override fun handleCopyUrl(item: HistoryItem) {
val urlClipData = ClipData.newPlainText(item.url, item.url)
clipboardManager.primaryClip = urlClipData
clipboardManager.setPrimaryClip(urlClipData)
with(snackbar) {
setText(resources.getString(R.string.url_copied))
show()
......
......@@ -18,6 +18,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
......@@ -270,8 +271,9 @@ class SavedLoginsAuthFragment : PreferenceFragmentCompat(), AccountObserver {
}
}
@Suppress("Deprecation")
private fun showPinVerification() {
val manager = activity?.getSystemService(KEYGUARD_SERVICE) as KeyguardManager
val manager = activity?.getSystemService<KeyguardManager>()!!
val intent = manager.createConfirmDeviceCredentialIntent(
getString(R.string.logins_biometric_prompt_message_pin),
getString(R.string.logins_biometric_prompt_message)
......
......@@ -7,6 +7,7 @@ package org.mozilla.fenix.utils
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.core.content.getSystemService
import mozilla.components.support.utils.WebURLFinder
private const val MIME_TYPE_TEXT_PLAIN = "text/plain"
......@@ -16,7 +17,7 @@ private const val MIME_TYPE_TEXT_HTML = "text/html"
* A clipboard utility class that allows copying and pasting links/text to & from the clipboard
*/
class ClipboardHandler(context: Context) {
private val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
private val clipboard = context.getSystemService<ClipboardManager>()!!
var text: String?
get() {
......@@ -29,7 +30,7 @@ class ClipboardHandler(context: Context) {
return null
}
set(value) {
clipboard.primaryClip = ClipData.newPlainText("Text", value)
clipboard.setPrimaryClip(ClipData.newPlainText("Text", value))
}
val url: String?
......
......@@ -6,7 +6,7 @@ package org.mozilla.fenix.whatsnew
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager
import java.util.concurrent.TimeUnit
// This file is a modified port from Focus Android
......
......@@ -37,7 +37,7 @@ class DrawableTest {
override fun draw(canvas: Canvas) {}
override fun setAlpha(alpha: Int) {}
override fun setColorFilter(cf: ColorFilter) {}
override fun setColorFilter(cf: ColorFilter?) {}
override fun onBoundsChange(bounds: Rect) {
boundsChanged = true
super.onBoundsChange(bounds)
......
......@@ -7,7 +7,6 @@ package org.mozilla.fenix.library.bookmarks
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.core.content.getSystemService
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavDirections
......@@ -18,7 +17,6 @@ import io.mockk.coVerify
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.slot
import io.mockk.spyk
......@@ -42,7 +40,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.bookmarkStorage
import org.mozilla.fenix.ext.components
@SuppressWarnings("TooManyFunctions", "LargeClass")
@Suppress("TooManyFunctions", "LargeClass")
@ExperimentalCoroutinesApi
class BookmarkControllerTest {
......@@ -51,6 +49,7 @@ class BookmarkControllerTest {
private val bookmarkStore = spyk(BookmarkFragmentStore(BookmarkFragmentState(null)))
private val context: Context = mockk(relaxed = true)
private val scope = TestCoroutineScope()
private val clipboardManager: ClipboardManager = mockk(relaxUnitFun = true)
private val navController: NavController = mockk(relaxed = true)
private val sharedViewModel: BookmarksSharedViewModel = mockk()
private val loadBookmarkNode: suspend (String) -> BookmarkNode? = mockk(relaxed = true)
......@@ -90,13 +89,6 @@ class BookmarkControllerTest {
@Before
fun setup() {
// needed for mocking 'getSystemService<ClipboardManager>()'
mockkStatic(
"androidx.core.content.ContextCompat",
"android.content.ClipData",
"org.mozilla.fenix.ext.ContextKt"
)
every { homeActivity.components.services } returns services
every { navController.currentDestination } returns NavDestination("").apply {
id = R.id.bookmarkFragment
......@@ -105,8 +97,9 @@ class BookmarkControllerTest {
every { sharedViewModel.selectedFolder = any() } just runs
controller = DefaultBookmarkController(
context = homeActivity,
activity = homeActivity,
navController = navController,
clipboardManager = clipboardManager,
scope = scope,
store = bookmarkStore,
sharedViewModel = sharedViewModel,
......@@ -247,10 +240,7 @@ class BookmarkControllerTest {
@Test
fun `handleCopyUrl should copy bookmark url to clipboard and show a toast`() {
val clipboardManager: ClipboardManager = mockk(relaxed = true)
val urlCopiedMessage = context.getString(R.string.url_copied)
every { any<Context>().getSystemService<ClipboardManager>() } returns clipboardManager
every { ClipData.newPlainText(any(), any()) } returns mockk(relaxed = true)
controller.handleCopyUrl(item)
......
......@@ -178,7 +178,7 @@ class HistoryControllerTest {
controller.handleCopyUrl(historyItem)
verify {
clipboardManager.primaryClip = capture(clipdata)
clipboardManager.setPrimaryClip(capture(clipdata))
snackbar.show()
}
assertEquals(1, clipdata.captured.itemCount)
......
......@@ -7,12 +7,12 @@ package org.mozilla.fenix.utils
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class ClipboardHandlerTest {
......@@ -32,7 +32,7 @@ class ClipboardHandlerTest {
fun getText() {
assertEquals(null, clipboardHandler.text)
clipboard.primaryClip = ClipData.newPlainText("Text", clipboardText)
clipboard.setPrimaryClip(ClipData.newPlainText("Text", clipboardText))
assertEquals(clipboardText, clipboardHandler.text)
}
......@@ -48,7 +48,7 @@ class ClipboardHandlerTest {
fun getUrl() {
assertEquals(null, clipboardHandler.url)
clipboard.primaryClip = ClipData.newPlainText("Text", clipboardUrl)
clipboard.setPrimaryClip(ClipData.newPlainText("Text", clipboardUrl))
assertEquals(clipboardUrl, clipboardHandler.url)
}
......@@ -56,7 +56,7 @@ class ClipboardHandlerTest {
fun getUrlfromTextUrlMIME() {
assertEquals(null, clipboardHandler.url)
clipboard.primaryClip = ClipData.newHtmlText("Html", clipboardUrl, clipboardUrl)
clipboard.setPrimaryClip(ClipData.newHtmlText("Html", clipboardUrl, clipboardUrl))
assertEquals(clipboardUrl, clipboardHandler.url)
}
}
......@@ -23,11 +23,11 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.HomeActivity.Companion.OPEN_TO_BROWSER_AND_LOAD
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.widget.VoiceSearchActivity.Companion.PREVIOUS_INTENT
import org.mozilla.fenix.widget.VoiceSearchActivity.Companion.SPEECH_PROCESSING
import org.mozilla.fenix.widget.VoiceSearchActivity.Companion.SPEECH_REQUEST_CODE
import org.robolectric.Robolectric
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.robolectric.Shadows
import org.robolectric.android.controller.ActivityController
import org.robolectric.shadows.ShadowActivity
......@@ -96,7 +96,7 @@ class VoiceSearchActivityTest {
controller.create(savedInstanceState)
controller.saveInstanceState(outState)
assertEquals(previousIntent, outState.getParcelable(PREVIOUS_INTENT) as Intent)
assertEquals(previousIntent, outState.getParcelable<Intent>(PREVIOUS_INTENT))
}
@Test
......
......@@ -13,9 +13,9 @@ import java.util.Locale
object Config {
// Synchronized build configuration for all modules
const val compileSdkVersion = 28
const val compileSdkVersion = 29
const val minSdkVersion = 21
const val targetSdkVersion = 28
const val targetSdkVersion = 29
@JvmStatic
private fun generateDebugVersionName(): String {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment