From 88c6e02e8c94f925195621177bc64032dcb8c90d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:23:10 +0000 Subject: [PATCH 1/4] ADFA-7240: Warn before removing or disabling a bundled add-on - Uninstalling a bundled plugin or template, and disabling a bundled plugin, now asks first with a warning that the installation will probably break. - PluginManagerViewModel/TemplateManagerViewModel take isBundledPlugin / isBundledTemplate (default: nothing bundled), read from BundledAddonsRecord in the Koin modules and called on Dispatchers.IO. - ShowUninstallConfirmation carries `bundled`; new ShowDisableConfirmation and public confirmDisablePlugin. The dialog states carry the flag through rememberSaveable (Parcelable). - New dialog texts scroll for large fonts; strings are English only. - The record is not changed. - Tests for both view models; ARCHITECTURE.md sentence. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw --- ARCHITECTURE.md | 2 +- .../com/itsaky/androidide/di/PluginModule.kt | 4 + .../itsaky/androidide/di/TemplateModule.kt | 5 + .../compose/plugins/PluginManagerContent.kt | 26 +++- .../compose/plugins/PluginManagerDialogs.kt | 45 +++++- .../templates/TemplateManagerDialogs.kt | 15 +- .../templates/TemplateManagerScreen.kt | 4 +- .../ui/models/PluginManagerUiState.kt | 7 + .../ui/models/TemplateManagerUiState.kt | 2 + .../viewmodels/PluginManagerViewModel.kt | 26 +++- .../viewmodels/TemplateManagerViewModel.kt | 7 +- .../viewmodels/PluginManagerViewModelTest.kt | 140 ++++++++++++++++++ .../TemplateManagerViewModelTest.kt | 51 +++++++ resources/src/main/res/values/strings.xml | 8 + 14 files changed, 328 insertions(+), 14 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 3c8b5273c3..aa92b9575c 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -107,7 +107,7 @@ These structural facts shape every module. Day-to-day build *commands* live in ` - **ABI product flavors.** Every Android module *except* `:plugin-api` and `:subprojects:sqlite-js` gets two flavors on the `abi` dimension — `v7` (`armeabi-v7a`) and `v8` (`arm64-v8a`) — defined centrally. There is no flavorless variant; tasks are `assembleV8Debug`, `assembleV7Release`, etc. - **SDK levels** (`build-logic/.../build/config/BuildConfig.kt`): `COMPILE_SDK=36`, `MIN_SDK=28`, `TARGET_SDK=28`. **`TARGET_SDK` is deliberately pinned at 28:** higher targets enforce W^X (write-xor-execute), which blocks executing code from app-writable files. That is fatal for an on-device IDE that compiles and runs code (Gradle, `javac`, Termux binaries), so it is a hard requirement, not tech debt. `MIN_SDK_FOR_APPS_BUILT_WITH_COGO=16` is the floor for the apps a *user* builds with CoGo — distinct from CoGo's own `MIN_SDK`. - **Native asset bundling.** The on-device LLM (`llama-impl`) ships as a per-flavor native AAR, wired through the root `build.gradle.kts` (`bundleLlamaV8Assets` / `assembleV8Assets`, …); prebuilt per-flavor assets live under `assets/release/v7/` and `assets/release/v8/`. -- **Bundled add-ons** (ADFA-7238). A build is *fat* when `assets/plugins/*.cgp` and `assets/templates/*.cgt` exist in the repo root: release builds put them in the APK assets as `plugins/` and `templates/` (`StageBundledAddons` in `app/build.gradle.kts`), and `createAssetsZip()` adds the same entries to the debug `assets-.zip`. Both also write the bundle index `bundled-addons.tsv` (one line per add-on: entry name, size, SHA-256; empty in a thin build), so the app lists and fingerprints the bundle without opening an add-on, which a release APK stores compressed, and a rebuilt add-on of the same size changes the fingerprint. A bundle without a valid index, such as an older debug zip, is listed from its folders by name and size. A missing or empty folder is the thin build. First-run setup (`AssetsInstallationHelper`) lists the bundle (`assets/addons/BundledAddons`), installs each file in the same parallel phase through `BundledAddonInstaller` (scratch file, then rename; a plugin lands in `filesDir/plugins` as `-.cgp`, a template in `Environment.TEMPLATES_DIR`; a copy whose SHA-256 differs from the index is rejected and reported like a plugin with no readable manifest), and writes `filesDir/bundled_addons.properties` last (`BundledAddonsRecord`: bundle fingerprint, bundled plugin IDs and template files, plugin load failures not yet reported to the user). `InstallationViewModel` then reloads the plugins once, and `MainActivity` shows one error bar for the recorded failures. +- **Bundled add-ons** (ADFA-7238). A build is *fat* when `assets/plugins/*.cgp` and `assets/templates/*.cgt` exist in the repo root: release builds put them in the APK assets as `plugins/` and `templates/` (`StageBundledAddons` in `app/build.gradle.kts`), and `createAssetsZip()` adds the same entries to the debug `assets-.zip`. Both also write the bundle index `bundled-addons.tsv` (one line per add-on: entry name, size, SHA-256; empty in a thin build), so the app lists and fingerprints the bundle without opening an add-on, which a release APK stores compressed, and a rebuilt add-on of the same size changes the fingerprint. A bundle without a valid index, such as an older debug zip, is listed from its folders by name and size. A missing or empty folder is the thin build. First-run setup (`AssetsInstallationHelper`) lists the bundle (`assets/addons/BundledAddons`), installs each file in the same parallel phase through `BundledAddonInstaller` (scratch file, then rename; a plugin lands in `filesDir/plugins` as `-.cgp`, a template in `Environment.TEMPLATES_DIR`; a copy whose SHA-256 differs from the index is rejected and reported like a plugin with no readable manifest), and writes `filesDir/bundled_addons.properties` last (`BundledAddonsRecord`: bundle fingerprint, bundled plugin IDs and template files, plugin load failures not yet reported to the user). `InstallationViewModel` then reloads the plugins once, and `MainActivity` shows one error bar for the recorded failures. The Add-ons Manager reads the same record to warn (ADFA-7240) before it uninstalls or disables a bundled plugin, or uninstalls a bundled template; the record is not changed by either. - **sqlite-js for apps built with CoGo** (ADFA-7082). `subprojects:sqlite-js` builds the AAR that the JavaScript-in-SQLite project template depends on: the sqlite-js release vendored (see its README), for arm64-v8a and armeabi-v7a, minSdk 26, without core-library desugaring. Nothing in CoGo depends on it. Its default entry point runs no code stored in a database; loading stored functions is a separate entry point, only for databases the app made, since loading runs their code. `test-sqlite-js.yml` runs its host tests on pull requests. The manual `release-sqlite-js.yml` publishes it to the moving `sqlite-js-latest` release, from which dev-assets fetches it into the template, as it fetches `plugin-api-latest` for the plugin template. - **Native lib compression** (ADFA-2306, ADFA-4729). The app manifest hard-codes `android:extractNativeLibs="true"` (required: the installer must materialize libs in `nativeLibraryDir`, e.g. `libshizuku.so` is an executable the adb shell runs from there). That attribute overrides the `jniLibs.useLegacyPackaging` DSL, so AGP packages `lib//*.so` deflate-compressed in **every** APK — ~5.9 MB smaller (`libtree-sitter-kotlin.so` alone is 4.18 MB → 339 kB). The trap is the `recompressApk` post-step (release always, debug in CI only): its no-compress lists in `app/build.gradle.kts` must NOT contain `"so"`, or it silently re-stores the libs and undoes the saving — which is what ADFA-2306 fixed for release and ADFA-4729 for CI debug. Locally built debug APKs (including the e2e farm's) never run that step and were always fine. - **Quick Build shares the Gradle distribution's toolchain** (ADFA-4931). `:app`'s `quickBuildDaemonZip` leaves the Kotlin compiler and eight other jars out of the daemon zip, because the on-device Gradle distribution already carries them; `QuickBuildArtifactStager` links them in at provision time. That makes the daemon's Kotlin version the distribution's, so `:quickbuild:daemon` takes its Kotlin artifacts at `org.adfa.constants.GRADLE_DISTRIBUTION_KOTLIN_VERSION`, and `:app:quickBuildDistJarCheck` fails the build when the distribution it packages lacks a linked jar. See [ADR 0016](docs/adr/0016-quick-build-compiles-outside-gradle.md). diff --git a/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt b/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt index 760695b316..1d9ba615ed 100644 --- a/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt +++ b/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt @@ -1,6 +1,7 @@ package com.itsaky.androidide.di import com.itsaky.androidide.app.IDEApplication +import com.itsaky.androidide.assets.addons.BundledAddonsRecord import com.itsaky.androidide.preferences.internal.BuildPreferences import com.itsaky.androidide.repositories.DownloadFilesRepository import com.itsaky.androidide.repositories.DownloadFilesRepositoryImpl @@ -53,6 +54,9 @@ val pluginModule = filesDir = IDEApplication.cachedFilesDir, connectivityObserver = get(), isOfflineModeEnabled = { BuildPreferences.isOfflineEnabled }, + isBundledPlugin = { id -> + BundledAddonsRecord.inFilesDir(IDEApplication.cachedFilesDir).read()?.pluginIds?.contains(id) == true + }, ) } diff --git a/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt b/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt index 44c4ec3542..c13fe0516e 100644 --- a/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt +++ b/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt @@ -1,5 +1,7 @@ package com.itsaky.androidide.di +import com.itsaky.androidide.app.IDEApplication +import com.itsaky.androidide.assets.addons.BundledAddonsRecord import com.itsaky.androidide.repositories.TemplateRepository import com.itsaky.androidide.repositories.TemplateRepositoryImpl import com.itsaky.androidide.utils.Environment @@ -25,6 +27,9 @@ val templateModule = viewModel { TemplateManagerViewModel( templateRepository = get(), + isBundledTemplate = { fileName -> + BundledAddonsRecord.inFilesDir(IDEApplication.cachedFilesDir).read()?.templateFiles?.contains(fileName) == true + }, ) } } diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt index ca3fc657b4..e161498e7a 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt @@ -89,6 +89,12 @@ private sealed interface PluginManagerDialogState : Parcelable { @Parcelize data class UninstallConfirm( val pluginId: String, + val bundled: Boolean, + ) : PluginManagerDialogState + + @Parcelize + data class DisableConfirm( + val pluginId: String, ) : PluginManagerDialogState @Parcelize @@ -167,7 +173,11 @@ fun PluginManagerContent( } is PluginManagerUiEffect.ShowUninstallConfirmation -> { - dialogState = PluginManagerDialogState.UninstallConfirm(effect.plugin.metadata.id) + dialogState = PluginManagerDialogState.UninstallConfirm(effect.plugin.metadata.id, effect.bundled) + } + + is PluginManagerUiEffect.ShowDisableConfirmation -> { + dialogState = PluginManagerDialogState.DisableConfirm(effect.plugin.metadata.id) } is PluginManagerUiEffect.ShowRestartPrompt -> { @@ -254,6 +264,7 @@ fun PluginManagerContent( if (plugin != null) { UninstallConfirmationDialog( plugin = plugin, + bundled = dialog.bundled, onConfirm = { viewModel.confirmUninstallPlugin(plugin.metadata.id) dialogState = PluginManagerDialogState.None @@ -263,6 +274,19 @@ fun PluginManagerContent( } } + is PluginManagerDialogState.DisableConfirm -> { + val plugin = uiState.plugins.firstOrNull { it.metadata.id == dialog.pluginId } + if (plugin != null) { + DisableBundledPluginDialog( + onConfirm = { + viewModel.confirmDisablePlugin(plugin.metadata.id) + dialogState = PluginManagerDialogState.None + }, + onDismiss = { dialogState = PluginManagerDialogState.None }, + ) + } + } + is PluginManagerDialogState.Details -> { val plugin = uiState.plugins.firstOrNull { it.metadata.id == dialog.pluginId } if (plugin != null) { diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt index 1e30b95006..3fbe7d3c87 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt @@ -81,13 +81,52 @@ fun UninstallConfirmationDialog( plugin: PluginInfo, onConfirm: () -> Unit, onDismiss: () -> Unit, + bundled: Boolean = false, ) { AlertDialog( onDismissRequest = onDismiss, - title = { Text(stringResource(R.string.title_uninstall_plugin)) }, - text = { Text(stringResource(R.string.msg_uninstall_plugin_confirm, plugin.metadata.name)) }, + title = { + Text(stringResource(if (bundled) R.string.title_uninstall_bundled_plugin else R.string.title_uninstall_plugin)) + }, + // AlertDialog's text slot does not scroll; at 2x font scale the text would clip. + text = { + Text( + if (bundled) { + stringResource(R.string.msg_uninstall_bundled_plugin_confirm) + } else { + stringResource(R.string.msg_uninstall_plugin_confirm, plugin.metadata.name) + }, + modifier = Modifier.verticalScroll(rememberScrollState()), + ) + }, + confirmButton = { + TextButton(onClick = onConfirm) { + Text(stringResource(if (bundled) R.string.action_continue else R.string.uninstall_plugin)) + } + }, + dismissButton = { + TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) } + }, + ) +} + +/** Disabling a plugin that came with the app can break the installation (ADFA-7240). */ +@Composable +fun DisableBundledPluginDialog( + onConfirm: () -> Unit, + onDismiss: () -> Unit, +) { + AlertDialog( + onDismissRequest = onDismiss, + title = { Text(stringResource(R.string.title_disable_bundled_plugin)) }, + text = { + Text( + stringResource(R.string.msg_disable_bundled_plugin_confirm), + modifier = Modifier.verticalScroll(rememberScrollState()), + ) + }, confirmButton = { - TextButton(onClick = onConfirm) { Text(stringResource(R.string.uninstall_plugin)) } + TextButton(onClick = onConfirm) { Text(stringResource(R.string.action_continue)) } }, dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) } diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt index 661bf7112e..dc9b9209cc 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt @@ -81,19 +81,28 @@ fun UninstallTemplateConfirmationDialog( item: CgtFileItem, onConfirm: () -> Unit, onDismiss: () -> Unit, + bundled: Boolean = false, ) { AlertDialog( onDismissRequest = onDismiss, - title = { Text(stringResource(R.string.title_uninstall_template)) }, + title = { + Text(stringResource(if (bundled) R.string.title_uninstall_bundled_template else R.string.title_uninstall_template)) + }, // AlertDialog's text slot does not scroll; a long file name at 2x font scale would clip. text = { Text( - stringResource(R.string.msg_uninstall_template_confirm, item.displayName), + if (bundled) { + stringResource(R.string.msg_uninstall_bundled_template_confirm) + } else { + stringResource(R.string.msg_uninstall_template_confirm, item.displayName) + }, modifier = Modifier.verticalScroll(rememberScrollState()), ) }, confirmButton = { - TextButton(onClick = onConfirm) { Text(stringResource(R.string.action_uninstall_template)) } + TextButton(onClick = onConfirm) { + Text(stringResource(if (bundled) R.string.action_continue else R.string.action_uninstall_template)) + } }, dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) } diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerScreen.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerScreen.kt index 135314207b..62289ab3e9 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerScreen.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerScreen.kt @@ -70,6 +70,7 @@ private sealed interface TemplateManagerDialogState : Parcelable { @Parcelize data class UninstallConfirm( val path: String, + val bundled: Boolean, ) : TemplateManagerDialogState @Parcelize @@ -165,7 +166,7 @@ fun TemplateManagerScreen( } is TemplateManagerUiEffect.ShowUninstallConfirmation -> { - dialogState = TemplateManagerDialogState.UninstallConfirm(effect.item.file.absolutePath) + dialogState = TemplateManagerDialogState.UninstallConfirm(effect.item.file.absolutePath, effect.bundled) } is TemplateManagerUiEffect.ShowDeleteConfirmation -> { @@ -239,6 +240,7 @@ fun TemplateManagerScreen( if (item != null) { UninstallTemplateConfirmationDialog( item = item, + bundled = dialog.bundled, onConfirm = { viewModel.confirmUninstallTemplate(item) dialogState = TemplateManagerDialogState.None diff --git a/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt b/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt index 011e370949..2a60434043 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt @@ -125,8 +125,15 @@ sealed class PluginManagerUiEffect { val source: PluginInstallSource, ) : PluginManagerUiEffect() + /** [bundled]: the plugin came with the app (ADFA-7240), so the dialog warns about removing it. */ data class ShowUninstallConfirmation( val plugin: PluginInfo, + val bundled: Boolean = false, + ) : PluginManagerUiEffect() + + /** Sent instead of disabling at once, for a plugin that came with the app (ADFA-7240). */ + data class ShowDisableConfirmation( + val plugin: PluginInfo, ) : PluginManagerUiEffect() object ShowRestartPrompt : PluginManagerUiEffect() diff --git a/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt b/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt index d8d8ec9dbe..978c9153c0 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt @@ -50,8 +50,10 @@ sealed class TemplateManagerUiEffect { val item: CgtFileItem, ) : TemplateManagerUiEffect() + /** [bundled]: the template came with the app (ADFA-7240), so the dialog warns about removing it. */ data class ShowUninstallConfirmation( val item: CgtFileItem, + val bundled: Boolean = false, ) : TemplateManagerUiEffect() data class ShowDeleteConfirmation( diff --git a/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt b/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt index 17c945ecf3..50fe20aed2 100644 --- a/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt +++ b/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt @@ -46,6 +46,8 @@ class PluginManagerViewModel( private val connectivityObserver: ConnectivityObserver, // Gradle's offline mode (Build & Run preferences). A function so tests need no preferences. private val isOfflineModeEnabled: () -> Boolean, + // Whether the plugin came with the app (ADFA-7240). Reads a file, so it is called from IO only. + private val isBundledPlugin: (String) -> Boolean = { false }, ) : ViewModel() { private companion object { private const val TAG = "PluginManagerViewModel" @@ -144,7 +146,7 @@ class PluginManagerViewModel( } is PluginManagerUiEvent.DisablePlugin -> { - disablePlugin(event.pluginId) + showDisableConfirmationIfBundled(event.pluginId) } is PluginManagerUiEvent.UninstallPlugin -> { @@ -266,9 +268,24 @@ class PluginManagerViewModel( } /** - * Disable a plugin + * A plugin that came with the app asks for confirmation first; any other disables at once. + * A plugin missing from the loaded list is disabled directly, as before. */ - private fun disablePlugin(pluginId: String) { + private fun showDisableConfirmationIfBundled(pluginId: String) { + val plugin = _uiState.value.plugins.find { it.metadata.id == pluginId } + viewModelScope.launch { + if (plugin != null && withContext(Dispatchers.IO) { isBundledPlugin(pluginId) }) { + _uiEffect.send(PluginManagerUiEffect.ShowDisableConfirmation(plugin)) + } else { + confirmDisablePlugin(pluginId) + } + } + } + + /** + * Disable a plugin (called after confirmation, or directly for a plugin the user added) + */ + fun confirmDisablePlugin(pluginId: String) { viewModelScope.launch { _currentOperation.value = PluginOperation.Disabling(pluginId) @@ -304,7 +321,8 @@ class PluginManagerViewModel( val plugin = _uiState.value.plugins.find { it.metadata.id == pluginId } if (plugin != null) { viewModelScope.launch { - _uiEffect.send(PluginManagerUiEffect.ShowUninstallConfirmation(plugin)) + val bundled = withContext(Dispatchers.IO) { isBundledPlugin(pluginId) } + _uiEffect.send(PluginManagerUiEffect.ShowUninstallConfirmation(plugin, bundled)) } } } diff --git a/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt b/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt index 999c6332ce..b9adfa0347 100644 --- a/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt +++ b/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt @@ -10,6 +10,7 @@ import com.itsaky.androidide.templates.manager.models.displayName import com.itsaky.androidide.ui.models.TemplateManagerUiEffect import com.itsaky.androidide.ui.models.TemplateManagerUiEvent import com.itsaky.androidide.ui.models.TemplateManagerUiState +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -17,12 +18,15 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext /** * ViewModel for the Templates tab. Same UDF shape as [PluginManagerViewModel]. */ class TemplateManagerViewModel( private val templateRepository: TemplateRepository, + // Whether an installed template file (by file name) came with the app (ADFA-7240). Reads a file, so IO only. + private val isBundledTemplate: (String) -> Boolean = { false }, ) : ViewModel() { private companion object { private const val TAG = "TemplateManagerViewModel" @@ -122,7 +126,8 @@ class TemplateManagerViewModel( private fun showUninstallConfirmation(item: CgtFileItem) { viewModelScope.launch { - _uiEffect.send(TemplateManagerUiEffect.ShowUninstallConfirmation(item)) + val bundled = item.installed && withContext(Dispatchers.IO) { isBundledTemplate(item.file.name) } + _uiEffect.send(TemplateManagerUiEffect.ShowUninstallConfirmation(item, bundled)) } } diff --git a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt index 7452f99eee..bd0284bad7 100644 --- a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt +++ b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt @@ -1,19 +1,30 @@ package com.itsaky.androidide.viewmodels +import androidx.arch.core.executor.testing.InstantTaskExecutorRule import com.google.common.truth.Truth.assertThat +import com.itsaky.androidide.plugins.PluginInfo +import com.itsaky.androidide.plugins.PluginMetadata import com.itsaky.androidide.repositories.PluginRepository +import com.itsaky.androidide.ui.models.PluginManagerUiEffect +import com.itsaky.androidide.ui.models.PluginManagerUiEvent import com.itsaky.androidide.utils.ConnectivityObserver import com.itsaky.androidide.viewmodel.MainDispatcherRule +import io.mockk.coEvery +import io.mockk.coVerify import io.mockk.every import io.mockk.mockk import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest +import kotlinx.coroutines.withTimeout import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import org.robolectric.RobolectricTestRunner import java.io.File /** A fake [ConnectivityObserver] whose emissions are driven by [state], for tests that need to simulate a change over time. */ @@ -103,3 +114,132 @@ class PluginManagerViewModelTest { assertThat(viewModel.uiState.value.showDiscoverPlugins).isFalse() } } + +/** + * Warnings before removing or disabling a plugin that came with the app (ADFA-7240). Robolectric + * because loading the plugin list refreshes [com.itsaky.androidide.utils.EditorDecorationBridge]. + */ +@RunWith(RobolectricTestRunner::class) +@OptIn(ExperimentalCoroutinesApi::class) +class PluginManagerViewModelBundledTest { + @get:Rule + val instantExecutorRule = InstantTaskExecutorRule() + + @get:Rule + val mainDispatcherRule = MainDispatcherRule() + + private fun plugin(id: String) = + PluginInfo( + metadata = PluginMetadata(id, id, "1.0", "d", "a", "1.0"), + isEnabled = true, + isLoaded = true, + ) + + private val bundledPlugin = plugin("bundled.plugin") + private val userPlugin = plugin("user.plugin") + + private val pluginRepository = + mockk(relaxed = true) { + every { isPluginManagerAvailable() } returns true + coEvery { getAllPlugins() } returns Result.success(listOf(bundledPlugin, userPlugin)) + coEvery { disablePlugin(any()) } returns Result.success(true) + } + + private fun TestScope.viewModel(isBundledPlugin: ((String) -> Boolean)? = null): PluginManagerViewModel { + val connectivity = FakeConnectivityObserver(initialValue = true) + val viewModel = + if (isBundledPlugin == null) { + PluginManagerViewModel(pluginRepository, mockk(relaxed = true), File("/tmp"), connectivity, { false }) + } else { + PluginManagerViewModel( + pluginRepository, + mockk(relaxed = true), + File("/tmp"), + connectivity, + { false }, + isBundledPlugin, + ) + } + advanceUntilIdle() + return viewModel + } + + private suspend fun PluginManagerViewModel.firstEffect() = withTimeout(5_000) { uiEffect.first() } + + @Test + fun uninstall_bundledPlugin_sendsBundledTrue() = + runTest { + val viewModel = viewModel { it == "bundled.plugin" } + + viewModel.onEvent(PluginManagerUiEvent.UninstallPlugin("bundled.plugin")) + + assertThat(viewModel.firstEffect()) + .isEqualTo(PluginManagerUiEffect.ShowUninstallConfirmation(bundledPlugin, bundled = true)) + } + + @Test + fun uninstall_userPlugin_sendsBundledFalse() = + runTest { + val viewModel = viewModel { it == "bundled.plugin" } + + viewModel.onEvent(PluginManagerUiEvent.UninstallPlugin("user.plugin")) + + assertThat(viewModel.firstEffect()) + .isEqualTo(PluginManagerUiEffect.ShowUninstallConfirmation(userPlugin, bundled = false)) + } + + @Test + fun uninstall_withoutABundledLambda_isNotBundled() = + runTest { + val viewModel = viewModel() + + viewModel.onEvent(PluginManagerUiEvent.UninstallPlugin("bundled.plugin")) + + assertThat(viewModel.firstEffect()) + .isEqualTo(PluginManagerUiEffect.ShowUninstallConfirmation(bundledPlugin, bundled = false)) + } + + @Test + fun disable_bundledPlugin_asksFirstAndDoesNotDisable() = + runTest { + val viewModel = viewModel { it == "bundled.plugin" } + + viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("bundled.plugin")) + + assertThat(viewModel.firstEffect()).isEqualTo(PluginManagerUiEffect.ShowDisableConfirmation(bundledPlugin)) + coVerify(exactly = 0) { pluginRepository.disablePlugin(any()) } + } + + @Test + fun disable_userPlugin_disablesAtOnce() = + runTest { + val viewModel = viewModel { it == "bundled.plugin" } + + viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("user.plugin")) + + assertThat(viewModel.firstEffect()).isInstanceOf(PluginManagerUiEffect.ShowSuccess::class.java) + coVerify(exactly = 1) { pluginRepository.disablePlugin("user.plugin") } + } + + @Test + fun disable_withoutABundledLambda_disablesAtOnce() = + runTest { + val viewModel = viewModel() + + viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("bundled.plugin")) + + assertThat(viewModel.firstEffect()).isInstanceOf(PluginManagerUiEffect.ShowSuccess::class.java) + coVerify(exactly = 1) { pluginRepository.disablePlugin("bundled.plugin") } + } + + @Test + fun confirmDisablePlugin_disables() = + runTest { + val viewModel = viewModel { true } + + viewModel.confirmDisablePlugin("bundled.plugin") + + assertThat(viewModel.firstEffect()).isInstanceOf(PluginManagerUiEffect.ShowSuccess::class.java) + coVerify(exactly = 1) { pluginRepository.disablePlugin("bundled.plugin") } + } +} diff --git a/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt b/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt index bdb90510b6..d5b4297475 100644 --- a/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt +++ b/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt @@ -220,6 +220,57 @@ class TemplateManagerViewModelTest { coVerify(exactly = 0) { repository.uninstallTemplate(any()) } } + @Test + fun uninstallTemplate_installedAndInTheBundledRecord_isMarkedBundled() = + runTest { + coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) + val asked = mutableListOf() + + val viewModel = + TemplateManagerViewModel( + repository, + isBundledTemplate = { name -> + asked += name + name == "install.cgt" + }, + ) + advanceUntilIdle() + + viewModel.onEvent(TemplateManagerUiEvent.UninstallTemplate(installedItem)) + + assertThat(viewModel.uiEffect.first()) + .isEqualTo(TemplateManagerUiEffect.ShowUninstallConfirmation(installedItem, bundled = true)) + assertThat(asked).containsExactly("install.cgt") + } + + @Test + fun uninstallTemplate_installedButNotInTheRecord_isNotBundled() = + runTest { + coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) + + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) + advanceUntilIdle() + + viewModel.onEvent(TemplateManagerUiEvent.UninstallTemplate(installedItem)) + + assertThat(viewModel.uiEffect.first()) + .isEqualTo(TemplateManagerUiEffect.ShowUninstallConfirmation(installedItem, bundled = false)) + } + + @Test + fun uninstallTemplate_notInstalled_isNeverBundledEvenIfTheNameMatches() = + runTest { + coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) + + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { true }) + advanceUntilIdle() + + viewModel.onEvent(TemplateManagerUiEvent.UninstallTemplate(item)) + + assertThat(viewModel.uiEffect.first()) + .isEqualTo(TemplateManagerUiEffect.ShowUninstallConfirmation(item, bundled = false)) + } + @Test fun confirmUninstallTemplate_onSuccess_reloadsAndSendsShowSuccessEffect() = runTest { diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index ca581c25d6..75504ad3f5 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -1351,6 +1351,14 @@ https://addons.appdevforall.org Uninstall Plugin Are you sure you want to uninstall \'%1$s\'? + + Remove a plugin that came with the app? + This plugin was installed automatically. If you don\'t replace it with something equivalent, the installation will probably break. + Disable a plugin that came with the app? + This plugin was installed automatically. If you disable it without replacing it with something equivalent, the installation will probably break. + Remove a template that came with the app? + This template was installed automatically. If you don\'t replace it with something equivalent, the installation will probably break. + Continue Name Plugin ID Version From 38657368cac3e98999b2f5f7dc6ba12b8fd29264 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:29:05 +0000 Subject: [PATCH 2/4] ADFA-7240: Address the independent review - Tests: drop withTimeout around the first effect. The bundled check runs on Dispatchers.IO, outside runTest's virtual time, so a virtual-time timeout could fire before it returned and fail the bundled-path tests. - Decide the disable warning by plugin ID, not by the loaded list, so a list being reloaded cannot skip it. ShowDisableConfirmation now carries the ID, and the dialog needs nothing else. - Make isBundledPlugin and isBundledTemplate required, and drop the effects' default bundled = false, so broken wiring cannot silently remove the warnings. Tests pass the lambdas explicitly; the two "without a lambda" tests go. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAZ6QqzwTmigaKYLNVw --- .../compose/plugins/PluginManagerContent.kt | 20 ++++--- .../ui/models/PluginManagerUiState.kt | 4 +- .../ui/models/TemplateManagerUiState.kt | 2 +- .../viewmodels/PluginManagerViewModel.kt | 9 ++-- .../viewmodels/TemplateManagerViewModel.kt | 2 +- .../PluginManagerViewModelSourceDeleteTest.kt | 1 + .../viewmodels/PluginManagerViewModelTest.kt | 53 +++++-------------- .../TemplateManagerViewModelTest.kt | 25 ++++----- 8 files changed, 45 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt index e161498e7a..5f2c8df580 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt @@ -177,7 +177,7 @@ fun PluginManagerContent( } is PluginManagerUiEffect.ShowDisableConfirmation -> { - dialogState = PluginManagerDialogState.DisableConfirm(effect.plugin.metadata.id) + dialogState = PluginManagerDialogState.DisableConfirm(effect.pluginId) } is PluginManagerUiEffect.ShowRestartPrompt -> { @@ -275,16 +275,14 @@ fun PluginManagerContent( } is PluginManagerDialogState.DisableConfirm -> { - val plugin = uiState.plugins.firstOrNull { it.metadata.id == dialog.pluginId } - if (plugin != null) { - DisableBundledPluginDialog( - onConfirm = { - viewModel.confirmDisablePlugin(plugin.metadata.id) - dialogState = PluginManagerDialogState.None - }, - onDismiss = { dialogState = PluginManagerDialogState.None }, - ) - } + // Needs only the ID, so it shows even while the plugin list reloads. + DisableBundledPluginDialog( + onConfirm = { + viewModel.confirmDisablePlugin(dialog.pluginId) + dialogState = PluginManagerDialogState.None + }, + onDismiss = { dialogState = PluginManagerDialogState.None }, + ) } is PluginManagerDialogState.Details -> { diff --git a/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt b/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt index 2a60434043..ecf7ec404f 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt @@ -128,12 +128,12 @@ sealed class PluginManagerUiEffect { /** [bundled]: the plugin came with the app (ADFA-7240), so the dialog warns about removing it. */ data class ShowUninstallConfirmation( val plugin: PluginInfo, - val bundled: Boolean = false, + val bundled: Boolean, ) : PluginManagerUiEffect() /** Sent instead of disabling at once, for a plugin that came with the app (ADFA-7240). */ data class ShowDisableConfirmation( - val plugin: PluginInfo, + val pluginId: String, ) : PluginManagerUiEffect() object ShowRestartPrompt : PluginManagerUiEffect() diff --git a/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt b/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt index 978c9153c0..b4adae7ba1 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/models/TemplateManagerUiState.kt @@ -53,7 +53,7 @@ sealed class TemplateManagerUiEffect { /** [bundled]: the template came with the app (ADFA-7240), so the dialog warns about removing it. */ data class ShowUninstallConfirmation( val item: CgtFileItem, - val bundled: Boolean = false, + val bundled: Boolean, ) : TemplateManagerUiEffect() data class ShowDeleteConfirmation( diff --git a/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt b/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt index 50fe20aed2..e0231e9f07 100644 --- a/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt +++ b/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt @@ -47,7 +47,7 @@ class PluginManagerViewModel( // Gradle's offline mode (Build & Run preferences). A function so tests need no preferences. private val isOfflineModeEnabled: () -> Boolean, // Whether the plugin came with the app (ADFA-7240). Reads a file, so it is called from IO only. - private val isBundledPlugin: (String) -> Boolean = { false }, + private val isBundledPlugin: (String) -> Boolean, ) : ViewModel() { private companion object { private const val TAG = "PluginManagerViewModel" @@ -269,13 +269,12 @@ class PluginManagerViewModel( /** * A plugin that came with the app asks for confirmation first; any other disables at once. - * A plugin missing from the loaded list is disabled directly, as before. + * Decided by ID, not by the loaded list, so a list being reloaded cannot skip the warning. */ private fun showDisableConfirmationIfBundled(pluginId: String) { - val plugin = _uiState.value.plugins.find { it.metadata.id == pluginId } viewModelScope.launch { - if (plugin != null && withContext(Dispatchers.IO) { isBundledPlugin(pluginId) }) { - _uiEffect.send(PluginManagerUiEffect.ShowDisableConfirmation(plugin)) + if (withContext(Dispatchers.IO) { isBundledPlugin(pluginId) }) { + _uiEffect.send(PluginManagerUiEffect.ShowDisableConfirmation(pluginId)) } else { confirmDisablePlugin(pluginId) } diff --git a/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt b/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt index b9adfa0347..7e2d070913 100644 --- a/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt +++ b/app/src/main/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModel.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.withContext class TemplateManagerViewModel( private val templateRepository: TemplateRepository, // Whether an installed template file (by file name) came with the app (ADFA-7240). Reads a file, so IO only. - private val isBundledTemplate: (String) -> Boolean = { false }, + private val isBundledTemplate: (String) -> Boolean, ) : ViewModel() { private companion object { private const val TAG = "TemplateManagerViewModel" diff --git a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelSourceDeleteTest.kt b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelSourceDeleteTest.kt index fe52ffb1ab..ba316dfa54 100644 --- a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelSourceDeleteTest.kt +++ b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelSourceDeleteTest.kt @@ -66,6 +66,7 @@ class PluginManagerViewModelSourceDeleteTest { override fun observe() = flowOf(true) }, isOfflineModeEnabled = { false }, + isBundledPlugin = { false }, ) private fun downloadedPlugin(): File = File(tempFolder.newFolder("Download"), "my-plugin.cgp").apply { writeText("cgp") } diff --git a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt index bd0284bad7..865fed4ea3 100644 --- a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt +++ b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt @@ -19,7 +19,6 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest -import kotlinx.coroutines.withTimeout import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -62,6 +61,7 @@ class PluginManagerViewModelTest { filesDir = File("/tmp"), connectivityObserver = connectivityObserver, isOfflineModeEnabled = { offlineMode }, + isBundledPlugin = { false }, ) @Test @@ -145,26 +145,23 @@ class PluginManagerViewModelBundledTest { coEvery { disablePlugin(any()) } returns Result.success(true) } - private fun TestScope.viewModel(isBundledPlugin: ((String) -> Boolean)? = null): PluginManagerViewModel { - val connectivity = FakeConnectivityObserver(initialValue = true) + private fun TestScope.viewModel(isBundledPlugin: (String) -> Boolean): PluginManagerViewModel { val viewModel = - if (isBundledPlugin == null) { - PluginManagerViewModel(pluginRepository, mockk(relaxed = true), File("/tmp"), connectivity, { false }) - } else { - PluginManagerViewModel( - pluginRepository, - mockk(relaxed = true), - File("/tmp"), - connectivity, - { false }, - isBundledPlugin, - ) - } + PluginManagerViewModel( + pluginRepository, + mockk(relaxed = true), + File("/tmp"), + FakeConnectivityObserver(initialValue = true), + { false }, + isBundledPlugin, + ) advanceUntilIdle() return viewModel } - private suspend fun PluginManagerViewModel.firstEffect() = withTimeout(5_000) { uiEffect.first() } + // No withTimeout: the bundled check runs on Dispatchers.IO, outside runTest's virtual time, and a + // virtual-time timeout could fire before it returns. + private suspend fun PluginManagerViewModel.firstEffect() = uiEffect.first() @Test fun uninstall_bundledPlugin_sendsBundledTrue() = @@ -188,17 +185,6 @@ class PluginManagerViewModelBundledTest { .isEqualTo(PluginManagerUiEffect.ShowUninstallConfirmation(userPlugin, bundled = false)) } - @Test - fun uninstall_withoutABundledLambda_isNotBundled() = - runTest { - val viewModel = viewModel() - - viewModel.onEvent(PluginManagerUiEvent.UninstallPlugin("bundled.plugin")) - - assertThat(viewModel.firstEffect()) - .isEqualTo(PluginManagerUiEffect.ShowUninstallConfirmation(bundledPlugin, bundled = false)) - } - @Test fun disable_bundledPlugin_asksFirstAndDoesNotDisable() = runTest { @@ -206,7 +192,7 @@ class PluginManagerViewModelBundledTest { viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("bundled.plugin")) - assertThat(viewModel.firstEffect()).isEqualTo(PluginManagerUiEffect.ShowDisableConfirmation(bundledPlugin)) + assertThat(viewModel.firstEffect()).isEqualTo(PluginManagerUiEffect.ShowDisableConfirmation("bundled.plugin")) coVerify(exactly = 0) { pluginRepository.disablePlugin(any()) } } @@ -221,17 +207,6 @@ class PluginManagerViewModelBundledTest { coVerify(exactly = 1) { pluginRepository.disablePlugin("user.plugin") } } - @Test - fun disable_withoutABundledLambda_disablesAtOnce() = - runTest { - val viewModel = viewModel() - - viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("bundled.plugin")) - - assertThat(viewModel.firstEffect()).isInstanceOf(PluginManagerUiEffect.ShowSuccess::class.java) - coVerify(exactly = 1) { pluginRepository.disablePlugin("bundled.plugin") } - } - @Test fun confirmDisablePlugin_disables() = runTest { diff --git a/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt b/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt index d5b4297475..a637b14038 100644 --- a/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt +++ b/app/src/test/java/com/itsaky/androidide/viewmodels/TemplateManagerViewModelTest.kt @@ -69,7 +69,7 @@ class TemplateManagerViewModelTest { runTest { coEvery { repository.listTemplateFiles() } returns Result.success(listOf(item)) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() assertThat(viewModel.uiState.value.isLoading).isFalse() @@ -81,7 +81,7 @@ class TemplateManagerViewModelTest { runTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.onEvent(TemplateManagerUiEvent.InstallTemplate(item)) @@ -97,7 +97,7 @@ class TemplateManagerViewModelTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) coEvery { repository.installTemplate(item) } returns Result.success(Unit) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmInstallTemplate(item, deleteSourceAfterInstall = false) @@ -113,7 +113,7 @@ class TemplateManagerViewModelTest { coEvery { repository.installTemplate(item) } returns Result.success(Unit) coEvery { repository.deleteDownloadFile(item) } returns Result.success(Unit) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmInstallTemplate(item, deleteSourceAfterInstall = true) @@ -132,7 +132,7 @@ class TemplateManagerViewModelTest { coEvery { repository.installTemplate(item) } returns Result.success(Unit) coEvery { repository.deleteDownloadFile(item) } returns Result.failure(java.io.IOException("ro")) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmInstallTemplate(item, deleteSourceAfterInstall = true) @@ -149,7 +149,7 @@ class TemplateManagerViewModelTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) coEvery { repository.installTemplate(item) } returns Result.failure(java.io.IOException("boom")) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmInstallTemplate(item, deleteSourceAfterInstall = true) @@ -173,7 +173,7 @@ class TemplateManagerViewModelTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) coEvery { repository.installTemplate(item) } returns Result.success(Unit) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmInstallTemplate(item, deleteSourceAfterInstall = false) @@ -191,7 +191,7 @@ class TemplateManagerViewModelTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) coEvery { repository.installTemplate(item) } returns Result.failure(java.io.IOException("boom")) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmInstallTemplate(item, deleteSourceAfterInstall = false) @@ -210,13 +210,14 @@ class TemplateManagerViewModelTest { // assertion below, rather than throwing inside the coroutine and hanging first(). coEvery { repository.uninstallTemplate(installedItem) } returns Result.success(Unit) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.onEvent(TemplateManagerUiEvent.UninstallTemplate(installedItem)) advanceUntilIdle() - assertThat(viewModel.uiEffect.first()).isEqualTo(TemplateManagerUiEffect.ShowUninstallConfirmation(installedItem)) + assertThat(viewModel.uiEffect.first()) + .isEqualTo(TemplateManagerUiEffect.ShowUninstallConfirmation(installedItem, bundled = false)) coVerify(exactly = 0) { repository.uninstallTemplate(any()) } } @@ -277,7 +278,7 @@ class TemplateManagerViewModelTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) coEvery { repository.uninstallTemplate(installedItem) } returns Result.success(Unit) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmUninstallTemplate(installedItem) @@ -295,7 +296,7 @@ class TemplateManagerViewModelTest { coEvery { repository.listTemplateFiles() } returns Result.success(emptyList()) coEvery { repository.uninstallTemplate(installedItem) } returns Result.failure(java.io.IOException("boom")) - val viewModel = TemplateManagerViewModel(repository) + val viewModel = TemplateManagerViewModel(repository, isBundledTemplate = { false }) advanceUntilIdle() viewModel.confirmUninstallTemplate(installedItem) From 02755489cb7904be2f2d1230b3c5792e317a872c Mon Sep 17 00:00:00 2001 From: ADFA Date: Mon, 23 Nov 2026 17:30:56 +0000 Subject: [PATCH 3/4] style: spotless reformat, no functional change --- app/src/main/java/com/itsaky/androidide/di/PluginModule.kt | 6 +++++- .../main/java/com/itsaky/androidide/di/TemplateModule.kt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt b/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt index 1d9ba615ed..6252214662 100644 --- a/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt +++ b/app/src/main/java/com/itsaky/androidide/di/PluginModule.kt @@ -55,7 +55,11 @@ val pluginModule = connectivityObserver = get(), isOfflineModeEnabled = { BuildPreferences.isOfflineEnabled }, isBundledPlugin = { id -> - BundledAddonsRecord.inFilesDir(IDEApplication.cachedFilesDir).read()?.pluginIds?.contains(id) == true + BundledAddonsRecord + .inFilesDir(IDEApplication.cachedFilesDir) + .read() + ?.pluginIds + ?.contains(id) == true }, ) } diff --git a/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt b/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt index c13fe0516e..d21c847d7a 100644 --- a/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt +++ b/app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt @@ -28,7 +28,11 @@ val templateModule = TemplateManagerViewModel( templateRepository = get(), isBundledTemplate = { fileName -> - BundledAddonsRecord.inFilesDir(IDEApplication.cachedFilesDir).read()?.templateFiles?.contains(fileName) == true + BundledAddonsRecord + .inFilesDir(IDEApplication.cachedFilesDir) + .read() + ?.templateFiles + ?.contains(fileName) == true }, ) } From 45b5ab1550a4dbb1dd1656d92e7282724abb360c Mon Sep 17 00:00:00 2001 From: David Schachter Date: Mon, 23 Nov 2026 12:59:04 -0800 Subject: [PATCH 4/4] ADFA-7240: Name the add-on in each bundled warning With several bundled plugins, "This plugin was installed automatically" did not say which one the user had tapped. Each warning's text now starts with the plugin's or template's name, as the non-bundled dialogs do. The disable warning is decided by ID so a reloading list cannot skip it, so ShowDisableConfirmation now carries the name from the loaded list, with the ID standing in when the list lacks the plugin. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH --- .../ui/compose/plugins/PluginManagerContent.kt | 6 ++++-- .../ui/compose/plugins/PluginManagerDialogs.kt | 5 +++-- .../templates/TemplateManagerDialogs.kt | 2 +- .../ui/models/PluginManagerUiState.kt | 6 +++++- .../viewmodels/PluginManagerViewModel.kt | 10 ++++++++-- .../viewmodels/PluginManagerViewModelTest.kt | 18 ++++++++++++++++-- resources/src/main/res/values/strings.xml | 6 +++--- 7 files changed, 40 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt index 5f2c8df580..ac225140cc 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerContent.kt @@ -95,6 +95,7 @@ private sealed interface PluginManagerDialogState : Parcelable { @Parcelize data class DisableConfirm( val pluginId: String, + val pluginName: String, ) : PluginManagerDialogState @Parcelize @@ -177,7 +178,7 @@ fun PluginManagerContent( } is PluginManagerUiEffect.ShowDisableConfirmation -> { - dialogState = PluginManagerDialogState.DisableConfirm(effect.pluginId) + dialogState = PluginManagerDialogState.DisableConfirm(effect.pluginId, effect.pluginName) } is PluginManagerUiEffect.ShowRestartPrompt -> { @@ -275,8 +276,9 @@ fun PluginManagerContent( } is PluginManagerDialogState.DisableConfirm -> { - // Needs only the ID, so it shows even while the plugin list reloads. + // Carries its own name, so it shows even while the plugin list reloads. DisableBundledPluginDialog( + pluginName = dialog.pluginName, onConfirm = { viewModel.confirmDisablePlugin(dialog.pluginId) dialogState = PluginManagerDialogState.None diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt index 3fbe7d3c87..076609af50 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/plugins/PluginManagerDialogs.kt @@ -92,7 +92,7 @@ fun UninstallConfirmationDialog( text = { Text( if (bundled) { - stringResource(R.string.msg_uninstall_bundled_plugin_confirm) + stringResource(R.string.msg_uninstall_bundled_plugin_confirm, plugin.metadata.name) } else { stringResource(R.string.msg_uninstall_plugin_confirm, plugin.metadata.name) }, @@ -113,6 +113,7 @@ fun UninstallConfirmationDialog( /** Disabling a plugin that came with the app can break the installation (ADFA-7240). */ @Composable fun DisableBundledPluginDialog( + pluginName: String, onConfirm: () -> Unit, onDismiss: () -> Unit, ) { @@ -121,7 +122,7 @@ fun DisableBundledPluginDialog( title = { Text(stringResource(R.string.title_disable_bundled_plugin)) }, text = { Text( - stringResource(R.string.msg_disable_bundled_plugin_confirm), + stringResource(R.string.msg_disable_bundled_plugin_confirm, pluginName), modifier = Modifier.verticalScroll(rememberScrollState()), ) }, diff --git a/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt b/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt index dc9b9209cc..e7c0890c32 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/compose/templates/TemplateManagerDialogs.kt @@ -92,7 +92,7 @@ fun UninstallTemplateConfirmationDialog( text = { Text( if (bundled) { - stringResource(R.string.msg_uninstall_bundled_template_confirm) + stringResource(R.string.msg_uninstall_bundled_template_confirm, item.displayName) } else { stringResource(R.string.msg_uninstall_template_confirm, item.displayName) }, diff --git a/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt b/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt index ecf7ec404f..16999020fd 100644 --- a/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt +++ b/app/src/main/java/com/itsaky/androidide/ui/models/PluginManagerUiState.kt @@ -131,9 +131,13 @@ sealed class PluginManagerUiEffect { val bundled: Boolean, ) : PluginManagerUiEffect() - /** Sent instead of disabling at once, for a plugin that came with the app (ADFA-7240). */ + /** + * Sent instead of disabling at once, for a plugin that came with the app (ADFA-7240). + * [pluginName] is the plugin's name, or its ID when the loaded list does not have it. + */ data class ShowDisableConfirmation( val pluginId: String, + val pluginName: String, ) : PluginManagerUiEffect() object ShowRestartPrompt : PluginManagerUiEffect() diff --git a/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt b/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt index e0231e9f07..f2f9e15a5d 100644 --- a/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt +++ b/app/src/main/java/com/itsaky/androidide/viewmodels/PluginManagerViewModel.kt @@ -269,12 +269,18 @@ class PluginManagerViewModel( /** * A plugin that came with the app asks for confirmation first; any other disables at once. - * Decided by ID, not by the loaded list, so a list being reloaded cannot skip the warning. + * Decided by ID, not by the loaded list, so a list being reloaded cannot skip the warning; the + * list only supplies the name, and the ID stands in when it lacks the plugin. */ private fun showDisableConfirmationIfBundled(pluginId: String) { viewModelScope.launch { if (withContext(Dispatchers.IO) { isBundledPlugin(pluginId) }) { - _uiEffect.send(PluginManagerUiEffect.ShowDisableConfirmation(pluginId)) + val name = + _uiState.value.plugins + .find { it.metadata.id == pluginId } + ?.metadata + ?.name ?: pluginId + _uiEffect.send(PluginManagerUiEffect.ShowDisableConfirmation(pluginId, name)) } else { confirmDisablePlugin(pluginId) } diff --git a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt index 865fed4ea3..cde6edeaaa 100644 --- a/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt +++ b/app/src/test/java/com/itsaky/androidide/viewmodels/PluginManagerViewModelTest.kt @@ -130,7 +130,8 @@ class PluginManagerViewModelBundledTest { private fun plugin(id: String) = PluginInfo( - metadata = PluginMetadata(id, id, "1.0", "d", "a", "1.0"), + // A name unlike the ID, so a warning that names the plugin by ID fails. + metadata = PluginMetadata(id, "Name of $id", "1.0", "d", "a", "1.0"), isEnabled = true, isLoaded = true, ) @@ -192,7 +193,20 @@ class PluginManagerViewModelBundledTest { viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("bundled.plugin")) - assertThat(viewModel.firstEffect()).isEqualTo(PluginManagerUiEffect.ShowDisableConfirmation("bundled.plugin")) + assertThat(viewModel.firstEffect()) + .isEqualTo(PluginManagerUiEffect.ShowDisableConfirmation("bundled.plugin", "Name of bundled.plugin")) + coVerify(exactly = 0) { pluginRepository.disablePlugin(any()) } + } + + @Test + fun disable_bundledPluginMissingFromTheList_asksAndNamesItById() = + runTest { + val viewModel = viewModel { true } + + viewModel.onEvent(PluginManagerUiEvent.DisablePlugin("reloading.plugin")) + + assertThat(viewModel.firstEffect()) + .isEqualTo(PluginManagerUiEffect.ShowDisableConfirmation("reloading.plugin", "reloading.plugin")) coVerify(exactly = 0) { pluginRepository.disablePlugin(any()) } } diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index 75504ad3f5..5fb17c40ed 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -1353,11 +1353,11 @@ Are you sure you want to uninstall \'%1$s\'? Remove a plugin that came with the app? - This plugin was installed automatically. If you don\'t replace it with something equivalent, the installation will probably break. + \'%1$s\' was installed automatically. If you don\'t replace it with something equivalent, the installation will probably break. Disable a plugin that came with the app? - This plugin was installed automatically. If you disable it without replacing it with something equivalent, the installation will probably break. + \'%1$s\' was installed automatically. If you disable it without replacing it with something equivalent, the installation will probably break. Remove a template that came with the app? - This template was installed automatically. If you don\'t replace it with something equivalent, the installation will probably break. + \'%1$s\' was installed automatically. If you don\'t replace it with something equivalent, the installation will probably break. Continue Name Plugin ID