Closed Bambooin closed 9 months ago
Found the root cause of this crash: the media is not mounted when setup Trime in another thread.
/**
* Return the path of /storage/emulated/0.
*
* @return the path of /storage/emulated/0
*/
public static String getExternalStoragePath() {
>>> if (!UtilsBridge.isSDCardEnableByEnvironment()) return "";
return getAbsolutePath(Environment.getExternalStorageDirectory());
}
Steps to triage:
// with the this log in DataManager.kt
Timber.i(
"""
profile: ${prefs.profile}
user data path: ${userDataDir.absolutePath}
shared data path: ${sharedDataDir.absolutePath}
default custom data path: ${customDefault.absolutePath}
""",
)
// media mounted
12-23 16:19:59.247 I/[DefaultDispatcher-worker-1](23339): profile: com.osfans.trime.data.AppPrefs$Profile@1cf583e
12-23 16:19:59.247 I/[DefaultDispatcher-worker-1](23339): user data path: /storage/emulated/0/rime
12-23 16:19:59.247 I/[DefaultDispatcher-worker-1](23339): shared data path: /storage/emulated/0/rime
12-23 16:19:59.247 I/[DefaultDispatcher-worker-1](23339): default custom data path: /storage/emulated/0/rime/default.custom.yaml
// media not mounted
12-23 16:23:47.046 I/[DefaultDispatcher-worker-2]( 3134): profile: com.osfans.trime.data.AppPrefs$Profile@a5e5e60
12-23 16:23:47.046 I/[DefaultDispatcher-worker-2]( 3134): user data path: /rime
12-23 16:23:47.046 I/[DefaultDispatcher-worker-2]( 3134): shared data path: /rime
12-23 16:23:47.046 I/[DefaultDispatcher-worker-2]( 3134): default custom data path: /rime/default.custom.yaml
Strange. Does it mean that it requires some time before storage is mounted? Or need to mount manually?
I think that I find out where the problem lies.
In DataManager
, the sharedDataDir
and userDataDir
are instantiated when the App first starts. Without calling DataChangeListener.Listener.onDataDirectoryChange()
, they won't be updated even if you choose other directories in "Preference".
In your case, the sharedDataDir
will be /rime
at the phone start, and will remain at /rime
even after the media is mounted.
The fix will be either call onDataDirectoryChange()
when media mounted is detected, or change the implementation in DataManager
so it will always return the latest directory.
Describe the bug A clear and concise description of what the bug is. Crash on phone restart.
To Reproduce Steps to reproduce the bug:
Expected behavior A clear and concise description of what you expected to happen. No crash on restart.
Log If applicable, add crash log to quick focus your problem.
Screenshots If applicable, add screenshots to help explain your problem.
Smartphone (please complete the following information):
Additional context Add any other context about the problem here.