Repository navigation
fix(avatar): decode and save the remote avatar off the main thread #6863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mahibi
merged 4 commits into
nextcloud:master
from
ToteMeiSter:fix/provider-main-avatar
Oct 15, 2026
+154
−32
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9ca1878
fix(avatar): decode and save the remote avatar off the main thread
ToteMeiSter 8e4c6f9
fix(avatar): tell the user when the remote avatar cannot be loaded
ToteMeiSter a0d9a78
fix(avatar): close the thumbnail body when the activity is already de…
ToteMeiSter ca2a708
test(avatar): run PickImageTest on API 33 like the other Robolectric …
ToteMeiSter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/src/test/java/com/nextcloud/talk/utils/PickImageTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Nextcloud Talk - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
|
|
||
| package com.nextcloud.talk.utils | ||
|
|
||
| import android.graphics.Bitmap | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.Job | ||
| import okhttp3.MediaType.Companion.toMediaType | ||
| import okhttp3.ResponseBody | ||
| import okhttp3.ResponseBody.Companion.toResponseBody | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNotNull | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.rules.TemporaryFolder | ||
| import org.junit.runner.RunWith | ||
| import org.mockito.Mockito.mock | ||
| import org.mockito.Mockito.verify | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
| import java.io.ByteArrayOutputStream | ||
| import java.io.File | ||
| import java.io.IOException | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(sdk = [33]) | ||
| class PickImageTest { | ||
|
|
||
| @get:Rule | ||
| val tmp = TemporaryFolder() | ||
|
|
||
| private fun pngBody(): ResponseBody { | ||
| val out = ByteArrayOutputStream() | ||
| Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888).compress(Bitmap.CompressFormat.PNG, 100, out) | ||
| return out.toByteArray().toResponseBody("image/png".toMediaType()) | ||
| } | ||
|
|
||
| @Test | ||
| fun nullBodyYieldsNull() { | ||
| assertNull(decodeAvatarToFile(null) { tmp.newFile() }) | ||
| } | ||
|
|
||
| @Test | ||
| fun undecodableBodyYieldsNull() { | ||
| val body = "not an image".toResponseBody("image/png".toMediaType()) | ||
| assertNull(decodeAvatarToFile(body, decode = { null }) { tmp.newFile() }) | ||
| } | ||
|
|
||
| @Test | ||
| fun writeFailureYieldsNull() { | ||
| assertNull(decodeAvatarToFile(pngBody()) { throw IOException("disk full") }) | ||
| } | ||
|
|
||
| @Test | ||
| fun unwritableTargetYieldsNull() { | ||
| val dir: File = tmp.newFolder() | ||
| assertNull(decodeAvatarToFile(pngBody()) { dir }) | ||
| } | ||
|
|
||
| @Test | ||
| fun validBodyIsSavedAsPng() { | ||
| val target = tmp.newFile() | ||
| val result = decodeAvatarToFile(pngBody()) { target } | ||
| assertNotNull(result) | ||
| assertEquals(target, result) | ||
| assertTrue(target.length() > 0) | ||
| } | ||
|
|
||
| @Test | ||
| fun bodyIsClosedWhenTheScopeIsAlreadyCancelled() { | ||
| val body = mock(ResponseBody::class.java) | ||
| var started = false | ||
| val scope = CoroutineScope(Job().apply { cancel() } + Dispatchers.Unconfined) | ||
|
|
||
| scope.launchClosing(body) { started = true } | ||
|
|
||
| assertTrue(!started) | ||
| verify(body).close() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.