Skip to content

Commit 624e316

Browse files
Update tooling to targetSdkVersion 29 and compileSdkVersion 29 (#899)
* Update targetSdkVersion and compileSdkVersion to 29 - Fixed nullability issue with StringHtmlExtension.kt extension function - Fixed nullability issue with NavigationAwareLoginDetector.kt - Fixed nullability issue with BrowserTabFragment.kt's interaction with ClipboardManager - Fixed nullability issue with NotificationHandlerService.kt's intent parsing * Lint fixes * Fix possible null pointer exceptions when getting host from Uri * change logic inside to fix compiling issues with api 29 Co-authored-by: Cristian Monforte <[email protected]>
1 parent cd5e991 commit 624e316

File tree

11 files changed

+54
-28
lines changed

11 files changed

+54
-28
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ ext {
1111
}
1212

1313
android {
14-
compileSdkVersion 28
14+
compileSdkVersion 29
1515
ndkVersion '21.0.6113669'
1616
defaultConfig {
1717
applicationId "com.duckduckgo.mobile.android"
1818
minSdkVersion 21
19-
targetSdkVersion 28
19+
targetSdkVersion 29
2020
versionCode buildVersionCode()
2121
versionName buildVersionName()
2222
testInstrumentationRunner "com.duckduckgo.app.TestRunner"

app/src/androidTest/java/com/duckduckgo/app/browser/filechooser/FileChooserIntentBuilderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ class FileChooserIntentBuilderTest {
6969
@Test
7070
fun whenUpperCaseTypesGivenThenNormalisedToLowercase() {
7171
val output = testee.intent(arrayOf("ImAgE/PnG"))
72-
assertEquals("image/png", output.getStringArrayExtra(Intent.EXTRA_MIME_TYPES)[0])
72+
assertEquals("image/png", output.getStringArrayExtra(Intent.EXTRA_MIME_TYPES)!![0])
7373
}
7474

7575
@Test
7676
fun whenEmptyTypesGivenThenNotIncludedInOutput() {
7777
val output = testee.intent(arrayOf("image/png", "", " ", "image/gif"))
7878
val mimeTypes = output.getStringArrayExtra(Intent.EXTRA_MIME_TYPES)
79-
assertEquals(2, mimeTypes.size)
79+
assertEquals(2, mimeTypes!!.size)
8080
assertEquals("image/png", mimeTypes[0])
8181
assertEquals("image/gif", mimeTypes[1])
8282
}

app/src/androidTest/java/com/duckduckgo/app/browser/logindetection/NextPageLoginDetectionTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ class NextPageLoginDetectionTest {
146146
assertEventNotIssued<LoginDetected>()
147147
}
148148

149+
@Test
150+
fun whenLoginAttemptedHasInvalidURLThenNewPageDoesNotDetectLogin() {
151+
loginDetector.onEvent(NavigationEvent.LoginAttempt(""))
152+
153+
loginDetector.onEvent(NavigationEvent.WebNavigationEvent(NewPage(url = "http://example.com", title = "")))
154+
155+
assertEventNotIssued<LoginDetected>()
156+
}
157+
158+
@Test
159+
fun whenLoginAttemptedAndUserForwardedToInvalidNewPageThenLoginDetected() {
160+
loginDetector.onEvent(NavigationEvent.LoginAttempt("http://example.com/login"))
161+
162+
loginDetector.onEvent(NavigationEvent.WebNavigationEvent(NewPage(url = "", title = "")))
163+
164+
assertEventNotIssued<LoginDetected>()
165+
}
166+
149167
private inline fun <reified T> assertEvent(instanceAssertions: T.() -> Unit = {}) {
150168
verify(loginObserver, atLeastOnce()).onChanged(loginEventCaptor.capture())
151169
val issuedCommand = loginEventCaptor.allValues.find { it is T }

app/src/androidTest/java/com/duckduckgo/app/di/StubJobSchedulerModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class StubJobSchedulerModule {
3636
@Provides
3737
fun providesJobScheduler(): JobScheduler {
3838
return object : JobScheduler() {
39-
override fun enqueue(job: JobInfo?, work: JobWorkItem?): Int = JobScheduler.RESULT_SUCCESS
39+
override fun enqueue(job: JobInfo, work: JobWorkItem): Int = JobScheduler.RESULT_SUCCESS
4040

41-
override fun schedule(job: JobInfo?): Int = JobScheduler.RESULT_SUCCESS
41+
override fun schedule(job: JobInfo): Int = JobScheduler.RESULT_SUCCESS
4242

4343
override fun cancel(jobId: Int) {}
4444

app/src/androidTest/java/com/duckduckgo/app/fire/RemoveCookiesTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import com.nhaarman.mockitokotlin2.mock
2020
import com.nhaarman.mockitokotlin2.verify
2121
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
2222
import com.nhaarman.mockitokotlin2.whenever
23+
import kotlinx.coroutines.ExperimentalCoroutinesApi
2324
import kotlinx.coroutines.test.runBlockingTest
2425
import org.junit.Test
2526

27+
@ExperimentalCoroutinesApi
2628
class RemoveCookiesTest {
2729

2830
private val selectiveCookieRemover = mock<CookieRemover>()

app/src/androidTest/java/com/duckduckgo/app/icon/ui/ChangeIconViewModelTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import com.duckduckgo.app.statistics.pixels.Pixel
2626
import com.nhaarman.mockitokotlin2.mock
2727
import com.nhaarman.mockitokotlin2.verify
2828
import com.nhaarman.mockitokotlin2.whenever
29-
import junit.framework.Assert.assertTrue
3029
import org.junit.After
30+
import org.junit.Assert.assertTrue
3131
import org.junit.Rule
3232
import org.junit.Test
3333
import org.mockito.Mockito

app/src/androidTest/java/com/duckduckgo/app/privacy/ui/ScorecardViewModelTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import org.junit.Before
3838
import org.junit.Rule
3939
import org.junit.Test
4040

41+
@ExperimentalCoroutinesApi
4142
class ScorecardViewModelTest {
4243

4344
@get:Rule

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope, DaxDialogLi
582582
is Command.FindInPageCommand -> webView?.findAllAsync(it.searchTerm)
583583
is Command.DismissFindInPage -> webView?.findAllAsync("")
584584
is Command.ShareLink -> launchSharePageChooser(it.url)
585-
is Command.CopyLink -> {
586-
clipboardManager.primaryClip = ClipData.newPlainText(null, it.url)
587-
}
585+
is Command.CopyLink -> clipboardManager.setPrimaryClip(ClipData.newPlainText(null, it.url))
588586
is Command.ShowFileChooser -> {
589587
launchFilePicker(it)
590588
}

app/src/main/java/com/duckduckgo/app/browser/logindetection/NavigationAwareLoginDetector.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ sealed class NavigationEvent {
4545

4646
class NextPageLoginDetection @Inject constructor() : NavigationAwareLoginDetector {
4747

48-
private var loginAttempt: NavigationEvent.LoginAttempt? = null
4948
override val loginEventLiveData = MutableLiveData<LoginDetected>()
49+
private var loginAttempt: ValidUrl? = null
5050

5151
override fun onEvent(navigationEvent: NavigationEvent) {
5252
Timber.i("LoginDetectionDelegate $navigationEvent")
@@ -67,7 +67,7 @@ class NextPageLoginDetection @Inject constructor() : NavigationAwareLoginDetecto
6767
}
6868

6969
private fun saveLoginAttempt(navigationEvent: NavigationEvent.LoginAttempt) {
70-
loginAttempt = navigationEvent
70+
loginAttempt = Uri.parse(navigationEvent.url).getValidUrl() ?: return
7171
}
7272

7373
private fun discardLoginAttempt() {
@@ -91,16 +91,21 @@ class NextPageLoginDetection @Inject constructor() : NavigationAwareLoginDetecto
9191
}
9292
}
9393

94-
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
9594
private fun detectLogin(forwardedToUrl: String) {
96-
val loginAttemptEvent = loginAttempt ?: return
97-
val loginURI = Uri.parse(loginAttemptEvent.url).takeUnless { it.host.isNullOrBlank() } ?: return
98-
val forwardedToUri = Uri.parse(forwardedToUrl).takeUnless { it.host.isNullOrBlank() } ?: return
95+
val validLoginAttempt = loginAttempt ?: return
96+
val forwardedToUri = Uri.parse(forwardedToUrl).getValidUrl() ?: return
9997

100-
Timber.i("LoginDetectionDelegate ${loginAttemptEvent.url} vs $forwardedToUrl")
101-
if (loginURI.host != forwardedToUri.host || loginURI.path != forwardedToUri.path) {
102-
loginEventLiveData.value = LoginDetected(loginURI.host, forwardedToUri.host)
98+
Timber.i("LoginDetectionDelegate $validLoginAttempt vs $forwardedToUrl")
99+
if (validLoginAttempt.host != forwardedToUri.host || validLoginAttempt.path != forwardedToUri.path) {
100+
loginEventLiveData.value = LoginDetected(validLoginAttempt.host, forwardedToUri.host)
103101
loginAttempt = null
104102
}
105103
}
104+
105+
private fun Uri.getValidUrl(): ValidUrl? {
106+
val validHost = host ?: return null
107+
return ValidUrl(validHost, path)
108+
}
109+
110+
private data class ValidUrl(val host: String, val path: String?)
106111
}

app/src/main/java/com/duckduckgo/app/global/view/StringHtmlExtension.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import android.net.Uri
2222
import android.os.Build
2323
import android.text.Html.*
2424
import android.text.Spanned
25+
import androidx.core.content.ContextCompat
2526

2627
@Suppress("deprecation")
2728
fun String.html(context: Context): Spanned {
@@ -31,10 +32,10 @@ fun String.html(context: Context): Spanned {
3132
return fromHtml(this, ImageGetter { htmlDrawable(context, it.toInt()) }, null)
3233
}
3334

34-
private fun htmlDrawable(context: Context, resource: Int): Drawable {
35-
val drawable = context.getDrawable(resource)
36-
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
37-
return drawable
35+
private fun htmlDrawable(context: Context, resource: Int): Drawable? {
36+
return ContextCompat.getDrawable(context, resource)?.also {
37+
it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight)
38+
}
3839
}
3940

4041
private const val HTTPS_PREFIX = "https://"

0 commit comments

Comments
 (0)