[GUIDE] Pixel 4a "sunfish": Unlock Bootloader, Update, Root, Pass SafetyNet

Search This thread

V0latyle

Forum Moderator
Staff member
OK, so doing the Magisk "direct install" or using adb tools to "flash boot" is an either/or thing? It sound like, if I have Magisk 24, that'll be easier.
If you want to be able to restore the stock images, yes.

Flashing the patched image to /boot is "permanent", meaning you won't be able to restore the stock image in Magisk, which may be necessary for OTA updates. If you don't intend to update via OTA, this isn't a problem. I personally prefer to dirty flash the factory image every time there's an update.

If you temporarily boot the patched image, Magisk will create a backup of the original boot image when you select Direct Install. This allows restoring the unpatched image.

As far as the Magisk version, I'd recommend the most recent - 25.1. You can use older versions of Magisk, but they won't include the same fixes and updates.
 

acspdx

Member
Dec 2, 2016
23
4
As far as the Magisk version, I'd recommend the most recent - 25.1. You can use older versions of Magisk, but they won't include the same fixes and updates.
I'll definitely update Magisk, but I'll wait until after I do this stuff. I don't want to do anything that might require a restart, with that erroneous Nexus update hanging around.
 

V0latyle

Forum Moderator
Staff member
I'll definitely update Magisk, but I'll wait until after I do this stuff. I don't want to do anything that might require a restart, with that erroneous Nexus update hanging around.
Simply restarting won't cause the phone to update. There are only two ways that will cause a reboot to the alternate slot. One is by selecting Restart Now under System Updates; the other is Install to Inactive Slot in Magisk. As long as you don't do either of those, simply commanding a reboot should reboot the device without switching slots.
 

acspdx

Member
Dec 2, 2016
23
4
Simply restarting won't cause the phone to update. There are only two ways that will cause a reboot to the alternate slot. One is by selecting Restart Now under System Updates...
Oh! I didn't realize that. So "Restart Now" on the system update panel really means "Restart and Install Update," whereas a normal reboot (say, via the power button) doesn't do anything other than reboot into the existing OS?

If so, that's a relief. I guess I could just ignore it indefinitely unless I really want whatever enhancements are in the update.

(However, having filled up this thread with all my questions, I almost feel an obligation to try the update now so I can let people know how it goes!)
 

V0latyle

Forum Moderator
Staff member
By the way...You aren't installing TWRP, are you? I just noticed on my Samsung tablet
Oh! I didn't realize that. So "Restart Now" on the system update panel really means "Restart and Install Update," whereas a normal reboot (say, via the power button) doesn't do anything other than reboot into the existing OS?
Yep
If so, that's a relief. I guess I could just ignore it indefinitely unless I really want whatever enhancements are in the update.

(However, having filled up this thread with all my questions, I almost feel an obligation to try the update now so I can let people know how it goes!)
I don't know how to prevent it from downloading updates...but again, I'll recommend returning the device signature to what the device actually is, just in case you make a mistake. It's easy to absentmindedly tap buttons you didn't mean to
 

ReservedName

Member
Oct 29, 2014
43
42
I'm on RQ1A.201205.008 right now and the last update for an app I use says it's incompatible in the app store. I've been able to sideload the app and it runs fine and the devs confirmed there shouldn't be any restriction for my device but I think I need to try taking the ota and going to Android 12. it's been so long since I took an ota and I have root and magisk. is there any reason to think taking the ota will fix that issue? I also need to find the right set of instructions to take an ota but preserve root and data (or preserve data and restore root)
 

V0latyle

Forum Moderator
Staff member
I'm on RQ1A.201205.008 right now and the last update for an app I use says it's incompatible in the app store. I've been able to sideload the app and it runs fine and the devs confirmed there shouldn't be any restriction for my device but I think I need to try taking the ota and going to Android 12. it's been so long since I took an ota and I have root and magisk. is there any reason to think taking the ota will fix that issue? I also need to find the right set of instructions to take an ota but preserve root and data (or preserve data and restore root)
Updating via OTA overwrites the boot image, meaning you lose root. However, after completing the update, you can use a previously patched boot image to temporarily gain root so that you can perform Direct Install in Magisk.

As far as whether updating will fix an issue, I can't answer that. Personally I always recommend staying updated.
 

S.Mayer

Member
Oct 10, 2011
23
4
GT-i9250
Google Nexus 5
Thanks for the guide, OP!

I've just updated to the release version of Android 13 (TP1A.220624.014), and have Magisk 25.2.

