#!/sbin/sh
# 
# /system/addon.d/99-d4-gsm-wlan.sh
#
# This preserves the GSM patch and WiFi calibration information
# across ROM-updates. The GSM-patch is based on the patches from
# Mentor.37 and tobby88.
# In contrast to these patches, it disables the LTE-modem (Wrigley)
# completely.
#

. /tmp/backuptool.functions

#Add etc/apns-conf.xml to preserve APN-list as well
list_files() {
cat <<EOF
etc/firmware/ti-connectivity/wl1271-nvs.bin
EOF
}

case "$1" in
  backup)
    list_files | while read FILE DUMMY; do
      backup_file $S/"$FILE"
    done
  ;;
  restore)
    list_files | while read FILE REPLACEMENT; do
      R=""
      [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
      [ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
    done
  ;;
  pre-backup)
    # Stub
  ;;
  post-backup)
    # Stub
  ;;
  pre-restore)
    # Stub
  ;;
  post-restore)
    cp "${S}/build.prop" "${S}/build.prop.orig"
    sed -i "s/\ =/=/g" "${S}/build.prop"
    sed -i "s/=\ /=/g" "${S}/build.prop"
    # General GSM Settings
    sed -i "s/telephony.lteOnGsmDevice=0/telephony.lteOnGsmDevice=1/g" "${S}/build.prop"
    sed -i "s/telephony.lteOnCdmaDevice=1/telephony.lteOnCdmaDevice=0/g" "${S}/build.prop"
    sed -i "s/telephony.rilV7NeedCDMALTEPhone=true/telephony.rilV7NeedCDMALTEPhone=false/g" "${S}/build.prop"
    sed -i "s/persist.ril.mux.noofchannels=8/persist.ril.mux.noofchannels=10/g" "${S}/build.prop"
    sed -i "s/persist.ril.modem.mode=1/persist.ril.modem.mode=2/g" "${S}/build.prop"
    sed -i "s/persist.ril.features=0x90A/persist.ril.features=0x102/g" "${S}/build.prop"
    sed -i "s/persist.radio.vzw.cdma.mdn=/persist.radio.vzw.cdma.mdn=deleted/g" "${S}/build.prop"
    sed -i "s/persist.radio.ap.phonetype=2/persist.radio.ap.phonetype=1/g" "${S}/build.prop"
    sed -i "s/persist.radio.lte.mm.disable=0/persist.radio.lte.mm.disable=1/g" "${S}/build.prop"
    sed -i "s/ro.telephony.default_network=10/ro.telephony.default_network=3/g" "${S}/build.prop"
    sed -i "s/ro.telephony.gsm-routes-us-smsc=1/ro.telephony.gsm-routes-us-smsc=0/g" "${S}/build.prop"
    sed -i "s/^\(ro.telephony.ril.v3=.*\)$/\1,signalstrength/" "${S}/build.prop"
    sed -i "s/ro.cdma.subscribe_on_ruim_ready=true/ro.cdma.subscribe_on_ruim_ready=false/g" "${S}/build.prop"
    sed -i "s/rild\.libpath=\/system\/lib\/moto-ril-multimode.so/#rild.libpath=\/system\/lib\/moto-ril-multimode.so/g" "${S}/build.prop"
    # European Settings
    #sed -i "s/ro.product.locale.region=US/ro.product.locale.region=GB/g" "${S}/build.prop"
    sed -i "s/android-verizon/android-google/g" "${S}/build.prop"
    # Motorola GSM Settings
    sed -i "s/ro.mot.eri=1/ro.mot.eri=0/g" "${S}/build.prop"
    sed -i "s/ro.mot.phonemode.vzwglobalphone=1/ro.mot.phonemode.vzwglobalphone=0/g" "${S}/build.prop"
    sed -i "s/ro.mot.phonemode.vzw4gphone=1/ro.mot.phonemode.vzw4gphone=0/g" "${S}/build.prop"
    sed -i "s/ro.mot.lte_on_cdma=1/ro.mot.lte_on_cdma=0/g" "${S}/build.prop"
    sed -i "s/ro.HorizontalBUA=true/ro.HorizontalBUA=false/g" "${S}/build.prop"
    sed -i "s/ro.HorizontalVVM=true/ro.HorizontalVVM=false/g" "${S}/build.prop"
  ;;
esac
