RohitKushvaha01 / Xed-Editor

Advanced Text Editor for android
MIT License
237 stars 13 forks source link

Cannot access directories or files on SD card #65

Closed bausensi closed 1 month ago

bausensi commented 1 month ago

Describe the bug I cannot access directories or files from the SD card. Internal storage works fine, but loading a file or a directory from the SD card causes an error screen immediately after granting SAF access.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Open a Directory'
  2. Click on 'SD Card/...'
  3. Click on 'Use this Folder'
  4. Allow access to all files
  5. See crash

Expected behavior Directory listing and file access on SD card

Screenshots If applicable, add screenshots to help explain your problem.

complete the following information):

logcat output/logcat.txt(if applicable)

Fatal Crash occurred on Thread named 'Thread-5'
Unix Time : 1722386359837
LocalTime : Jul 30, 2024 20:39:19

ACTIVE_CODENAMES = []
app_version = 2.5.0
device_model = SM-G930F
SECURITY_PATCH = 2024-05-05
BASE_OS = 
RELEASE = 14
MEDIA_PERFORMANCE_CLASS = 0
CODENAME = REL
manufacturer = samsung
RELEASE_OR_CODENAME = 14
RELEASE_OR_PREVIEW_DISPLAY = 14
KNOWN_CODENAMES = {HoneycombMr1, HoneycombMr2, Lollipop, Kitkat, Tiramisu, Gingerbread, Cupcake, IceCreamSandwichMr1, JellyBean, IceCreamSandwich, LollipopMr1, M, N, O, P, Q, R, S, Sv2, Base, NMr1, OMr1, JellyBeanMr1, JellyBeanMr2, Donut, Froyo, GingerbreadMr1, EclairMr1, UpsideDownCake, Honeycomb, Eclair01, VanillaIceCream, KitkatWatch, Base11, Eclair}
SDK_INT = 34
PREVIEW_SDK_FINGERPRINT = REL
PREVIEW_SDK_INT = 0
SDK = 34
brand = samsung
supported_abi = [arm64-v8a,armeabi-v7a,armeabi]
INCREMENTAL = eng.ivanme.20240620.225337

Error Message : Only the original thread that created a view hierarchy can touch its views. Expected: main Calling: Thread-5
Error Cause : null
Error StackTrace : 

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. Expected: main Calling: Thread-5
    at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:10493)
    at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:2247)
    at android.view.View.requestLayout(View.java:27344)
    at android.view.View.requestLayout(View.java:27344)
    at android.view.View.requestLayout(View.java:27344)
    at android.view.View.requestLayout(View.java:27344)
    at android.view.View.requestLayout(View.java:27344)
    at android.view.View.requestLayout(View.java:27344)
    at androidx.drawerlayout.widget.DrawerLayout.requestLayout(DrawerLayout.java:1353)
    at android.view.View.requestLayout(View.java:27344)
    at android.view.View.requestLayout(View.java:27344)
    at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:380)
    at android.view.View.setFlags(View.java:17755)
    at android.view.View.setVisibility(View.java:13019)
    at com.rk.xededitor.MainActivity.Init._init_$lambda$10(Init.kt:122)
    at com.rk.xededitor.MainActivity.Init.$r8$lambda$BxCBM8_mpw2154JrNc-6Qz4e3tg(Unknown Source:0)
    at com.rk.xededitor.MainActivity.Init$$ExternalSyntheticLambda8.run(D8$$SyntheticClass:0)
    at java.lang.Thread.run(Thread.java:1012)

Additional context Opening a file from 'Open File' and selecting from the Android file manager yields an empty file (read issue)

bausensi commented 1 month ago

it seems there's an issue with some threaded task regarding drawing?

RohitKushvaha01 commented 1 month ago

@bausensi try this https://github.com/RohitKushvaha01/Xed-Editor/actions/runs/10193024313#artifacts

bausensi commented 1 month ago

Thank you for your quick response, sadly it didn't change anything and the crash is exactly the same. I might be clueless but by opening from the SD card it causes a thread access exception because it uses a separate thread for something that expects the main thread, if I understand correctly.

