π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Make Ensu pass shared Android lint
Manav Rathifd27770809bb
diff --git a/android/apps/ensu/app/build.gradle.kts b/android/apps/ensu/app/build.gradle.ktsindex d6f14a8e11..c85b517723 100644--- a/android/apps/ensu/app/build.gradle.kts+++ b/android/apps/ensu/app/build.gradle.kts@@ -125,38 +125,34 @@ android {kotlin { compilerOptions { jvmTarget.set(JvmTarget.JVM_17) } }dependencies {- val composeBom = platform("androidx.compose:compose-bom:2024.02.02")-- implementation(composeBom)- androidTestImplementation(composeBom)+ val composeBom = platform("androidx.compose:compose-bom:2025.02.00")+ implementation(project(":ensu:rust"))implementation("androidx.activity:activity-compose:1.8.2")- implementation("androidx.compose.material3:material3")- implementation("androidx.compose.ui:ui")- implementation("androidx.compose.ui:ui-tooling-preview")implementation("androidx.compose.animation:animation")+ implementation("androidx.compose.material3:material3")implementation("androidx.compose.material:material-icons-core")implementation("androidx.compose.material:material-icons-extended")+ implementation("androidx.compose.ui:ui")implementation("androidx.compose.ui:ui-text")- implementation("com.google.android.material:material:1.11.0")+ implementation("androidx.compose.ui:ui-tooling-preview")implementation("androidx.core:core-ktx:1.12.0")+ implementation("androidx.datastore:datastore-preferences:1.1.1")implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")implementation("androidx.navigation:navigation-compose:2.7.7")- implementation(project(":ensu:rust"))-- implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")- implementation("androidx.datastore:datastore-preferences:1.1.1")implementation("androidx.security:security-crypto:1.1.0-alpha06")- implementation("com.squareup.okhttp3:okhttp:4.12.0")- implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")-implementation("com.github.gregcockroft:AndroidMath:v1.1.0") {exclude(group = "com.google.guava", module = "listenablefuture")}+ implementation("com.google.android.material:material:1.11.0")+ implementation("com.squareup.okhttp3:okhttp:4.12.0")+ implementation(composeBom)+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")+ implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")+ androidTestImplementation(composeBom)testImplementation("junit:junit:4.13.2")-- debugImplementation("androidx.compose.ui:ui-tooling")debugImplementation("androidx.compose.ui:ui-test-manifest")+ debugImplementation("androidx.compose.ui:ui-tooling")}diff --git a/android/apps/ensu/app/src/main/AndroidManifest.xml b/android/apps/ensu/app/src/main/AndroidManifest.xmlindex 58fc539e32..c6394f38ed 100644--- a/android/apps/ensu/app/src/main/AndroidManifest.xml+++ b/android/apps/ensu/app/src/main/AndroidManifest.xml@@ -1,5 +1,6 @@<?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">+<manifest xmlns:android="http://schemas.android.com/apk/res/android"+ xmlns:tools="http://schemas.android.com/tools"><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />@@ -11,18 +12,20 @@android:name=".EnsuApplication"android:label="@string/app_name"android:icon="@mipmap/ic_launcher"- android:roundIcon="@mipmap/ic_launcher_round"+ android:roundIcon="@mipmap/ic_launcher"android:largeHeap="true"android:allowBackup="false"android:fullBackupContent="false"android:dataExtractionRules="@xml/data_extraction_rules"android:theme="@style/Theme.Ensu"android:usesCleartextTraffic="true">+ <!-- Older Android versions safely ignore the predictive-back opt-in. --><activityandroid:name=".MainActivity"android:exported="true"android:windowSoftInputMode="adjustResize"- android:enableOnBackInvokedCallback="true">+ android:enableOnBackInvokedCallback="true"+ tools:ignore="UnusedAttribute"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" />diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/AppViewModel.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/AppViewModel.ktindex 67752eb987..bb68943b74 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/AppViewModel.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/AppViewModel.kt@@ -7,6 +7,7 @@ import androidx.lifecycle.AndroidViewModelimport androidx.lifecycle.viewModelScopeimport io.ente.ensu.chat.ChatRepositoryimport io.ente.ensu.config.loadConfigDefaults+import io.ente.ensu.coroutines.runCatchingCancellableimport io.ente.ensu.device.AndroidDeviceCapabilityProviderimport io.ente.ensu.llm.LlmProviderimport io.ente.ensu.logging.LogLevel@@ -66,12 +67,12 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {logRepository.log(LogLevel.Info, launchMessage, tag = "App")viewModelScope.launch {- runCatching {+ runCatchingCancellable {advancedSettingsDataStore.migrateLegacyModelSelection { url, mmproj ->withContext(Dispatchers.IO) { assetStore.migrate(url, mmproj) }}}- val initialSettings = runCatching {+ val initialSettings = runCatchingCancellable {advancedSettingsDataStore.settingsFlow.first()}.getOrDefault(AdvancedSettingsSnapshot())@@ -80,7 +81,7 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {modelSettings = initialSettings.modelSettings,)store.hydrateModelDownloadRequested(- runCatching { sessionPreferences.modelDownloadRequested.first() }+ runCatchingCancellable { sessionPreferences.modelDownloadRequested.first() }.getOrDefault(false))store.bootstrap(viewModelScope)diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.ktindex 24838f36db..87658544ac 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/HomeView.kt@@ -2,6 +2,7 @@package io.ente.ensu+import android.annotation.SuppressLintimport android.content.Contextimport android.content.Intentimport android.net.Uri@@ -38,11 +39,11 @@ import androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.runtime.rememberUpdatedStateimport androidx.compose.runtime.setValueimport androidx.compose.ui.Modifier-import androidx.compose.ui.platform.LocalLifecycleOwnerimport androidx.compose.ui.unit.dpimport androidx.core.content.FileProviderimport androidx.lifecycle.Lifecycleimport androidx.lifecycle.LifecycleEventObserver+import androidx.lifecycle.compose.LocalLifecycleOwnerimport androidx.navigation.compose.currentBackStackEntryAsStateimport androidx.navigation.compose.rememberNavControllerimport io.ente.ensu.bindings.ConfigDefaults@@ -66,6 +67,7 @@ import io.ente.ensu.whatsnew.WhatsNewServiceimport java.io.Fileimport java.io.FileOutputStreamimport java.util.UUID+import kotlinx.coroutines.CancellationExceptionimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.delayimport kotlinx.coroutines.launch@@ -130,6 +132,8 @@ fun HomeView(zipFile.inputStream().use { input -> input.copyTo(out) }}Toast.makeText(context, "Logs exported", Toast.LENGTH_SHORT).show()+ } catch (err: CancellationException) {+ throw err} catch (err: Throwable) {Toast.makeText(context,@@ -158,6 +162,8 @@ fun HomeView(addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)}context.startActivity(Intent.createChooser(intent, "Share logs"))+ } catch (err: CancellationException) {+ throw err} catch (err: Throwable) {Toast.makeText(context,@@ -454,6 +460,8 @@ private fun buildAttachmentFromUri(FileOutputStream(destination).use { output -> output.write(compressedBytes) }finalName = normalizedJpegAttachmentName(name ?: safeName)} else {+ // Lint misses the close performed by use.+ @SuppressLint("Recycle")val inputStream = resolver.openInputStream(uri) ?: return@runCatching nullinputStream.use { input ->FileOutputStream(destination).use { output -> input.copyTo(output) }@@ -528,6 +536,8 @@ private fun openAttachment(context: Context, attachment: Attachment) {}}+// Lint misses the close performed by use.+@SuppressLint("Recycle")private fun queryDisplayName(resolver: android.content.ContentResolver, uri: Uri): String? {resolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)?.use { cursor ->if (cursor.moveToFirst()) {@@ -538,6 +548,8 @@ private fun queryDisplayName(resolver: android.content.ContentResolver, uri: Urireturn null}+// Lint misses the close performed by use.+@SuppressLint("Recycle")private fun querySize(resolver: android.content.ContentResolver, uri: Uri): Long? {resolver.query(uri, arrayOf(OpenableColumns.SIZE), null, null, null)?.use { cursor ->if (cursor.moveToFirst()) {diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetDownloadJobService.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetDownloadJobService.ktindex ebe31487c1..1c796085ab 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetDownloadJobService.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetDownloadJobService.kt@@ -10,14 +10,13 @@ import android.content.Contextimport android.os.Buildimport android.os.SystemClockimport android.util.Log-import androidx.annotation.RequiresApiimport androidx.core.app.NotificationChannelCompatimport androidx.core.app.NotificationCompatimport androidx.core.app.NotificationManagerCompat-@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)class AssetDownloadJobService : JobService() {override fun onStartJob(params: JobParameters): Boolean {+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) return falsesynchronized(lock) {if (cancellations.isEmpty()) return falserunningJob = thisdiff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetStore.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetStore.ktindex e4a8a80823..37ee6aba84 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetStore.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/assets/AssetStore.kt@@ -16,7 +16,6 @@ import io.ente.ensu.bindings.needsAssetMigrationimport io.ente.ensu.bindings.reconcileKnowledgePackimport io.ente.ensu.bindings.uniffiEnsureInitializedimport java.io.File-import kotlinx.coroutines.CancellationExceptionimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.withContext@@ -98,10 +97,8 @@ class AssetStore(context: Context) {},token,)- } catch (e: CancellationException) {- token.cancel()- throw e} finally {+ token.cancel()AssetDownloadJobService.end(lease)}}diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.ktindex 6fecb316d3..9ad4234134 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatMessages.kt@@ -42,6 +42,7 @@ import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.collectAsStateimport androidx.compose.runtime.derivedStateOfimport androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue@@ -53,6 +54,7 @@ import androidx.compose.ui.graphics.Colorimport androidx.compose.ui.hapticfeedback.HapticFeedbackTypeimport androidx.compose.ui.input.pointer.pointerInputimport androidx.compose.ui.platform.LocalClipboardManager+import androidx.compose.ui.platform.LocalConfigurationimport androidx.compose.ui.platform.LocalUriHandlerimport androidx.compose.ui.text.AnnotatedStringimport androidx.compose.ui.text.style.TextAlign@@ -80,7 +82,6 @@ import io.ente.ensu.notes.LocalNotesStoreimport io.ente.ensu.platform.rememberHapticsimport java.text.SimpleDateFormatimport java.util.Date-import java.util.Localeimport kotlin.math.roundToIntimport kotlin.math.roundToLongimport kotlinx.coroutines.delay@@ -143,10 +144,12 @@ internal fun MessageList(var didPerformStreamingStartHaptic by remember { mutableStateOf(false) }var shouldJumpToBottomOnLoad by remember { mutableStateOf(true) }var wasAtBottomBeforeResize by remember { mutableStateOf(true) }- var lastViewportHeight by remember { mutableStateOf(0) }+ var lastViewportHeight by remember { mutableIntStateOf(0) }var lastUserMessageId by remember { mutableStateOf<String?>(null) }- var previousScrollIndex by remember { mutableStateOf(listState.firstVisibleItemIndex) }- var previousScrollOffset by remember { mutableStateOf(listState.firstVisibleItemScrollOffset) }+ var previousScrollIndex by remember { mutableIntStateOf(listState.firstVisibleItemIndex) }+ var previousScrollOffset by remember {+ mutableIntStateOf(listState.firstVisibleItemScrollOffset)+ }val isAtBottom by remember { derivedStateOf { !listState.canScrollForward } }val bottomItemIndex byremember(messages.size, isGenerating) {@@ -949,13 +952,13 @@ private fun StreamingMessageBubble()}- generatingDotsIndicator()+ GeneratingDotsIndicator()}}@Composable-private fun generatingDotsIndicator() {- var dotCount by remember { mutableStateOf(1) }+private fun GeneratingDotsIndicator() {+ var dotCount by remember { mutableIntStateOf(1) }LaunchedEffect(Unit) {while (true) {@@ -988,11 +991,11 @@ private fun hasVisibleStreamingContent(text: String): Boolean {@Composableprivate fun TimestampText(timestampMillis: Long) {+ val locale = LocalConfiguration.current.locales[0]+ val timestampFormatter = remember(locale) { SimpleDateFormat("h:mm a", locale) }Text(text = timestampFormatter.format(Date(timestampMillis)),style = EnsuTypography.mini,color = EnsuColor.textMuted(),)}--private val timestampFormatter = SimpleDateFormat("h:mm a", Locale.getDefault())diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.ktindex c396c061cc..11a60a521e 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatStoreActions.kt@@ -529,9 +529,18 @@ internal class ChatStoreActions(}if (!isActive()) return@launchhits+ } catch (error: kotlinx.coroutines.CancellationException) {+ throw error+ } catch (_: LlmProvider.EmbeddingAssetInvalid) {+ embeddingAssetInvalid = true+ emptyList()} catch (error: Throwable) {- if (error is kotlinx.coroutines.CancellationException) return@launch- embeddingAssetInvalid = error is LlmProvider.EmbeddingAssetInvalid+ logRepository.log(+ LogLevel.Warning,+ "Context retrieval failed",+ tag = "Chat",+ throwable = error,+ )emptyList()}} else {@@ -539,6 +548,8 @@ internal class ChatStoreActions(}if (!isActive()) return@launch+ var modelReady = false+ var loadFailure: Throwable? = nulltry {llmProvider.ensureModelReady(selection) { progress ->if (!isActive()) return@ensureModelReady@@ -558,41 +569,47 @@ internal class ChatStoreActions()}}+ modelReady = true+ } catch (err: kotlinx.coroutines.CancellationException) {+ throw err} catch (err: Throwable) {- val cancelled =- err is kotlinx.coroutines.CancellationException ||- err is LlmException.Cancelled ||- err is AssetDownloadException.Cancelled- if (!isActive()) return@launch- streamingParentId = null- state.update { appState ->- appState.copy(- chat =- appState.chat.copy(- isGenerating = false,- isDownloading = false,- streamingParentId = null,- downloadPercent = null,- downloadStatus = if (cancelled) "Download cancelled" else null,- downloadPhase = null,- hasRequestedModelDownload =- if (cancelled) false- else appState.chat.hasRequestedModelDownload,- )- )- }- modelSettingsActions.refreshModelDownloadInfo()- if (!cancelled) {- logRepository.log(- LogLevel.Error,- "Model load failed",- details = err.message,- tag = "Model",- throwable = err,- )+ loadFailure = err+ } finally {+ if (!modelReady && isActive()) {+ val cancelled =+ loadFailure == null ||+ loadFailure is LlmException.Cancelled ||+ loadFailure is AssetDownloadException.Cancelled+ streamingParentId = null+ state.update { appState ->+ appState.copy(+ chat =+ appState.chat.copy(+ isGenerating = false,+ isDownloading = false,+ streamingParentId = null,+ downloadPercent = null,+ downloadStatus = if (cancelled) "Download cancelled" else null,+ downloadPhase = null,+ hasRequestedModelDownload =+ if (cancelled) false+ else appState.chat.hasRequestedModelDownload,+ )+ )+ }+ modelSettingsActions.refreshModelDownloadInfo()+ if (!cancelled) {+ logRepository.log(+ LogLevel.Error,+ "Model load failed",+ details = loadFailure.message,+ tag = "Model",+ throwable = loadFailure,+ )+ }}- return@launch}+ if (!modelReady) return@launchif (!isActive()) return@launch@@ -690,6 +707,8 @@ internal class ChatStoreActions(val buffer = StringBuilder()var tokenCount = 0+ var totalTimeMs: Long? = null+ var interrupted = truetry {val generate: suspend () -> io.ente.ensu.llm.GenerationSummary = {@@ -714,12 +733,8 @@ internal class ChatStoreActions(val summary =try {generate()- } catch (error: Throwable) {- if (- error is LlmException.PromptTooLong &&- buffer.isEmpty() &&- activeCitations.isNotEmpty()- ) {+ } catch (error: LlmException.PromptTooLong) {+ if (buffer.isEmpty() && activeCitations.isNotEmpty()) {activeCitations = emptyList()llmMessages =listOf(LlmMessage(normalSystemPrompt, LlmMessageRole.System)) +@@ -735,28 +750,14 @@ internal class ChatStoreActions(}}- finishGeneration(- sessionId,- userMessage,- buffer,- tokenCount,- summary.totalTimeMs,- interrupted = false,- shouldUpdateUi = isActive(),- citations = activeCitations,- )+ totalTimeMs = summary.totalTimeMs+ interrupted = false+ } catch (err: kotlinx.coroutines.CancellationException) {+ throw err+ } catch (_: LlmException.Cancelled) {+ interrupted = true} catch (err: Throwable) {- val interrupted = stopRequested || err is LlmException.Cancelled- finishGeneration(- sessionId,- userMessage,- buffer,- tokenCount,- totalTimeMs = null,- interrupted = interrupted,- shouldUpdateUi = isActive(),- citations = activeCitations,- )+ interrupted = stopRequestedif (!interrupted) {logRepository.log(LogLevel.Error,@@ -766,6 +767,17 @@ internal class ChatStoreActions(throwable = err,)}+ } finally {+ finishGeneration(+ sessionId,+ userMessage,+ buffer,+ tokenCount,+ totalTimeMs,+ interrupted = interrupted,+ shouldUpdateUi = isActive(),+ citations = activeCitations,+ )}if (embeddingAssetInvalid) modelSettingsActions.refreshModelDownloadInfo()}@@ -1004,7 +1016,15 @@ internal class ChatStoreActions() { token ->buffer.append(token)}+ } catch (err: kotlinx.coroutines.CancellationException) {+ throw err} catch (err: Throwable) {+ logRepository.log(+ LogLevel.Warning,+ "Session summary failed",+ tag = "Chat",+ throwable = err,+ )val fallbackSummary = summarizeQuestion(fallback)return if (fallbackSummary.isBlank()) nullelse sessionTitleFromText(fallbackSummary, fallback = fallback)diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.ktindex 652a40aba3..21b9338ba4 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/ChatView.kt@@ -33,6 +33,7 @@ import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.derivedStateOfimport androidx.compose.runtime.getValueimport androidx.compose.runtime.key+import androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.rememberUpdatedState@@ -142,7 +143,7 @@ fun ChatView(val focusManager = LocalFocusManager.currentvar didAutoFocusInput by remember { mutableStateOf(false) }- var focusRequestId by remember { mutableStateOf(0) }+ var focusRequestId by remember { mutableIntStateOf(0) }var wasDrawerOpen by remember { mutableStateOf(false) }val shouldAutoFocusInput =@@ -353,7 +354,7 @@ fun ChatView(}if (showToast) {DownloadToastOverlay(- status = status ?: "",+ status = status.orEmpty(),percent = chatState.downloadPercent ?: 0,totalBytes = chatState.modelDownloadSizeBytes,isLoading = isLoading,diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/VoiceInput.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/VoiceInput.ktindex fccbf2f75e..dd3500e1cf 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/VoiceInput.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/chat/VoiceInput.kt@@ -11,9 +11,9 @@ import androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue-import androidx.compose.ui.platform.LocalLifecycleOwnerimport androidx.lifecycle.Lifecycleimport androidx.lifecycle.LifecycleEventObserver+import androidx.lifecycle.compose.LocalLifecycleOwnerimport io.ente.ensu.assets.AssetStoreimport io.ente.ensu.bindings.AssetDownloadExceptionimport io.ente.ensu.bindings.LlmException@@ -157,18 +157,14 @@ internal class VoiceTranscriptionController(} catch (error: TranscriptionException) {Log.w(TAG, "Voice model preparation failed: ${error.message}", error)state = VoiceInputState.Error(transcriptionErrorMessage(error))+ } catch (_: AssetDownloadException.Cancelled) {+ state = VoiceInputState.Idle} catch (error: AssetDownloadException) {- if (error is AssetDownloadException.Cancelled) {- state = VoiceInputState.Idle- return@launch- }Log.w(TAG, "Voice model download failed: ${error.message}", error)state = VoiceInputState.Error(downloadErrorMessage)+ } catch (_: LlmException.Cancelled) {+ state = VoiceInputState.Idle} catch (error: LlmException) {- if (error is LlmException.Cancelled) {- state = VoiceInputState.Idle- return@launch- }Log.w(TAG, "Voice model download failed: ${error.message}", error)state = VoiceInputState.Error(downloadErrorMessage)} catch (error: Throwable) {@@ -316,18 +312,14 @@ internal class VoiceTranscriptionController(} catch (error: TranscriptionException) {Log.w(TAG, "Voice transcription failed: ${error.message}", error)state = VoiceInputState.Error(transcriptionErrorMessage(error))+ } catch (_: AssetDownloadException.Cancelled) {+ state = VoiceInputState.Idle} catch (error: AssetDownloadException) {- if (error is AssetDownloadException.Cancelled) {- state = VoiceInputState.Idle- return@withMaintenanceSuspended- }Log.w(TAG, "Voice model download failed: ${error.message}", error)state = VoiceInputState.Error(downloadErrorMessage)+ } catch (_: LlmException.Cancelled) {+ state = VoiceInputState.Idle} catch (error: LlmException) {- if (error is LlmException.Cancelled) {- state = VoiceInputState.Idle- return@withMaintenanceSuspended- }Log.w(TAG, "Voice model download failed: ${error.message}", error)state = VoiceInputState.Error(downloadErrorMessage)} catch (error: Throwable) {diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/coroutines/RunCatching.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/coroutines/RunCatching.ktnew file mode 100644index 0000000000..f1c10e28fd--- /dev/null+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/coroutines/RunCatching.kt@@ -0,0 +1,12 @@+package io.ente.ensu.coroutines++import kotlinx.coroutines.CancellationException++internal inline fun <T> runCatchingCancellable(block: () -> T): Result<T> =+ try {+ Result.success(block())+ } catch (error: CancellationException) {+ throw error+ } catch (error: Throwable) {+ Result.failure(error)+ }diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeProvider.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeProvider.ktindex c359f02832..de2c49dafd 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeProvider.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeProvider.kt@@ -11,6 +11,7 @@ import kotlinx.coroutines.Deferredimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.NonCancellableimport kotlinx.coroutines.async+import kotlinx.coroutines.cancelAndJoinimport kotlinx.coroutines.coroutineScopeimport kotlinx.coroutines.currentCoroutineContextimport kotlinx.coroutines.ensureActive@@ -36,7 +37,13 @@ class KnowledgeProvider(private val assetStore: AssetStore) {lifecycleGate(dataset.stableId).withLock {val activeMutation = mutationGate.withLock { mutations[dataset.stableId] }if (activeMutation != null) {- val result = runCatching { activeMutation.task.await() }+ val result =+ try {+ activeMutation.task.await()+ } catch (error: Throwable) {+ if (error is CancellationException) currentCoroutineContext().ensureActive()+ null+ }mutationGate.withLock {if (mutations[dataset.stableId] === activeMutation &&@@ -45,7 +52,7 @@ class KnowledgeProvider(private val assetStore: AssetStore) {mutations.remove(dataset.stableId)}}- result.getOrNull()?.let {+ result?.let {return@withLock it}currentCoroutineContext().ensureActive()@@ -66,6 +73,7 @@ class KnowledgeProvider(private val assetStore: AssetStore) {ownsMutation = trueval task =async(Dispatchers.IO) {+ var completed = falsetry {assetStore.download(listOf(knowledgePackAsset(dataset.stableId))@@ -82,15 +90,17 @@ class KnowledgeProvider(private val assetStore: AssetStore) {) {"Downloaded knowledge pack failed current revision validation"}+ completed = trueresult}- } catch (error: Throwable) {- withContext(NonCancellable) {- indexGate.withLock {- runCatching { reconcileAndOpenLocked(dataset) }+ } finally {+ if (!completed) {+ withContext(NonCancellable) {+ indexGate.withLock {+ runCatching { reconcileAndOpenLocked(dataset) }+ }}}- throw error}}ActiveMutation(task).also { mutations[dataset.stableId] = it }@@ -100,14 +110,9 @@ class KnowledgeProvider(private val assetStore: AssetStore) {try {mutation.task.await()- } catch (error: CancellationException) {- if (ownsMutation) mutation.task.cancel()- throw error} finally {withContext(NonCancellable) {- if (ownsMutation && !mutation.task.isCompleted) {- mutation.task.join()- }+ if (ownsMutation) mutation.task.cancelAndJoin()mutationGate.withLock {if (mutations[dataset.stableId] === mutation && mutation.task.isCompleted) {mutations.remove(dataset.stableId)@@ -119,8 +124,7 @@ class KnowledgeProvider(private val assetStore: AssetStore) {suspend fun cancel(dataset: KnowledgeDatasetConfig): KnowledgeReconciliation {val mutation = mutationGate.withLock { mutations[dataset.stableId] }- mutation?.task?.cancel()- runCatching { mutation?.task?.await() }+ mutation?.task?.cancelAndJoin()mutationGate.withLock {if (mutations[dataset.stableId] === mutation) {mutations.remove(dataset.stableId)diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeStore.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeStore.ktindex 5861b11e21..20a80b6f7c 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeStore.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/knowledge/KnowledgeStore.kt@@ -9,6 +9,7 @@ import io.ente.ensu.bindings.AssetDownloadExceptionimport io.ente.ensu.bindings.KnowledgeDatasetConfigimport io.ente.ensu.bindings.KnowledgeReconciliationimport io.ente.ensu.bindings.KnowledgeReconciliationStatus+import io.ente.ensu.coroutines.runCatchingCancellableimport io.ente.ensu.device.isChatSupportedimport io.ente.ensu.logging.FileLogRepositoryimport io.ente.ensu.logging.LogLevel@@ -75,7 +76,7 @@ class KnowledgeStore()}bootstrapJob = scope.launch {- val requestedEnabled = runCatching {+ val requestedEnabled = runCatchingCancellable {preferences.enabledDatasetIds.first()}.getOrDefault(emptySet())@@ -130,7 +131,7 @@ class KnowledgeStore(} catch (error: CancellationException) {throw error} catch (error: Throwable) {- val reconciled = runCatching { provider.reconcile(dataset) }.getOrNull()+ val reconciled = runCatchingCancellable { provider.reconcile(dataset) }.getOrNull()updatePack(stableId) { current ->(reconciled?.let { current.fromReconciliation(it, current.enabled) } ?: current).copy(@@ -155,7 +156,7 @@ class KnowledgeStore(val ownerScope = scope ?: returnval ownerJob = jobs[stableId]ownerScope.launch {- val result = runCatching { provider.cancel(dataset) }.getOrNull()+ val result = runCatchingCancellable { provider.cancel(dataset) }.getOrNull()ownerJob?.join()if (jobs[stableId]?.isActive == true) return@launchupdatePack(stableId) { current ->@@ -193,7 +194,7 @@ class KnowledgeStore(dataset: KnowledgeDatasetConfig,enabled: Boolean,) {- val result = runCatching { provider.reconcile(dataset) }+ val result = runCatchingCancellable { provider.reconcile(dataset) }updatePack(dataset.stableId) { current ->result.fold(onSuccess = { reconciliation ->diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/LlmProvider.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/LlmProvider.ktindex e28803e8df..b2f0782769 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/LlmProvider.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/LlmProvider.kt@@ -18,6 +18,7 @@ import io.ente.ensu.bindings.knowledgeEmbeddingModelAssetimport io.ente.ensu.bindings.llmAssetimport io.ente.ensu.bindings.llmCancelimport io.ente.ensu.bindings.llmInitBackend+import io.ente.ensu.coroutines.runCatchingCancellableimport io.ente.ensu.device.AndroidDeviceCapabilityProviderimport io.ente.ensu.device.requireChatSupportedimport io.ente.ensu.settings.IS_ENSU_PACKS_ENABLED@@ -137,7 +138,7 @@ class LlmProvider(): GenerationSummary = withModelContext {modelLoadMutex.withLock {deviceCapabilityProvider.chatCapability().requireChatSupported()- val context = loadedContext ?: throw IllegalStateException("Model context not loaded")+ val context = checkNotNull(loadedContext) { "Model context not loaded" }currentJobId = nullval mmprojPath =if (imageFiles.isEmpty()) {@@ -219,7 +220,7 @@ class LlmProvider(suspend fun prewarmImageInference(selection: LlmModelSelection) {withModelContext {- runCatching {+ runCatchingCancellable {modelLoadMutex.withLock {val asset = chatAsset(selection)if (!assetStore.isDownloaded(asset)) return@withLock@@ -399,7 +400,7 @@ class LlmProvider(}}unloadModel()- throw lastError ?: IllegalStateException("Failed to load model")+ throw (lastError ?: error("Failed to load model"))}private fun generateStreamWithCallback(diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsActions.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsActions.ktindex d387ed5a2e..dd7a7392da 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsActions.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsActions.kt@@ -7,6 +7,7 @@ import io.ente.ensu.bindings.AssetDownloadExceptionimport io.ente.ensu.bindings.LlmExceptionimport io.ente.ensu.bindings.ModelRuntimeSurfaceimport io.ente.ensu.bindings.resolveEffectiveModelId+import io.ente.ensu.coroutines.runCatchingCancellableimport io.ente.ensu.device.isChatSupportedimport io.ente.ensu.logging.FileLogRepositoryimport io.ente.ensu.logging.LogLevel@@ -201,6 +202,8 @@ internal class ModelSettingsActions(initialPercent = if (isDownloaded) null else 0,initialStatus = if (isDownloaded) null else "Starting download...",)+ var completed = false+ var downloadFailure: Throwable? = nulltry {var retryCount = 0while (true) {@@ -235,6 +238,8 @@ internal class ModelSettingsActions(}}break+ } catch (err: kotlinx.coroutines.CancellationException) {+ throw err} catch (err: Throwable) {if (!shouldRetryDownload(err, retryCount)) {throw err@@ -244,44 +249,54 @@ internal class ModelSettingsActions(delay(retryDelayMs(retryCount))}}+ completed = true+ } catch (err: kotlinx.coroutines.CancellationException) {+ throw err} catch (err: Throwable) {- val cancelled =- err is kotlinx.coroutines.CancellationException ||- err is LlmException.Cancelled ||- err is AssetDownloadException.Cancelled- val failureMessage =- if (cancelled) {- "Download cancelled"- } else {- userFacingDownloadError(err, isDownloaded)+ downloadFailure = err+ } finally {+ if (!completed) {+ val cancelled =+ downloadFailure == null ||+ downloadFailure is LlmException.Cancelled ||+ downloadFailure is AssetDownloadException.Cancelled+ val failureMessage =+ if (cancelled) {+ "Download cancelled"+ } else {+ userFacingDownloadError(downloadFailure, isDownloaded)+ }+ state.update { appState ->+ appState.copy(+ chat =+ appState.chat.copy(+ isDownloading = false,+ downloadPercent = null,+ downloadStatus = failureMessage,+ downloadPhase = if (cancelled) null else DownloadPhase.Failed,+ hasRequestedModelDownload = false,+ )+ )}- state.update { appState ->- appState.copy(- chat =- appState.chat.copy(- isDownloading = false,- downloadPercent = null,- downloadStatus = failureMessage,- downloadPhase = if (cancelled) null else DownloadPhase.Failed,- hasRequestedModelDownload = false,+ persistModelDownloadRequested(false)+ if (cancelled) {+ if (!isDownloaded) {+ logRepository.log(+ LogLevel.Info,+ "Model download cancelled",+ tag = "Model",)- )- }- persistModelDownloadRequested(false)- if (cancelled) {- if (!isDownloaded) {- logRepository.log(LogLevel.Info, "Model download cancelled", tag = "Model")+ }+ } else {+ logRepository.log(+ LogLevel.Error,+ if (isDownloaded) "Model load failed" else "Model download failed",+ details = downloadFailure.message,+ tag = "Model",+ throwable = downloadFailure,+ )}- } else {- logRepository.log(- LogLevel.Error,- if (isDownloaded) "Model load failed" else "Model download failed",- details = err.message,- tag = "Model",- throwable = err,- )}- } finally {modelDownloadJob = nullrefreshModelDownloadInfo()}@@ -300,6 +315,8 @@ internal class ModelSettingsActions(scope.launch {try {llmProvider.prewarmImageInference(selection)+ } catch (err: kotlinx.coroutines.CancellationException) {+ throw err} catch (err: Throwable) {logRepository.log(LogLevel.Warning,@@ -332,7 +349,7 @@ internal class ModelSettingsActions(private fun persistModelDownloadRequested(requested: Boolean) {scope?.launch {- runCatching {+ runCatchingCancellable {sessionPreferences.setModelDownloadRequested(requested)}.onFailure { error ->diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsScreen.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsScreen.ktindex 41dc8d5494..5426797042 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsScreen.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/ModelSettingsScreen.kt@@ -20,6 +20,7 @@ import androidx.compose.material3.ExperimentalMaterial3Apiimport androidx.compose.material3.ExposedDropdownMenuBoximport androidx.compose.material3.ExposedDropdownMenuDefaultsimport androidx.compose.material3.HorizontalDivider+import androidx.compose.material3.MenuAnchorTypeimport androidx.compose.material3.OutlinedTextFieldimport androidx.compose.material3.Textimport androidx.compose.material3.TextButton@@ -115,7 +116,7 @@ fun ModelSettingsScreen(trailingIcon = {ExposedDropdownMenuDefaults.TrailingIcon(expanded = isModelMenuExpanded)},- modifier = Modifier.menuAnchor().fillMaxWidth(),+ modifier = Modifier.menuAnchor(MenuAnchorType.PrimaryNotEditable).fillMaxWidth(),)ExposedDropdownMenu(diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/logging/LogViewerScreen.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/logging/LogViewerScreen.ktindex d35530cab5..7984565ff7 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/logging/LogViewerScreen.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/logging/LogViewerScreen.kt@@ -36,6 +36,7 @@ import androidx.compose.runtime.setValueimport androidx.compose.ui.Alignmentimport androidx.compose.ui.Modifierimport androidx.compose.ui.graphics.Color+import androidx.compose.ui.platform.LocalConfigurationimport androidx.compose.ui.platform.LocalContextimport androidx.compose.ui.res.painterResourceimport androidx.compose.ui.text.style.TextOverflow@@ -48,7 +49,6 @@ import io.ente.ensu.designsystem.EnsuTypographyimport io.ente.ensu.designsystem.HugeIconsimport java.text.SimpleDateFormatimport java.util.Date-import java.util.Locale@Composablefun LogViewerScreen(logRepository: FileLogRepository) {@@ -155,6 +155,8 @@ private fun NativeLogDetailsDialog(logEntry: LogEntry, onDismiss: () -> Unit) {@Composableprivate fun LogRow(logEntry: LogEntry, onOpenDetails: () -> Unit) {+ val locale = LocalConfiguration.current.locales[0]+ val logTimestampFormatter = remember(locale) { SimpleDateFormat("MMM d, h:mm:ss a", locale) }val hasDetails = !logEntry.details.isNullOrBlank()Column(@@ -215,5 +217,3 @@ private fun levelColor(level: LogLevel): Color =LogLevel.Warning -> EnsuColor.accent()LogLevel.Error -> EnsuColor.error}--private val logTimestampFormatter = SimpleDateFormat("MMM d, h:mm:ss a", Locale.getDefault())diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/AndroidNotesSource.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/AndroidNotesSource.ktindex ec77313165..7955be0d9f 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/AndroidNotesSource.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/AndroidNotesSource.kt@@ -1,5 +1,6 @@package io.ente.ensu.notes+import android.annotation.SuppressLintimport android.content.ContentResolverimport android.net.Uriimport android.os.Build@@ -264,6 +265,8 @@ internal class AndroidNotesSource(}private fun bytes(id: String): ByteArray = access { request ->+ // Lint misses the close performed by use.+ @SuppressLint("Recycle")val descriptor =resolver.openAssetFileDescriptor(uri(id), "r", request)?: throw NotesException.SourceRead("Could not read the note")diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/NotesStore.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/NotesStore.ktindex 1be69ee2ef..c888f7802d 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/NotesStore.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/notes/NotesStore.kt@@ -16,6 +16,7 @@ import io.ente.ensu.bindings.NotesProgressCallbackimport io.ente.ensu.bindings.NotesSummaryimport io.ente.ensu.bindings.notesLimitsimport io.ente.ensu.bindings.withNotesCollectionLabel+import io.ente.ensu.coroutines.runCatchingCancellableimport io.ente.ensu.llm.LlmProviderimport io.ente.ensu.llm.ModelMaintenanceimport io.ente.ensu.llm.withMaintenanceSuspended@@ -117,7 +118,9 @@ class NotesStore(val summary = provider.inspect(record.id)if (!summary.initialComplete) enqueue(record.id, immediate = true)fromSummary(record, summary)- } catch (e: NotesException.RebuildRequired) {+ } catch (e: CancellationException) {+ throw e+ } catch (_: NotesException.RebuildRequired) {enqueue(record.id, rebuild = true, immediate = true)NoteCollectionState(record.id, record.label)} catch (e: Exception) {@@ -138,6 +141,8 @@ class NotesStore(_state.value = NotesState(states)loaded = truescans.addAll(registrations.keys)+ } catch (e: CancellationException) {+ throw e} catch (e: Exception) {logRepository.log(LogLevel.Error,@@ -265,7 +270,7 @@ class NotesStore(hits += provider.search(record.id, query)} catch (error: CancellationException) {throw error- } catch (error: NotesException.RebuildRequired) {+ } catch (_: NotesException.RebuildRequired) {enqueue(record.id, rebuild = true, immediate = true)update(record.id) {it.copy(status = NotesStatus.Pending, indexAvailable = false)@@ -303,7 +308,7 @@ class NotesStore(accepted++} catch (error: CancellationException) {throw error- } catch (error: NotesException.SourceChanged) {+ } catch (_: NotesException.SourceChanged) {enqueue(record.id, forced = setOf(note.documentId), immediate = true)} catch (error: Exception) {fail(record.id, error)@@ -326,6 +331,8 @@ class NotesStore(})clearError()+ } catch (e: CancellationException) {+ throw e} catch (e: Exception) {val error =when (e) {@@ -404,6 +411,8 @@ class NotesStore(val job =owner.launch(start = CoroutineStart.LAZY) {scans.remove(id)+ var completed = false+ var failure: Throwable? = nulltry {cancel.check()if (snapshot == null) {@@ -487,35 +496,47 @@ class NotesStore(}}}- } catch (e: Exception) {- when (e) {- is NotesException.Cancelled,- is CancellationException -> {- if (snapshot == null) scans.add(id)- val saved =- withContext(NonCancellable) {- runCatching { provider.inspect(id) }.getOrNull()- }- update(id) {- it.copy(- status = NotesStatus.Pending,- indexAvailable =- hadIndex &&- saved?.initialComplete == true &&- saved.documentCount > 0uL,- )- }- if (e is CancellationException) throw e- }- is NotesException.RebuildRequired -> {- if (snapshot == null) {- enqueue(id, rebuild = true, immediate = true)+ completed = true+ } catch (error: CancellationException) {+ throw error+ } catch (error: Exception) {+ failure = error+ } catch (error: Throwable) {+ failure = error+ throw error+ } finally {+ if (!completed) {+ when (failure) {+ null,+ is NotesException.Cancelled -> {+ if (snapshot == null) scans.add(id)+ val saved =+ withContext(NonCancellable) {+ runCatchingCancellable { provider.inspect(id) }.getOrNull()+ }update(id) {- it.copy(status = NotesStatus.Pending, indexAvailable = false)+ it.copy(+ status = NotesStatus.Pending,+ indexAvailable =+ hadIndex &&+ saved?.initialComplete == true &&+ saved.documentCount > 0uL,+ )}- } else fail(id, e)+ }+ is NotesException.RebuildRequired -> {+ if (snapshot == null) {+ enqueue(id, rebuild = true, immediate = true)+ update(id) {+ it.copy(+ status = NotesStatus.Pending,+ indexAvailable = false,+ )+ }+ } else fail(id, failure)+ }+ is Exception -> fail(id, failure)}- else -> fail(id, e)}}}diff --git a/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt b/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.ktindex b9800f46f8..a2dafdcda1 100644--- a/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt+++ b/android/apps/ensu/app/src/main/java/io/ente/ensu/settings/SettingsScreen.kt@@ -25,6 +25,7 @@ import androidx.compose.material3.Textimport androidx.compose.material3.TextFieldDefaultsimport androidx.compose.runtime.Composableimport androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOfimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue@@ -58,7 +59,7 @@ fun SettingsScreen(onSignIn: () -> Unit,) {var query by remember { mutableStateOf("") }- var buildVersionTapCount by remember { mutableStateOf(0) }+ var buildVersionTapCount by remember { mutableIntStateOf(0) }var lastBuildVersionTapAt by remember { mutableStateOf<Long?>(null) }val context = LocalContext.currentdiff --git a/android/apps/ensu/app/src/main/res/drawable/ensu_ducky.png b/android/apps/ensu/app/src/main/res/drawable-nodpi/ensu_ducky.pngsimilarity index 100%rename from android/apps/ensu/app/src/main/res/drawable/ensu_ducky.pngrename to android/apps/ensu/app/src/main/res/drawable-nodpi/ensu_ducky.pngdiff --git a/android/apps/ensu/app/src/main/res/drawable/ic_launcher_background.png b/android/apps/ensu/app/src/main/res/drawable-nodpi/ic_launcher_background.pngsimilarity index 100%rename from android/apps/ensu/app/src/main/res/drawable/ic_launcher_background.pngrename to android/apps/ensu/app/src/main/res/drawable-nodpi/ic_launcher_background.pngdiff --git a/android/apps/ensu/app/src/main/res/drawable/ic_launcher_foreground.png b/android/apps/ensu/app/src/main/res/drawable-nodpi/ic_launcher_foreground.pngsimilarity index 100%rename from android/apps/ensu/app/src/main/res/drawable/ic_launcher_foreground.pngrename to android/apps/ensu/app/src/main/res/drawable-nodpi/ic_launcher_foreground.pngdiff --git a/android/apps/ensu/app/src/main/res/drawable/ensu_logo.xml b/android/apps/ensu/app/src/main/res/drawable/ensu_logo.xmlindex fa912ccfae..bbcca209a8 100644--- a/android/apps/ensu/app/src/main/res/drawable/ensu_logo.xml+++ b/android/apps/ensu/app/src/main/res/drawable/ensu_logo.xml@@ -1,6 +1,6 @@<vector xmlns:android="http://schemas.android.com/apk/res/android"- android:width="906dp"- android:height="255dp"+ android:width="85.27dp"+ android:height="24dp"android:viewportWidth="906"android:viewportHeight="255"><pathdiff --git a/android/apps/ensu/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/android/apps/ensu/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xmldeleted file mode 100644index 6b78462d61..0000000000--- a/android/apps/ensu/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml+++ /dev/null@@ -1,5 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">- <background android:drawable="@drawable/ic_launcher_background" />- <foreground android:drawable="@drawable/ic_launcher_foreground" />-</adaptive-icon>diff --git a/android/apps/ensu/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/apps/ensu/app/src/main/res/mipmap-hdpi/ic_launcher_round.pngdeleted file mode 100644index 8ab3b6a5bb..0000000000Binary files a/android/apps/ensu/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differdiff --git a/android/apps/ensu/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/apps/ensu/app/src/main/res/mipmap-mdpi/ic_launcher_round.pngdeleted file mode 100644index c2ed8fbe8c..0000000000Binary files a/android/apps/ensu/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differdiff --git a/android/apps/ensu/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/apps/ensu/app/src/main/res/mipmap-xhdpi/ic_launcher_round.pngdeleted file mode 100644index 21fbcf31f1..0000000000Binary files a/android/apps/ensu/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differdiff --git a/android/apps/ensu/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/apps/ensu/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.pngdeleted file mode 100644index 3f7fb9be5e..0000000000Binary files a/android/apps/ensu/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differdiff --git a/android/apps/ensu/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/apps/ensu/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.pngdeleted file mode 100644index 35be36bc24..0000000000Binary files a/android/apps/ensu/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differdiff --git a/android/apps/ensu/app/src/main/res/values/colors.xml b/android/apps/ensu/app/src/main/res/values/colors.xmldeleted file mode 100644index a28de239be..0000000000--- a/android/apps/ensu/app/src/main/res/values/colors.xml+++ /dev/null@@ -1,3 +0,0 @@-<resources>- <color name="ic_launcher_background">#1C1C1E</color>-</resources>diff --git a/android/apps/ensu/app/src/test/java/io/ente/ensu/coroutines/RunCatchingTest.kt b/android/apps/ensu/app/src/test/java/io/ente/ensu/coroutines/RunCatchingTest.ktnew file mode 100644index 0000000000..32999bb040--- /dev/null+++ b/android/apps/ensu/app/src/test/java/io/ente/ensu/coroutines/RunCatchingTest.kt@@ -0,0 +1,34 @@+package io.ente.ensu.coroutines++import kotlinx.coroutines.CompletableDeferred+import kotlinx.coroutines.awaitCancellation+import kotlinx.coroutines.cancelAndJoin+import kotlinx.coroutines.launch+import kotlinx.coroutines.runBlocking+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class RunCatchingTest {+ @Test+ fun cancellationRunsCleanupWithoutExecutingTheFallback() = runBlocking {+ val entered = CompletableDeferred<Unit>()+ var fallback = false+ var cleanedUp = false+ val worker = launch {+ try {+ runCatchingCancellable<Unit> {+ entered.complete(Unit)+ awaitCancellation()+ }+ .getOrElse { fallback = true }+ } finally {+ cleanedUp = true+ }+ }+ entered.await()+ worker.cancelAndJoin()+ assertTrue(cleanedUp)+ assertFalse(fallback)+ }+}diff --git a/android/apps/ensu/rust/build.gradle.kts b/android/apps/ensu/rust/build.gradle.ktsindex 69e00a7b50..865d7eefe2 100644--- a/android/apps/ensu/rust/build.gradle.kts+++ b/android/apps/ensu/rust/build.gradle.kts@@ -71,7 +71,10 @@ fun registerBuildRustJni(val version = android.ndkVersionval ndkDir = runCatching {android.ndkDirectory- }.getOrElse { error("NDK $version is not installed. Run: sdkmanager \"ndk;$version\"") }+ }+ .getOrElse {+ error("NDK $version is not installed. Run: sdkmanager \"ndk;$version\"")+ }val toolchain = ndkToolchain(ndkDir)val outDir = outputDir.get().asFile@@ -142,11 +145,11 @@ tasks.matching { it.name == "preDebugBuild" }.configureEach { dependsOn(buildRustasks.matching { it.name == "preReleaseBuild" }.configureEach { dependsOn(buildRustJniRelease) }dependencies {- api("net.java.dev.jna:jna:5.18.1@aar")api("androidx.annotation:annotation:1.7.1")- implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")// Custom WebGPU/XNNPACK build; the Rust runtime dynamically loads its// libonnxruntime.so. Resolved from the Ivy repository declared in// settings.gradle.kts and SHA-256 pinned in android/gradle/verification-metadata.xml.api("io.ente.onnxruntime:onnxruntime-webgpu-android:1.28.1-r1@aar")+ api("net.java.dev.jna:jna:5.18.1@aar")+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")}diff --git a/android/build.gradle.kts b/android/build.gradle.ktsindex c5ac95925e..f57dee0a70 100644--- a/android/build.gradle.kts+++ b/android/build.gradle.kts@@ -35,6 +35,14 @@ allprojects {extensions.configure<CommonExtension<*, *, *, *, *, *>>("android") {lint {warningsAsErrors = true+ disable +=+ setOf(+ "ChromeOsAbiSupport",+ "GradleDependency",+ "IconLauncherShape",+ "UseKtx",+ "VectorPath",+ )checkTestSources = truecheckDependencies = true}diff --git a/android/detekt.yml b/android/detekt.ymlindex 964c7b6798..411c8d0e13 100644--- a/android/detekt.yml+++ b/android/detekt.yml@@ -12,6 +12,10 @@ coroutines:SuspendFunSwallowedCancellation:active: true+exceptions:+ TooGenericExceptionCaught:+ active: false+naming:FunctionNaming:ignoreAnnotated: ['Composable']