topjohnwu / Magisk

The Magic Mask for Android
GNU General Public License v3.0
48.22k stars 12.3k forks source link

Simple module hangs leaving Magisk unusable #3050

Closed bsngardner closed 4 years ago

bsngardner commented 4 years ago

Magisk Manager 7.5.1 Magisk 20.4 Pixel 3 Android 10

I started making a simple Magisk Module to turn a user app into a system app. It failed, and while I would like to know why, my main concern is getting Magisk to work again. With the Magisk-patched boot image, the phone hangs on the Google logo. I can get the phone back to working order by simply flashing back to the stock boot.img, but then I cannot remove the module from /data/adb/modules. Any advice on that front would be appreciated.

In case it helps, this is what I have for the module:

❯ tree fakegps 
fakegps
├── fakegps_sysapp.zip
├── META-INF
│   └── com
│       └── google
│           └── android
│               ├── update-binary
│               └── updater-script
├── module.prop
└── system
    └── priv-app
        └── com.incorporateapps.fakegps_route
            ├── base.apk
            ├── lib
            └── oat
                └── arm64
                    ├── base.odex
                    └── base.vdex

10 directories, 7 files

❯ cat fakegps/module.prop 
id=fakegps_sysapp
name=Fake GPS Route as System App
version=0.0.1
versionCode=1
author=Broderick Gardner
description=Just sticks the Fake GPS Route app into /system/priv-apps

update-binary contains only the text #MAGISK with no newline. I wasn't sure if this was correct, but a strict reading of the guide indicated that. updater-script I copied from https://github.com/topjohnwu/Magisk/blob/master/scripts/module_installer.sh as indicated by the dev guide.

I am mostly unfamiliar with android bootloader shenanigans, so I don't know where to get logs and the like. I am a software engineer though, so I can pick it up quickly with some direction.

Thanks

bsngardner commented 4 years ago

I found the problem with the module; nothing I had previously read indicated I needed to add permissions to make it a system app, but clearly I did. From adb logcat:

--------- beginning of crash
08-05 01:11:36.299  1345  1345 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: main
08-05 01:11:36.299  1345  1345 E AndroidRuntime: java.lang.IllegalStateException: Signature|privileged permissions not in privapp-permissions whitelist: {com.incorporateapps.fakegps_route: android.permission.UPDATE_APP_OPS_STATS, com.incorporateapps.fakegps_route: android.permission.WRITE_SECURE_SETTINGS, com.incorporateapps.fakegps_route: android.permission.CHANGE_COMPONENT_ENABLED_STATE, com.incorporateapps.fakegps_route: android.permission.INSTALL_LOCATION_PROVIDER}
...

Sorry for the noise. This can be closed as soon as I figure out if there is a way to disable the bad module without a factory reset.

osm0sis commented 4 years ago

Recovery to delete or Safe Mode to disable

bsngardner commented 4 years ago

Can you be slightly more specific? I don't have a rooted recovery because TWRP doesn't have a release for Pixel 3's android 10 yet. Will safe mode stop Magisk from loading modules? Thanks

osm0sis commented 4 years ago

Yep there's a key combo that will force disable them all. Should be in the documentation.

bsngardner commented 4 years ago

If you are referring to a key combo specific to Magisk, I haven't seen anything about that. If you are referring to the safe mode combo specific to my device, that is not disabling modules. My device still hangs on the google logo. I tested that combo (hold volume down at google splash) with a normal boot.img, and it correctly enters safe mode.

bsngardner commented 4 years ago

I found in the magisk source where it checks for the volume down press for 3 seconds (I never found anything about that in the docs). I tried holding volume down for over 30 seconds starting from immediately after the bootloader, and it didn't do anything. The permission error happens, indicating that the module loaded. At this point, I have to assume something is incompatible in my hardware for magisk's way of detecting button presses during boot. I guess I have to factory reset. Thanks for your help.

tytydraco commented 4 years ago

I found in the magisk source where it checks for the volume down press for 3 seconds (I never found anything about that in the docs). I tried holding volume down for over 30 seconds starting from immediately after the bootloader, and it didn't do anything. The permission error happens, indicating that the module loaded. At this point, I have to assume something is incompatible in my hardware for magisk's way of detecting button presses during boot. I guess I have to factory reset. Thanks for your help.

It should be part of the Canary builds

bsngardner commented 4 years ago

I'm using the Canary builds. To be specific, I started only using the release, but while preparing this ticket, I installed Magisk Manager from app-debug.apk in the canary builds. I repatched the boot.img from that, and that is the patched boot image I have been using since. Either the check_key_combo code is somehow still not enabled in what I'm running or I'm missing the window to press it (if I press too early, it enters fastboot instead).

tytydraco commented 4 years ago

I thought it just checks the system prop for safe mode not a key combo. I just hold volume down immediately after the screen turns on and it boots into safe mode. Maybe the key combo is different per-device?

bsngardner commented 4 years ago

Safe mode works with the stock boot.img. It's magisk that's not detecting it.

edit: *and not disabling all the modules

tytydraco commented 4 years ago

https://github.com/tytydraco/safetymode

Try this. I made it recently. Rapidly press volume up while booting and it'll disable all modules and reboot you.

I put a submission in the modules page but I closed it when I learned this was being added to magisk.

bsngardner commented 4 years ago

That looks great, but I can't install it. If I could, then I could also fix my problem already. I can't root my device because magisk fails to boot. I have been searching for hours for another way to root, but none of them work. Thanks though.