@@ -43,7 +43,7 @@ import java.io.File
4343class ProfileManager private constructor(
4444 context : Context ,
4545) {
46- private val appContext = context.applicationContext
46+ private val profileContext = context.applicationContext
4747
4848 lateinit var activeProfileContext: Context
4949 private set
@@ -53,7 +53,7 @@ class ProfileManager private constructor(
5353 * ID of the currently active profile.
5454 */
5555 private val globalProfilePrefs by lazy {
56- appContext .getSharedPreferences(PROFILE_REGISTRY_FILENAME , Context .MODE_PRIVATE )
56+ profileContext .getSharedPreferences(PROFILE_REGISTRY_FILENAME , Context .MODE_PRIVATE )
5757 }
5858
5959 private val profileRegistry by lazy { ProfileRegistry (globalProfilePrefs) }
@@ -171,7 +171,7 @@ class ProfileManager private constructor(
171171 try {
172172 val wrapper =
173173 ProfileContextWrapper .create(
174- context = appContext ,
174+ context = profileContext ,
175175 profileId = profileId,
176176 profileBaseDir = profileBaseDir.file,
177177 )
@@ -208,7 +208,7 @@ class ProfileManager private constructor(
208208 if (prefs.getString(PREF_COLLECTION_PATH , null ) != null ) return
209209
210210 val profileCollectionDir =
211- getDefaultAnkiDroidDirectory(appContext , directoryName = profileId.value).apply { mkdirs() }
211+ getDefaultAnkiDroidDirectory(profileContext , directoryName = profileId.value).apply { mkdirs() }
212212
213213 prefs.edit { putString(PREF_COLLECTION_PATH , profileCollectionDir.absolutePath) }
214214 }
@@ -243,8 +243,8 @@ class ProfileManager private constructor(
243243 */
244244 private fun resolveProfileDirectory (profileId : ProfileId ): ProfileRestrictedDirectory {
245245 val appDataRoot =
246- ContextCompat .getDataDir(appContext )
247- ? : appContext .filesDir.parentFile
246+ ContextCompat .getDataDir(profileContext )
247+ ? : profileContext .filesDir.parentFile
248248
249249 if (appDataRoot == null ) {
250250 val e = IllegalStateException (" Cannot resolve Application Data Directory" )
@@ -333,7 +333,7 @@ class ProfileManager private constructor(
333333
334334 Timber .i(" deleteProfile: starting deletion of %s" , profileId)
335335
336- val appDataRoot = ContextCompat .getDataDir(appContext )
336+ val appDataRoot = ContextCompat .getDataDir(profileContext )
337337
338338 if (profileId.isDefault()) {
339339 Timber .d(" deleteProfile: wiping legacy default-profile data under %s" , appDataRoot)
@@ -405,13 +405,13 @@ class ProfileManager private constructor(
405405 * The default-location fallback used when the profile has never written `PREF_COLLECTION_PATH`.
406406 *
407407 * TODO: consolidate with the profile-creation path this should delegate to
408- * `CollectionHelper.getDefaultAnkiDroidDirectory(appContext , directoryName = ...)`
408+ * `CollectionHelper.getDefaultAnkiDroidDirectory(profileContext , directoryName = ...)`
409409 * that gives us legacy-storage handling and `SystemStorageException`-on-null for free, and keeps
410410 * the "where does a profile collection live" decision in a single place shared with
411411 * `ensureProfileCollectionPath`.
412412 */
413413 private fun defaultCollectionDirFor (profileId : ProfileId ): File ? {
414- val externalFilesDir = appContext .getExternalFilesDir(null ) ? : return null
414+ val externalFilesDir = profileContext .getExternalFilesDir(null ) ? : return null
415415 return if (profileId.isDefault()) {
416416 File (externalFilesDir, " AnkiDroid" )
417417 } else {
@@ -430,10 +430,10 @@ class ProfileManager private constructor(
430430 * TODO: extract a `ProfilePreferences` accessor (e.g. `prefsForProfile(profileId).collectionPath`)
431431 */
432432 private fun readStoredCollectionPath (profileId : ProfileId ): String? {
433- val defaultPrefsName = " ${appContext .packageName} _preferences"
433+ val defaultPrefsName = " ${profileContext .packageName} _preferences"
434434 val prefsName =
435435 if (profileId.isDefault()) defaultPrefsName else " profile_${profileId.value} _$defaultPrefsName "
436- return appContext
436+ return profileContext
437437 .getSharedPreferences(prefsName, Context .MODE_PRIVATE )
438438 .getString(PREF_COLLECTION_PATH , null )
439439 }
0 commit comments