RohitKushvaha01 commented 1 month ago

Thank you for your quick response, sadly it didn't change anything and the crash is exactly the same. I might be clueless but by opening from the SD card it causes a thread access exception because it uses a separate thread for something that expects the main thread, if I understand correctly.

@bausensi

  1. Install the Application:

  2. Open a Directory from SD Card:

    • Launch the installed Xed-Editor app.
    • Navigate to and open a directory located on your SD card.
  3. Check for Toast Message:

    • After opening the directory, observe any toast message that appears on the screen.
    • Please report the content of this toast message.
bausensi commented 1 month ago

I've opened: SD/Documents

Toast message: /storage/0000-0000/Documents (the actual path of my SD card's documents folder)

The error still appears but this time it appears to be different:

Fatal Crash occurred on Thread named 'Thread-19'
Unix Time : 1722544271672
LocalTime : Aug 1, 2024 16:31:11

ACTIVE_CODENAMES = []
app_version = 2.5.0
device_model = SM-G930F
SECURITY_PATCH = 2024-05-05
BASE_OS = 
RELEASE = 14
MEDIA_PERFORMANCE_CLASS = 0
CODENAME = REL
manufacturer = samsung
RELEASE_OR_CODENAME = 14
RELEASE_OR_PREVIEW_DISPLAY = 14
KNOWN_CODENAMES = {HoneycombMr1, HoneycombMr2, Lollipop, Kitkat, Tiramisu, Gingerbread, Cupcake, IceCreamSandwichMr1, JellyBean, IceCreamSandwich, LollipopMr1, M, N, O, P, Q, R, S, Sv2, Base, NMr1, OMr1, JellyBeanMr1, JellyBeanMr2, Donut, Froyo, GingerbreadMr1, EclairMr1, UpsideDownCake, Honeycomb, Eclair01, VanillaIceCream, KitkatWatch, Base11, Eclair}
SDK_INT = 34
PREVIEW_SDK_FINGERPRINT = REL
PREVIEW_SDK_INT = 0
SDK = 34
brand = samsung
supported_abi = [arm64-v8a,armeabi-v7a,armeabi]
INCREMENTAL = eng.ivanme.20240620.225337

Error Message : listFiles(...) must not be null
Error Cause : null
Error StackTrace : 

java.lang.NullPointerException: listFiles(...) must not be null
    at com.rk.xededitor.MainActivity.treeview2.TreeViewAdapter$Companion.merge(TreeViewAdapter.kt:188)
    at com.rk.xededitor.MainActivity.treeview2.TreeView._init_$lambda$3(TreeView.kt:36)
    at com.rk.xededitor.MainActivity.treeview2.TreeView.$r8$lambda$JBvSDOOqbKRJBQ0KIXzLdcjWoLM(Unknown Source:0)
    at com.rk.xededitor.MainActivity.treeview2.TreeView$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
    at java.lang.Thread.run(Thread.java:1012)
RohitKushvaha01 commented 1 month ago

I've opened: SD/Documents

Toast message: /storage/0000-0000/Documents (the actual path of my SD card's documents folder)

The error still appears but this time it appears to be different:

Fatal Crash occurred on Thread named 'Thread-19'
Unix Time : 1722544271672
LocalTime : Aug 1, 2024 16:31:11

ACTIVE_CODENAMES = []
app_version = 2.5.0
device_model = SM-G930F
SECURITY_PATCH = 2024-05-05
BASE_OS = 
RELEASE = 14
MEDIA_PERFORMANCE_CLASS = 0
CODENAME = REL
manufacturer = samsung
RELEASE_OR_CODENAME = 14
RELEASE_OR_PREVIEW_DISPLAY = 14
KNOWN_CODENAMES = {HoneycombMr1, HoneycombMr2, Lollipop, Kitkat, Tiramisu, Gingerbread, Cupcake, IceCreamSandwichMr1, JellyBean, IceCreamSandwich, LollipopMr1, M, N, O, P, Q, R, S, Sv2, Base, NMr1, OMr1, JellyBeanMr1, JellyBeanMr2, Donut, Froyo, GingerbreadMr1, EclairMr1, UpsideDownCake, Honeycomb, Eclair01, VanillaIceCream, KitkatWatch, Base11, Eclair}
SDK_INT = 34
PREVIEW_SDK_FINGERPRINT = REL
PREVIEW_SDK_INT = 0
SDK = 34
brand = samsung
supported_abi = [arm64-v8a,armeabi-v7a,armeabi]
INCREMENTAL = eng.ivanme.20240620.225337

Error Message : listFiles(...) must not be null
Error Cause : null
Error StackTrace : 

java.lang.NullPointerException: listFiles(...) must not be null
  at com.rk.xededitor.MainActivity.treeview2.TreeViewAdapter$Companion.merge(TreeViewAdapter.kt:188)
  at com.rk.xededitor.MainActivity.treeview2.TreeView._init_$lambda$3(TreeView.kt:36)
  at com.rk.xededitor.MainActivity.treeview2.TreeView.$r8$lambda$JBvSDOOqbKRJBQ0KIXzLdcjWoLM(Unknown Source:0)
  at com.rk.xededitor.MainActivity.treeview2.TreeView$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
  at java.lang.Thread.run(Thread.java:1012)

@bausensi

Please try this one https://github.com/RohitKushvaha01/Xed-Editor/actions/runs/10208513844#artifacts

And also make sure to verify that the app can access the sdcard by typing this command in the terminal

cd /storage/0000-0000/Documents && ls

bausensi commented 1 month ago

Thank you! The issue is partially solved! It was related to permissions. Now I can open a directory into the editor and edit files from there. Opening a file from a third place and handling it with Karbon works correctly too. However, when I try to open the same file using the Open File dialog it yields a blank file. I guess it is also related to permissions. The bug is almost solved c:

However I can't use the spacebar in the terminal since it is mapped to ESC. Is this a debug behavior?

RohitKushvaha01 commented 1 month ago

Thank you! The issue is partially solved! It was related to permissions. Now I can open a directory into the editor and edit files from there. Opening a file from a third place and handling it with Karbon works correctly too. However, when I try to open the same file using the Open File dialog it yields a blank file. I guess it is also related to permissions. The bug is almost solved c:

However I can't use the spacebar in the terminal since it is mapped to ESC. Is this a debug behavior?

@bausensi same as before give me the output of toast message when opening file from sdcard https://github.com/RohitKushvaha01/Xed-Editor/actions/runs/10211386818#artifacts

bausensi commented 1 month ago

File appears blank when opened directly from "open a file". Toast message is "/document/0000-0000:Documents/todo.txt" on both toasts

Opening the Documents directory with the "open a directory" button: "/storage/0000-0000/Documents" on both toasts, directory loads OK. Opening todo.txt from the loaded directory: no toast, file loads. The canonical path should look like "/storage/0000-0000/Documents/todo.txt" when opened from "open a file"

Excuse the delay, was busy with real life.

EDIT: added a small screen recording, please check it

https://github.com/user-attachments/assets/c2141abd-ed98-460f-81cb-571545d37c3e

RohitKushvaha01 commented 1 month ago

File appears blank when opened directly from "open a file". Toast message is "/document/0000-0000:Documents/todo.txt" on both toasts

Opening the Documents directory with the "open a directory" button: "/storage/0000-0000/Documents" on both toasts, directory loads OK. Opening todo.txt from the loaded directory: no toast, file loads. The canonical path should look like "/storage/0000-0000/Documents/todo.txt" when opened from "open a file"

Excuse the delay, was busy with real life.

EDIT: added a small screen recording, please check it 8mb.video-2wA-qskINlFe.mp4

this should fix the issue https://github.com/RohitKushvaha01/Xed-Editor/actions/runs/10259788283

bausensi commented 1 month ago

Thank you for addressing this so fast. Problem solved.