Describe the bug
When setting an external repository, using the top bar back arrow bypasses the permission pop up dialog, which result in an internal crash.
Pressing the system back button after the crash screen makes the permission dialog appears.
Pressing the system back button instead of the top bar back arrow does not crash.
To Reproduce
Steps to reproduce the behavior:
Get your local git repository on your phone
Click on 'Use Local Directory'
Click on 'SD-CARD', then 'OK'
Select your repository
Click on 'Allow' (I think it is only for Android 10+)
Click on your back button
Click on the top arrow to go back (not the back button)
Using the system back arrow does bring the permission dialog.
Expected behavior
The storage permission pop up should appear, then the main screen should appear.
Screenshots
Crash Log
kotlin.KotlinNullPointerException
at com.zeapo.pwdstore.utils.PasswordRepository$Companion.initialize(PasswordRepository.kt:175)
at com.zeapo.pwdstore.PasswordStore.createRepository(PasswordStore.kt:368)
at com.zeapo.pwdstore.PasswordStore.initializeRepositoryInfo(PasswordStore.kt:411)
at com.zeapo.pwdstore.PasswordStore.onActivityResult(PasswordStore.kt:673)
at android.app.Activity.dispatchActivityResult(Activity.java:8131)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Device information (please complete the following information):
Device: onePlus 6T
OS: LineageOS 17.1
App version 1.7.0 / master
Additional context
The issue is, I think, because onActivityResult is called before onResume when using the top back arrow, so initializeRepositoryInfo is called before the permission dialog.
Given that the app does not have the permission, dir in PasswordRepository L.175 does not exist.
On the other hand, when using the system back button, no resultCode is set, which makes the app to bypass onActivityResult (initializeRepositoryInfo is then not called) , so onResume can show the permission dialog, and then everything works fine.
I think actually that the non crashing path is also wrong, because setResult is not called when using this button, so both path should be fixed:
Add a callback to onBackPressed in order to add setResult(Activity.RESULT_OK) when pressing the system back button
Make the content of onResume called before onActivityResult, or at least before initializeRepositoryInfo
I might have the time to make a fix for this later this week :grinning:
Describe the bug When setting an external repository, using the top bar back arrow bypasses the permission pop up dialog, which result in an internal crash. Pressing the system back button after the crash screen makes the permission dialog appears.
Pressing the system back button instead of the top bar back arrow does not crash.
To Reproduce Steps to reproduce the behavior:
Using the system back arrow does bring the permission dialog.
Expected behavior The storage permission pop up should appear, then the main screen should appear.
Screenshots
Crash Log
Device information (please complete the following information):
Additional context The issue is, I think, because
onActivityResult
is called beforeonResume
when using the top back arrow, soinitializeRepositoryInfo
is called before the permission dialog. Given that the app does not have the permission,dir
inPasswordRepository
L.175 does not exist.On the other hand, when using the system back button, no
resultCode
is set, which makes the app to bypassonActivityResult
(initializeRepositoryInfo
is then not called) , soonResume
can show the permission dialog, and then everything works fine.I think actually that the non crashing path is also wrong, because
setResult
is not called when using this button, so both path should be fixed:onBackPressed
in order to addsetResult(Activity.RESULT_OK)
when pressing the system back buttononResume
called beforeonActivityResult
, or at least beforeinitializeRepositoryInfo
I might have the time to make a fix for this later this week :grinning: