Unable to create a folder with mkdir on Android device with Superuser

91 Views Asked by At

I am using LIBSU by John Wu to run superuser commands on my android app. My objective is to create a folder with mkdir but it seems that the command runs successfully but the folder isn't created.

Here's my code:

fun createDialog(packageInfo: ApplicationInfo) {
    val folderName = "LOL"
    val packageName = packageInfo.packageName
    sudo(packageName)
}

fun sudo(packageName: String) {
    val path = "/data/data/$packageName"
    val file = "lol"
    Shell.su("mount -o remount,rw $path").exec()
    if (!Shell.getShell().isRoot) {
        Log.e("Daniel", "Not rooted")
    }
    val result = Shell.su("mkdir -p $path/$file").exec()
    Shell.su("mount -o remount,ro $path").exec()
    Log.e("Daniel", result.isSuccess().toString())
}
1

There are 1 best solutions below

0
DDeveloper On

I found a fix to this problem. I don't know the exact reason why it didn't work but I need to use '-mm' as well while executing a command. For example: 'su -mm ls /data/data'

It fixed the problem.