From 7a65160e0e23e20080091a30abdd4c05fc610e06 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 31 Aug 2023 07:44:03 +1000 Subject: [PATCH] Drop legacy schema, and update to 2.1.66 backend (#14171) * Update target API to 23 * Update to 2.1.66, and switch to new schema by default + Temporarily disable unused resource warnings * Drop legacy syncing code * Drop legacy import/export code * Drop legacy tag handling * Drop legacy config handling * Drop legacy database check * Stub out unused v1 scheduler code Can't be fully removed, as we still need to be able to open a v1 collection so the user can upgrade. moveVersions test has been removed, as backend code is used for moving outside of unit tests. * Drop legacy deck handling * Drop legacy search code * Drop legacy notetype code This breaks the card template editor, so I've temporarily disabled it in the GUI. Getting it working again will require switching to the new template rendering code in the new backend. Also breaks an "empty cards" action in CardContentProvider, as I was not sure what it was trying to accomplish. * Drop legacy media code This removes oakkitten's custom media checking code, as keeping it would require keeping a bunch of the duplicated Kotlin logic. His comment about cancellation is incorrect: the call can be cancelled with backend. setWantsAbort() on a background thread. And since the app enforces filenames are normalized when they're added anyway, I don't think avoiding automatic normalization is worth the duplicated code. * Drop legacy Collection/DB code * Drop most references to defaultLegacySchema * Remove legacy schema tests from CI CI won't work yet, because backend version needs updating * Fix import CSV call * Remove some unused symbols from anki module * Drop majority of old stats code * Remove unused symbols from libanki * Remove some broken Android tests, and fix one checkIfStudyOptionsIsDisplayedOnTablet() is also consistently failing, but was doing so before I started on these changes. * Move config methods into col.config * Simplify config API - Use kotlinx.serialization so that arbitrary typed objects can be (de)serialized - There is a single generic get(), that always returns an optional value, which will be null if the key is missing, is null, or is not the correct type. There will always be collections that have invalid data, so the calling code always needs to be prepared to substitute a reasonable default in such cases. - Expose the typed getBool() method from the backend. * Remove unused legacy importer * Drop jackson * Models -> Notetypes * Remove some more unused symbols * Remove generic type aliases * Rename Model -> Notetype I had to leave ModelTest.kt's filename alone, as changing it to Notetype.kt reorders the unit tests, and causes about 4 tests to start flaking. * Get card template editor preview working again * Enable undo on edits; fix test hang * Use backend for bulk suspend/undo By default, undoableOp() notifies all screens listening for opExecuted, so the refreshing happens automatically, and the manual refresh code at the end of the old routine is no longer required. It is possible to bypass this when you want to manually update the UI, but this is probably not worth attempting until the card browser is either switched over to a recycler view, or reimplemented as a web component. The LongArrays have been switched to simple lists, as Google's protobuf code expects Iterable * Use backend for marking/undo, and change deck/undo * Migrate reviewer actions/undo to backend * Migrate remainder of undo code to backend, apart from v2 undo Couple of notes: - The legacy v2 undo no longer returns the undone card, and instead rebuilds the queue. In some circumstances (eg a learning card has become due), this can result in a different card being shown after undoing. This is not ideal, but v2 does not have long to live at this point. - The reset/reposition tests were reusing the old card cache values, which have to be reloaded after an operation. - A test in AbstractSched had to be moved to ReviewerTest so it can have access to an activity. - UndoTest has been removed, as it mainly focused on removed code. * GetCard() -> getNextCardAndRedraw() * render_output -> renderOutput() * Drop AsyncTask Probably the hardest part of AnkiDroid's code base to follow; very glad to see the end of it. Closes #7108 * Make note addition undoable * Make bulk tag update undoable * Remove remaining explicit transaction handling The backend automatically wraps backend actions in a transaction, and removing the explicit calls will allow us to drop the redundant mutex that rsdroid acquires. * Remove remaining unused classes/methods/properties * Remove FunctionalInterfaces * Switch to backend answer comparison * Remove unused locking code + legacy storage code * Switch ContentProviderTest to new schema, and fix bug * Remove legacy Deck Options settings * fix: remove minSdkVersion < 23 code * Use short time in snackbars People complained about snackbars interrupting their reviews before * fix: don't duplicate undo label It were showing a message like `Undo Undo Add Note` * Remove "Advanced statistics" * Remove legacy_schema local property * Leave zip validation up to the backend The backend takes care of validating the zip file and ensuring files aren't written outside of the media folder. I've expanded the mime match to include the zip mime, on the assumption that's what the mime type is being changed to on some devices. If that proves to be insufficient, a much simpler approach would be to look for 50 4B 03 04 at the start of the file to determine if it's a zip file or not. This leaves only Mani's add-on code using commons-compression, so you could potentially switch to a simpler tgz-specific library in the future if that is easier. * Disable two flaky tests They started to flaky reliably after the legacy deck options test was removed. * Improve logging of HTTP requests * Remove ModelBrowser Replaced by ManageNotetypes * Remove legacy CardInfo replaced by com.ichi2.anki.pages.CardInfo * Change comments at AdvancedSettingsFragment * test: check if prefs analytics list don't have extra elements * ContextCompat.getColor -> getColor that compat method is for implementations in API < 23 * Remove more unused files * refactor: move SECONDS_PER_DAY to a separate util file in order to be able to remove Stats.kt later * refactor: remove Stats and OverviewStatsBuilder * Access sched.card directly in tests The helper was adding a 500ms sleep on every fetch, which slowed the scheduler tests down considerably. * Make v3 scheduler the default; drop support for v2 The v3 scheduler was originally released in 2021, and we've been waiting for a stable AnkiDroid release to support it before we could switch users over to it. Now that 2.16 is out, we can finally push v3 out across the ecosystem. While we could theoretically make v3 the default without removing v2, here are the reasons why I think we're better off switching to v3 only: - AnkiWeb's review interface will likely switch over to v3-only in the coming weeks, and AnkiMobile will likely drop v2 around the same time 2.17 comes out. - v2 and v3 differ in a few ways that makes maintaining the two separate paths more complicated: things like the different undo paths, counts not including the current card, and the way the v3 scheduler supports custom scheduler js. 2.17 is a chance to clean up a lot of old cruft in the code base, and the old scheduling code is part of that. - v2 and v3 are compatible with each other, and don't require a full sync to change, so it doesn't break syncing with old clients (though depending on settings, due counts may differ, which needs explanation) I had to disable a couple of tests for this that we'll probably want to restore in some form: - corruptVersion16CollectionShowsDatabaseError() needs an update, and it may be time to rip out the old CollectionHelper colIsOpen(), getColSafe() and so on, migrating code that uses it over to withCol() instead. The 'collection inaccessible' dialog also needs a rethink - perhaps the various exceptions could be handled in launchCatchingTask instead. - testUndoResetsCardCountsToCorrectValue() is failing because initLayout() creates a gesture listener, which fails with an error about the looper not being initialized. I am not sure what's going on there - one option would be to move the test to androidTest. * Drop v2 sched file; rename files * Drop AbstractSched and legacy undo code/queue code * Migrate BaseSched into Scheduler * More unused symbol removal * Remove DeckTreeNode * Remove unused processChildren() * Remove shouldDisplayCounts(), as counts always available * Remove manual hashCode()/compareTo() implementations * Drop AbstractDeckTreeNode * Turn DeckNode into a wrapper for DeckTreeNode * Drop TreeNode and simplify filtering * Remove `New card position` global preference Overridden by per-deck configuration Closes #12319 * fix: remove chess.css from card_template_html * Store current queue state in reviewer Prerequisite for solving #12620 Also dropped answerButtons(), as it's always 4 * Use local HTTP server for serving flashcard content Prerequisite for solving #12620 * Implement support for custom JS scheduling Enables FSRS and closes #12620 * Remove more unused code * Remove separate Deck(Config)V16 objects and more unused code * Move some NotetypeJson methods into its file * Finish tidying Decks.kt * Drop redundant col property on Collection * Remove some usages of CollectionGetter * Rename col->getColUnsafe to encourage migration * Remove Reviewer.sched * Handle deck tree not initialized in empty collection * refactor: move syncStatus() to Collection to avoid direct calls to the backend * fix: do not show error when updating the menu if there is no internet Reproduction steps: 1. have the collection synced 2. disable the device internet connection 3. Restart the app * Remove unused resources and re-enable lint * Restore sync cancel strings * Defer loading webpage until server has initialized * Ignore translations without a base entry https://github.com/ankidroid/Anki-Android/pull/14171#issuecomment-1660286342 * Remove the SortOrder deprecation * Remove the apparently-unused Backup.kt * Remove last remaining use of Collection's context field * Stop passing Context to backend The library loading is now AnkiDroid's responsibility, so the backend does not require access to an Android context. Also remove the unused context field from Collection. * Use backend for rendering next time labels * Use backend for rendering finished message The custom study & unbury descriptions are slightly different, but should suffice until AnkiDroid can start using the Svelte finished screen. * Run SchedulerTest without Robolectric Halves the run time. To do this, I implemented a new JvmTest class and copied some of the helpers in RobolectricTest into it. * Remove unused Kotlin implementation of template parsing * Move Util code dealing with resources out of libanki * Migrate remaining libanki tests to raw JVM + Remove some commented-out tests Total savings are a drop from about 3m40s to 2m40s, with the scheduler test class dropping its runtime by about half. * Lazy-initialize col in tests * Restore 'experimental' string * Add comments to update-localizations.py * Restore AcraAnalyticsInteraction.kt --------- Co-authored-by: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> --- .github/dependabot.yml | 4 - .github/workflows/tests_unit.yml | 9 +- AnkiDroid/build.gradle | 22 +- .../com/ichi2/anki/NoteEditorTabOrderTest.kt | 2 +- .../ichi2/anki/tests/ContentProviderTest.kt | 102 +- .../com/ichi2/anki/tests/InstrumentedTest.kt | 4 +- .../java/com/ichi2/anki/tests/RustTest.kt | 47 - .../java/com/ichi2/anki/tests/Shared.kt | 4 +- .../com/ichi2/anki/tests/libanki/HttpTest.kt | 127 - .../ichi2/anki/tests/libanki/ImportTest.kt | 243 -- .../com/ichi2/anki/tests/libanki/MediaTest.kt | 148 +- .../libanki/{ModelTest.kt => NotetypeTest.kt} | 6 +- .../com/ichi2/anki/utils/DiffEngineTest.kt | 37 - .../java/com/ichi2/libanki/DBTest.kt | 44 - AnkiDroid/src/main/AndroidManifest.xml | 26 - AnkiDroid/src/main/assets/card_template.html | 10 +- AnkiDroid/src/main/assets/mathjax/conf.js | 2 +- .../main/java/com/ichi2/anim/ViewAnimation.kt | 110 - .../com/ichi2/anki/AbstractFlashcardViewer.kt | 456 ++- .../main/java/com/ichi2/anki/AnkiActivity.kt | 46 +- .../main/java/com/ichi2/anki/AnkiDroidApp.kt | 25 +- .../java/com/ichi2/anki/AnkiDroidJsAPI.kt | 3 +- .../src/main/java/com/ichi2/anki/AnkiFont.kt | 6 +- .../java/com/ichi2/anki/AnkiSerialization.kt | 38 - .../java/com/ichi2/anki/BackendBackups.kt | 6 +- .../java/com/ichi2/anki/BackendImporting.kt | 20 +- .../main/java/com/ichi2/anki/BackupManager.kt | 8 +- .../main/java/com/ichi2/anki/CardBrowser.kt | 524 +--- .../src/main/java/com/ichi2/anki/CardInfo.kt | 384 --- .../java/com/ichi2/anki/CardTemplateEditor.kt | 100 +- ...poraryModel.kt => CardTemplateNotetype.kt} | 35 +- .../com/ichi2/anki/CardTemplatePreviewer.kt | 88 +- .../src/main/java/com/ichi2/anki/CardUtils.kt | 35 - .../java/com/ichi2/anki/CollectionHelper.kt | 46 +- .../java/com/ichi2/anki/CollectionManager.kt | 62 +- .../java/com/ichi2/anki/CoroutineHelpers.kt | 20 - .../CustomMaterialTapTargetPromptBuilder.kt | 3 +- .../main/java/com/ichi2/anki/DatabaseCheck.kt | 2 +- .../com/ichi2/anki/DeckOptionsActivity.kt | 686 ---- .../main/java/com/ichi2/anki/DeckPicker.kt | 545 +--- .../com/ichi2/anki/DeckSpinnerSelection.kt | 64 +- .../main/java/com/ichi2/anki/FieldEditLine.kt | 5 +- .../main/java/com/ichi2/anki/FieldEditText.kt | 4 - .../ichi2/anki/FilterSheetBottomFragment.kt | 21 +- .../com/ichi2/anki/FilteredDeckOptions.kt | 6 +- .../src/main/java/com/ichi2/anki/Import.kt | 50 - .../src/main/java/com/ichi2/anki/Info.kt | 2 +- .../java/com/ichi2/anki/InitialActivity.kt | 6 +- .../main/java/com/ichi2/anki/IntentHandler.kt | 2 +- .../java/com/ichi2/anki/MediaRegistration.kt | 2 +- .../src/main/java/com/ichi2/anki/MetaDB.kt | 43 +- .../main/java/com/ichi2/anki/ModelBrowser.kt | 473 --- .../java/com/ichi2/anki/ModelFieldEditor.kt | 38 +- .../src/main/java/com/ichi2/anki/MyAccount.kt | 149 +- .../ichi2/anki/NavigationDrawerActivity.kt | 12 +- .../main/java/com/ichi2/anki/NoteEditor.kt | 148 +- .../src/main/java/com/ichi2/anki/Previewer.kt | 10 +- .../src/main/java/com/ichi2/anki/Reviewer.kt | 258 +- .../java/com/ichi2/anki/ReviewerServer.kt | 105 + .../com/ichi2/anki/SharedDecksActivity.kt | 2 +- .../main/java/com/ichi2/anki/Statistics.kt | 523 ---- .../com/ichi2/anki/StudyOptionsActivity.kt | 9 +- .../com/ichi2/anki/StudyOptionsFragment.kt | 88 +- .../src/main/java/com/ichi2/anki/Sync.kt | 479 +-- .../ichi2/anki/{BackendUndo.kt => Undo.kt} | 32 +- .../main/java/com/ichi2/anki/Whiteboard.kt | 9 +- .../ichi2/anki/analytics/UsageAnalytics.kt | 2 - .../com/ichi2/anki/cardviewer/CardHtml.kt | 22 +- .../java/com/ichi2/anki/cardviewer/Gesture.kt | 6 +- .../ichi2/anki/cardviewer/HtmlGenerator.kt | 11 +- .../com/ichi2/anki/cardviewer/TypeAnswer.kt | 76 +- .../ichi2/anki/dialogs/BackupPromptDialog.kt | 2 +- .../ichi2/anki/dialogs/CreateDeckDialog.kt | 25 +- .../ichi2/anki/dialogs/DatabaseErrorDialog.kt | 16 +- .../anki/dialogs/DeckPickerContextMenu.kt | 34 +- .../dialogs/DeckPickerNoSpaceLeftDialog.kt | 7 +- .../ichi2/anki/dialogs/DeckSelectionDialog.kt | 54 +- .../java/com/ichi2/anki/dialogs/HelpDialog.kt | 4 + .../dialogs/ImportFileSelectionFragment.kt | 3 +- .../anki/dialogs/ModelBrowserContextMenu.kt | 44 - .../anki/dialogs/RecursivePictureMenu.kt | 1 + .../ichi2/anki/dialogs/RescheduleDialog.kt | 4 +- .../com/ichi2/anki/dialogs/SyncErrorDialog.kt | 5 +- .../CreateCustomStudySessionListener.kt | 2 +- .../dialogs/customstudy/CustomStudyDialog.kt | 21 +- .../com/ichi2/anki/dialogs/tags/TagsDialog.kt | 2 +- .../anki/exception/ImportExportException.kt | 6 - .../anki/exception/MediaSyncException.kt | 6 - .../anki/exception/OutOfSpaceException.kt | 22 - .../exception/UnknownHttpResponseException.kt | 21 - .../anki/export/ActivityExportingDelegate.kt | 49 +- .../java/com/ichi2/anki/jsaddons/AddonData.kt | 33 +- .../com/ichi2/anki/jsaddons/AddonModel.kt | 2 +- .../anki/multimediacard/fields/AudioField.kt | 2 +- .../fields/BasicImageFieldController.kt | 10 - .../anki/multimediacard/fields/ImageField.kt | 2 +- .../com/ichi2/anki/noteeditor/FieldState.kt | 12 +- .../ichi2/anki/notetype/ManageNotetypes.kt | 26 +- .../java/com/ichi2/anki/pages/AnkiServer.kt | 50 +- .../java/com/ichi2/anki/pages/DeckOptions.kt | 6 +- .../java/com/ichi2/anki/pages/PageFragment.kt | 6 +- .../com/ichi2/anki/pages/PagesActivity.kt | 12 +- .../permissions/PermissionsRequestResults.kt | 13 - .../ichi2/anki/preferences/AboutFragment.kt | 2 +- .../preferences/AdvancedSettingsFragment.kt | 109 - .../AdvancedStatisticsSettingsFragment.kt | 28 - .../preferences/AppearanceSettingsFragment.kt | 8 +- .../CustomSyncServerSettingsFragment.kt | 3 - .../anki/preferences/DevOptionsFragment.kt | 3 +- .../preferences/GeneralSettingsFragment.kt | 9 +- .../com/ichi2/anki/preferences/Preferences.kt | 13 +- .../preferences/ReviewingSettingsFragment.kt | 22 +- .../anki/provider/CardContentProvider.kt | 264 +- .../com/ichi2/anki/receiver/SdCardReceiver.kt | 2 +- .../ichi2/anki/reviewer/ActionButtonStatus.kt | 8 - .../com/ichi2/anki/reviewer/AnswerTimer.kt | 2 - .../ichi2/anki/reviewer/AutomaticAnswer.kt | 4 +- .../java/com/ichi2/anki/reviewer/Binding.kt | 9 +- .../ichi2/anki/reviewer/MappableBinding.kt | 4 - .../anki/reviewer/PreviousAnswerIndicator.kt | 10 +- .../com/ichi2/anki/servicelayer/AsyncLayer.kt | 76 - .../anki/servicelayer/AsyncLayerAdapter.kt | 175 -- .../anki/servicelayer/DebugInfoService.kt | 19 +- .../ichi2/anki/servicelayer/DeckService.kt | 64 - .../anki/servicelayer/LanguageHintService.kt | 10 +- .../ichi2/anki/servicelayer/MediaService.kt | 2 +- .../ichi2/anki/servicelayer/NoteService.kt | 14 +- .../anki/servicelayer/SchedulerService.kt | 263 +- .../anki/servicelayer/ScopedStorageService.kt | 3 - .../ichi2/anki/servicelayer/SearchService.kt | 53 - .../java/com/ichi2/anki/servicelayer/Undo.kt | 59 - .../java/com/ichi2/anki/servicelayer/Utils.kt | 50 - .../scopedstorage/MigrateEssentialFiles.kt | 9 +- .../migrateuserdata/MigrateUserData.kt | 8 - .../com/ichi2/anki/services/BootService.kt | 35 +- .../anki/services/NotificationService.kt | 3 +- .../ichi2/anki/services/ReminderService.kt | 30 +- .../ichi2/anki/stats/AnkiStatsTaskHandler.kt | 152 - .../java/com/ichi2/anki/stats/ChartBuilder.kt | 365 --- .../java/com/ichi2/anki/stats/ChartView.kt | 89 - .../ichi2/anki/stats/OverviewStatsBuilder.kt | 308 -- .../com/ichi2/anki/stats/StatsMetaInfo.kt | 43 - .../com/ichi2/anki/ui/NoteTypeSpinnerUtils.kt | 2 +- .../screens/BackupLimitsPresenter.kt | 20 +- .../managespace/ManageSpaceFragment.kt | 28 +- .../java/com/ichi2/anki/utils/KotlinUtils.kt | 22 - .../main/java/com/ichi2/anki/utils/Time.kt | 211 ++ .../com/ichi2/anki/web/CustomSyncServer.kt | 52 - .../java/com/ichi2/anki/web/HostNumFactory.kt | 27 - .../java/com/ichi2/anki/web/HttpFetcher.kt | 12 +- .../ichi2/anki/web/PreferenceBackedHostNum.kt | 75 - .../com/ichi2/anki/widgets/DeckAdapter.kt | 196 +- .../ichi2/anki/widgets/DeckDropDownAdapter.kt | 8 +- .../java/com/ichi2/async/BaseAsyncTask.kt | 83 - .../java/com/ichi2/async/CancelListener.kt | 31 - .../main/java/com/ichi2/async/Cancellable.kt | 59 - .../java/com/ichi2/async/CollectionLoader.kt | 24 +- .../com/ichi2/async/CollectionOperations.kt | 295 +- .../java/com/ichi2/async/CollectionTask.kt | 298 -- .../main/java/com/ichi2/async/Connection.kt | 592 ---- .../java/com/ichi2/async/ProgressSender.kt | 27 - .../async/ProgressSenderAndCancelListener.kt | 19 - .../java/com/ichi2/async/SingleTaskManager.kt | 176 -- .../main/java/com/ichi2/async/TaskDelegate.kt | 53 - .../main/java/com/ichi2/async/TaskListener.kt | 49 - .../ichi2/async/TaskListenerWithContext.kt | 71 - .../main/java/com/ichi2/async/TaskManager.kt | 160 - .../main/java/com/ichi2/async/UndoActions.kt | 118 - .../src/main/java/com/ichi2/compat/Compat.kt | 6 +- .../java/com/ichi2/compat/CompatHelper.kt | 3 +- .../main/java/com/ichi2/compat/CompatV21.kt | 271 -- .../main/java/com/ichi2/compat/CompatV23.kt | 259 +- .../com/ichi2/libanki/AnkiPackageExporter.kt | 534 ---- .../com/ichi2/libanki/BackendDeckOptions.kt | 6 +- .../com/ichi2/libanki/BackendImportExport.kt | 20 +- .../java/com/ichi2/libanki/BackendMedia.kt | 71 - .../java/com/ichi2/libanki/BackendUndo.kt | 18 +- .../src/main/java/com/ichi2/libanki/Card.kt | 156 +- .../java/com/ichi2/libanki/ChangeManager.kt | 11 +- .../main/java/com/ichi2/libanki/Collection.kt | 2270 ++------------ .../com/ichi2/libanki/CollectionGetter.kt | 20 - .../java/com/ichi2/libanki/CollectionV16.kt | 269 -- .../src/main/java/com/ichi2/libanki/Config.kt | 67 +- .../java/com/ichi2/libanki/ConfigManager.kt | 60 - .../main/java/com/ichi2/libanki/ConfigV16.kt | 100 - .../src/main/java/com/ichi2/libanki/Consts.kt | 64 - .../src/main/java/com/ichi2/libanki/DB.kt | 74 +- .../src/main/java/com/ichi2/libanki/Deck.kt | 41 +- .../main/java/com/ichi2/libanki/DeckConfig.kt | 69 +- .../java/com/ichi2/libanki/DeckManager.kt | 261 -- .../src/main/java/com/ichi2/libanki/Decks.kt | 1248 ++------ .../main/java/com/ichi2/libanki/DecksV16.kt | 923 ------ .../src/main/java/com/ichi2/libanki/Finder.kt | 950 ------ .../src/main/java/com/ichi2/libanki/Media.kt | 1000 +----- .../java/com/ichi2/libanki/ModelManager.kt | 346 -- .../src/main/java/com/ichi2/libanki/Models.kt | 1121 ------- .../src/main/java/com/ichi2/libanki/Note.kt | 126 +- .../libanki/{Model.kt => NotetypeJson.kt} | 75 +- .../libanki/{ModelsV16.kt => Notetypes.kt} | 422 +-- .../java/com/ichi2/libanki/PythonTypes.kt | 9 +- .../main/java/com/ichi2/libanki/SortOrder.kt | 4 - .../src/main/java/com/ichi2/libanki/Sound.kt | 44 +- .../main/java/com/ichi2/libanki/SoundKt.kt | 12 +- .../main/java/com/ichi2/libanki/StdModels.kt | 30 +- .../main/java/com/ichi2/libanki/Storage.kt | 115 +- .../libanki/{sync/BackendSync.kt => Sync.kt} | 20 +- .../main/java/com/ichi2/libanki/TagManager.kt | 137 - .../src/main/java/com/ichi2/libanki/Tags.kt | 319 +- .../main/java/com/ichi2/libanki/TagsV16.kt | 220 -- .../java/com/ichi2/libanki/TemplateManager.kt | 63 +- .../com/ichi2/libanki/TextCardExporter.kt | 68 - .../com/ichi2/libanki/TextNoteExporter.kt | 81 - .../main/java/com/ichi2/libanki/UndoAction.kt | 102 - .../src/main/java/com/ichi2/libanki/Utils.kt | 587 ---- .../com/ichi2/libanki/backend/BackendUtils.kt | 13 - .../libanki/backend/RustConfigBackend.kt | 86 - .../libanki/backend/model/TagUsnTuple.kt | 19 - .../libanki/exception/NoSuchDeckException.kt | 28 - .../ichi2/libanki/importer/Anki2Importer.kt | 904 ------ .../libanki/importer/AnkiPackageImporter.kt | 183 -- .../libanki/importer/BackendCsvImportV16.kt | 29 - .../com/ichi2/libanki/importer/Importer.kt | 86 - .../libanki/sched/AbstractDeckTreeNode.kt | 160 - .../com/ichi2/libanki/sched/AbstractSched.kt | 210 -- .../java/com/ichi2/libanki/sched/CardQueue.kt | 72 - .../java/com/ichi2/libanki/sched/Counts.kt | 14 - .../ichi2/libanki/sched/DeckDueTreeNode.kt | 141 - .../java/com/ichi2/libanki/sched/DeckNode.kt | 144 + .../com/ichi2/libanki/sched/DeckTreeNode.kt | 27 - .../sched/{LrnCard.kt => DummyScheduler.kt} | 26 +- .../com/ichi2/libanki/sched/LrnCardQueue.kt | 48 - .../java/com/ichi2/libanki/sched/Sched.kt | 1247 -------- .../java/com/ichi2/libanki/sched/SchedV2.kt | 2789 ----------------- .../java/com/ichi2/libanki/sched/SchedV3.kt | 188 -- .../sched/{BaseSched.kt => Scheduler.kt} | 518 +-- .../ichi2/libanki/sched/SimpleCardQueue.kt | 25 - .../java/com/ichi2/libanki/sched/TreeNode.kt | 49 - .../ichi2/libanki/stats/AdvancedStatistics.kt | 1506 --------- .../com/ichi2/libanki/stats/BackendStats.kt | 13 +- .../java/com/ichi2/libanki/stats/Stats.kt | 1351 -------- .../libanki/sync/CountingFileRequestBody.kt | 60 - .../sync/CustomSyncServerUrlException.kt | 36 - .../java/com/ichi2/libanki/sync/FullSyncer.kt | 169 - .../java/com/ichi2/libanki/sync/HostNum.kt | 47 - .../java/com/ichi2/libanki/sync/HttpSyncer.kt | 360 --- .../com/ichi2/libanki/sync/MediaSyncer.kt | 268 -- .../ichi2/libanki/sync/RemoteMediaServer.kt | 170 - .../com/ichi2/libanki/sync/RemoteServer.kt | 131 - .../java/com/ichi2/libanki/sync/Syncer.kt | 866 ----- .../ichi2/libanki/sync/Tls12SocketFactory.kt | 157 - .../ichi2/libanki/sync/UnifiedTrustManager.kt | 79 - .../com/ichi2/libanki/template/Conditional.kt | 47 - .../com/ichi2/libanki/template/EmptyNode.kt | 36 - .../libanki/template/NegatedConditional.kt | 52 - .../com/ichi2/libanki/template/ParsedNode.kt | 173 - .../com/ichi2/libanki/template/ParsedNodes.kt | 93 - .../com/ichi2/libanki/template/Replacement.kt | 82 - .../ichi2/libanki/template/TemplateError.kt | 54 - .../ichi2/libanki/template/TemplateFilters.kt | 200 -- .../java/com/ichi2/libanki/template/Text.kt | 44 - .../com/ichi2/libanki/template/Tokenizer.kt | 327 -- .../com/ichi2/libanki/utils/EnumMirror.kt | 28 - .../com/ichi2/libanki/utils/NotInLibAnki.kt | 29 - .../ichi2/libanki/utils/PythonExtensions.kt | 11 - .../main/java/com/ichi2/libanki/utils/Time.kt | 5 - .../com/ichi2/libanki/utils/TimeManager.kt | 12 - .../AutoFocusEditTextPreference.kt | 3 +- .../preferences/CustomDialogPreference.kt | 51 - .../IncrementerNumberRangePreferenceCompat.kt | 7 + .../com/ichi2/preferences/TimePreference.kt | 68 - .../com/ichi2/themes/StyledProgressDialog.kt | 85 - .../src/main/java/com/ichi2/themes/Themes.kt | 3 +- .../ichi2/ui/AppCompatPreferenceActivity.kt | 2 +- .../ichi2/ui/AutoSizeCheckBoxPreference.kt | 59 - .../main/java/com/ichi2/ui/BadgeDrawable.kt | 3 - .../java/com/ichi2/ui/BadgeDrawableBuilder.kt | 7 - .../java/com/ichi2/ui/CheckBoxTriStates.kt | 1 + .../java/com/ichi2/ui/SeekBarPreference.kt | 162 - .../main/java/com/ichi2/upgrade/Upgrade.kt | 27 - .../java/com/ichi2/utils/ClipboardUtil.kt | 7 - .../main/java/com/ichi2/utils/Computation.kt | 66 - .../main/java/com/ichi2/utils/DiffEngine.kt | 87 - .../java/com/ichi2/utils/ExceptionUtil.kt | 10 - .../ichi2/utils/ExtendedFragmentFactory.kt | 7 - .../src/main/java/com/ichi2/utils/FileUtil.kt | 10 - .../ichi2/utils/FragmentManagerSupplier.kt | 2 - .../com/ichi2/utils/FunctionalInterfaces.kt | 39 - .../main/java/com/ichi2/utils/HandlerUtils.kt | 8 - .../main/java/com/ichi2/utils/ImportUtils.kt | 97 +- .../src/main/java/com/ichi2/utils/JSON.kt | 13 - .../main/java/com/ichi2/utils/JSONArray.kt | 65 - .../main/java/com/ichi2/utils/LanguageUtil.kt | 1 + .../com/ichi2/utils/MaterialBuilderUtil.kt | 11 - .../main/java/com/ichi2/utils/MethodLogger.kt | 100 - .../main/java/com/ichi2/utils/NetworkUtils.kt | 19 +- .../main/java/com/ichi2/utils/Permissions.kt | 4 - .../src/main/java/com/ichi2/utils/Repeater.kt | 56 - .../main/java/com/ichi2/utils/SyncStatus.kt | 37 +- .../src/main/java/com/ichi2/utils/Threads.kt | 23 - .../src/main/java/com/ichi2/utils/UiUtil.kt | 7 - .../com/ichi2/widget/AnkiDroidWidgetSmall.kt | 4 +- .../java/com/ichi2/widget/WidgetStatus.kt | 100 +- .../java/com/wildplot/android/parsing/Atom.kt | 154 - .../parsing/AtomTypes/FunctionXAtom.kt | 79 - .../parsing/AtomTypes/FunctionXYAtom.kt | 95 - .../parsing/AtomTypes/MathFunctionAtom.kt | 110 - .../android/parsing/AtomTypes/NumberAtom.kt | 60 - .../android/parsing/AtomTypes/VariableAtom.kt | 45 - .../parsing/AtomTypes/XVariableAtom.kt | 36 - .../parsing/AtomTypes/YVariableAtom.kt | 36 - .../wildplot/android/parsing/Expression.kt | 113 - .../parsing/ExpressionFormatException.kt | 23 - .../com/wildplot/android/parsing/Factor.kt | 99 - .../java/com/wildplot/android/parsing/Pow.kt | 125 - .../java/com/wildplot/android/parsing/Term.kt | 108 - .../android/parsing/TopLevelParser.kt | 159 - .../wildplot/android/parsing/TreeElement.kt | 21 - .../wildplot/android/rendering/BarGraph.kt | 170 - .../android/rendering/DrawableContainer.kt | 48 - .../android/rendering/LegendDrawable.kt | 48 - .../com/wildplot/android/rendering/Lines.kt | 100 - .../android/rendering/MultiScreenPart.kt | 85 - .../wildplot/android/rendering/PieChart.kt | 154 - .../wildplot/android/rendering/PlotSheet.kt | 482 --- .../com/wildplot/android/rendering/XAxis.kt | 415 --- .../com/wildplot/android/rendering/XGrid.kt | 124 - .../com/wildplot/android/rendering/YAxis.kt | 472 --- .../com/wildplot/android/rendering/YGrid.kt | 144 - .../graphics/wrapper/BasicStrokeWrap.kt | 19 - .../rendering/graphics/wrapper/ColorWrap.kt | 70 - .../graphics/wrapper/FontMetricsWrap.kt | 26 - .../graphics/wrapper/GraphicsWrap.kt | 127 - .../graphics/wrapper/RectangleWrap.kt | 43 - .../rendering/graphics/wrapper/StrokeWrap.kt | 19 - .../android/rendering/interfaces/Drawable.kt | 40 - .../rendering/interfaces/Function2D.kt | 28 - .../rendering/interfaces/Function3D.kt | 31 - .../rendering/interfaces/Legendable.kt | 24 - .../main/res/drawable/ic_schedule_white.xml | 5 - .../main/res/layout/activity_anki_stats.xml | 28 - AnkiDroid/src/main/res/layout/card_info.xml | 393 --- .../main/res/layout/fragment_anki_stats.xml | 22 - .../layout/fragment_anki_stats_overview.xml | 24 - .../src/main/res/layout/model_browser.xml | 22 - .../res/layout/model_browser_list_item.xml | 26 - AnkiDroid/src/main/res/menu/anki_stats.xml | 26 - AnkiDroid/src/main/res/menu/deck_picker.xml | 8 +- AnkiDroid/src/main/res/menu/model_browser.xml | 9 - AnkiDroid/src/main/res/values/01-core.xml | 33 +- AnkiDroid/src/main/res/values/02-strings.xml | 62 +- AnkiDroid/src/main/res/values/03-dialogs.xml | 29 - AnkiDroid/src/main/res/values/04-network.xml | 65 - .../src/main/res/values/06-statistics.xml | 130 - .../src/main/res/values/07-cardbrowser.xml | 26 - .../src/main/res/values/10-preferences.xml | 82 +- AnkiDroid/src/main/res/values/11-arrays.xml | 8 - .../src/main/res/values/17-model-manager.xml | 2 - AnkiDroid/src/main/res/values/constants.xml | 40 - .../src/main/res/values/deck_options.xml | 54 - AnkiDroid/src/main/res/values/preferences.xml | 11 - AnkiDroid/src/main/res/values/theme_dark.xml | 2 +- AnkiDroid/src/main/res/xml/deck_options.xml | 235 -- .../src/main/res/xml/preferences_advanced.xml | 27 - .../xml/preferences_advanced_statistics.xml | 40 - .../res/xml/preferences_backup_limits.xml | 11 - .../main/res/xml/preferences_reviewing.xml | 10 +- .../ichi2/anki/AbstractFlashcardViewerTest.kt | 5 +- .../anki/ActivityStartupUnderBackupTest.kt | 1 - .../java/com/ichi2/anki/AnkiDroidJsAPITest.kt | 43 +- .../anki/BackupManagerIntegrationTest.kt | 81 - .../java/com/ichi2/anki/CardBrowserTest.kt | 41 +- .../java/com/ichi2/anki/CardInfoModelTest.kt | 71 - .../com/ichi2/anki/CardTemplateEditorTest.kt | 132 +- ...delTest.kt => CardTemplateNotetypeTest.kt} | 84 +- .../ichi2/anki/CardTemplatePreviewerTest.kt | 50 +- .../com/ichi2/anki/DeckAdapterFilterTest.kt | 93 +- .../com/ichi2/anki/DeckOptionsActivityTest.kt | 27 - .../DeckPickerCheckDatabaseListenerTest.kt | 160 - .../ichi2/anki/DeckPickerCheckMediaTest.kt | 53 - .../java/com/ichi2/anki/DeckPickerTest.kt | 45 +- .../com/ichi2/anki/ModelFieldEditorTest.kt | 4 +- .../java/com/ichi2/anki/NoteEditorTest.kt | 95 +- .../ichi2/anki/ReviewerKeyboardInputTest.kt | 61 +- .../test/java/com/ichi2/anki/ReviewerTest.kt | 119 +- .../java/com/ichi2/anki/RobolectricTest.kt | 109 +- .../src/test/java/com/ichi2/anki/SyncTest.kt | 62 - .../analytics/PreferencesAnalyticsTest.kt | 36 +- .../ichi2/anki/cardviewer/CardTemplateTest.kt | 10 +- .../ichi2/anki/cardviewer/TypeAnswerTest.kt | 38 +- .../anki/dialogs/CreateDeckDialogTest.kt | 31 - .../anki/dialogs/CustomStudyDialogTest.kt | 7 +- .../anki/dialogs/DeckPickerContextMenuTest.kt | 33 +- .../com/ichi2/anki/jsaddons/AddonModelTest.kt | 10 +- .../anki/multimediacard/AudioPlayerTest.kt | 5 - .../multimediacard/fields/ImageFieldTest.kt | 2 +- .../ichi2/anki/preferences/PreferencesTest.kt | 4 +- .../reviewer/AutomaticAnswerActionTest.kt | 24 +- .../reviewer/AutomaticAnswerAndroidTest.kt | 4 +- .../ichi2/anki/reviewer/BindingAndroidTest.kt | 7 - .../MigrateEssentialFilesTest.kt | 6 +- .../ScopedStorageMigrationIntegrationTest.kt | 3 +- .../anki/servicelayer/scopedstorage/Utils.kt | 2 +- .../ichi2/anki/services/NoteServiceTest.kt | 28 +- .../anki/stats/AnkiStatsTaskHandlerTest.kt | 39 - .../anki/stats/OverviewStatsBuilderTest.kt | 111 - .../com/ichi2/anki/web/HostNumFactoryTest.kt | 33 - .../java/com/ichi2/async/CheckDatabaseTest.kt | 42 - .../java/com/ichi2/async/CountModelsTest.kt | 36 - .../com/ichi2/async/ForegroundTaskManager.kt | 90 - .../com/ichi2/compat/CompatDeleteFileTest.kt | 2 +- .../test/java/com/ichi2/compat/Test21And26.kt | 8 +- .../com/ichi2/libanki/AbstractSchedTest.kt | 111 + .../ichi2/libanki/AnkiPackageExporterTest.kt | 161 - .../test/java/com/ichi2/libanki/CardTest.kt | 39 +- .../test/java/com/ichi2/libanki/ClozeTest.kt | 130 - .../ichi2/libanki/CollectionPersistentTest.kt | 42 - .../java/com/ichi2/libanki/CollectionTest.kt | 29 +- .../test/java/com/ichi2/libanki/ConfigTest.kt | 73 +- .../test/java/com/ichi2/libanki/DecksTest.kt | 137 +- .../java/com/ichi2/libanki/ExportingTest.kt | 178 -- .../test/java/com/ichi2/libanki/FinderTest.kt | 148 +- .../test/java/com/ichi2/libanki/FlagTest.kt | 4 +- .../java/com/ichi2/libanki/ImportingTest.kt | 357 --- .../test/java/com/ichi2/libanki/LaTeXTest.kt | 6 +- .../java/com/ichi2/libanki/LegacyDecksTest.kt | 125 - .../com/ichi2/libanki/MathJaxClozeTest.kt | 76 +- .../test/java/com/ichi2/libanki/MediaTest.kt | 100 - .../test/java/com/ichi2/libanki/MetaTest.kt | 4 +- .../test/java/com/ichi2/libanki/ModelTest.kt | 574 +--- .../java/com/ichi2/libanki/NoteWithColTest.kt | 4 +- .../SchedV2Test.kt => SchedulerTest.kt} | 921 +----- .../test/java/com/ichi2/libanki/StatsTest.kt | 65 - .../com/ichi2/libanki/StorageLockingTest.kt | 86 - .../java/com/ichi2/libanki/StorageRustTest.kt | 6 +- .../java/com/ichi2/libanki/StorageTest.kt | 336 -- .../test/java/com/ichi2/libanki/TagsTest.kt | 14 +- .../com/ichi2/libanki/TextCardExporterTest.kt | 90 - .../com/ichi2/libanki/TextNoteExporterTest.kt | 101 - .../test/java/com/ichi2/libanki/UndoTest.kt | 143 - .../test/java/com/ichi2/libanki/UtilsTest.kt | 43 - .../ichi2/libanki/sched/AbstractSchedTest.kt | 523 ---- .../java/com/ichi2/libanki/sched/SchedTest.kt | 1442 --------- .../ichi2/libanki/sched/SchedUpgradeTest.kt | 62 - .../com/ichi2/libanki/sched/SchedV3Test.kt | 22 - .../com/ichi2/libanki/sync/HttpSyncerTest.kt | 122 - .../libanki/sync/RemoteMediaServerTest.kt | 122 - .../com/ichi2/libanki/template/ParserTest.kt | 184 -- .../ichi2/libanki/template/TemplateTest.kt | 162 - .../ichi2/libanki/template/TokenizerTest.kt | 392 --- .../com/ichi2/libanki/utils/EnumMirrorTest.kt | 57 - .../ichi2/preferences/TimePreferenceTest.kt | 46 - .../java/com/ichi2/testutils/ActivityList.kt | 4 - .../java/com/ichi2/testutils/AnkiAssert.kt | 4 +- .../testutils/BackendEmulatingOpenConflict.kt | 5 +- .../BackendEmulatingOpenConflictTest.kt | 2 +- .../test/java/com/ichi2/testutils/Backup.kt | 66 - .../ichi2/testutils/CollectionDBCorruption.kt | 2 +- .../com/ichi2/testutils/CollectionUtils.kt | 39 - .../test/java/com/ichi2/testutils/JvmTest.kt | 170 + .../testutils/libanki/FilteredDeckUtil.kt | 33 - .../java/com/ichi2/utils/ComputationTest.kt | 40 - .../java/com/ichi2/utils/DiffEngineTest.kt | 80 - .../test/java/com/ichi2/utils/UnzipFile.kt | 34 - .../UtilsIntegrationTest.kt | 8 +- .../android/rendering/FloatMatcher.kt | 7 - .../rendering/PieChartParameterizedTest.kt | 157 - .../android/rendering/PieChartTest.kt | 153 - .../PieChartTestParametersBuilder.kt | 59 - .../java/com/ichi2/anki/FlashCardsContract.kt | 2 + .../java/com/ichi2/anki/api/AddContentApi.kt | 1 + .../main/java/com/ichi2/anki/api/NoteInfo.kt | 1 + build.gradle | 3 +- lint-release.xml | 97 + .../lint/utils/ImportStatementDetector.kt | 40 - .../rules/InvalidStringFormatDetectorTest.kt | 6 +- tools/update-localizations.py | 5 +- 476 files changed, 4822 insertions(+), 50359 deletions(-) delete mode 100644 AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/RustTest.kt delete mode 100644 AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/HttpTest.kt delete mode 100644 AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/ImportTest.kt rename AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/{ModelTest.kt => NotetypeTest.kt} (96%) delete mode 100644 AnkiDroid/src/androidTest/java/com/ichi2/anki/utils/DiffEngineTest.kt delete mode 100644 AnkiDroid/src/androidTest/java/com/ichi2/libanki/DBTest.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anim/ViewAnimation.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/AnkiSerialization.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/CardInfo.kt rename AnkiDroid/src/main/java/com/ichi2/anki/{TemporaryModel.kt => CardTemplateNotetype.kt} (94%) delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/DeckOptionsActivity.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/ModelBrowser.kt create mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/ReviewerServer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/Statistics.kt rename AnkiDroid/src/main/java/com/ichi2/anki/{BackendUndo.kt => Undo.kt} (70%) delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/dialogs/ModelBrowserContextMenu.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/exception/ImportExportException.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/exception/MediaSyncException.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/exception/OutOfSpaceException.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/exception/UnknownHttpResponseException.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/preferences/AdvancedStatisticsSettingsFragment.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/AsyncLayer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/AsyncLayerAdapter.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/DeckService.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/SearchService.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/Undo.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/Utils.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/stats/AnkiStatsTaskHandler.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/stats/ChartBuilder.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/stats/ChartView.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/stats/OverviewStatsBuilder.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/stats/StatsMetaInfo.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/utils/KotlinUtils.kt create mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/utils/Time.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/web/CustomSyncServer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/web/HostNumFactory.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/anki/web/PreferenceBackedHostNum.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/BaseAsyncTask.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/CancelListener.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/Cancellable.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/CollectionTask.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/Connection.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/ProgressSender.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/ProgressSenderAndCancelListener.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/SingleTaskManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/TaskDelegate.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/TaskListener.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/TaskListenerWithContext.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/TaskManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/async/UndoActions.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/compat/CompatV21.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/AnkiPackageExporter.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/BackendMedia.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/CollectionGetter.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/ConfigManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/ConfigV16.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/DeckManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/DecksV16.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/Finder.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/ModelManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/Models.kt rename AnkiDroid/src/main/java/com/ichi2/libanki/{Model.kt => NotetypeJson.kt} (73%) rename AnkiDroid/src/main/java/com/ichi2/libanki/{ModelsV16.kt => Notetypes.kt} (56%) rename AnkiDroid/src/main/java/com/ichi2/libanki/{sync/BackendSync.kt => Sync.kt} (76%) delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/TagManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/TagsV16.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/TextCardExporter.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/TextNoteExporter.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/UndoAction.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/backend/RustConfigBackend.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/backend/model/TagUsnTuple.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/exception/NoSuchDeckException.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/importer/Anki2Importer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/importer/AnkiPackageImporter.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/importer/BackendCsvImportV16.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/importer/Importer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/AbstractDeckTreeNode.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/AbstractSched.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/CardQueue.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckDueTreeNode.kt create mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckNode.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckTreeNode.kt rename AnkiDroid/src/main/java/com/ichi2/libanki/sched/{LrnCard.kt => DummyScheduler.kt} (58%) delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/LrnCardQueue.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV3.kt rename AnkiDroid/src/main/java/com/ichi2/libanki/sched/{BaseSched.kt => Scheduler.kt} (62%) delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/SimpleCardQueue.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sched/TreeNode.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/stats/AdvancedStatistics.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/stats/Stats.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/CountingFileRequestBody.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/CustomSyncServerUrlException.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/FullSyncer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/HostNum.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/HttpSyncer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/MediaSyncer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/RemoteMediaServer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/RemoteServer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/Syncer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/Tls12SocketFactory.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/sync/UnifiedTrustManager.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/Conditional.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/EmptyNode.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/NegatedConditional.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/ParsedNode.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/ParsedNodes.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/Replacement.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/TemplateError.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/Text.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/template/Tokenizer.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/utils/EnumMirror.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/utils/NotInLibAnki.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/preferences/CustomDialogPreference.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/preferences/TimePreference.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/themes/StyledProgressDialog.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/ui/AutoSizeCheckBoxPreference.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/ui/SeekBarPreference.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/upgrade/Upgrade.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/utils/Computation.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/utils/DiffEngine.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/utils/FunctionalInterfaces.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/utils/MethodLogger.kt delete mode 100644 AnkiDroid/src/main/java/com/ichi2/utils/Repeater.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/Atom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/FunctionXAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/FunctionXYAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/MathFunctionAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/NumberAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/VariableAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/XVariableAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/AtomTypes/YVariableAtom.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/Expression.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/ExpressionFormatException.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/Factor.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/Pow.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/Term.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/TopLevelParser.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/parsing/TreeElement.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/BarGraph.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/DrawableContainer.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/LegendDrawable.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/Lines.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/MultiScreenPart.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/PieChart.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/PlotSheet.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/XAxis.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/XGrid.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/YAxis.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/YGrid.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/graphics/wrapper/BasicStrokeWrap.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/graphics/wrapper/ColorWrap.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/graphics/wrapper/FontMetricsWrap.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/graphics/wrapper/GraphicsWrap.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/graphics/wrapper/RectangleWrap.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/graphics/wrapper/StrokeWrap.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/interfaces/Drawable.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/interfaces/Function2D.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/interfaces/Function3D.kt delete mode 100644 AnkiDroid/src/main/java/com/wildplot/android/rendering/interfaces/Legendable.kt delete mode 100644 AnkiDroid/src/main/res/drawable/ic_schedule_white.xml delete mode 100644 AnkiDroid/src/main/res/layout/activity_anki_stats.xml delete mode 100644 AnkiDroid/src/main/res/layout/card_info.xml delete mode 100644 AnkiDroid/src/main/res/layout/fragment_anki_stats.xml delete mode 100644 AnkiDroid/src/main/res/layout/fragment_anki_stats_overview.xml delete mode 100644 AnkiDroid/src/main/res/layout/model_browser.xml delete mode 100644 AnkiDroid/src/main/res/layout/model_browser_list_item.xml delete mode 100644 AnkiDroid/src/main/res/menu/anki_stats.xml delete mode 100644 AnkiDroid/src/main/res/menu/model_browser.xml delete mode 100644 AnkiDroid/src/main/res/values/deck_options.xml delete mode 100644 AnkiDroid/src/main/res/xml/deck_options.xml delete mode 100644 AnkiDroid/src/main/res/xml/preferences_advanced_statistics.xml delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/BackupManagerIntegrationTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/CardInfoModelTest.kt rename AnkiDroid/src/test/java/com/ichi2/anki/{TemporaryModelTest.kt => CardTemplateNotetypeTest.kt} (68%) delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/DeckOptionsActivityTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerCheckDatabaseListenerTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerCheckMediaTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/SyncTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/stats/AnkiStatsTaskHandlerTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/stats/OverviewStatsBuilderTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/anki/web/HostNumFactoryTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/async/CheckDatabaseTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/async/CountModelsTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/async/ForegroundTaskManager.kt create mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/AbstractSchedTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/AnkiPackageExporterTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/ClozeTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/CollectionPersistentTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/ExportingTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/ImportingTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/LegacyDecksTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/MediaTest.kt rename AnkiDroid/src/test/java/com/ichi2/libanki/{sched/SchedV2Test.kt => SchedulerTest.kt} (63%) delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/StatsTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/StorageLockingTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/StorageTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/TextCardExporterTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/TextNoteExporterTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/UndoTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/sched/AbstractSchedTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedUpgradeTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedV3Test.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/sync/HttpSyncerTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/sync/RemoteMediaServerTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/template/ParserTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/template/TemplateTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/template/TokenizerTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/utils/EnumMirrorTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/preferences/TimePreferenceTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/testutils/Backup.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/testutils/CollectionUtils.kt create mode 100644 AnkiDroid/src/test/java/com/ichi2/testutils/JvmTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/testutils/libanki/FilteredDeckUtil.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/utils/ComputationTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/utils/DiffEngineTest.kt delete mode 100644 AnkiDroid/src/test/java/com/ichi2/utils/UnzipFile.kt rename AnkiDroid/src/test/java/com/ichi2/{libanki => utils}/UtilsIntegrationTest.kt (90%) delete mode 100644 AnkiDroid/src/test/java/com/wildplot/android/rendering/FloatMatcher.kt delete mode 100644 AnkiDroid/src/test/java/com/wildplot/android/rendering/PieChartParameterizedTest.kt delete mode 100644 AnkiDroid/src/test/java/com/wildplot/android/rendering/PieChartTest.kt delete mode 100644 AnkiDroid/src/test/java/com/wildplot/android/rendering/PieChartTestParametersBuilder.kt delete mode 100644 lint-rules/src/main/java/com/ichi2/anki/lint/utils/ImportStatementDetector.kt diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 95bf00e74f89..990718b12344 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,7 +20,3 @@ updates: - dependency-name: org.apache.commons:commons-compress versions: - ">= 1.12, < 1.23" - # We cannot update this one until minimum API24. Ignore range should slide with known versions so we stay informed. - - dependency-name: com.fasterxml.jackson.core:jackson-databind - versions: - - ">= 2.13.5, < 2.16" diff --git a/.github/workflows/tests_unit.yml b/.github/workflows/tests_unit.yml index d23a135f7dfe..6c0df7a48efd 100644 --- a/.github/workflows/tests_unit.yml +++ b/.github/workflows/tests_unit.yml @@ -39,16 +39,12 @@ concurrency: jobs: unit: - name: JUnit Tests (${{ matrix.os}}, legacy_schema = ${{ matrix.legacy_schema }}) + name: JUnit Tests (${{ matrix.os}} timeout-minutes: 40 strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - legacy_schema: [true, false] - exclude: - - os: macos-latest - legacy_schema: false runs-on: ${{ matrix.os }} #env: # CODACY_TOKEN: ${{ secrets.CODACY_TOKEN }} @@ -103,9 +99,6 @@ jobs: max_attempts: 3 command: ./gradlew robolectricSdkDownload --daemon - - name: Set legacy schema property - run: echo "legacy_schema = ${{ matrix.legacy_schema }}" >> local.properties - - name: Run Unit Tests uses: gradle/gradle-build-action@v2 with: diff --git a/AnkiDroid/build.gradle b/AnkiDroid/build.gradle index aab7bad0413e..e0f2f38552a6 100644 --- a/AnkiDroid/build.gradle +++ b/AnkiDroid/build.gradle @@ -1,6 +1,7 @@ plugins { // Gradle plugin portal id 'com.github.triplet.play' version '3.8.4' + id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0' } apply plugin: 'com.android.application' @@ -46,7 +47,6 @@ android { defaultConfig { applicationId "com.ichi2.anki" buildConfigField "Boolean", "CI", (System.getenv("CI") == "true").toString() - buildConfigField "Boolean", "LEGACY_SCHEMA", "true" buildConfigField "String", "ACRA_URL", '"https://ankidroid.org/acra/report"' buildConfigField "String", "BACKEND_VERSION", "\"$ankidroid_backend_version\"" buildConfigField "Boolean", "ENABLE_LEAK_CANARY", "false" @@ -77,7 +77,7 @@ android { // needed for upgrades to be offered correctly. versionCode=21700101 versionName="2.17alpha1" - minSdkVersion 21 + minSdkVersion 23 // change api/build.gradle // change robolectricDownloader.gradle // After #13695: change .tests_emulator.yml @@ -113,10 +113,6 @@ android { if (localProperties['enable_languages'] == "false") { android.defaultConfig.resConfigs "en" } - // allow overriding default schema version - if (localProperties["legacy_schema"] != null) { - buildConfigField "Boolean", "LEGACY_SCHEMA", localProperties["legacy_schema"] - } // allows the scoped storage migration when the user is not logged in if (localProperties["allow_unsafe_migration"] != null) { buildConfigField "Boolean", "ALLOW_UNSAFE_MIGRATION", localProperties["allow_unsafe_migration"] @@ -237,7 +233,6 @@ android { kotlinOptions { jvmTarget = JavaVersion.VERSION_11 } - ndkVersion "22.0.7026061" } play { @@ -317,14 +312,13 @@ dependencies { // Note: the design support library can be quite buggy, so test everything thoroughly before updating it // Changing the version from 1.8.0 to 1.7.0 because the item in navigation drawer is getting bold unnecessarily implementation 'com.google.android.material:material:1.7.0' - // noinspection GradleDependency jackson-databind 2.13 requires SDK 24+: https://github.com/FasterXML/jackson-databind#compatibility - implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.5' implementation 'com.vanniktech:android-image-cropper:4.5.0' implementation 'org.nanohttpd:nanohttpd:2.3.1' + implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1" // Backend libraries - implementation 'com.google.protobuf:protobuf-kotlin:3.24.1' // This is required when loading from a file + implementation 'com.google.protobuf:protobuf-kotlin-lite:3.24.1' // This is required when loading from a file Properties localProperties = new Properties() if (project.rootProject.file('local.properties').exists()) { @@ -332,9 +326,7 @@ dependencies { } if (localProperties['local_backend'] == "true") { implementation files("../../Anki-Android-Backend/rsdroid/build/outputs/aar/rsdroid-release.aar") - testImplementation files("../../Anki-Android-Backend/rsdroid-testing/build/libs/rsdroid-testing-${ankidroid_backend_version}.jar") - // On Windows, you can use something like - // implementation files("C:\\GitHub\\Rust-Test\\rsdroid\\build\\outputs\\aar\\rsdroid-release.aar") + testImplementation files("../../Anki-Android-Backend/rsdroid-testing/build/libs/rsdroid-testing.jar") } else { implementation "io.github.david-allison-1:anki-android-backend:$ankidroid_backend_version" testImplementation "io.github.david-allison-1:anki-android-backend-testing:$ankidroid_backend_version" @@ -352,10 +344,8 @@ dependencies { implementation 'com.afollestad.material-dialogs:core:3.3.0' implementation 'com.afollestad.material-dialogs:input:3.3.0' - // io.github.java-diff-utils:java-diff-utils is the natural successor here, but requires API24, #7091 - implementation 'org.bitbucket.cowwoc:diff-match-patch:1.2' // noinspection GradleDependency - commons-compress 1.12 - later versions use `File.toPath`; API26 can remove? - implementation 'org.apache.commons:commons-compress:1.12' // #6419 - handle >2GB apkg files + implementation 'org.apache.commons:commons-compress:1.12' implementation 'org.apache.commons:commons-collections4:4.4' // SetUniqueList implementation 'commons-io:commons-io:2.13.0' // FileUtils.contentEquals implementation 'net.mikehardy:google-analytics-java7:2.0.13' diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/NoteEditorTabOrderTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/NoteEditorTabOrderTest.kt index 0077f0add41c..64861b60ac55 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/NoteEditorTabOrderTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/NoteEditorTabOrderTest.kt @@ -89,6 +89,6 @@ class NoteEditorTabOrderTest : NoteEditorTest() { } private fun ensureCollectionLoaded() { - CollectionHelper.instance.getCol(targetContext) + CollectionHelper.instance.getColUnsafe(targetContext) } } diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt index e6f3525631b9..f71e00155a08 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ContentProviderTest.kt @@ -30,11 +30,8 @@ import com.ichi2.anki.exception.ConfirmModSchemaException import com.ichi2.anki.testutil.DatabaseUtils.cursorFillWindow import com.ichi2.anki.testutil.GrantStoragePermission.storagePermission import com.ichi2.anki.testutil.grantPermissions -import com.ichi2.async.TaskManager.Companion.waitToFinish import com.ichi2.libanki.* -import com.ichi2.utils.BlocksSchemaUpgrade import com.ichi2.utils.KotlinCleanup -import net.ankiweb.rsdroid.BackendFactory.defaultLegacySchema import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* import org.json.JSONObject @@ -45,8 +42,6 @@ import org.junit.Assert.assertNotEquals import org.junit.Assert.assertTrue import org.junit.Assert.fail import org.junit.Assume.* -import org.junit.runner.RunWith -import org.junit.runners.Parameterized import timber.log.Timber import java.util.* import kotlin.test.assertNotNull @@ -59,13 +54,7 @@ import kotlin.test.junit.JUnitAsserter.assertNotNull * These tests should cover all supported operations for each URI. */ @KotlinCleanup("is -> equalTo") -@RunWith(Parameterized::class) class ContentProviderTest : InstrumentedTest() { - @JvmField // required for Parameter - @Parameterized.Parameter - @KotlinCleanup("lateinit") - var schedVersion = 0 - @get:Rule var runtimePermissionRule = grantPermissions(storagePermission, FlashCardsContract.READ_WRITE_PERMISSION) @@ -87,32 +76,16 @@ class ContentProviderTest : InstrumentedTest() { * Initially create one note for each model. */ @Before - @BlocksSchemaUpgrade("some of these tests are failing; need to investigate why") @Throws( Exception::class ) @KotlinCleanup("remove 'requireNoNulls' and fix mDummyFields") fun setUp() { - assumeThat(defaultLegacySchema, `is`(true)) Timber.i("setUp()") mCreatedNotes = ArrayList() val col = col - // We have parameterized the "schedVersion" variable, if we are on an emulator - // (so it is safe) we will try to run with multiple scheduler versions - mTearDown = false - if (isEmulator()) { - col.changeSchedulerVer(schedVersion) - } else { - if (schedVersion == 1) { - assumeThat(col.sched.name, equalTo("std")) - } else { - assumeThat(col.sched.name, equalTo("std2")) - } - } mTearDown = true - // Do not teardown if setup was aborted - // Add a new basic model that we use for testing purposes (existing models could potentially be corrupted) val model = StdModels.BASIC_MODEL.add(col, BASIC_MODEL_NAME) mModelId = model.getLong("id") @@ -132,10 +105,7 @@ class ContentProviderTest : InstrumentedTest() { /* If parent already exists, don't add the deck, so * that we are sure it won't get deleted at * set-down, */ - if (col.decks.byName(partialName!!) != null) { - continue - } - val did = col.decks.id(partialName) + val did = col.decks.byName(partialName!!)?.id ?: col.decks.id(partialName) mTestDeckIds.add(did) mCreatedNotes.add(setupNewNote(col, mModelId, did, mDummyFields.requireNoNulls(), TEST_TAG)) partialName += "::" @@ -161,7 +131,7 @@ class ContentProviderTest : InstrumentedTest() { if (remnantNotes.isNotEmpty()) { val noteIds = remnantNotes.toLongArray() col.remNotes(noteIds) - col.save() + assertEquals( "Check that remnant notes have been deleted", 0, @@ -169,10 +139,7 @@ class ContentProviderTest : InstrumentedTest() { ) } // delete test decks - for (did in mTestDeckIds) { - col.decks.rem(did, cardsToo = true, childrenToo = true) - } - col.decks.flush() + col.decks.removeDecks(mTestDeckIds) assertEquals( "Check that all created decks have been deleted", mNumDecksBeforeTest, @@ -186,10 +153,10 @@ class ContentProviderTest : InstrumentedTest() { @Throws(Exception::class) private fun removeAllModelsByName(col: com.ichi2.libanki.Collection, name: String) { - var testModel = col.models.byName(name) + var testModel = col.notetypes.byName(name) while (testModel != null) { - col.models.rem(testModel) - testModel = col.models.byName(name) + col.notetypes.rem(testModel) + testModel = col.notetypes.byName(name) } } @@ -248,7 +215,7 @@ class ContentProviderTest : InstrumentedTest() { TEST_NOTE_FIELDS ) assertEquals("Check that tag was set correctly", TEST_TAG, addedNote.tags[0]) - val model: JSONObject? = col.models.get(mModelId) + val model: JSONObject? = col.notetypes.get(mModelId) assertNotNull("Check model", model) val expectedNumCards = model!!.getJSONArray("tmpls").length() assertEquals("Check that correct number of cards generated", expectedNumCards, addedNote.numberOfCards()) @@ -272,7 +239,7 @@ class ContentProviderTest : InstrumentedTest() { val cr = contentResolver var col = col // Add a new basic model that we use for testing purposes (existing models could potentially be corrupted) - var model: Model? = StdModels.BASIC_MODEL.add(col, BASIC_MODEL_NAME) + var model: NotetypeJson? = StdModels.BASIC_MODEL.add(col, BASIC_MODEL_NAME) val modelId = model!!.getLong("id") // Add the note val modelUri = ContentUris.withAppendedId(FlashCardsContract.Model.CONTENT_URI, modelId) @@ -297,7 +264,7 @@ class ContentProviderTest : InstrumentedTest() { templateUri!! ) ) - model = col.models.get(modelId) + model = col.notetypes.get(modelId) assertNotNull("Check model", model) val template = model!!.getJSONArray("tmpls").getJSONObject(expectedOrd) assertEquals( @@ -314,7 +281,7 @@ class ContentProviderTest : InstrumentedTest() { assertEquals("Check afmt", TEST_MODEL_AFMT[testIndex], template.getString("afmt")) assertEquals("Check bqfmt", TEST_MODEL_QFMT[testIndex], template.getString("bqfmt")) assertEquals("Check bafmt", TEST_MODEL_AFMT[testIndex], template.getString("bafmt")) - col.models.rem(model) + col.notetypes.rem(model) } /** @@ -326,7 +293,7 @@ class ContentProviderTest : InstrumentedTest() { // Get required objects for test val cr = contentResolver var col = col - var model: Model? = StdModels.BASIC_MODEL.add(col, BASIC_MODEL_NAME) + var model: NotetypeJson? = StdModels.BASIC_MODEL.add(col, BASIC_MODEL_NAME) val modelId = model!!.getLong("id") val initialFieldsArr = model.getJSONArray("flds") val initialFieldCount = initialFieldsArr.length() @@ -337,7 +304,7 @@ class ContentProviderTest : InstrumentedTest() { assertNotNull("Check field uri", fieldUri) // Ensure that the changes are physically saved to the DB col = reopenCol() - model = col.models.get(modelId) + model = col.notetypes.get(modelId) // Test the field is as expected val fieldId = ContentUris.parseId(fieldUri!!) assertEquals("Check field id", initialFieldCount.toLong(), fieldId) @@ -353,7 +320,7 @@ class ContentProviderTest : InstrumentedTest() { TEST_FIELD_NAME, fldsArr.getJSONObject(fldsArr.length() - 1).optString("name", "") ) - col.models.rem(model) + col.notetypes.rem(model) } /** @@ -562,7 +529,7 @@ class ContentProviderTest : InstrumentedTest() { val mid = modelUri.lastPathSegment!!.toLong() var col = reopenCol() try { - var model: JSONObject? = col.models.get(mid) + var model: JSONObject? = col.notetypes.get(mid) assertNotNull("Check model", model) assertEquals("Check model name", TEST_MODEL_NAME, model!!.getString("name")) assertEquals( @@ -591,7 +558,7 @@ class ContentProviderTest : InstrumentedTest() { `is`(greaterThan(0)) ) col = reopenCol() - model = col.models.get(mid) + model = col.notetypes.get(mid) assertNotNull("Check model", model) assertEquals("Check css", TEST_MODEL_CSS, model!!.getString("css")) // Update each of the templates in model (to test updating MODELS_ID_TEMPLATES_ID Uri) @@ -615,7 +582,7 @@ class ContentProviderTest : InstrumentedTest() { ) ) col = reopenCol() - model = col.models.get(mid) + model = col.notetypes.get(mid) assertNotNull("Check model", model) val template = model!!.getJSONArray("tmpls").getJSONObject(i) assertEquals( @@ -632,9 +599,9 @@ class ContentProviderTest : InstrumentedTest() { // Delete the model (this will force a full-sync) col.modSchemaNoCheck() try { - val model = col.models.get(mid) + val model = col.notetypes.get(mid) assertNotNull("Check model", model) - col.models.rem(model!!) + col.notetypes.rem(model!!) } catch (e: ConfirmModSchemaException) { // This will never happen } @@ -910,7 +877,7 @@ class ContentProviderTest : InstrumentedTest() { it.getLong(it.getColumnIndex(FlashCardsContract.Deck.DECK_ID)) val deckName = it.getString(it.getColumnIndex(FlashCardsContract.Deck.DECK_NAME)) - val deck = decks.get(deckID) + val deck = decks.get(deckID)!! assertNotNull("Check that the deck we received actually exists", deck) assertEquals( "Check that the received deck has the correct name", @@ -940,7 +907,7 @@ class ContentProviderTest : InstrumentedTest() { decksCursor.getLong(decksCursor.getColumnIndex(FlashCardsContract.Deck.DECK_ID)) val returnedDeckName = decksCursor.getString(decksCursor.getColumnIndex(FlashCardsContract.Deck.DECK_NAME)) - val realDeck = col.decks.get(deckId) + val realDeck = col.decks.get(deckId)!! assertEquals( "Check that received deck ID equals real deck ID", deckId, @@ -978,11 +945,8 @@ class ContentProviderTest : InstrumentedTest() { reviewInfoCursor.getLong(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID)) var nextCard: Card? = null for (i in 0..9) { // minimizing fails, when sched.reset() randomly chooses between multiple cards - col.reset() nextCard = sched.card - waitToFinish() if (nextCard != null && nextCard.note().id == noteID && nextCard.ord == cardOrd) break - waitToFinish() } assertNotNull("Check that there actually is a next scheduled card", nextCard) assertEquals( @@ -1033,7 +997,6 @@ class ContentProviderTest : InstrumentedTest() { col.decks.select(deckToTest) var nextCard: Card? = null for (i in 0..9) { // minimizing fails, when sched.reset() randomly chooses between multiple cards - col.reset() nextCard = sched.card if (nextCard != null && nextCard.note().id == noteID && nextCard.ord == cardOrd) break try { @@ -1079,7 +1042,6 @@ class ContentProviderTest : InstrumentedTest() { private fun getFirstCardFromScheduler(col: com.ichi2.libanki.Collection): Card? { val deckId = mTestDeckIds[0] col.decks.select(deckId) - col.reset() return col.sched.card } @@ -1098,8 +1060,7 @@ class ContentProviderTest : InstrumentedTest() { val reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI val noteId = card.note().id val cardOrd = card.ord - val earlyGraduatingEase = - if (schedVersion == 1) AbstractFlashcardViewer.EASE_3 else AbstractFlashcardViewer.EASE_4 + val earlyGraduatingEase = AbstractFlashcardViewer.EASE_4 val values = ContentValues().apply { val timeTaken: Long = 5000 // 5 seconds put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId) @@ -1113,7 +1074,6 @@ class ContentProviderTest : InstrumentedTest() { Thread.currentThread().join(500) } catch (e: Exception) { /* do nothing */ } - col.reset() val newCard = col.sched.card if (newCard != null) { if (newCard.note().id == card.note().id && newCard.ord == card.ord) { @@ -1167,7 +1127,7 @@ class ContentProviderTest : InstrumentedTest() { // QUEUE_TYPE_MANUALLY_BURIED was also used for SIBLING_BURIED in sched v1 assertEquals( "Card is user-buried", - if (schedVersion == 1) Consts.QUEUE_TYPE_SIBLING_BURIED else Consts.QUEUE_TYPE_MANUALLY_BURIED, + Consts.QUEUE_TYPE_MANUALLY_BURIED, cardAfterUpdate.queue ) @@ -1220,8 +1180,7 @@ class ContentProviderTest : InstrumentedTest() { // cleanup, unsuspend card and reschedule // -------------------------------------- - col.sched.unsuspendCards(longArrayOf(cardId)) - col.reset() + col.sched.unsuspendCards(listOf(cardId)) } /** @@ -1272,8 +1231,8 @@ class ContentProviderTest : InstrumentedTest() { isEmulator() ) val col = col - col.models.all()[0].put("did", JSONObject.NULL) - col.save() + col.notetypes.all()[0].put("did", JSONObject.NULL) + val cr = contentResolver // Query all available models val allModels = cr.query(FlashCardsContract.Model.CONTENT_URI, null, null, null, null) @@ -1281,7 +1240,7 @@ class ContentProviderTest : InstrumentedTest() { } private fun reopenCol(): com.ichi2.libanki.Collection { - CollectionHelper.instance.closeCollection(false, "ContentProviderTest: reopenCol") + CollectionHelper.instance.closeCollection("ContentProviderTest: reopenCol") return col } @@ -1289,13 +1248,6 @@ class ContentProviderTest : InstrumentedTest() { get() = testContext.contentResolver companion object { - @Parameterized.Parameters - @JvmStatic // required for initParameters - fun initParameters(): Collection> { - // This does one run with schedVersion injected as 1, and one run as 2 - return listOf(arrayOf(1), arrayOf(2)) - } - private const val BASIC_MODEL_NAME = "com.ichi2.anki.provider.test.basic.x94oa3F" private const val TEST_FIELD_NAME = "TestFieldName" private const val TEST_FIELD_VALUE = "test field value" @@ -1326,7 +1278,7 @@ class ContentProviderTest : InstrumentedTest() { fields: Array, tag: String ): Uri { - val newNote = Note(col, col.models.get(mid)!!) + val newNote = Note(col, col.notetypes.get(mid)!!) for (idx in fields.indices) { newNote.setField(idx, fields[idx]) } diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt index 54e31efff036..37c63fe08146 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt @@ -29,11 +29,11 @@ import java.io.IOException abstract class InstrumentedTest { protected val col: Collection - get() = CollectionHelper.instance.getCol(testContext)!! + get() = CollectionHelper.instance.getColUnsafe(testContext)!! @get:Throws(IOException::class) protected val emptyCol: Collection - get() = Shared.getEmptyCol(testContext) + get() = Shared.getEmptyCol() @get:Rule val ensureAllFilesAccessRule = EnsureAllFilesAccessRule() diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/RustTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/RustTest.kt deleted file mode 100644 index fb9728b0ebf4..000000000000 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/RustTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 David Allison - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 3 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -package com.ichi2.anki.tests - -import com.ichi2.libanki.Storage -import net.ankiweb.rsdroid.BackendException -import net.ankiweb.rsdroid.BackendFactory -import org.hamcrest.MatcherAssert -import org.hamcrest.Matchers.equalTo -import org.junit.Assume.assumeThat -import org.junit.Rule -import org.junit.Test -import org.junit.rules.Timeout -import java.io.IOException -import java.util.concurrent.TimeUnit - -class RustTest : InstrumentedTest() { - /** Ensure that the database isn't be locked - * This happened before the database code was converted to use the Rust backend. - */ - @get:Rule - var timeout = Timeout(30, TimeUnit.SECONDS) - - @Test - @Throws(BackendException::class, IOException::class) - fun collectionIsVersion11AfterOpen() { - assumeThat(BackendFactory.defaultLegacySchema, equalTo(true)) - // This test will be decommissioned, but before we get an upgrade strategy, we need to ensure we're not upgrading the database. - val path = Shared.getTestFilePath(testContext, "initial_version_2_12_1.anki2") - val collection = Storage.collection(testContext, path) - val ver = collection.db.queryScalar("select ver from col") - MatcherAssert.assertThat(ver, equalTo(11)) - } -} diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/Shared.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/Shared.kt index a98a33485c02..9b97e80d320b 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/Shared.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/Shared.kt @@ -31,13 +31,13 @@ import java.io.IOException @KotlinCleanup("maybe delete Shared object and make inner functions as top level") object Shared { @Throws(IOException::class) - fun getEmptyCol(context: Context): Collection { + fun getEmptyCol(): Collection { val f = File.createTempFile("test", ".anki2") // Provide a string instead of an actual File. Storage.Collection won't populate the DB // if the file already exists (it assumes it's an existing DB). val path = f.absolutePath assertTrue(f.delete()) - return Storage.collection(context, path) + return Storage.collection(path) } /** diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/HttpTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/HttpTest.kt deleted file mode 100644 index 70273bea0fcd..000000000000 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/HttpTest.kt +++ /dev/null @@ -1,127 +0,0 @@ -/*************************************************************************************** - * * - * Copyright (c) 2018 Mike Hardy * - * * - * This program is free software; you can redistribute it and/or modify it under * - * the terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 3 of the License, or (at your option) any later * - * version. * - * * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY * - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * - * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along with * - * this program. If not, see . * - ****************************************************************************************/ - -package com.ichi2.anki.tests.libanki - -import android.Manifest -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import com.ichi2.anki.testutil.GrantStoragePermission.storagePermission -import com.ichi2.anki.testutil.grantPermissions -import com.ichi2.async.Connection -import com.ichi2.libanki.sync.HostNum -import com.ichi2.utils.NetworkUtils -import org.junit.Assert -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class HttpTest { - - @get:Rule - var runtimeStoragePermissionRule = grantPermissions( - storagePermission, - Manifest.permission.INTERNET, - Manifest.permission.ACCESS_NETWORK_STATE - ) - - // #7108: AsyncTask - @Suppress("DEPRECATION") - @Test - fun testLogin() { - val username = "AnkiDroidInstrumentedTestUser" - val password = "AnkiDroidInstrumentedTestInvalidPass" - val invalidPayload = Connection.Payload(arrayOf(username, password, HostNum(null))) - val testListener = TestTaskListener(invalidPayload) - - // We have to carefully run things on the main thread here or the threading protections in BaseAsyncTask throw - // The first one is just to run the static initializer, really - val onlineRunnable = Runnable { - try { - Class.forName("com.ichi2.async.Connection") - } catch (e: Exception) { - Assert.fail("Unable to load Connection class: " + e.message) - } - } - InstrumentationRegistry.getInstrumentation().runOnMainSync(onlineRunnable) - - // If we are not online this test is not nearly as interesting - // TODO simulate offline programmatically - currently exercised by manually toggling an emulator offline pre-test - if (!NetworkUtils.isOnline) { - Connection.login(testListener, invalidPayload) - Assert.assertFalse( - "Successful login despite being offline", - testListener.getPayload()!!.success - ) - Assert.assertTrue( - "onDisconnected not called despite being offline", - testListener.disconnectedCalled - ) - return - } - - val r = Runnable { - val conn = Connection.login(testListener, invalidPayload) - try { - // This forces us to synchronously wait for the AsyncTask to do it's work - conn!!.get() - } catch (e: Exception) { - Assert.fail("Caught exception while trying to login: " + e.message) - } - } - InstrumentationRegistry.getInstrumentation().runOnMainSync(r) - Assert.assertFalse( - "Successful login despite invalid credentials", - testListener.getPayload()!!.success - ) - } - - class TestTaskListener(payload: Connection.Payload) : - Connection.TaskListener { - - private var payload: Connection.Payload? = null - var disconnectedCalled = false - private fun setPayload(payload: Connection.Payload) { - this.payload = payload - } - - override fun onPreExecute() { - // do nothing - } - - override fun onProgressUpdate(vararg values: Any?) { - // do nothing - } - - fun getPayload(): Connection.Payload? { - return payload - } - - override fun onPostExecute(data: Connection.Payload) { - // do nothing - } - - override fun onDisconnected() { - disconnectedCalled = true - } - - init { - setPayload(payload) - } - } -} diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/ImportTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/ImportTest.kt deleted file mode 100644 index 3dfae8df7118..000000000000 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/ImportTest.kt +++ /dev/null @@ -1,243 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2016 Houssam Salem * - * * - * This program is free software; you can redistribute it and/or modify it under * - * the terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 3 of the License, or (at your option) any later * - * version. * - * * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY * - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * - * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along with * - * this program. If not, see . * - ****************************************************************************************/ -package com.ichi2.anki.tests.libanki - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.ichi2.anki.exception.ImportExportException -import com.ichi2.anki.tests.InstrumentedTest -import com.ichi2.anki.tests.Shared -import com.ichi2.anki.testutil.GrantStoragePermission -import com.ichi2.libanki.Collection -import com.ichi2.libanki.importer.Anki2Importer -import com.ichi2.libanki.importer.AnkiPackageImporter -import com.ichi2.libanki.importer.Importer -import net.ankiweb.rsdroid.BackendFactory.defaultLegacySchema -import org.hamcrest.Matchers.equalTo -import org.json.JSONException -import org.junit.After -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Assume.assumeThat -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import java.io.File -import java.io.FileOutputStream -import java.io.IOException - -@RunWith(AndroidJUnit4::class) -class ImportTest : InstrumentedTest() { - private lateinit var testCol: Collection - - @get:Rule - var runtimePermissionRule = GrantStoragePermission.instance - - // testAnki2Mediadupes() failed on Travis API=22 EMU_FLAVOR=default ABI=armeabi-v7a - // com.ichi2.anki.tests.libanki.ImportTest > testAnki2Mediadupes[test(AVD) - 5.1.1] FAILED - // error: - // android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly database (code 1032) - // at io.requery.android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method) - // :AnkiDroid:connectedDebugAndroidTest FAILED - // - // Error code 1032 is https://www.sqlite.org/rescode.html#readonly_dbmoved - which should be impossible - // - // I was unable to reproduce it on the same emulator locally, even with thousands of iterations. - // Allowing it to re-run now, 3 times, in case it flakes again. - @get:Rule - var retry = RetryRule(10) - - @Before - @Throws(IOException::class) - fun setUp() { - testCol = emptyCol - // the backend provides its own importing methods - assumeThat(defaultLegacySchema, equalTo(true)) - } - - @After - fun tearDown() { - testCol.close() - } - - @Test - @Throws(IOException::class, JSONException::class, ImportExportException::class) - fun testAnki2Mediadupes() { - // add a note that references a sound - var n = testCol.newNote() - n.setField(0, "[sound:foo.mp3]") - val mid = n.model().getLong("id") - testCol.addNote(n) - // add that sound to the media directory - var os = FileOutputStream(File(testCol.media.dir(), "foo.mp3"), false) - os.write("foo".toByteArray()) - os.close() - testCol.close() - // it should be imported correctly into an empty deck - val empty = emptyCol - var imp: Importer = Anki2Importer(empty, testCol.path) - imp.run() - var expected = listOf("foo.mp3") - var actual = File(empty.media.dir()).list()!!.toMutableList() - actual.retainAll(expected) - assertEquals(expected.size.toLong(), actual.size.toLong()) - // and importing again will not duplicate, as the file content matches - empty.removeCardsAndOrphanedNotes(empty.db.queryLongList("select id from cards")) - imp = Anki2Importer(empty, testCol.path) - imp.run() - expected = listOf("foo.mp3") - actual = mutableListOf(*File(empty.media.dir()).list()!!) - actual.retainAll(expected) - assertEquals(expected.size.toLong(), actual.size.toLong()) - n = empty.getNote(empty.db.queryLongScalar("select id from notes")) - assertTrue("foo.mp3" in n.fields[0]) - // if the local file content is different, and import should trigger a rename - empty.removeCardsAndOrphanedNotes(empty.db.queryLongList("select id from cards")) - os = FileOutputStream(File(empty.media.dir(), "foo.mp3"), false) - os.write("bar".toByteArray()) - os.close() - imp = Anki2Importer(empty, testCol.path) - imp.run() - expected = listOf("foo.mp3", "foo_$mid.mp3") - actual = mutableListOf(*File(empty.media.dir()).list()!!) - actual.retainAll(expected) - assertEquals(expected.size.toLong(), actual.size.toLong()) - n = empty.getNote(empty.db.queryLongScalar("select id from notes")) - assertTrue(n.fields[0].contains("_")) - // if the localized media file already exists, we rewrite the note and media - empty.removeCardsAndOrphanedNotes(empty.db.queryLongList("select id from cards")) - os = FileOutputStream(File(empty.media.dir(), "foo.mp3")) - os.write("bar".toByteArray()) - os.close() - imp = Anki2Importer(empty, testCol.path) - imp.run() - expected = listOf("foo.mp3", "foo_$mid.mp3") - actual = mutableListOf(*File(empty.media.dir()).list()!!) - actual.retainAll(expected) - assertEquals(expected.size.toLong(), actual.size.toLong()) - n = empty.getNote(empty.db.queryLongScalar("select id from notes")) - assertTrue(n.fields[0].contains("_")) - empty.close() - } - - @Test - @Throws(IOException::class, ImportExportException::class) - fun testApkg() { - val apkg = Shared.getTestFilePath(testContext, "media.apkg") - var imp: Importer = AnkiPackageImporter(testCol, apkg) - var expected: List = emptyList() - var actual = mutableListOf( - *File( - testCol.media.dir() - ).list()!! - ) - actual.retainAll(expected) - assertEquals(actual.size.toLong(), 0) - imp.run() - expected = listOf("foo.wav") - actual = mutableListOf(*File(testCol.media.dir()).list()!!) - actual.retainAll(expected) - assertEquals(expected.size.toLong(), actual.size.toLong()) - // import again should be idempotent in terms of media - testCol.removeCardsAndOrphanedNotes(testCol.db.queryLongList("select id from cards")) - imp = AnkiPackageImporter(testCol, apkg) - imp.run() - expected = listOf("foo.wav") - actual = mutableListOf(*File(testCol.media.dir()).list()!!) - actual.retainAll(expected) - assertEquals(expected.size.toLong(), actual.size.toLong()) - // but if the local file has different data, it will rename - testCol.removeCardsAndOrphanedNotes(testCol.db.queryLongList("select id from cards")) - val os = FileOutputStream(File(testCol.media.dir(), "foo.wav"), false) - os.write("xyz".toByteArray()) - os.close() - imp = AnkiPackageImporter(testCol, apkg) - imp.run() - assertEquals(2, File(testCol.media.dir()).list()!!.size.toLong()) - } - - @Test - @Throws(IOException::class, JSONException::class, ImportExportException::class) - fun testAnki2DiffmodelTemplates() { - // different from the above as this one tests only the template text being - // changed, not the number of cards/fields - // import the first version of the model - var tmp = Shared.getTestFilePath(testContext, "diffmodeltemplates-1.apkg") - var imp = AnkiPackageImporter(testCol, tmp) - imp.setDupeOnSchemaChange(true) - imp.run() - // then the version with updated template - tmp = Shared.getTestFilePath(testContext, "diffmodeltemplates-2.apkg") - imp = AnkiPackageImporter(testCol, tmp) - imp.setDupeOnSchemaChange(true) - imp.run() - // collection should contain the note we imported - assertEquals(1, testCol.noteCount().toLong()) - // the front template should contain the text added in the 2nd package - val tcid = testCol.findCards("")[0] - val tnote = testCol.getCard(tcid).note() - assertTrue( - testCol.findTemplates(tnote)[0].getString("qfmt").contains("Changed Front Template") - ) - } - - @Test - @Throws(IOException::class, ImportExportException::class) - fun testAnki2Updates() { - // create a new empty deck - var tmp = Shared.getTestFilePath(testContext, "update1.apkg") - var imp = AnkiPackageImporter(testCol, tmp) - imp.run() - assertEquals(0, imp.dupes) - assertEquals(1, imp.added) - assertEquals(0, imp.updated) - // importing again should be idempotent - imp = AnkiPackageImporter(testCol, tmp) - imp.run() - assertEquals(1, imp.dupes) - assertEquals(0, imp.added) - assertEquals(0, imp.updated) - // importing a newer note should update - assertEquals(1, testCol.noteCount().toLong()) - assertTrue(testCol.db.queryString("select flds from notes").startsWith("hello")) - tmp = Shared.getTestFilePath(testContext, "update2.apkg") - imp = AnkiPackageImporter(testCol, tmp) - imp.run() - assertEquals(1, imp.dupes) - assertEquals(0, imp.added) - assertEquals(1, imp.updated) - assertTrue(testCol.db.queryString("select flds from notes").startsWith("goodbye")) - } - - /** - * Custom tests for AnkiDroid. - */ - @Test - @Throws(IOException::class, ImportExportException::class) - fun testDupeIgnore() { - // create a new empty deck - var tmp = Shared.getTestFilePath(testContext, "update1.apkg") - var imp = AnkiPackageImporter(testCol, tmp) - imp.run() - tmp = Shared.getTestFilePath(testContext, "update3.apkg") - imp = AnkiPackageImporter(testCol, tmp) - imp.run() - // there is a dupe, but it was ignored - assertEquals(1, imp.dupes) - assertEquals(0, imp.added) - assertEquals(0, imp.updated) - } -} diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt index 1648d5b7d77f..b2bc4392feaa 100644 --- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt +++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt @@ -22,9 +22,6 @@ import com.ichi2.anki.testutil.GrantStoragePermission import com.ichi2.libanki.Collection import com.ichi2.libanki.Media import com.ichi2.libanki.exception.EmptyMediaException -import net.ankiweb.rsdroid.BackendFactory.defaultLegacySchema -import org.hamcrest.MatcherAssert -import org.hamcrest.Matchers import org.junit.* import org.junit.runner.RunWith import java.io.File @@ -32,7 +29,6 @@ import java.io.FileOutputStream import java.io.IOException import kotlin.test.assertEquals import kotlin.test.assertNotEquals -import kotlin.test.assertNotNull import kotlin.test.assertTrue import kotlin.test.fail @@ -99,71 +95,11 @@ class MediaTest : InstrumentedTest() { } } - @Test - @Suppress("SpellCheckingInspection") - fun testStrings() { - val mid = mTestCol!!.models.getModels().entries.iterator().next().key - - var expected: List = emptyList() - var actual = mTestCol!!.media.filesInStr(mid, "aoeu").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("foo.jpg") - actual = mTestCol!!.media.filesInStr(mid, "aoeuao").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("foo.jpg", "bar.jpg") - actual = mTestCol!!.media.filesInStr(mid, """aoeuao""").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("foo.jpg") - actual = mTestCol!!.media.filesInStr(mid, "aoeuao").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("one", "two") - actual = mTestCol!!.media.filesInStr(mid, "").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("foo.jpg") - actual = mTestCol!!.media.filesInStr(mid, """aoeuao""").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("foo.jpg", "fo") - actual = - mTestCol!!.media.filesInStr(mid, """aoeuao""").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - expected = listOf("foo.mp3") - actual = mTestCol!!.media.filesInStr(mid, "aou[sound:foo.mp3]aou").toMutableList() - actual.retainAll(expected) - assertEquals(expected.size, actual.size) - - assertEquals("aoeu", mTestCol!!.media.strip("aoeu")) - assertEquals("aoeuaoeu", mTestCol!!.media.strip("aoeu[sound:foo.mp3]aoeu")) - assertEquals("aoeu", mTestCol!!.media.strip("aoeu")) - assertEquals("aoeu", Media.escapeImages("aoeu")) - assertEquals( - "", - Media.escapeImages("") - ) - assertEquals( - """""", - Media.escapeImages("""""") - ) - } - @Test @Throws(IOException::class, EmptyMediaException::class) fun testDeckIntegration() { // create a media dir - mTestCol!!.media.dir() + mTestCol!!.media.dir // Put a file into it val file = createNonEmptyFile("fake.png") mTestCol!!.media.addFile(file) @@ -178,7 +114,7 @@ class MediaTest : InstrumentedTest() { f.setField(1, "") mTestCol!!.addNote(f) // and add another file which isn't used - val os = FileOutputStream(File(mTestCol!!.media.dir(), "foo.jpg"), false) + val os = FileOutputStream(File(mTestCol!!.media.dir, "foo.jpg"), false) os.write("test".toByteArray()) os.close() // check media @@ -193,86 +129,6 @@ class MediaTest : InstrumentedTest() { assertEquals(expected.size, actual.size) } - @Test - @Suppress("SpellCheckingInspection") - fun testAudioTags() { - assertEquals("aoeu", mTestCol!!.media.strip("a