[Samsung Galaxy S9  Guides, News, & Discussion] Hekarath:
This guide was made for those who own Exynos S9, like the stock firmware with some exceptions (bloatware) and would like to use Google Pay and Galaxy Wearable with Samsung Health even while KNOX was tripped.

The guide works for Samsung firmware based on Android 9 and 10.

In this guide we're going to modify stock S9 firmware in a way that:

all bloatware incl. Bixby is completely removed,

storage encryption works,

Google Pay works,

Galaxy Wearable and Samsung Health works,

Bixby button is mapped to whatever you want it to.

NOTE 1: We're not going to use TWRP in this guide. TWRP disables storage encryption on Samsung devices as it is not supported yet, allowing everyone who'll lay his hands on your phone to get your private data easily.

NOTE 2: This guide is based on information found on XDA Developers Forum, I simply merged things together.

What is needed:

Galaxy S9 (should work for other Samsung phones too),

computer running Linux and/or Windows (Windows is actually needed only for fast firmware download using SamFirm and for that it can be installed in a VM. If you have a better method to fetch the firmware - use it instead),

Heimdall/Odin, Android Tools, proper drivers (if you're under Windows),

USB-C cable,

stock firmware in version you're interested in (preferably current release),

Magisk and Magisk Manager downloaded from the official page,

terminal .apk of your choice,

SQL editor .apk of your choice.

Guide is divided into following parts:

Obtaining and installing stock firmware,

Rooting the device,

Debloating,

Making Google Pay work,

Fixing OS losing Bluetooth pairing after reboot,

Making Galaxy Wearable and Samsung Health work,

Remapping Bixby button.

PART I - Obtaining and installing stock firmware

Download the firmware, since fw.udpato.com doesn't allow fast downloads without viewing potentially malicious ads or purchasing premium, use the good old SamFirm tool which still works well: link.

SamFirm requires Windows (can be a VM). Windows 10 should prompt you for installing missing libraries, in case it doesn't make sure that you have all the required .NET libs installed:

Link 1

Link 2

Extract the firmware, If you're going to use Odin simply unzip the file, if you're going to use Heimdall you need the .bin and .img files, on Linux the following will do the trick:

unzip SM-G960F_1_20190806183240_zbnoluw1xu_fac.zip -d firmware && cd firmware
for f in *.tar.md5; do tar xvf $f; done
lz4 -dm *.lz4
rm -f *.tar.md5 *.lz4

Boot the phone into download mode by pressing Volume Down + Bixby + Power.

For Odin skip this step. Obtain the partition table layout:

heimdall print-pit > phone.pit
grep 'Partition\ Name\|Flash\ Filename' phone.pit

Flash the firmware, in Odin simply select proper .zip files. If you're going to use Heimdall check the output from the command above and use Partition Name value as an option, f.e. --BOOTLOADER and put the corresponding Flash Filename right after, f.e. sboot.bin. Use only pair where both Partition Name and Flash Filename exist, also the file from Flash Filename should be part of the extracted FW - if it's not, skip it (f.e. ect.bin). In some cases you will have to replace .img extension with .bin and the other way round. The final command should look like:

sudo heimdall flash --BOOTLOADER sboot.bin --PARAM param.bin --UP_PARAM up_param.bin --CM cm.bin --KEYSTORAGE keystorage.bin --BOOT boot.img --RECOVERY recovery.img --SYSTEM system.img --VENDOR vendor.img --DQMDBG dqmdbg.img --USERDATA userdata.img --RADIO modem.bin --CP_DEBUG modem_debug.bin --CACHE cache.img --OMR omr.img --ODM odm.img --HIDDEN hidden.img

Double check before executing the command.

When reboot is complete perform initial configuration of your phone. You can safely skip all the setup options except Wi-Fi access (Internet access is needed for fetching Magisk but instead you can copy required files over a wire) - phone will reset to factory defaults later anyway.

PART II - Rooting the device

Enable developers mode.

From the previously extracted Firmware copy the boot.img as well as Magisk Manager .apk files to your phone's storage, f.e. to Download folder.

Install Magisk Manager using .apk file.

From the Magisk Manager app select Install Magisk and point it to boot.img file.

Magisk will create the magisk_patched.img file. Copy it to your computer.

Reboot your phone to download mode again.

Flash the patched boot partition:

sudo heimdall flash --BOOT magisk_patched.img

The device will reboot afterwards.

You will be notified that the integrity check failed and reset is required - go on with that.

PART III - Debloating

When reboot is done perform the initial setup of your phone. Logging into Google Play is required - we will need SQL Editor. Wait for all the apps to install.

Enable developers mode.

In Developer options enable USB debugging.

On your computer start the ADB shell:

adb shell

Get rid of bloatware by entering these commands (or copy-pasting actually) into the shell:

Bixby

pm uninstall -k --user 0 com.samsung.android.bixby.agent
pm uninstall -k --user 0 com.samsung.android.bixby.es.globalaction
pm uninstall -k --user 0 com.samsung.android.bixbyvision.framework
pm uninstall -k --user 0 com.samsung.android.bixby.wakeup
pm uninstall -k --user 0 com.samsung.android.bixby.plmsync
pm uninstall -k --user 0 com.samsung.android.app.spage
pm uninstall -k --user 0 com.samsung.android.bixby.voiceinput
pm uninstall -k --user 0 com.samsung.systemui.bixby
pm uninstall -k --user 0 com.samsung.android.bixby.agent.dummy
pm uninstall -k --user 0 com.samsung.android.visionintelligence
pm uninstall -k --user 0 flipboard.boxer.app

Panel

pm uninstall -k --user 0 com.samsung.android.app.sbrowseredge
pm uninstall -k --user 0 com.samsung.android.widgetapp.yahooedge.finance
pm uninstall -k --user 0 com.samsung.android.widgetapp.yahooedge.sport
pm uninstall -k --user 0 com.samsung.android.app.taskedge
pm uninstall -k --user 0 com.samsung.android.app.appsedge
pm uninstall -k --user 0 com.samsung.android.app.clipboardedge
pm uninstall -k --user 0 com.samsung.android.app.cocktailbarservice

Game Service

pm uninstall -k --user 0 com.samsung.android.game.gamehome
pm uninstall -k --user 0 com.enhance.gameservice
pm uninstall -k --user 0 com.samsung.android.game.gametools

Smart Manager

pm uninstall -k --user 0 com.samsung.android.sm.devicesecurity
pm uninstall -k --user 0 com.samsung.android.sm.policy
pm uninstall -k --user 0 com.samsung.android.lool

Facebook

pm uninstall -k --user 0 com.facebook.services
pm uninstall -k --user 0 com.facebook.katana
pm uninstall -k --user 0 com.facebook.system
pm uninstall -k --user 0 com.facebook.appmanager

Microsoft

pm uninstall -k --user 0 com.microsoft.office.excel
pm uninstall -k --user 0 com.microsoft.skydrive
pm uninstall -k --user 0 com.microsoft.office.word
pm uninstall -k --user 0 com.microsoft.office.powerpoint

LinkedIn

pm uninstall -k --user 0 com.linkedin.android

Google

#Uncomment the one below to remove Maps
#pm uninstall -k --user 0 com.google.android.apps.maps
#Uncomment the one below to remove Chrome
#pm uninstall -k --user 0 com.android.chrome
#Uncomment the one below to remove YouTube
#pm uninstall -k --user 0 com.google.android.youtube
#Uncomment the one below to remove GMail
#pm uninstall -k --user 0 com.google.android.gm
pm uninstall -k --user 0 com.google.android.googlequicksearchbox
pm uninstall -k --user 0 com.android.hotwordenrollment.okgoogle
pm uninstall -k --user 0 com.google.vr.vrcore
pm uninstall -k --user 0 com.google.android.apps.docs
pm uninstall -k --user 0 com.google.android.apps.tachyon
pm uninstall -k --user 0 com.google.android.videos
pm uninstall -k --user 0 com.google.android.music
pm uninstall -k --user 0 com.google.android.apps.photos
pm uninstall -k --user 0 com.google.android.tts
pm uninstall -k --user 0 com.google.android.configupdater
pm uninstall -k --user 0 com.google.android.partnersetup
pm uninstall -k --user 0 com.google.android.feedback
pm uninstall -k --user 0 com.samsung.android.aircommandmanager
pm uninstall -k --user 0 com.google.android.onetimeinitializer
pm uninstall -k --user 0 com.google.android.backuptransport
pm uninstall -k --user 0 com.google.android.marvin.talkback

Samsung

#Uncomment the one below to remove Samsung Health
#pm uninstall -k --user 0 com.sec.android.service.health
#Uncomment the one below to remove SMS app
#pm uninstall -k --user 0 com.samsung.android.messaging
#Uncomment the one below to remove Theme Store (also used for setting up the wallpaper)
#pm uninstall -k --user 0 com.samsung.android.themestore
#Uncomment the one below to remove Smart Capture tool used for taking screeshots
#pm uninstall -k --user 0 com.samsung.android.app.smartcapture
pm uninstall -k --user 0 com.sec.android.app.apex
pm uninstall -k --user 0 com.sec.android.app.billing
pm uninstall -k --user 0 com.samsung.android.scloud
pm uninstall -k --user 0 com.sec.android.desktopmode.uiservice
pm uninstall -k --user 0 com.sec.android.app.desktoplauncher
pm uninstall -k --user 0 com.samsung.android.mateagent
pm uninstall -k --user 0 com.samsung.android.samsungpass
pm uninstall -k --user 0 com.samsung.android.samsungpassautofill
pm uninstall -k --user 0 com.samsung.SMT
pm uninstall -k --user 0 com.samsung.android.spayfw
pm uninstall -k --user 0 com.sec.android.easyMover.Agent
pm uninstall -k --user 0 com.samsung.android.easysetup
pm uninstall -k --user 0 com.samsung.android.beaconmanager
pm uninstall -k --user 0 com.samsung.android.universalswitch
pm uninstall -k --user 0 com.samsung.android.visioncloudagent
pm uninstall -k --user 0 com.samsung.android.app.withtv
pm uninstall -k --user 0 com.samsung.svoice.sync
pm uninstall -k --user 0 com.samsung.android.svoiceime
pm uninstall -k --user 0 com.samsung.android.svoice
pm uninstall -k --user 0 com.sec.android.widgetapp.samsungapps
pm uninstall -k --user 0 com.samsung.android.da.daagent
pm uninstall -k --user 0 com.samsung.android.drivelink.stub
pm uninstall -k --user 0 com.wsomacp
pm uninstall -k --user 0 com.sec.android.cover.ledcover
pm uninstall -k --user 0 com.samsung.android.app.ledcoverdream
pm uninstall -k --user 0 com.samsung.knox.securefolder
pm uninstall -k --user 0 com.samsung.android.knox.containeragent
pm uninstall -k --user 0 com.samsung.android.smartmirroring
pm uninstall -k --user 0 com.samsung.android.app.mirrorlink
pm uninstall -k --user 0 com.mobeam.barcodeService
pm uninstall -k --user 0 android.autoinstalls.config.samsung
pm uninstall -k --user 0 com.samsung.android.app.omcagent
pm uninstall -k --user 0 com.samsung.android.keyguardwallpaperupdator
pm uninstall -k --user 0 com.samsung.android.app.simplesharing
pm uninstall -k --user 0 com.sec.enterprise.knox.cloudmdm.smdms
pm uninstall -k --user 0 com.samsung.android.app.talkback
pm uninstall -k --user 0 com.samsung.klmsagent
pm uninstall -k --user 0 com.skms.android.agent
pm uninstall -k --user 0 com.samsung.android.bbc.bbcagent
pm uninstall -k --user 0 com.sec.enterprise.knox.attestation
pm uninstall -k --user 0 com.samsung.android.knox.containercore
pm uninstall -k --user 0 com.samsung.knox.securefolder.setuppage
pm uninstall -k --user 0 com.knox.vpn.proxyhandler
pm uninstall -k --user 0 com.sec.android.app.safetyassurance
pm uninstall -k --user 0 com.samsung.safetyinformation
pm uninstall -k --user 0 com.samsung.visionprovider
pm uninstall -k --user 0 service.odtcfactory.sec.com.odtcfactoryservice
pm uninstall -k --user 0 com.samsung.faceservice
pm uninstall -k --user 0 com.samsung.android.smartface
pm uninstall -k --user 0 com.samsung.android.bio.face.service
pm uninstall -k --user 0 com.samsung.android.app.assistantmenu
pm uninstall -k --user 0 com.samsung.android.sdk.handwriting
pm uninstall -k --user 0 com.samsung.android.mdm
pm uninstall -k --user 0 com.samsung.android.dlp.service
pm uninstall -k --user 0 com.samsung.android.sdk.professionalaudio.utility.jammonitor
pm uninstall -k --user 0 com.samsung.android.service.peoplestripe
pm uninstall -k --user 0 com.samsung.storyservice
pm uninstall -k --user 0 com.samsung.android.app.galaxyfinder
pm uninstall -k --user 0 com.samsung.android.server.iris
pm uninstall -k --user 0 com.samsung.InputEventApp
pm uninstall -k --user 0 com.samsung.android.allshare.service.fileshare
pm uninstall -k --user 0 com.samsung.android.allshare.service.mediashare
pm uninstall -k --user 0 com.samsung.android.app.soundpicker
pm uninstall -k --user 0 com.samsung.android.app.watchmanagerstub
pm uninstall -k --user 0 com.samsung.android.provider.stickerprovider
pm uninstall -k --user 0 com.samsung.android.stickercenter
pm uninstall -k --user 0 com.samsung.android.stickerplugin
pm uninstall -k --user 0 com.samsung.mlp

Reboot the device, just in case.

PART IV - Making Google Pay work

Install Magisk Manager just like you did previously. Confirm that the device is rooted.

Install terminal, f.e. Termux (you can use adb shell from your computer instead if you prefer it, it's still good to have a terminal on your phone, just in case) and SQL editor, SQLite Database Editor works well.

Run SQL editor. When asked to provide root privileges select once (you should always use that option) and confirm.

From the menu pane select File explorer and navigate do /data/data/com.google.android.gms/databases.

Open dg.db file and change value in column c of any item that has attest in its name to 0.

Run terminal. Execute the following commands to make dg.db file read-only:

su
cd /data/data/com.google.android.gms/databases
chmod 440 dg.db

Reboot the device, Google Pay will work from now on, just remember to hide Magisk from it in the Magisk Manager.

PART V - Fixing OS losing Bluetooth pairing after reboot

Samsung is using secure storage to keep Bluetooth pairing secure. The problem is that on a rooted phone this storage will always get wiped on phone reboot. There is no nice way (at least I wasn't able to find it) which makes it work however it is possible to disable secure storage on boot using Magisk Manager module.

Open Magisk Manager.

From menu (top left corner) select Downloads, find the libsecure_storage companion for rooted Samsung devices and install it.

Tap the Restart button to reboot your device.

PART VI - Making Galaxy Wearable and Samsung Health work

This part can be handled simply by going to terminal, escalating privileges with su and executing the following command:

sed -i 's/ro.config.tima=1/ro.config.tima=0/g' /system/build.prop

The disadvantage of this method is that it will have to be executed after every update. The better alternative is to use Magisk Manager plugin for props configuration.

Open Magisk Manager. If it asks for some tasks to complete, allow it.

From menu (top left corner) select Downloads, find the Busybox for Android NDK and MagiskHide Props Config modules and install them both. Reboot.

When anothe reboot is done, launch terminal and escalate your privileges with su.

From command line run props tool, which is used to modify /system/build.prop file.

Select 4 to add custom props, n for new prop. Type in ro.config.tima, confirm and provide value 0. Confirm with y and again with y to reboot the phone.

Install Galaxy Wearable and Samsung Health from the Galaxy Store. Don't launch anything yet.

Now go to Magisk Manager and hide Magisk from Samsung Health, Galaxy Wearable and Galaxy Watch Plugin.

Reboot the device, configure your watch and confirm that the Samsung Health app works.

PART VII - Remapping Bixby button

Remapping Bixby button can be achieved either by modifying keyboard layout manually or by installing Bixby button remapper module in Magisk Manager. Second option is preferred as it doesn't require modifying files on '/system' partition and will survive system updates.

Method 1: manual modification

Run terminal (or adb shell) and escalate your privileges with su.

Remount /system partition as read-write:

mount -o remount,rw /system

Navigate to /system/usr/keylayout:

cd /system/usr/keylayout

Edit the Generic.kl file:

vi Generic.kl

Go to key 703 - that's the one responsible for the Bixby key. Set the action you want for the key - it's written in capital letters. Look throughout the file for action you're interested in. Some examples:

VOLUME_MUTE

, MEDIA_PLAY_PAUSE, CAMERA, MUSIC, ASSIST.

key 703 VOLUME_MUTE

Save the file and exit editor (:wq).

Remount /system partition as read only:

mount -o remount,ro /system

Reboot the phone.

Method 2: Magisk Manager module

Launch Magisk Manager.

Pick Downloads from menu.

Find the Bixby button remapper module and install it.

Follow on-screen instructions.

Tap the Restart button to reboot the phone.