#!/system/xbin/bash # # Copyright (C) 2017 Jeremy Rand # Partially based on code by Wolfgang Wiedmeyer and Filippo Fil Bergamo # # This file is part of "SlightlyBetterAirplaneMode", a set of shell scripts to shut off # the Samsung phone modem without trusting the non-free modem firmware. # # SlightlyBetterAirplaneMode is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # SlightlyBetterAirplaneMode is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . set -euf -o pipefail usage() { echo "Usage: modem.sh [on|off]" echo "Examples:" echo "modem.sh off" echo "|-> disable the modem" echo " and reboot" echo "modem.sh on" echo "|-> enable the modem" echo " and reboot" exit 1 } check_permissions() { modem_command="$1" root_access="$(getprop persist.sys.root_access)" uid="$(id -u)" # 0: Root access: Disabled, 2: Root access: ADB only # For both the terminal application and ADB we have something # like that: # shell@i9100:/ $ su # 255|shell@i9100:/ $ # 1: Root access: Apps only # From ADB: # shell@i9100:/ $ su # Permission denied # 1|shell@i9100:/ $ # From the terminal application # u0_a51@i9100:/ $ su # root@i9100:/ # if [ "${uid}" != "0" ] ; then echo "" echo "This script requires root." echo "To give it root:" case "${root_access}" in "0"|"1"|"2") echo "- Go in Settings" echo "- Go in Developer options" echo "- Select Root access" echo "- Set it to \"Apps and ADB\"" ;; esac echo "- Run these 2 commands:" echo " su" echo " modem.sh ${modem_command}" exit 1 fi } modem() { command="$1" check_permissions "${command}" echo "Remounting system partition as writable..." mount -o rw,remount /system if [ "${command}" = "on" ] ; then echo "Enabling RIL..." mv /system/lib/libsamsung-ril.so.disabled \ /system/lib/libsamsung-ril.so || \ echo 'RIL was already enabled.' elif [ "${command}" = "off" ] ; then echo "Disabling RIL..." mv /system/lib/libsamsung-ril.so \ /system/lib/libsamsung-ril.so.disabled || \ echo 'RIL was already disabled.' fi echo "Syncing filesystem..." sync sync echo "Remounting system partition as read-only..." mount -o ro,remount /system echo "Syncing filesystem..." sync sync am force-stop org.smssecure.smssecure # https://android.stackexchange.com/a/139139 echo "Modem will be disabled after we reboot now..." am start -a android.intent.action.REBOOT } if [ $# -ne 1 ] ; then usage fi if [ "$1" = "on" -o "$1" = "off" ] ;then modem "$1" else usage fi