Skip to content

Commit 80b194e

Browse files
committed
Fix top crashes from Play Store
1 parent a6fc5b4 commit 80b194e

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

opencloudApp/src/main/java/eu/opencloud/android/presentation/thumbnails/ThumbnailsRequester.kt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,16 @@ object ThumbnailsRequester : KoinComponent {
148148
}
149149

150150
private fun buildThumbnailImageLoader(account: Account): ImageLoader {
151-
val openCloudClient = clientManager.getClientForCoilThumbnails(account.name)
152151
val interceptor = CoilRequestHeaderInterceptor(clientManager, account.name)
153152
return ImageLoader(appContext).newBuilder()
154-
.okHttpClient(
155-
openCloudClient.okHttpClient.newBuilder()
153+
.okHttpClient {
154+
// Lazy: deferred to first image request (off main thread).
155+
// getClientForCoilThumbnails calls blockingGetAuthToken which
156+
// must not run on the main thread.
157+
clientManager.getClientForCoilThumbnails(account.name)
158+
.okHttpClient.newBuilder()
156159
.addInterceptor(interceptor).build()
157-
)
160+
}
158161
.apply { if (preferencesProvider.getBoolean("enable_logging", false)) logger(DebugLogger()) }
159162
.memoryCache { sharedMemoryCache }
160163
.diskCache { sharedDiskCache }
@@ -163,15 +166,15 @@ object ThumbnailsRequester : KoinComponent {
163166
}
164167

165168
private fun buildAvatarImageLoader(account: Account): ImageLoader {
166-
val openCloudClient = clientManager.getClientForCoilThumbnails(account.name)
167169
val interceptor = CoilRequestHeaderInterceptor(clientManager, account.name)
168170
return ImageLoader(appContext).newBuilder()
169-
.okHttpClient(
170-
openCloudClient.okHttpClient.newBuilder()
171+
.okHttpClient {
172+
clientManager.getClientForCoilThumbnails(account.name)
173+
.okHttpClient.newBuilder()
171174
.addInterceptor(interceptor)
172175
.cache(avatarHttpCache)
173176
.build()
174-
)
177+
}
175178
.apply { if (preferencesProvider.getBoolean("enable_logging", false)) logger(DebugLogger()) }
176179
.memoryCache { sharedMemoryCache }
177180
// No Coil disk cache — OkHttp's HTTP cache handles persistence
@@ -187,7 +190,18 @@ object ThumbnailsRequester : KoinComponent {
187190
) : Interceptor {
188191

189192
override fun intercept(chain: Interceptor.Chain): Response {
190-
val openCloudClient = clientManager.getClientForCoilThumbnails(accountName)
193+
val openCloudClient = try {
194+
clientManager.getClientForCoilThumbnails(accountName)
195+
} catch (e: Exception) {
196+
Timber.d(e, "Account $accountName not found, skipping thumbnail request")
197+
return Response.Builder()
198+
.request(chain.request())
199+
.protocol(okhttp3.Protocol.HTTP_1_1)
200+
.code(401)
201+
.message("Account not found")
202+
.body(okhttp3.ResponseBody.create(null, ""))
203+
.build()
204+
}
191205
val credentials = openCloudClient.credentials
192206
?: return Response.Builder()
193207
.request(chain.request())

opencloudApp/src/main/java/eu/opencloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,10 @@ class FileDisplayActivity : FileActivity(),
17751775
}
17761776

17771777
private fun navigateTo(newFileListOption: FileListOption, initialState: Boolean = false) {
1778+
// account can be null if it was removed while the activity was still visible.
1779+
// swapToDefaultAccount (called from onRestart/onNewIntent) launches the login
1780+
// wizard asynchronously, but we can't navigate without an account.
1781+
if (account == null) return
17781782
val previousFileListOption = fileListOption
17791783
when (newFileListOption) {
17801784
FileListOption.ALL_FILES -> {

opencloudDomain/src/main/java/eu/opencloud/android/domain/spaces/usecases/GetSpaceWithSpecialsByIdForAccountUseCase.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class GetSpaceWithSpecialsByIdForAccountUseCase(
3030

3131
override fun run(params: Params): OCSpace? {
3232
if (params.spaceId == null) return null
33-
return spacesRepository.getSpaceWithSpecialsByIdForAccount(params.spaceId, params.accountName)
33+
return try {
34+
spacesRepository.getSpaceWithSpecialsByIdForAccount(params.spaceId, params.accountName)
35+
} catch (_: Exception) {
36+
null
37+
}
3438
}
3539

3640
data class Params(

0 commit comments

Comments
 (0)