@@ -190,7 +190,7 @@ open class AnkiDroidApp :
190190 setupContextMenus()
191191 setupNotificationChannels(applicationContext)
192192
193- makeBackendUsable(this )
193+ setup( " makeBackendUsable" ) { makeBackendUsable (this ) }
194194
195195 // Probe WebView availability before any other init touches it (#5794).
196196 if (! checkWebViewAvailable()) {
@@ -259,41 +259,42 @@ open class AnkiDroidApp :
259259 * In most cases the Anki Backend now creates the collection and [initializeAnkiDroidDirectory]
260260 * is called on startup of the activity.
261261 */
262- private fun initializeAnkiDroidDirectory () {
263- // #13207: `getCurrentAnkiDroidDirectory` failing is an unconditional be a fatal error
264- // TODO: For now, a null getExternalFilesDir, but a valid AnkiDroid Directory in prefs
265- // is not considered to be a fatal error, unless the directory itself is not writable.
266- val ankiDroidDir =
267- try {
268- CollectionHelper .getCurrentAnkiDroidDirectory(this )
269- } catch (e: SystemStorageException ) {
270- fatalInitializationError = FatalInitializationError .StorageError (e)
271- return
272- }
262+ private fun initializeAnkiDroidDirectory () =
263+ setup(" initializeAnkiDroidDirectory" ) {
264+ // #13207: `getCurrentAnkiDroidDirectory` failing is an unconditional be a fatal error
265+ // TODO: For now, a null getExternalFilesDir, but a valid AnkiDroid Directory in prefs
266+ // is not considered to be a fatal error, unless the directory itself is not writable.
267+ val ankiDroidDir =
268+ try {
269+ CollectionHelper .getCurrentAnkiDroidDirectory(this )
270+ } catch (e: SystemStorageException ) {
271+ fatalInitializationError = FatalInitializationError .StorageError (e)
272+ return @setup
273+ }
273274
274- // TODO: This line is questionable, as it doesn't work on most post-scoped-storage
275- // builds/Android versions, but we call initializeAnkiDroidDirectory later on startup
276- if (! Permissions .hasLegacyStorageAccessPermission(this )) return
275+ // TODO: This line is questionable, as it doesn't work on most post-scoped-storage
276+ // builds/Android versions, but we call initializeAnkiDroidDirectory later on startup
277+ if (! Permissions .hasLegacyStorageAccessPermission(this )) return @setup
277278
278- try {
279- CollectionHelper .initializeAnkiDroidDirectory(ankiDroidDir)
280- return
281- } catch (e: StorageAccessException ) {
282- Timber .e(e, " Could not initialize AnkiDroid directory" )
283279 try {
284- val defaultDir = CollectionHelper .getDefaultAnkiDroidDirectory(this )
285- if (SdCard .isMounted && CollectionHelper .getCurrentAnkiDroidDirectory(this ) == defaultDir) {
286- // Don't send report if the user is using a custom directory as SD cards trip up here a lot
287- sendExceptionReport(e, " AnkiDroidApp.onCreate" )
280+ CollectionHelper .initializeAnkiDroidDirectory(ankiDroidDir)
281+ return @setup
282+ } catch (e: StorageAccessException ) {
283+ Timber .e(e, " Could not initialize AnkiDroid directory" )
284+ try {
285+ val defaultDir = CollectionHelper .getDefaultAnkiDroidDirectory(this )
286+ if (SdCard .isMounted && CollectionHelper .getCurrentAnkiDroidDirectory(this ) == defaultDir) {
287+ // Don't send report if the user is using a custom directory as SD cards trip up here a lot
288+ sendExceptionReport(e, " AnkiDroidApp.onCreate" )
289+ }
290+ } catch (e: SystemStorageException ) {
291+ // The user can't write to the AnkiDroid directory (=> cant write to the collection)
292+ // AND getExternalFilesDir is null - file permissions are likely corrupted (Android 16 bug)
293+ // => show the 'fatal storage error' screen
294+ fatalInitializationError = FatalInitializationError .StorageError (e)
288295 }
289- } catch (e: SystemStorageException ) {
290- // The user can't write to the AnkiDroid directory (=> cant write to the collection)
291- // AND getExternalFilesDir is null - file permissions are likely corrupted (Android 16 bug)
292- // => show the 'fatal storage error' screen
293- fatalInitializationError = FatalInitializationError .StorageError (e)
294296 }
295297 }
296- }
297298
298299 /* *
299300 * Sets up display of the context menus which appear when long pressing text on external apps,
0 commit comments