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 753 forks source link

Support for deleting system apps remounted via Magisk modules #1125

Closed d4rken closed 1 year ago

d4rken commented 7 years ago

Some Magisk modules mirror /system and replace apps in /system/app with mounts. SD Maid does currently not delete mounts and would also not understand which files to delete as SD Maid is unware of what these Magisk modules did.

Relevant modules:

also see https://github.com/d4rken/sdmaid-public/issues/1125#issuecomment-327487317

504589348384 D/Debug: Install id: 0013d19a-f4ab-450d-814c-9aa443e7862b
1504589348385 I/Debug: F: VERSIONNAME:4.8.0; VERSIONCODE:40800
1504589348385 I/Debug: P: VERSIONNAME:4.1.2; VERSIONCODE:40102
1504589348387 V/Shell:Static:Executor: SHELLDELAY:100
1504589348388 D/Debug: ro.build.id=NRD90M
1504589348388 D/Debug: ro.build.display.id=RENOVATE Dream G95X r179
1504589348388 D/Debug: ro.build.version.incremental=G950FXXU1AQH3
1504589348388 D/Debug: ro.build.version.sdk=24
1504589348388 D/Debug: ro.build.version.preview_sdk=0
1504589348388 D/Debug: ro.build.version.codename=REL
1504589348389 D/Debug: ro.build.version.all_codenames=REL
1504589348389 D/Debug: ro.build.version.release=7.0
1504589348389 D/Debug: ro.build.version.security_patch=2017-08-01
1504589348389 D/Debug: ro.build.version.base_os=
1504589348389 D/Debug: ro.build.date=Tue Aug  8 23:42:10 KST 2017
1504589348389 D/Debug: ro.build.date.utc=1502203330
1504589348389 D/Debug: ro.build.type=user
1504589348390 D/Debug: ro.build.user=dpi
1504589348390 D/Debug: ro.build.host=SWDG9810
1504589348390 D/Debug: ro.build.tags=release-keys
1504589348390 D/Debug: ro.build.flavor=dreamltexx-user
1504589348390 D/Debug: ro.product.model=SM-G950F
1504589348390 D/Debug: ro.product.brand=samsung
1504589348390 D/Debug: ro.product.name=dreamltexx
1504589348391 D/Debug: ro.product.device=dreamlte
1504589348391 D/Debug: ro.product.board=universal8895
1504589348391 D/Debug: ro.product.cpu.abi=arm64-v8a
1504589348391 D/Debug: ro.product.cpu.abilist=arm64-v8a,armeabi-v7a,armeabi
1504589348391 D/Debug: ro.product.cpu.abilist32=armeabi-v7a,armeabi
1504589348391 D/Debug: ro.product.cpu.abilist64=arm64-v8a
1504589348391 D/Debug: ro.product.manufacturer=samsung
1504589348391 D/Debug: ro.product.locale=en-GB
1504589348392 D/Debug: ro.build.product=dreamlte
1504589348392 D/Debug: ro.build.description=dreamltexx-user 7.0 NRD90M G950FXXU1AQH3 release-keys
1504589348392 D/Debug: ro.build.fingerprint=samsung/dreamltexx/dreamlte:7.0/NRD90M/G950FXXU1AQH3:user/release-keys
1504589348392 D/Debug: ro.build.characteristics=phone,emulator
1504589348392 D/Debug: ro.build.PDA=G950FXXU1AQH3
1504589348392 D/Debug: ro.build.official.release=true
1504589348392 D/Debug: ro.build.changelist=12050265
1504589348392 D/Debug: ro.product_ship=true
1504589348392 D/Debug: ro.product.first_api_level=24
1504589348393 D/Debug: ro.build.scafe.version=2017A
1504589348393 D/Debug: ro.build.selinux=1
1504589348393 D/Debug: ro.build.version.sem=2403
1504589348393 D/Debug: ro.build.version.sep=80100
1504589348974 D/RootContext:Factory: SuBinary: SuBinary(type=MAGISKSU, version=13.6, extra=null, raw=13.6:MAGISKSU (topjohnwu))
1504589348977 D/RootContext:Factory: SuApp: SuApp(packageName=com.topjohnwu.magisk, versionName=5.2.0, versionCode=52, path=/data/app/com.topjohnwu.magisk-2/base.apk)

Deleting a system app with a mount