When I used fastboot boot to temporarily boot from my patched boot image, Magisk didn't give me the option to "Install Directly", so I had to flash it myself. (I'm not sure if I messed it up somehow.)

I am passing SafetyNet on my otherwise stock Pixel 5 using USNF + MHPC, no "under the hood" changes, although I have DenyList enabled on banking/DRM apps as well as Play Store.
Does installing MHPC do anything, by itself? I thought it was a tool that can be used up change system properties. I don't see any mention of what to change, and the above comment seems to say that no changes are necessary.

I currently can pass SafetyNet with just USNF, and my banking apps work. When I tried to setup a card for contactless in Google Pay, it given an error:

Couldn't finish setup to pay in stores
This phone can't be used to pay in stores. This may be because it is rooted or altered in some other way.
From what I've found, it looks like my next step is to use MHPC to pick another device fingerprint and hope that works. I'll update after trying that
 

V0latyle

Forum Moderator
Staff member
Thanks for the guide, OP!

I've just updated to the release version of Android 13 (TP1A.220624.014), and have Magisk 25.2.

When I used fastboot boot to temporarily boot from my patched boot image, Magisk didn't give me the option to "Install Directly", so I had to flash it myself. (I'm not sure if I messed it up somehow.)
You probably didn't have root for some reason.
Does installing MHPC do anything, by itself? I thought it was a tool that can be used up change system properties. I don't see any mention of what to change, and the above comment seems to say that no changes are necessary.
Correct, I need to edit that out. MHPC alone doesn't do anything without configuration
I currently can pass SafetyNet with just USNF, and my banking apps work. When I tried to setup a card for contactless in Google Pay, it given an error:

From what I've found, it looks like my next step is to use MHPC to pick another device fingerprint and hope that works. I'll update after trying that
Negative. This is due to GPay shifting from SafetyNet to Play Integrity, which cannot be spoofed. See this thread. The solution for now is to use a modified version of Universal SafetyNet Fix which forces the legacy attestation.
 
  • Like
Reactions: S.Mayer

S.Mayer

Member
Oct 10, 2011
23
4
GT-i9250
Google Nexus 5
You probably didn't have root for some reason.
That must be it. I thought I had checked for that, but Magisk does give me the option to Install Directly now, so there's not much else it could be.
This is due to GPay shifting from SafetyNet to Play Integrity, which cannot be spoofed. See this thread. The solution for now is to use a modified version of Universal SafetyNet Fix which forces the legacy attestation.
That worked, thanks!

