How to access /data/data with granted root access in Flutter?

Viewed 394

I have an app that has been granted root. I use root_access with a bit of bloc.

The cubit I have written and how I implemented it with BlocProvider and BlocBuilder works well. My app boots up, I grant superuser rights. An image for context:

how i grant superuser rights

Notice how I grant superuser rights once. That's because there are some components in my project that I need to show if root request is denied. I test it manually. At times, I restart the app and deny once to see how it behaves and vice versa. And it works.

The problem, however, is that I request superuser rights in order to read some files under /data/data (specific directory in the logs below).

E/flutter (10663): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Directory listing failed, path = '/data/data/com.shatteredpixel.shatteredpixeldungeon/files/' (OS Error: Permission denied, errno = 13)

I think I'm missing a detail here. I grant root rights, which means my app can do anything, right? Or the "root" as I know doesn't work as I know in Android (unlike Linux, where you are basically god)?

Is this impossible to solve? If not, how can I solve it?

Thanks in advance.


Further Troubleshooting

Providing Required Permissions

I have tried adding the permissions below to debug/AndroidManifest.xml but it did not help at all.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Also, I have seen an answer changing the target SDK version so I have changed it as below in app/build.gradle. It didn't work either.

targetSdkVersion 28

Using permission_handler

I have used permission_handler to request the permission but it does not work again.


Environment

Flutter (flutter --version) (installed with Snap):

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (13 days ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1
  • KDE Neon 5.23 (based on Ubuntu 20.04) if relevant
  • Android 9 (aosp_shamrock-userdebug 9 PQ3A. 190605.003 eng.tnhnsh.20190610.211402 test-keys)
1 Answers

add this four permission in main/AndroidManifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

and using permission handler to request the permission

   if (await Permission.storage.request().isGranted &&
       await Permission.accessMediaLocation.request().isGranted &&
       await Permission.manageExternalStorage.request().isGranted) 
                      {
                        // some useful code
                      } else {
                        print("No Permission Granted");
                      }

doing this way

E/flutter (10663): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Directory listing failed, path = '/data/data/com.shatteredpixel.shatteredpixeldungeon/files/' (OS Error: Permission denied, errno = 13)

this error will removed

**NOTE THAT**

permission handler have some android/ios configurations

Related