d4rken-org / sdmaid

SD Maid is an Android app that helps you manage files and apps.
https://play.google.com/store/apps/details?id=eu.thedarken.sdm
1.53k stars 755 forks source link

AppCleaner & SystemCleaner failed to clean multiple files/folders (eg. 2 mb deleted | 1 ok | 96 failed) #5179

Closed erfirya closed 3 years ago

erfirya commented 3 years ago

POCO/surya_global/surya:11/RKQ1.200826.002/V12.5.3.0.RJGMIXM:user/release-keys

sdmaid_logfile_1636381916838.txt sdmaid_logfile_1636381916838.txt.zip

d4rken commented 3 years ago

AppCleaner skips a few apps because the clear cache button was disable by the system, e.g. Gallery:

Spec(parent=AppCleaner:ACS:MIUI12Specs, label=Find & click MIUI 'Clear data' (targets=[Clear data]), pkg=com.miui.gallery), retrying: java.lang.IllegalStateException: Clickable target is disabled.

This is a bit curious:

E/AppTools: Failed to query app size for com.miui.cloudservice

This is the issue you are seeing I think:

D/AppCleaner:Worker: AppJunk(pkg=com.miui.gallery, content.size=743, nonRootPrivateCache=FPCacheFile(path=/data/user/0/com.miui.gallery/cache/private_default_cache, size=0)) has 4 roots: [SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data), SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/full_size), SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/small_size), SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/trashBin/.nomedia)]
D/SmartIO: Processing SmartDeleteTask(...)
D/d: WorkerStatus: WorkerStatus(isWorking=true, primary='Gallery', secondary='/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data', progress=[1/6], isCancelable=true, progressType=DETERMINATE, isNewWorker=false)
V/SmartIO: determine access write: NORMAL -> [SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data)]
D/ShellDeleteTask: Deleting: /storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data
D/RXS:CmdProcessor: Submitted: Cmd(timeout=0, commands=[$V530F178EB7C3 du -sk '/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data', $V530F178EB7C3 rm -r '/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data'])
V/RXS:Harvester:Error: du: No /storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data: Permission denied
V/RXS:Harvester:Error: rm: /storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data: Permission denied
W/RXS:CmdProcessor: Processed: Cmd.Result(cmd=Cmd(timeout=0, commands=[$V530F178EB7C3 du -sk '/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data', $V530F178EB7C3 rm -r '/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data']), exitcode=1, output.size()=0, errors.size()=2)
V/ShellDeleteTask: Exitcode: 1
W/SmartIO: Couldn't delete: /storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data
D/SmartIO: Delete result: ShellDeleteResult(state=ERROR, affectedsize=0, deletedFiles=0, errorFiles=1)
D/SmartIO: Processing SmartDeleteTask(...)

On Android 11, afaict you are not rooted, SD Maid can't access Android/data/...,

determine access write: NORMAL -> [SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache/remote_data)]

but SD Maid also should not be able to read that location, so how did SD Maid read Android/data on an Android 11 ROM without root :thinking:

That part is not in the log, can you share another log that includes the scan portion? Did you make changes to storage accessibility on your ROM?

erfirya commented 3 years ago

sdmaid_logfile_1636415765990.txt.zip I haven't made any changes to storage accessibility.

d4rken commented 3 years ago

Thanks for the log.

This is a tough one. I think there is just something irregular regarding storage on this POCO ROM. The queston is how to fix this without breaking it for other ROMs and without requiring "POCO ROM" checks.... :thinking:

Let's think a bit aloud...

The order in which SD Maid v5.3.5 checks determineReadAccess means that isJavaReadable() returned false, while locationInfo.hasSafAccess(checkWrite = false) returned true. We know this worked because the log shows that we got SAFFile based content back for e.g. the gallery SAFFile(path=/storage/emulated/0/Android/data/com.miui.gallery/files/gallery_disk_cache.

determineWriteAccess has a slightly different order with this clause:

location.isPublic && storage.hasFlags(Storage.Flag.PRIMARY) -> {
    AccessType.NORMAL
}

and we fall into this trap as Android/data is still considered a public location in SD Maids code. Only after this check would we check isJavaWriteable (I assume this returns false), followed by hasSafAccess(checkWrite = true) (probably returns true).

So the issue is location.isPublic && storage.hasFlags(Storage.Flag.PRIMARY) which is an optimization to allow for faster deletion as the other checks that ACTUALLY check are more expensive to run.

So we could remove this optimization or we change location.isPublic to no longer contain data and obb :thinking:

Keeping the opmization would be good for deletion speed, removing it would be good for compatibility, who knows how many weird storage permission setups will come to light when all the OEM "custom ROMs" based on Android 11/12 land :thinking:

d4rken commented 3 years ago

I think the way to go is basically:

!ApiHelper.hasAndroid11() && location.isPublic && storage.hasFlags(Storage.Flag.PRIMARY) -> {
    AccessType.NORMAL
}

Will be included in v5.3.6, if you are up for an early test, send me a mail and I'll give you a build.