(For one of my two cards, GPay is giving me an error saying I need to contact the bank, but since the other one worked I can only assume that's unrelated to device security.)

So if I'm reading the thread (and the diffs between the original and the mod) correctly, it looks like the modified USNF uses the same principle as the MHPC approach, just more targeted. Meaning that it's still using a fingerprint for a non-HWKA device, but only for certain checks. Is that accurate?

I've spoofed my fingerprint with MHPC before, over a year ago, and it was kind of ugly because some Google services would refer to the spoofed device name.

I can see the mod uses the fingerprint from a Nexus 6P, but the Play Store and 2FA prompts still call my phone a Pixel 4a, so that's nice.
 

V0latyle

Forum Moderator
Staff member
That must be it. I thought I had checked for that, but Magisk does give me the option to Install Directly now, so there's not much else it could be.

That worked, thanks!

(For one of my two cards, GPay is giving me an error saying I need to contact the bank, but since the other one worked I can only assume that's unrelated to device security.)

So if I'm reading the thread (and the diffs between the original and the mod) correctly, it looks like the modified USNF uses the same principle as the MHPC approach, just more targeted. Meaning that it's still using a fingerprint for a non-HWKA device, but only for certain checks. Is that accurate?
More or less. But the device fingerprint actually is the easiest part of the puzzle - all it means is that the device, as well as the Android build running on it, are approved by Google. The only time this is really ever an issue is when you're using a custom ROM that doesn't already spoof a fingerprint for something else. All MHPC does is say "this is a Pixel 5 running factory Android".

See https://forum.xda-developers.com/t/magisk-module-universal-safetynet-fix-2-3-1.4217823/post-87199557 for a more concise explanation.

I've spoofed my fingerprint with MHPC before, over a year ago, and it was kind of ugly because some Google services would refer to the spoofed device name.

I can see the mod uses the fingerprint from a Nexus 6P, but the Play Store and 2FA prompts still call my phone a Pixel 4a, so that's nice.
What the modded USNF does is essentially force the SafetyNet attestation, which USNF has pretty much always been able to fix - the few exceptions being those with "unapproved" fingerprints as described above that require using MHPC. Unfortunately, this is just a temporary fix, and the only thing really on our side is the high degree of fragmentation among Android devices; anything below Android 8.0 is not capable of passing MEETS_STRONG_INTEGRITY, so these devices depend on the legacy SafetyNet. If app developers (including Google) decide that they want to exclusively use Play Integrity, and remove any legacy support for SafetyNet from their applications, there will be no way for us to use those apps on rooted devices.
 
  • Like
Reactions: S.Mayer

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    If you are looking for my guide on a different Pixel, find it here:
    For best results, use the latest stable Magisk release.
    Discussion thread for migration to 24.0+.
    Note: Magisk prior to Canary 23016 does not incorporate the necessary fixes for Android 12+.


    WARNING: YOU AND YOU ALONE ARE RESPONSIBLE FOR ANYTHING THAT HAPPENS TO YOUR DEVICE. THIS GUIDE IS WRITTEN WITH THE EXPRESS ASSUMPTION THAT YOU ARE FAMILIAR WITH ADB, MAGISK, ANDROID, AND ROOT. IT IS YOUR RESPONSIBILITY TO ENSURE YOU KNOW WHAT YOU ARE DOING.

    Prerequisites:


    Android Source - Setting up a device for development


    1. Follow these instructions to enable Developer Options and USB Debugging.
    2. Enable OEM Unlocking. If this option is grayed out, unlocking the bootloader is not possible.
    3. Connect your device to your PC, and open a command window in your Platform Tools folder.
    4. Ensure ADB sees your device:
      Code:
      adb devices
      If you don't see a device, make sure USB Debugging is enabled, reconnect the USB cable, or try a different USB cable.
      If you see "unauthorized", you need to authorize the connection on your device.
      If you see the device without "unauthorized", you're good to go.
    5. Reboot to bootloader:
      Code:
      adb reboot bootloader
    6. Unlock bootloader: THIS WILL WIPE YOUR DEVICE!
      Code:
      fastboot flashing unlock
      Select Continue on the device screen.

    1. Install Magisk on your device.
    2. Download the factory zip for your build.
    3. Inside the factory zip is the update zip: "device-image-buildnumber.zip". Open this, and extract boot.img
    4. Copy boot.img to your device.
    5. Patch boot.img with Magisk: "Install" > "Select and Patch a File"
    6. Copy the patched image back to your PC. It will be named "magisk_patched-23xxx_xxxxx.img". Rename this to "master root.img" and retain it for future updates.
    7. Reboot your device to bootloader.
    8. Flash the patched image:
      Code:
      fastboot flash boot <drag and drop master root.img here>
    9. Reboot to Android. Open Magisk to confirm root - under Magisk at the top, you should see "Installed: <Magisk build number>

    1. Before you download the OTA, open Magisk, tap Uninstall, then Restore Images. If you have any Magisk modules that modify system, uninstall them now.
    2. Take the OTA update when prompted. To check for updates manually, go to Settings > System > System Update > Check for Update
    3. Allow the update to download and install. DO NOT REBOOT WHEN PROMPTED. Open Magisk, tap Install at the top, then Install to inactive slot. Magisk will then reboot your device.
    4. You should now be updated with root.

    1. Download the OTA.
    2. Reboot to recovery and sideload the OTA:
      Code:
      adb reboot sideload
      Once in recovery:
      Code:
      adb sideload ota.zip
    3. When the OTA completes, you will be in recovery mode. Select "Reboot to system now".
    4. Allow system to boot and wait for the update to complete. You must let the system do this before proceeding.
    5. Reboot to bootloader.
    6. Boot the master root image (See note 1):
      Code:
      fastboot boot <drag and drop master root.img here>
      Note: If you prefer, you can download the factory zip and manually patch the new boot image, then flash it after the update. Do not flash an older boot image after updating.
    7. Your device should boot with root. Open Magisk, tap Install, and select Direct Install.
    8. Reboot your device. You should now be updated with root.
    Note: You can use Payload Dumper to extract the contents of the OTA if you want to manually patch the new boot image. However, I will not cover that in this guide.

    Please note that the factory update process expects an updated bootloader and radio. If these are not up to date, the update will fail.
    1. Download the factory zip and extract the contents.
    2. Reboot to bootloader.
    3. Compare bootloader versions between phone screen and bootloader.img build number
      Code:
      fastboot flash bootloader <drag and drop new bootloader.img here>
      If bootloader is updated, reboot to bootloader.
    4. Compare baseband versions between phone screen and radio.img build number
      Code:
      fastboot flash radio <drag and drop radio.img here>
      If radio is updated, reboot to bootloader.
    5. Apply update:
      Code:
      fastboot update --skip-reboot image-codename-buildnumber.zip
      When the update completes, the device will be in fastbootd. Reboot to bootloader.
    6. Boot the master root image (See note 1):
      Code:
      fastboot boot <drag and drop master root.img here>
      Note: If you prefer, you can manually patch the new boot image, then flash it after the update. Do not flash an older boot image after updating.
    7. Your device should boot with root. Open Magisk, tap Install, and select Direct Install.
    8. Reboot your device. You should now be updated with root.
    Note: If you prefer, you can update using the flash-all script included in the factory zip. You will have to copy the script, bootloader image, radio image, and update zip into the Platform Tools folder; you will then have to edit the script to remove the -w option so it doesn't wipe your device.
    The scripted commands should look like this:
    Code:
    fastboot flash bootloader <bootloader image name>
    fastboot reboot bootloader
    ping -n 5 127.0.0.1 > nul
    fastboot flash radio <radio image name>
    fastboot reboot bootloader
    ping -n 5 127.0.0.1 > nul
    fastboot update  --skip-reboot <image-device-buildnumber.zip>
    Once this completes, you can reboot to bootloader and either boot your master patched image, or if you patched the new image, flash it at this time.

    PixelFlasher by @badabing2003 is an excellent tool that streamlines the update process - it even patches the boot image for you.
    The application essentially automates the ADB interface to make updating and rooting much easier. However, it is STRONGLY recommended that you still learn the "basics" of using ADB.

    For instructions, downloads, and support, please refer to the PixelFlasher thread.

    1. Follow the instructions on the Android Flash Tool to update your device. Make sure Lock Bootloader and Wipe Device are UNCHECKED.
    2. When the update completes, the device will be in fastbootd. Reboot to bootloader.
    3. Boot the master root image (See note 1):
      Code:
      fastboot boot <drag and drop master root.img here>
      Note: If you prefer, you can download the factory zip and manually patch the new boot image, then flash it after the update. Do not flash an older boot image after updating.
    4. Your device should boot with root. Open Magisk, tap Install, and select Direct Install.
    5. Reboot your device. You should now be updated with root.

    SafetyNet has been deprecated for the new Play Integrity API. More information here.

    In a nutshell, Play Integrity uses the same mechanisms as SafetyNet for the BASIC and DEVICE verdicts, but uses the Trusted Execution Environment to validate those verdicts. TEE does not function on an unlocked bootloader, so legacy SafetyNet solutions will fail.

    However, @Displax has modified the original Universal SafetyNet Fix by kdrag0n; his mod is able to force basic attestation instead of hardware, meaning that the device will pass BASIC and DEVICE integrity.

    Mod available here. Do not use MagiskHide Props Config with this mod.

    This is my configuration that is passing Safety Net. I will not provide instructions on how to accomplish this. Attempt at your own risk.

    Zygisk + DenyList enabled
    All subcomponents of these apps hidden under DenyList:
    • Google Play Store
    • GPay
    • Any banking/financial apps
    • Any DRM media apps
    Modules:
    • Universal SafetyNet Fix 2.3.1 Mod - XDA post
    To check SafetyNet status:
    To check Play Integrity status:
    I do not provide support for Magisk or modules. If you need help with Magisk, here is the Magisk General Support thread. For support specifically with Magisk v24+, see this thread.

    Points of note:
    • The boot image is NOT the bootloader image. Do not confuse the two - YOU are expected to know the difference. Flashing the wrong image to bootloader could brick your device.
    • While the Magisk app is used for patching the boot image, the app and the patch are separate. This is what you should see in Magisk for functioning root:
      screenshot_20230323-072859-3-png.5870161
    • "Installed" shows the version of patch in the boot image. If this says N/A, you do not have root access - the boot image is not patched, or you have a problem with Magisk.
    • "App" simply shows the version of the app itself.
    • If you do not have a patched master boot image, you will need to download the factory zip if you haven't already, extract the system update inside it, then patch boot.img.
    • If you prefer updating with the factory image, you can also extract and manually patch the boot image if desired.
    • Some Magisk modules, especially those that modify read only partitions like /system, may cause a boot loop after updating. As a general rule, disable these modules before updating. You are responsible for knowing what you have installed, and what modules to disable.


    Credits:
    Thanks to @badabing2003 , @pndwal , @Displax , @Az Biker , @ipdev , @kdrag0n , @Didgeridoohan , and last but not least, @topjohnwu for all their hard work!
    2
    @ V0latyle Thanks very much for your incredibly helpful reply - much appreciated. Just some quick follow-ups for clarity please.
    • Zygisk - I assume that is enabled within Magisk somewhere?
    • DenyList - how exactly do I enable this 'on the Play Store'?
    • When you say DenyList will not work on system processes, I assume you mean things like Google Play Store etc? If so, is the mere installation of Magisk through the process you describe in the op now enough to hide Magisk and root from system processes?
    Thanks again for your help and patience.
    Not to be rude but these are questions you should be asking in the Magisk support thread. Also, Google is your friend.

    Here's how to get to the settings:
    Screenshot_20220614-092537.png

    Screenshot_20220614-092617.png

    Screenshot_20220614-092646~2.png

    Google Play Store is not a system process. Google Play Services on the other hand is, and blocking it in MagiskHide used to be pretty standard for passing SafetyNet attestation.

    For further questions please use the Magisk support threads, linked in the OP under "Pass SafetyNet"
    1
    @V0latyle and all you other helpful people

    A few basic questions please. I intend to use your guide to unlock the bootloader and root a Pixel 4a (non-5g) which is currently on stock rom Android 12 SP2A.220405.003. (Auto system updates are currently off in Developer options).
    1. Should I update to the latest June version of Android 12 before doing anything?
    You can, but you don't have to. You'll be downloading the factory image so you can patch the boot image anyway, so you might as well take advantage of the newest security update.
    1. Which versions of Magisk and Magisk Manager should I use to root the device?
    The two are the same. First, make sure you are only using the authentic Magisk from John Wu's Github, linked in the OP. Secondly, you can use almost any version of Magisk, but Android 12 support wasn't included until Canary 23010, meaning any version prior, including Stable v23.0 may not work properly. Since Public Beta 25.0 is out, just use that.
    1. Which elements of Magisk do I need to activate and which modules do I need to install to pass all SafetyNet checks so I can use UK banking apps?
    Ensure Zygisk and DenyList are enabled. Enable DenyList on the Play Store and the apps you want to hide root from; it will not work on system processes. Install the Universal SafetyNet Fix module, linked in the OP. Installing USNF will likely also install MagiskHide Props Config.

    Confirm SafetyNet is passing with YASNAC.
    1. I've used older versions of Magisk when the repository was built in but am unfamiliar with more recent versions where apparently there is no repo. How does one install modules now?
    Again, the only legitimate source for Magisk is the Magisk Github. Do not use any other version from any other site. The repository continues to be alive and well. If you're talking about the module library, that is no longer included in Magisk, so you have to install the modules manually through Magisk. For more help with this, please see the Magisk help threads, also linked in the OP
    1
    Apologies for raising questions that, as you rightly point out, should have been posed in other threads. Lesson learnt.

    A quick follow-up to my original set of questions. Given that I will be rooting with the latest (June) Magisk-patched factory image, will I need to update the bootloader and radio prior to flashing the patched stock img?

    I've compared the versions between phone screen and those contained in the stock factory zip. Both versions appear to be older the current stock one:-
    • bootloader version on phone is c2f2-0.4-8048765 vs bootloader-sunfish-s5-0.4-8351029 on stock image
    • radio version on phone g8150-00123-220122-B-8106568 vs radio-sunfish-g7150-00090-220406-b-8411773.
    Thanks again for all your advice. Much appreciated.
    If the build numbers are different, you should update them. Don't worry about the numbers appearing "older"; as far as I can tell it doesn't seem like Google uses consecutive numbers for bootloader and radio.
    1
    Thanks for the guide, OP!

    I've just updated to the release version of Android 13 (TP1A.220624.014), and have Magisk 25.2.

    When I used fastboot boot to temporarily boot from my patched boot image, Magisk didn't give me the option to "Install Directly", so I had to flash it myself. (I'm not sure if I messed it up somehow.)
    You probably didn't have root for some reason.
    Does installing MHPC do anything, by itself? I thought it was a tool that can be used up change system properties. I don't see any mention of what to change, and the above comment seems to say that no changes are necessary.
    Correct, I need to edit that out. MHPC alone doesn't do anything without configuration
    I currently can pass SafetyNet with just USNF, and my banking apps work. When I tried to setup a card for contactless in Google Pay, it given an error:

    From what I've found, it looks like my next step is to use MHPC to pick another device fingerprint and hope that works. I'll update after trying that
    Negative. This is due to GPay shifting from SafetyNet to Play Integrity, which cannot be spoofed. See this thread. The solution for now is to use a modified version of Universal SafetyNet Fix which forces the legacy attestation.