1504589352834 V/Shell:Interactive: Output: /dev/block/sda17 on /system/priv-app/FBInstaller_NS type ext4 (ro,seclabel,relatime,block_validity,delalloc,norecovery,barrier,user_xattr,errors=panic)

leads to

1504589397271 W/SmartIO: eu.thedarken.sdm.tools.exceptions.IllegalDeletionAttempt: Illegal delete attempt on mountpoint:/system/priv-app/FBInstaller_NS
    at eu.thedarken.sdm.tools.io.x.a(SmartIO.java:285)
    at eu.thedarken.sdm.tools.io.w$a.a(SmartDeleteTask.java:72)
    at eu.thedarken.sdm.appcontrol.core.modules.uninstaller.a.b(UninstallModule.java:279)
    at eu.thedarken.sdm.appcontrol.core.modules.uninstaller.a.a(UninstallModule.java:6155)
    at eu.thedarken.sdm.appcontrol.core.modules.uninstaller.a.a(UninstallModule.java:50084)
    at eu.thedarken.sdm.appcontrol.core.AppControlWorker.b(AppControlWorker.java:19099)
    at eu.thedarken.sdm.tools.worker.a.c(AbstractWorker.java:228)
    at eu.thedarken.sdm.tools.worker.h$b.run(WorkerHub.java:206)
    at eu.thedarken.sdm.u.a(ThreadOverlord.java:142)
    at eu.thedarken.sdm.w.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at eu.thedarken.sdm.p.a(SDMThreadFactory.java:51)
    at eu.thedarken.sdm.q.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:762)

This would be required to delete system apps on some ROMs after fixing #1005 :

SuperSandro2000 commented 7 years ago

I basically run a standard magisk installation. Beta 13.6, Magisk Hide, Systemless hosts. I disabled Force encryption and dm verify to run twrp.

SuperSandro2000 commented 7 years ago

Running magisk in core only mode solves the problem. I searched trough the magisk log and it mounts the apps under /system/priv-app/ from a dummy location to their 'real' location. But this method completely destroys the purpose of magisk and requires a reboot each time to change that setting.

SuperSandro2000 commented 7 years ago

I took a log for you to take a look at it. Here is the interesting part:

I( 3147: 3259) * Loading modules
I( 3147: 3259) Fdroid-Priv: constructing magic mount structure
D( 3147: 3259) bind_mount: /dev/magisk/dummy/system/priv-app -> /system/priv-app
D( 3147: 3259) bind_mount: /magisk/Fdroid-Priv/system/priv-app/Fdroid -> /system/priv-app/Fdroid
D( 3147: 3259) bind_mount: /dev/magisk/mirror/system/priv-app/AODService_v25 -> /system/priv-app/AODService_v25
D( 3147: 3259) bind_mount: /dev/magisk/mirror/system/priv-app/AccessControl_N -> /system/priv-app/AccessControl_N
D( 3147: 3259) bind_mount: /dev/magisk/mirror/system/priv-app/AppLock -> /system/priv-app/AppLock

I can't test it today but I think FDroid Priviliges Extension adds an Systemless app under /priv-app/ and so all apps get mounted from a mirror location. No idea what to do about it. Full logs attached with core only mode which disables all modules and solves that problem. magisk logs.zip

Edit: I could imagine that if I had a module installed that replaces an app under/system/app/ that magisk would fail to delete it, too. This would need further testing.

d4rken commented 7 years ago

Just unmounting /system/priv-app/AppLock doesn't help then right? It would just delete an empty dir and the files remain under /dev/magisk/mirror/system/priv-app/AppLock? So for this to be useful we need mountpoint deletion and for SD Maids AppControl to understand "Magisk".

SuperSandro2000 commented 7 years ago

I have a very basic understanding of magisk. Generally I know that it is not magic but as far as I understand it you should be right. I am free for testing if you need it and maybe you ask @topjohnwu for advice that you not accidentally break something important.

d4rken commented 7 years ago

As Magisk is open source we should be able to figure this out ourselves, let's not bother him until necessary. I fear this might be a bit lower on my TODO list though as it's quite specific support.

SuperSandro2000 commented 7 years ago

I did further testing. This only applies if you have a module installed that replaces apps under /system/priv-app/ or /system/app/. maybe you should change the first post to reflect that.

d4rken commented 7 years ago

Got a link to the module?

SuperSandro2000 commented 7 years ago

This module places an app under /system/priv-app/ and this module replaces youtube. F-Droid Priviliges Extension is avaible in them agisk launcher and iYTBG can be downloaded from the post.