Mod at your own risk and I don't hold any responsibility for any consequence that may have been caused by this mod.
Remember to make a backup first though I have tested on my pixel.
My company uses channel 132,136,140,144 to broadcast 5G wifi, however, the wifi region code on my phone is set to 'CN', so my phone could not even detect the wifi. For a complete list of available wifi channel in each region, please refer to this wiki.
I tried to set wifi_country_code via 'settings put global wifi_country code US' or add 'country=US' in /etc/wifi/wpa_supplicant.conf, but without vain. Then I came across this post https://forum.xda-developers.com/sho....php?t=2368501, and I decide to hack the setCountryCode function in the wifiservice to force the country to be 'US'. According to the wiki, region 'US' has the most available number of channels.
This post will tell you how you could bypass this restriction on your phone. Your phone shall be rooted, of course.
[Step to step guide]
1) Setup tools, which includes
2) Connect your phone and pull all the related files ( actually only wifi-service.odex and boot.oat is needed )
adb pull /system/framework framework
3) Decompile the odex file by using the following command
java -Xms1g -jar baksmali-2.2b4.jar x -d framework/arm64 framework/oat/arm64/wifi-service.odex -o wifi-service
The output goes to wifi-service folder
4) Mod wifi-service/com/android/server/wifi/WifiServiceImpl.smali
Search for 'method public setCountryCode', which is around line 5605, basically we just want to force the country code to "US".
a) Change .register 8 to '.register 9'
This is because we are going to use one more register to hold the static content 'US', aka, your desired country code
The original code uses 8 registers, aka, v0 - v4 for local varialbe, v5-v7 for parameter, they are also alised to p0-p2.
After this change, we can use the register named v5, v6-v8 will be aliased to p0-p2.
b) Add a line under const-string/jumbo v2, "WifiService"
const-string/jumbo v5, "US"
Therefore, v5 hold the content 'US', which is the desired country code.
c) Replace all p1 with v5 inside this method
Originally the country code is passed from outside the call, we just force it to 'US', which is stored in variable v5
5) Repack by the following command
java -Xms1g -jar smali-2.2b4.jar a -o classes.dex wifi-service
jar -cvf wifi-service.jar classes.dex
6) Install on the phone
adb push wifi-service.jar /sdcard/
The following commands shall be executed on the phone and with root prividelege
mount -o rw,remount /system
#Make a backup first
cp -p framework/oat/arm64/wifi-service.odex framework/oat/arm64/wifi-service.odex.bak
cp -p framework/wifi-service.jar framework/wifi-service.jar.bak
#Install the new file
cp /sdcard/wifi-service.jar /system/framework/
chown root.root framework/wifi-service.jar
chmod 644 framework/wifi-service.jar
A modified wifi-service.jar is also uploaded and I have tested on my pixel. Everything seems fine.