#!/system/xbin/bash # # Copyright (C) 2017 Jeremy Rand # Partially based on code by Wolfgang Wiedmeyer and Filippo Fil Bergamo # # This file is part of "Replicant Renderer Switcher", a set of shell scripts to switch between # the Android Software Renderer and the llvmpipe renderer in Replicant. # # Replicant Renderer Switcher 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. # # Replicant Renderer Switcher 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: graphics.sh [faster|compatible]" echo "Examples:" echo "graphics.sh faster" echo "|-> Uses Android's libagl" echo " which is faster" echo " but some applications" echo " like icecat won't work" echo "graphics.sh compatible" echo "|-> Uses llvmpipe" echo " which is slower" echo " but more compatible" exit 1 } check_permissions() { new_renderer="$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 " graphics.sh ${new_renderer}" exit 1 fi } graphics() { new_renderer="$1" # libagl || llvmpipe check_permissions "${new_renderer}" grep -q "ro.libagl=0" /system/build.prop && \ old_renderer="llvmpipe" || old_renderer="libagl" if [ "${old_renderer}" == "${new_renderer}" ] ; then if [ "${old_renderer}" = "libagl" ] ; then echo "Android software renderer is already enabled!" else echo "${old_renderer} renderer is already enabled!" fi exit 1 fi echo "Remounting system partition as writable..." mount -o rw,remount /system if [ "${new_renderer}" == "libagl" ] ; then echo "Enabling Android software renderer..." sed "s/ro.libagl=0/ro.libagl=1/" -i /system/build.prop else echo "Enabling ${new_renderer}..." sed "s/ro.libagl=1/ro.libagl=0/" -i /system/build.prop fi echo "Syncing filesystem..." sync sync echo "Remounting system partition as read-only..." mount -o ro,remount /system echo "Syncing filesystem..." sync sync if [ "${new_renderer}" == "libagl" ] ; then echo "Android software renderer will be enabled after we reboot now..." else echo "${new_renderer} will be enabled after we reboot now..." fi # https://android.stackexchange.com/a/139139 am start -a android.intent.action.REBOOT } if [ $# -ne 1 ] ; then usage fi if [ "$1" = "faster" ] ; then graphics libagl elif [ "$1" = "compatible" ] ;then graphics llvmpipe else usage fi