Storage access permission not always sufficient for CreateFile outside scoped storage

6 views
Skip to first unread message

FrickelPit

unread,
2:02 PM (9 hours ago) 2:02 PM
to DroidScript
Hello, on my Motorola Edge 50 Neo with Android 15, I've noticed with DroidScript version 2.79.1 that the storage access permission for CreateFile is only sufficient within the Downloads and Documents folders. CopyFile, for example, doesn't have this restriction and works in other folders as well. Has anyone else experienced this? I'd like to know if this is due to Android 15 or Motorola.
Attached is a SPK file for testing.
Regards, Peter
testSharedFolderAccess.spk

Alan Hendry

unread,
4:49 PM (7 hours ago) 4:49 PM
to DroidScript
HI,
Forgotten exactly where this test came from.
It was fairly recent to test whuch DS functions work with Uri
Regards, ah

appFilename  = app.GetAppName() + ".js"
testFilename = "test.js"
myFilename   = "myFile.js"
permUri      = ""

function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );
    permBtn = app.AddButton(lay, "GetPermission - choose a foldername without spaces", -1, -1, "Monospace");
    permBtn.SetOnTouch(permBtnOnTouch)

    app.AddLayout( lay );
}

function permBtnOnTouch() {
    permUri = ""
    app.GetPermission("internal", onPermission)
}

function onPermission(uri) {
    if (uri) {
        uri = app.Uri2Path(uri) // ?
        txtUriHeader = app.AddText(lay, "Choosed Uri folder", -1, -1, "Bold")
        txtUri = app.AddText(lay, "", -1, -1, "MultiLine")
        txtListUriFolderHeader = app.AddText(lay, "Files in Uri folder (no indication)", -1, -1, "Bold")
        txtListUriFolderHeader.SetTextColor("red")
        txtListUriFolder = app.AddText(lay, "", -1, -1, "MultiLine")
        copyFileBtn = app.AddButton(lay, "Copy appFile to Uri folder", -1, -1, "Monospace");
        copyFileBtn.SetOnTouch(copyFileBtnOnTouch)
        copyFolderBtn = app.AddButton(lay, "Copy Uri folder to 'copiedFolder' in Uri folder (warning)", -1, -1, "Monospace");
        copyFolderBtn.SetTextColor("red")
        copyFolderBtn.SetOnTouch(copyFolderBtnOnTouch)
        fileExistsBtn = app.AddButton(lay, "Check existence of appFile in Uri folder (always false)", -1, -1, "Monospace");
        fileExistsBtn.SetTextColor("red")
        fileExistsBtn.SetOnTouch(fileExistsBtnOnTouch)
        folderExistsBtn = app.AddButton(lay, "Check existence of Uri folder (always false)", -1, -1, "Monospace");
        folderExistsBtn.SetTextColor("red")
        folderExistsBtn.SetOnTouch(folderExistsBtnOnTouch)
        delFileBtn = app.AddButton(lay, "Delete appFile in Uri folder", -1, -1, "Monospace");
        delFileBtn.SetOnTouch(delFileBtnOnTouch)
        delFolderBtn = app.AddButton(lay, "Delete Uri folder (no indication)", -1, -1, "Monospace");
        delFolderBtn.SetTextColor("red")
        delFolderBtn.SetOnTouch(delFolderBtnOnTouch)
        readFileBtn = app.AddButton(lay, "Read content of appFile in Uri folder", -1, -1, "Monospace");
        readFileBtn.SetOnTouch(readFileBtnOnTouch)
        writeFileBtn = app.AddButton(lay, "Write 'myFile.js' to Uri folder", -1, -1, "Monospace");
        writeFileBtn.SetOnTouch(writeFileBtnOnTouch)
        renFileBtn = app.AddButton(lay, "Rename newly written 'myFile.js' in Uri folder to 'renamedFile.js'", -1, -1, "Monospace");
        renFileBtn.SetOnTouch(renFileBtnOnTouch)
        zipFileBtn = app.AddButton(lay, "Zip newly written 'myFile.js' in Uri folder to 'myFile.js.zip' (warning)", -1, -1, "Monospace");
        zipFileBtn.SetTextColor("red")
        zipFileBtn.SetOnTouch(zipFileBtnOnTouch)
        zipFolderBtn = app.AddButton(lay, "Zip Uri folder to 'zippedFolder' in Uri folder (warning)", -1, -1, "Monospace");
        zipFolderBtn.SetTextColor("red")
        zipFolderBtn.SetOnTouch(zipFolderBtnOnTouch)
       
        permUri = uri
        txtUri.SetText(permUri)
        listUriFolder()
    }
}

function copyFileBtnOnTouch() {
    app.CopyFile(appFilename, permUri + "/" + appFilename)
    listUriFolder()
}

function copyFolderBtnOnTouch() {
    app.CopyFolder(permUri, permUri + "/" + "copiedFolder")
    listUriFolder()
}

function fileExistsBtnOnTouch() {
    app.Alert("File exists: " + app.FileExists(permUri + "/" + appFilename))
}

function folderExistsBtnOnTouch() {
    app.Alert("Folder exists: " + app.FolderExists(permUri))
}

function delFileBtnOnTouch() {
    app.DeleteFile(permUri + "/" + appFilename)
    listUriFolder()
}

function delFolderBtnOnTouch() {
    app.DeleteFolder(permUri)
    listUriFolder()
}

function readFileBtnOnTouch() {
    app.Alert("File read: " + app.ReadFile(permUri + "/" + appFilename))
}

function writeFileBtnOnTouch() {
    app.WriteFile(permUri + "/" + myFilename, "//My file")
    listUriFolder()
}

function renFileBtnOnTouch() {
    app.WriteFile(permUri + "/" + myFilename, "//My file")
    app.RenameFile(permUri + "/" + myFilename, permUri + "/" + "renamedFile.js")
    listUriFolder()
}

function zipFileBtnOnTouch() {
    app.WriteFile(permUri + "/" + myFilename, "//My file")
    app.ZipFile(permUri + "/" + myFilename, permUri + "/" + myFilename + ".zip")
    listUriFolder()
}

function zipFolderBtnOnTouch() {
    app.ZipFolder(permUri, permUri + "/" + "zippedFolder")
    listUriFolder()
}

function listUriFolder() {
    txtListUriFolder.SetText(app.ListFolder(permUri).join("\n"))
}
Reply all
Reply to author
Forward
0 new messages