Make : Motorola/Google

Model : Moto G5

Model Code : XT1676

Model Codename : Cedric

Purchased : 2017-05-30

Storage : 16GB

RAM : 3GB

Latest : NPP25.137-93

Rooting

  1. Unlock Bootloader

    adb reboot-bootloader sudo fastboot oem get_unlock_data

    paste together code and post into moto form ...

    wait for unlock key from motorola ...

    sudo fastboot oem unlock KEY sudo fastboot oem unlock KEY  # have to run it twice sudo fastboot reboot

  2. Flash TWRP

    adb reboot-bootloader sudo fastboot flash recovery twrp-3.3.1--cedric.img

    "Image not signed or corrupt" is harmless.

    Immediately select recovery using bootloader screen

     otherwise boot will overwrite twrp

  3. Wipe

    1. In the Decrypt /data screen, press cancel, then "Swipe to Allow Modifications"
    2. Go to WIPE, then "Swipe to Factory Reset"
    3. Come back to TWRP main menu, go to REBOOT, then RECOVERY, then DO NOT INSTALL
    4. "Swipe to Allow Modifications"
  4. Disable forced encryption
    1. Push and flash "no-verity-opt-encrypt-5.1.zip"
  5. Flash SuperSU
  6. Flash Magisk
    1. Push and flash "Magisk-v11.6.zip" # NOT VERSION 12!
    2. After the setup, come back to TWRP main menu, go to REBOOT, then SYSTEM, then DO NOT INSTALL
    3. Run and update Magisk App

Updates for Oreo

It seems like twrp-3.3.1 can unlock encrypted partitions so no-verity-opt-encrypt may not be needed.

Troubleshooting

Slow Google search widget

Clear Launcher3 Data

Settings > Apps > top right tri-colon > Show System > Launcher3 > storage > delete

This will reset the home screen.

Backup and Restore

UIDs and GIDs

adb shell
su
cat /data/system/packages.xml

List userIds or sharedUserIds:

xmlstarlet sel -t -m '//package'  -v @sharedUserId -v @userId -o '     ' -v @name -n