MagiskHidePropsConf/common/util_functions.sh

1368 lines
35 KiB
Bash
Raw Normal View History

2018-03-18 15:39:43 +00:00
#!/system/bin/sh
# MagiskHide Props Config
2019-02-02 12:37:20 +00:00
# Copyright (c) 2018-2019 Didgeridoohan @ XDA Developers
# Licence: MIT
2018-03-18 15:39:43 +00:00
2019-02-02 12:37:20 +00:00
# ======================== Variables ========================
2018-04-15 22:05:33 +00:00
MODVERSION=VER_PLACEHOLDER
2018-07-26 09:03:13 +00:00
MIRRORPATH=$COREPATH/mirror
2018-11-18 06:31:58 +00:00
LATEFILE=LATE_PLACEHOLDER
2019-02-02 12:37:20 +00:00
MIRRORLOC=MIRROR_PLACEHOLDER
2018-04-15 22:05:33 +00:00
CACHELOC=CACHE_PLACEHOLDER
2018-05-29 07:29:19 +00:00
POSTCHKFILE=$CACHELOC/propsconf_postchk
2018-04-19 03:13:40 +00:00
RUNFILE=$MODPATH/script_check
2018-04-15 22:05:33 +00:00
LOGFILE=$CACHELOC/propsconf.log
LASTLOGFILE=$CACHELOC/propsconf_last.log
2018-06-19 09:56:08 +00:00
TMPLOGLOC=$CACHELOC/propslogs
TMPLOGLIST="
$CACHELOC/magisk.log
$CACHELOC/magisk.log.bak
/data/adb/magisk_debug.log
$CACHELOC/propsconf*
2018-07-26 09:03:13 +00:00
$MIRRORPATH/system/build.prop
$MIRRORPATH/vendor/build.prop
$LATEFILE
2018-06-19 09:56:08 +00:00
"
2019-02-02 12:37:20 +00:00
CONFFILELST="
/sdcard/propsconf_conf
/data/propsconf_conf
$CACHELOC/propsconf_conf
"
2018-04-15 22:05:33 +00:00
RESETFILE=$CACHELOC/reset_mhpc
2018-03-18 15:39:43 +00:00
MAGISKLOC=/data/adb/magisk
2019-02-02 12:37:20 +00:00
# Make sure that the terminal app used actually can see resetprop
alias resetprop="$MAGISKLOC/magisk resetprop"
# Finding installed Busybox
2018-12-05 15:22:57 +00:00
if [ -d "$IMGPATH/busybox-ndk" ]; then
BBPATH=$(find $IMGPATH/busybox-ndk -name 'busybox')
else
BBPATH=$(which busybox)
2018-06-03 16:40:24 +00:00
fi
2018-05-29 07:29:19 +00:00
PRINTSLOC=$MODPATH/prints.sh
PRINTSTMP=$CACHELOC/prints.sh
PRINTSWWW="https://raw.githubusercontent.com/Magisk-Modules-Repo/MagiskHide-Props-Config/master/common/prints.sh"
2018-10-30 08:28:47 +00:00
PRINTSDEV="https://raw.githubusercontent.com/Didgeridoohan/Playground/master/prints.sh"
2018-10-25 06:37:05 +00:00
PRINTFILES=$MODPATH/printfiles
2018-10-30 08:28:47 +00:00
CSTMPRINTS=/sdcard/printslist
CSTMFILE=$PRINTFILES/Custom.sh
2018-05-29 07:29:19 +00:00
BIN=BIN_PLACEHOLDER
USNFLIST=USNF_PLACEHOLDER
2018-03-18 15:39:43 +00:00
# MagiskHide props
PROPSLIST="
ro.debuggable
ro.secure
ro.build.type
ro.build.tags
ro.build.selinux
"
# Safe values
SAFELIST="
ro.debuggable=0
ro.secure=1
ro.build.type=user
ro.build.tags=release-keys
ro.build.selinux=0
"
2019-02-02 12:37:20 +00:00
# Fingerprint props to change
2018-04-26 20:40:46 +00:00
PRINTPROPS="
ro.build.fingerprint
ro.bootimage.build.fingerprint
ro.vendor.build.fingerprint
"
2019-02-02 12:37:20 +00:00
# Print parts
PRINTPARTS="
ro.product.brand
ro.product.name
ro.product.device
ro.build.version.release
ro.build.id
ro.build.version.incremental
"
2018-10-30 08:28:47 +00:00
# Additional SafetyNet props
SNPROPS="
ro.build.version.security_patch
"
2019-02-02 12:37:20 +00:00
# Additional props
ADNPROPS="
ro.build.fingerprint
ro.vendor.build.fingerprint
ro.build.description
"
# Values props list
VALPROPSLIST=$PROPSLIST$PRINTPARTS$SNPROPS$ADNPROPS
# Loading module settings
. $LATEFILE
# ======================== General functions ========================
2018-04-25 22:17:32 +00:00
# Finding file values
get_file_value() {
2018-07-01 05:29:20 +00:00
if [ -f "$1" ]; then
2019-02-02 12:37:20 +00:00
grep $2 $1 | sed "s|.*${2}||" | sed 's|\"||g'
2018-07-01 05:29:20 +00:00
fi
2018-04-25 22:17:32 +00:00
}
2018-08-07 11:50:01 +00:00
# Log functions
2018-04-29 09:14:35 +00:00
# Saves the previous log (if available) and creates a new one
log_start() {
if [ -f "$LOGFILE" ]; then
mv -f $LOGFILE $LASTLOGFILE
fi
touch $LOGFILE
2018-08-07 11:50:01 +00:00
echo "***************************************************" >> $LOGFILE 2>&1
echo "********* MagiskHide Props Config $MODVERSION ********" >> $LOGFILE 2>&1
echo "***************** By Didgeridoohan ***************" >> $LOGFILE 2>&1
echo "***************************************************" >> $LOGFILE 2>&1
2018-04-29 09:14:35 +00:00
log_script_chk "Log start."
}
2018-03-18 15:39:43 +00:00
log_handler() {
2018-10-05 05:28:36 +00:00
if [ "$(id -u)" == 0 ] ; then
2018-08-07 11:50:01 +00:00
echo "" >> $LOGFILE 2>&1
2019-02-02 12:37:20 +00:00
echo -e "$(date +"%Y-%m-%d %H:%M:%S:%N") - $1" >> $LOGFILE 2>&1
2018-07-26 09:03:13 +00:00
fi
2018-03-18 15:39:43 +00:00
}
2018-03-26 16:25:58 +00:00
log_print() {
echo "$1"
log_handler "$1"
}
2018-04-19 03:13:40 +00:00
log_script_chk() {
log_handler "$1"
2018-08-07 11:50:01 +00:00
echo -e "$(date +"%m-%d-%Y %H:%M:%S") - $1" >> $RUNFILE 2>&1
2018-04-19 03:13:40 +00:00
}
2018-03-26 16:25:58 +00:00
#Divider
DIVIDER="${Y}=====================================${N}"
# Header
menu_header() {
2018-06-19 09:56:08 +00:00
if [ -z "$LOGNAME" ] && [ "$DEVTESTING" == "false" ]; then
2018-04-19 03:13:40 +00:00
clear
fi
2018-03-26 16:25:58 +00:00
if [ "$MODVERSION" == "VER_PLACEHOLDER" ]; then
VERSIONTXT=""
else
VERSIONTXT=$MODVERSION
fi
echo ""
echo "${W}MagiskHide Props Config $VERSIONTXT${N}"
echo "${W}by Didgeridoohan @ XDA Developers${N}"
echo ""
echo $DIVIDER
echo -e " $1"
echo $DIVIDER
}
2018-03-18 15:39:43 +00:00
2019-02-02 12:37:20 +00:00
# Get module version
module_v_ctrl() {
VERSIONTMP=$(get_file_value $MODPATH/module.prop "version=")
VERSIONCMP=$(echo $VERSIONTMP | sed 's|v||g' | sed 's|-.*||' | sed 's|\.||g')
}
2018-03-18 15:39:43 +00:00
# Find prop type
get_prop_type() {
2019-02-02 12:37:20 +00:00
if [ "$1" == "ro.vendor.build.fingerprint" ]; then
echo "vendprint"
else
echo $1 | sed 's|.*\.||' | sed 's|.*\_||'
fi
2018-03-18 15:39:43 +00:00
}
2018-04-15 22:05:33 +00:00
# Get left side of =
get_eq_left() {
2019-02-02 12:37:20 +00:00
echo $1 | cut -f 1 -d '='
2018-03-18 15:39:43 +00:00
}
2018-04-15 22:05:33 +00:00
# Get right side of =
get_eq_right() {
2019-02-02 12:37:20 +00:00
echo $1 | cut -f 2 -d '='
2018-03-18 15:39:43 +00:00
}
2019-02-02 12:37:20 +00:00
# Get first word in fingerprint string
2018-04-15 22:05:33 +00:00
get_first() {
2018-04-25 22:17:32 +00:00
case $1 in
2018-05-06 09:57:49 +00:00
*\ *) echo $1 | sed 's|\ .*||'
2018-04-25 22:17:32 +00:00
;;
2018-05-06 09:57:49 +00:00
*=*) get_eq_left "$1"
2018-04-25 22:17:32 +00:00
;;
esac
}
2018-05-06 09:57:49 +00:00
# Get the device for current fingerprint
get_device_used() {
PRINTTMP=$(cat $MODPATH/prints.sh | grep "$1")
if [ "$PRINTTMP" ]; then
echo "${C}$(get_eq_left "$PRINTTMP" | sed "s| (.*||")${N}"
echo ""
2018-12-09 09:05:50 +00:00
elif [ -s "$CSTMPRINTS" ]; then
PRINTTMP=$(cat $CSTMPRINTS | grep "$1")
if [ "$PRINTTMP" ]; then
echo "${C}$(get_eq_left "$PRINTTMP" | sed "s| (.*||")${N} (from custom list)"
echo ""
fi
2018-05-06 09:57:49 +00:00
fi
}
2019-02-02 12:37:20 +00:00
# Get Android version with 3 digits for current fingerprint
2018-10-21 14:17:11 +00:00
get_android_version() {
2019-02-02 12:37:20 +00:00
print_parts $1 "var"
VERTMP=$VARRELEASE
2018-10-21 14:17:11 +00:00
if [ "${#VERTMP}" -lt 3 ]; then
until [ "${#VERTMP}" == 3 ]
do
VERTMP="$(echo ${VERTMP}0)"
done
fi
echo $VERTMP
}
# Get security patch date for current fingerprint
get_sec_patch() {
2018-10-25 10:22:27 +00:00
echo $1 | sed 's|.*\_\_||'
2018-10-21 14:17:11 +00:00
}
# Get the fingerprint for displaying in the ui
get_print_display() {
2018-10-25 10:22:27 +00:00
echo $1 | sed 's|\_\_.*||'
2018-10-21 14:17:11 +00:00
}
2018-04-25 22:17:32 +00:00
# Replace file values
replace_fn() {
2018-05-06 09:57:49 +00:00
sed -i "s|${1}=${2}|${1}=${3}|" $4
2018-03-18 15:39:43 +00:00
}
2019-02-02 12:37:20 +00:00
# Format user files to remove Windows file endings
2018-12-09 09:05:50 +00:00
format_file() {
log_handler "Formating file (${1})."
# Remove Windows line endings
sed -i 's/\r$//' $1
# Check for newline at EOF
if [ ! -z "$(tail -c 1 "$1")" ]; then
echo "" >> $1
fi
}
2018-03-18 15:39:43 +00:00
# Updates placeholders
placeholder_update() {
FILEVALUE=$(get_file_value $1 "$2=")
2018-04-29 09:14:35 +00:00
log_handler "Checking for ${3} in ${1}. Current value is ${FILEVALUE}."
2018-03-18 15:39:43 +00:00
case $FILEVALUE in
2018-04-25 22:17:32 +00:00
*PLACEHOLDER*) replace_fn $2 $3 $4 $1
2018-04-29 09:14:35 +00:00
log_handler "Placeholder ${3} updated to ${4} in ${1}."
2018-03-18 15:39:43 +00:00
;;
esac
}
2018-03-20 18:31:57 +00:00
2019-02-02 12:37:20 +00:00
# Check if boot scripts ran during boot
script_ran_check() {
POSTCHECK=0
if [ -f "$RUNFILE" ] && [ "$(grep "post-fs-data.sh module script finished" $RUNFILE)" ]; then
POSTCHECK=1
fi
LATECHECK=0
if [ -f "$RUNFILE" ] && [ "$(grep "service.sh module script finished" $RUNFILE)" ]; then
LATECHECK=1
fi
}
2018-08-07 11:50:01 +00:00
# Check for original prop values
2018-04-15 22:05:33 +00:00
orig_check() {
2019-02-02 12:37:20 +00:00
PROPSTMPLIST=$VALPROPSLIST
2018-04-15 22:05:33 +00:00
ORIGLOAD=0
for PROPTYPE in $PROPSTMPLIST; do
PROP=$(get_prop_type $PROPTYPE)
2018-06-03 16:40:24 +00:00
ORIGPROP=$(echo "ORIG${PROP}" | tr '[:lower:]' '[:upper:]')
2019-02-02 12:37:20 +00:00
ORIGVALUE="$(echo ${ORIGPROP})"
2018-04-15 22:05:33 +00:00
if [ "$ORIGVALUE" ]; then
ORIGLOAD=1
fi
done
}
2018-08-07 11:50:01 +00:00
# Load currently set values
2018-04-15 22:05:33 +00:00
curr_values() {
2019-02-02 12:37:20 +00:00
for ITEM in $VALPROPSLIST; do
CURRTMP=$(resetprop -v $ITEM) >> $LOGFILE 2>&1
TMPPROP=$(get_prop_type $ITEM | tr '[:lower:]' '[:upper:]')
eval "CURR${TMPPROP}='$CURRTMP'"
done
2018-04-15 22:05:33 +00:00
if [ -z "$CURRFINGERPRINT" ]; then
2018-08-07 11:50:01 +00:00
CURRFINGERPRINT=$(resetprop -v ro.bootimage.build.fingerprint) >> $LOGFILE 2>&1
2018-04-26 20:40:46 +00:00
if [ -z "$CURRFINGERPRINT" ]; then
2018-08-07 11:50:01 +00:00
CURRFINGERPRINT=$(resetprop -v ro.vendor.build.fingerprint) >> $LOGFILE 2>&1
2018-04-26 20:40:46 +00:00
fi
2018-04-15 22:05:33 +00:00
fi
}
2019-02-02 12:37:20 +00:00
# Check if original file values are safe
orig_safe() {
replace_fn FILESAFE 0 1 $LATEFILE
for V in $PROPSLIST; do
PROP=$(get_prop_type $V)
FILEPROP=$(echo "CURR${PROP}" | tr '[:lower:]' '[:upper:]')
FILEVALUE=$(eval "echo \$$FILEPROP")
log_handler "Checking ${FILEPROP}=${FILEVALUE}"
safe_props $V $FILEVALUE
if [ "$SAFE" == 0 ]; then
log_handler "Prop $V set to triggering value in prop file."
replace_fn FILESAFE 1 0 $LATEFILE
else
if [ -z "$FILEVALUE" ]; then
log_handler "Could not retrieve value for prop $V."
elif [ "$SAFE" == 1 ]; then
log_handler "Prop $V set to \"safe\" value in prop file."
fi
fi
done
2018-04-15 22:05:33 +00:00
}
2018-08-07 11:50:01 +00:00
# Run all value loading functions
2018-04-15 22:05:33 +00:00
all_values() {
2018-06-19 09:56:08 +00:00
log_handler "Loading values."
2018-04-15 22:05:33 +00:00
# Currently set values
curr_values
2019-02-02 12:37:20 +00:00
# Module saved values
. $LATEFILE
2018-04-15 22:05:33 +00:00
}
2018-08-07 11:50:01 +00:00
# Run after updated props/settings
2018-04-15 22:05:33 +00:00
after_change() {
2019-02-02 12:37:20 +00:00
if [ "$2" == "file" ]; then
# Load module settings
. $LATEFILE
else
# Update the reboot variable
reboot_chk
# Load all values
all_values
# Ask to reboot
reboot_fn "$1" "$2"
fi
2018-04-15 22:05:33 +00:00
}
2018-08-07 11:50:01 +00:00
# Run after changing props/settings with configuration file
2018-04-15 22:05:33 +00:00
after_change_file() {
# Update the reboot variable
reboot_chk
# Load all values
INPUT=""
all_values
# Ask to reboot
reboot_fn "$1" "$2"
}
2018-08-07 11:50:01 +00:00
# Check if module needs a reboot
2018-04-15 22:05:33 +00:00
reboot_chk() {
2018-04-25 22:17:32 +00:00
replace_fn REBOOTCHK 0 1 $LATEFILE
2018-04-15 22:05:33 +00:00
}
2018-08-07 11:50:01 +00:00
# Reset module
2018-04-15 22:05:33 +00:00
reset_fn() {
2018-08-07 11:50:01 +00:00
cp -af $MODPATH/propsconf_late $LATEFILE >> $LOGFILE 2>&1
2018-05-29 07:29:19 +00:00
if [ "$BUILDPROPENB" ] && [ "$BUILDPROPENB" != 1 ]; then
2018-04-25 22:17:32 +00:00
replace_fn BUILDPROPENB 1 $BUILDPROPENB $LATEFILE
2018-04-15 22:05:33 +00:00
fi
2018-05-29 07:29:19 +00:00
if [ "$FINGERPRINTENB" ] && [ "$FINGERPRINTENB" != 1 ]; then
2018-04-25 22:17:32 +00:00
replace_fn FINGERPRINTENB 1 $FINGERPRINTENB $LATEFILE
2018-04-15 22:05:33 +00:00
fi
2018-08-07 11:50:01 +00:00
chmod -v 755 $LATEFILE >> $LOGFILE 2>&1
2019-02-02 12:37:20 +00:00
placeholder_update $LATEFILE CACHELOC CACHE_PLACEHOLDER "$CACHELOC"
placeholder_update $LATEFILE COREPATH CORE_PLACEHOLDER "$COREPATH"
2018-04-15 22:05:33 +00:00
2018-05-29 07:29:19 +00:00
if [ "$1" != "post" ]; then
# Update the reboot variable
reboot_chk
# Update all prop value variables
all_values
fi
2018-04-15 22:05:33 +00:00
}
# Checks for configuration file
config_file() {
2018-04-25 22:17:32 +00:00
log_handler "Checking for configuration file."
2019-02-02 12:37:20 +00:00
CONFFILE=""
for ITEM in $CONFFILELST; do
if [ -s "$ITEM" ]; then
CONFFILE="$ITEM"
break
fi
done
if [ "$CONFFILE" ]; then
2018-06-19 09:56:08 +00:00
log_handler "Configuration file detected (${CONFFILE})."
2018-12-09 09:05:50 +00:00
format_file $CONFFILE
2018-04-15 22:05:33 +00:00
# Loads custom variables
. $CONFFILE
2019-02-02 12:37:20 +00:00
module_v_ctrl
if [ "$CONFTRANSF" -le $VERSIONCMP ]; then
# Check if vendor fingerprint is set
if [ "$CONFVENDPRINT" == "true" ]; then
log_handler "Using vendor fingerprint"
CONFFINGERPRINT=$(resetprop -v ro.vendor.build.fingerprint) >> $LOGFILE 2>&1
fi
# Updates prop values (including fingerprint)
PROPSTMPLIST=$PROPSLIST"
ro.build.fingerprint
"
for PROPTYPE in $PROPSTMPLIST; do
CONFPROP=$(echo "CONF$(get_prop_type $PROPTYPE)" | tr '[:lower:]' '[:upper:]')
TMPPROP=$(eval "echo \$$CONFPROP")
if [ "$TMPPROP" ]; then
log_handler "Checking $PROPTYPE settings."
if [ "$TMPPROP" != "preserve" ]; then
if [ "$PROPTYPE" == "ro.build.fingerprint" ]; then
if [ "$FINGERPRINTENB" == 1 ]; then
change_print "$PROPTYPE" "$TMPPROP" "file"
fi
else
change_prop "$PROPTYPE" "$TMPPROP" "file"
fi
fi
else
2018-04-15 22:05:33 +00:00
if [ "$PROPTYPE" == "ro.build.fingerprint" ]; then
2019-02-02 12:37:20 +00:00
if [ "$FINGERPRINTENB" == 1 ]; then
reset_print "$PROPTYPE" "file"
2018-04-15 22:05:33 +00:00
fi
else
2019-02-02 12:37:20 +00:00
reset_prop "$PROPTYPE" "file"
2018-04-15 22:05:33 +00:00
fi
fi
2019-02-02 12:37:20 +00:00
done
# Updates device simulation options, only if fingerprint editing is enabled
if [ "$PRINTEDIT" == 1 ]; then
# Fingerprint parts
if [ "$CONFDEVSIM" == "true" ]; then
change_dev_sim "Device simulation" "file"
for ITEM in $PRINTPARTS; do
TMPVAR="CONF$(get_prop_type $ITEM | tr '[:lower:]' '[:upper:]')"
if [ $(eval "echo \$$TMPVAR") == "true" ]; then
TMPVAL=1
else
TMPVAL=0
fi
change_sim_prop "Device simulation" "$ITEM" "$TMPVAL" "file"
done
fi
# Device description
if [ "$CONFDESCRIPTION" == "true" ]; then
change_sim_descr "Device simulation" 1 "file"
2018-04-15 22:05:33 +00:00
else
2019-02-02 12:37:20 +00:00
change_sim_descr "Device simulation" 0 "file"
2018-04-15 22:05:33 +00:00
fi
fi
2019-02-02 12:37:20 +00:00
# Updates prop file editing
if [ "$FILESAFE" == 0 ]; then
if [ "$CONFPROPFILES" == "true" ]; then
edit_prop_files "file" "" " (configuration file)"
elif [ "$CONFPROPFILES" == "false" ]; then
reset_prop_files "file" "" " (configuration file)"
fi
2018-04-15 22:05:33 +00:00
fi
2019-02-02 12:37:20 +00:00
# Updates custom props
if [ "$PROPOPTION" != "preserve" ]; then
if [ "$CONFPROPS" ] || [ "$CONFPROPSPOST" ] || [ "$CONFPROPSLATE" ]; then
if [ "$PROPOPTION" == "add" ] || [ "$PROPOPTION" == "replace" ]; then
if [ "$PROPOPTION" == "replace" ]; then
reset_all_custprop "file"
fi
if [ "$CONFPROPS" ]; then
for ITEM in $CONFPROPS; do
set_custprop "$(get_eq_left "$ITEM")" "$(get_eq_right "$ITEM")" "default" "file"
done
fi
if [ "$CONFPROPSPOST" ]; then
for ITEM in $CONFPROPSPOST; do
set_custprop "$(get_eq_left "$ITEM")" "$(get_eq_right "$ITEM")" "post" "file"
done
fi
if [ "$CONFPROPSLATE" ]; then
for ITEM in $CONFPROPSLATE; do
set_custprop "$(get_eq_left "$ITEM")" "$(get_eq_right "$ITEM")" "late" "file"
done
fi
2018-09-04 07:55:57 +00:00
fi
2019-02-02 12:37:20 +00:00
else
reset_all_custprop "file"
2018-04-15 22:05:33 +00:00
fi
fi
2019-02-02 12:37:20 +00:00
# Updates props to delete
if [ "$DELPROPOPTION" != "preserve" ]; then
if [ "$CONFDELPROPS" ]; then
if [ "$DELPROPOPTION" == "add" ] || [ "$DELPROPOPTION" == "replace" ]; then
if [ "$DELPROPOPTION" == "replace" ]; then
reset_all_delprop "file"
fi
for ITEM in $CONFDELPROPS; do
set_delprop "$ITEM" "file"
done
2018-06-19 09:56:08 +00:00
fi
2019-02-02 12:37:20 +00:00
else
reset_all_delprop "file"
2018-06-19 09:56:08 +00:00
fi
fi
2019-02-02 12:37:20 +00:00
# Updates options
if [ "$CONFLATE" == "true" ]; then
OPTLCHNG=1
TMPTXT="late_start service"
else
OPTLCHNG=0
TMPTXT="post-fs-data"
fi
replace_fn OPTIONLATE $OPTIONLATE $OPTLCHNG $LATEFILE
log_handler "Boot stage is ${TMPTXT}."
if [ "$CONFCOLOUR" == "true" ]; then
OPTCCHNG=1
else
OPTCCHNG=0
fi
replace_fn OPTIONCOLOUR $OPTIONCOLOUR $OPTCCHNG $LATEFILE
log_handler "Colour $CONFCOLOUR."
if [ "$CONFWEB" == "true" ]; then
OPTWCHNG=1
else
OPTWCHNG=0
fi
replace_fn OPTIONWEB $OPTIONWEB $OPTWCHNG $LATEFILE
log_handler "Automatic fingerprints list update $CONFWEB."
2018-04-15 22:05:33 +00:00
else
2019-02-02 12:37:20 +00:00
log_handler "The configuration file is not compatible with the current module version."
2018-04-15 22:05:33 +00:00
fi
# Deletes the configuration file
log_handler "Deleting configuration file."
rm -f $CONFFILE
2019-02-02 12:37:20 +00:00
log_handler "Configuration file import complete."
2018-04-25 22:17:32 +00:00
else
log_handler "No configuration file."
2018-04-15 22:05:33 +00:00
fi
}
2018-06-19 09:56:08 +00:00
# Connection test
test_connection() {
2018-08-07 11:50:01 +00:00
ping -c 1 -W 1 google.com >> $LOGFILE 2>&1 && CNTTEST="true" || CNTTEST="false"
2018-06-19 09:56:08 +00:00
}
2018-04-15 22:05:33 +00:00
# ======================== Fingerprint functions ========================
2018-05-29 07:29:19 +00:00
# Set new fingerprint
print_edit() {
2019-02-02 12:37:20 +00:00
if [ "$FINGERPRINTENB" == 1 -o "$PRINTMODULE" == 0 ] && [ "$PRINTEDIT" == 1 ]; then
2018-05-29 07:29:19 +00:00
log_handler "Changing fingerprint."
2019-02-02 12:37:20 +00:00
if [ "$PRINTVEND" == 1 ]; then
log_handler "Using vendor fingerprint (for Treble GSI ROMs)."
PRINTCHNG="$(resetprop ro.vendor.build.fingerprint)"
# Set device simulation variables
print_parts "$PRINTCHNG"
else
PRINTCHNG="$(echo $MODULEFINGERPRINT | sed 's|\_\_.*||')"
fi
2018-05-29 07:29:19 +00:00
for ITEM in $PRINTPROPS; do
log_handler "Changing/writing $ITEM."
2018-08-07 11:50:01 +00:00
resetprop -v $ITEM >> $LOGFILE 2>&1
2018-10-21 14:17:11 +00:00
resetprop -nv $ITEM $PRINTCHNG >> $LOGFILE 2>&1
2018-07-19 19:47:43 +00:00
done
2018-10-25 06:37:05 +00:00
# Edit security patch date if included
2019-02-02 12:37:20 +00:00
if [ "$PRINTVEND" != 1 ]; then
SECPATCH="$(get_sec_patch $MODULEFINGERPRINT)"
case "$MODULEFINGERPRINT" in
*__*)
if [ "$SECPATCH" ]; then
log_handler "Updating security patch date to match fingerprint used."
resetprop -v ro.build.version.security_patch >> $LOGFILE 2>&1
resetprop -nv ro.build.version.security_patch $SECPATCH >> $LOGFILE 2>&1
fi
;;
esac
fi
# Edit device description
if [ "$DESCRIPTIONSET" == 1 ]; then
if [ "$SIMDESCRIPTION" ]; then
log_handler "Changing/writing ro.build.description."
resetprop -v ro.build.description >> $LOGFILE 2>&1
resetprop -nv ro.build.description "$SIMDESCRIPTION" >> $LOGFILE 2>&1
fi
else
log_handler "Changing/writing ro.build.description is disabled."
fi
2018-05-29 07:29:19 +00:00
fi
}
2018-10-25 06:37:05 +00:00
# Create fingerprint files
print_files() {
log_print "Creating fingerprint files."
rm -rf $PRINTFILES >> $LOGFILE 2>&1
mkdir -pv $PRINTFILES >> $LOGFILE 2>&1
# Loading prints
. $PRINTSLOC
# Saving manufacturers
log_handler "Saving manufacturers."
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for ITEM in $PRINTSLIST; do
TMPOEMLIST=$(echo "$OEMLIST $(get_first $ITEM)" | sed 's|^[ \t]*||')
OEMLIST="$TMPOEMLIST"
done
IFS=$SAVEIFS
TMPOEMLIST=$(echo $(printf '%s\n' $OEMLIST | sort -u))
OEMLIST="$TMPOEMLIST"
log_handler "Creating files."
for OEM in $OEMLIST; do
echo -e "PRINTSLIST=\"" >> $PRINTFILES/${OEM}\.sh
2019-02-02 12:37:20 +00:00
grep $OEM >> $PRINTFILES/${OEM}\.sh $PRINTSLOC
2018-10-25 06:37:05 +00:00
echo -e "\"" >> $PRINTFILES/${OEM}\.sh
done
2019-02-02 12:37:20 +00:00
# Check for updated fingerprint
device_print_update "Updating module fingerprint."
}
device_print_update() {
if [ "$OPTIONUPDATE" == 1 ]; then
if [ "$FINGERPRINTENB" == 1 -o "$PRINTMODULE" == 0 ] && [ "$PRINTEDIT" == 1 ] && [ "$MODULEFINGERPRINT" ]; then
TMPDEV="${SIMBRAND}/${SIMNAME}/${SIMDEVICE}"
for ITEM in $PRINTSLIST; do
case $ITEM in
*$TMPDEV*)
TMPPRINT=$ITEM
break
;;
esac
done
log_handler "Checking for updated fingerprint ($TMPDEV)."
if [ "$TMPDEV" ] && [ "$TMPPRINT" ]; then
if [ "$MODULEFINGERPRINT" != "$(get_eq_right $TMPPRINT))" ]; then
log_handler "$1"
change_print "$1" $(get_eq_right $TMPPRINT) "update"
replace_fn PRINTCHK 0 1 $LATEFILE
# Load module values
. $LATEFILE
else
log_handler "No update available."
fi
fi
fi
fi
2018-10-25 06:37:05 +00:00
}
2018-04-15 22:05:33 +00:00
# Checks and updates the prints list
2018-03-20 18:31:57 +00:00
download_prints() {
2018-06-19 09:56:08 +00:00
if [ -z "$LOGNAME" ] && [ "$DEVTESTING" == "false" ]; then
2018-04-19 03:13:40 +00:00
clear
fi
2018-05-12 16:29:05 +00:00
if [ "$1" == "Dev" ]; then
2018-10-30 08:28:47 +00:00
PRINTSWWW=$PRINTSDEV
2018-05-06 09:57:49 +00:00
fi
2018-03-26 16:25:58 +00:00
menu_header "Updating fingerprints list"
echo ""
2018-06-19 09:56:08 +00:00
# Testing connection
log_print "Checking connection."
test_connection
# Checking and downloading fingerprints list
if [ "$CNTTEST" == "true" ]; then
log_print "Checking list version."
2018-09-04 07:55:57 +00:00
wget -T 5 -q -O $PRINTSTMP $PRINTSWWW >> $LOGFILE 2>&1
if [ -s "$PRINTSTMP" ]; then
2018-06-19 09:56:08 +00:00
LISTVERSION=$(get_file_value $PRINTSTMP "PRINTSV=")
2018-09-04 07:55:57 +00:00
if [ "$LISTVERSION" ]; then
if [ "$LISTVERSION" == "Dev" ] || [ "$LISTVERSION" -gt "$(get_file_value $PRINTSLOC "PRINTSV=")" ]; then
2019-02-02 12:37:20 +00:00
module_v_ctrl
2018-10-25 06:37:05 +00:00
if [ "$(get_file_value $PRINTSTMP "PRINTSTRANSF=")" -le $VERSIONCMP ]; then
2018-09-04 07:55:57 +00:00
mv -f $PRINTSTMP $PRINTSLOC >> $LOGFILE 2>&1
# Updates list version in module.prop
replace_fn version $VERSIONTMP "${MODVERSION}-v${LISTVERSION}" $MODPATH/module.prop
log_print "Updated list to v${LISTVERSION}."
2018-10-25 06:37:05 +00:00
print_files
2018-09-04 07:55:57 +00:00
else
rm -f $PRINTSTMP
log_print "New fingerprints list requires module update."
fi
2018-06-19 09:56:08 +00:00
else
rm -f $PRINTSTMP
2018-09-04 07:55:57 +00:00
log_print "Fingerprints list up-to-date."
2018-06-19 09:56:08 +00:00
fi
2018-03-26 16:25:58 +00:00
else
rm -f $PRINTSTMP
2018-09-04 07:55:57 +00:00
log_print "! File not downloaded!"
log_handler "Couldn't extract list version."
2018-03-26 16:25:58 +00:00
fi
2018-09-04 07:55:57 +00:00
elif [ -f "$PRINTSTMP" ]; then
rm -f $PRINTSTMP
log_print "! File not downloaded!"
log_handler "File is empty."
2018-03-26 16:25:58 +00:00
else
2018-09-04 07:55:57 +00:00
log_print "! File not downloaded!"
2018-03-20 18:31:57 +00:00
fi
else
2018-03-26 16:25:58 +00:00
log_print "No connection."
2018-03-20 18:31:57 +00:00
fi
2018-04-15 22:05:33 +00:00
if [ "$1" == "manual" ]; then
sleep 2
2018-04-19 03:13:40 +00:00
else
sleep 0.5
2018-04-15 22:05:33 +00:00
fi
2018-03-28 16:39:57 +00:00
}
2018-04-15 22:05:33 +00:00
# Reset the module fingerprint change
reset_print() {
2018-04-29 09:14:35 +00:00
log_handler "Resetting device fingerprint to default system value."
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
# Saves new module valueS
replace_fn MODULEFINGERPRINT "\"$MODULEFINGERPRINT\"" "\"\"" $LATEFILE
# Updates vendor print setting
replace_fn PRINTVEND 1 0 $LATEFILE
2018-04-15 22:05:33 +00:00
# Updates prop change variables in propsconf_late
2018-04-25 22:17:32 +00:00
replace_fn PRINTEDIT 1 0 $LATEFILE
# Updates improved hiding setting
2019-02-02 12:37:20 +00:00
replace_fn SETFINGERPRINT "true" "false" $LATEFILE
# Updates simulation setting
replace_fn DEVSIM 1 0 $LATEFILE
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
# Clear out device simulation variables
print_parts "none"
after_change "$1" "$2"
2018-04-15 22:05:33 +00:00
}
# Use fingerprint
change_print() {
log_handler "Changing device fingerprint to $2."
2019-02-02 12:37:20 +00:00
# Saves new module values
replace_fn MODULEFINGERPRINT "\"$MODULEFINGERPRINT\"" "\"$2\"" $LATEFILE
2018-04-15 22:05:33 +00:00
# Updates prop change variables in propsconf_late
2018-04-25 22:17:32 +00:00
replace_fn PRINTEDIT 0 1 $LATEFILE
# Updates improved hiding setting
2019-02-02 12:37:20 +00:00
replace_fn SETFINGERPRINT "false" "true" $LATEFILE
# Set device simulation variables
print_parts "$2"
2018-04-15 22:05:33 +00:00
NEWFINGERPRINT=""
2019-02-02 12:37:20 +00:00
if [ "$DEVSIM" == 1 ]; then
after_change "$1" "$3"
fi
}
# Use vendor fingerprint
change_print_vendor() {
if [ $2 == 1 ]; then
STATETXT="Enabling"
TMPVAL=0
BUILD1="false"
BUILD2="true"
else
STATETXT="Disabling"
TMPVAL=1
BUILD1="true"
BUILD2="false"
fi
log_handler "$STATETXT using the stock vendor fingerprint (for Treble GSI ROMs)."
# Enables or disables the setting
replace_fn PRINTVEND $TMPVAL $2 $LATEFILE
# Updates prop change variables in propsconf_late
replace_fn PRINTEDIT $TMPVAL $2 $LATEFILE
# Clearing out module value
replace_fn MODULEFINGERPRINT "\"$MODULEFINGERPRINT\"" "\"\"" $LATEFILE
# Updates improved hiding setting
replace_fn SETFINGERPRINT $BUILD1 $BUILD2 $LATEFILE
# Updates simulation setting
replace_fn DEVSIM $TMPVAL $2 $LATEFILE
# Set device simulation variables
print_parts "$ORIGVENDPRINT"
if [ "$DEVSIM" == 1 ]; then
after_change "$1" "$3"
fi
}
# Save props values from fingerprint parts
print_parts() {
DLIM1=1
DLIM2=1
for ITEM in $PRINTPARTS; do
TMPVALUE=""
TMPPROP=$(get_prop_type $ITEM | tr '[:lower:]' '[:upper:]')
if [ $1 != "none" ]; then
TMPVALUE=$(echo $1 | sed 's|\:user\/release-keys||' | cut -f $DLIM1 -d ':' | cut -f $DLIM2 -d '/')
eval "VAR${TMPPROP}='$TMPVALUE'"
fi
DLIM2=$(($DLIM2 + 1))
if [ "$DLIM2" == 4 ]; then
DLIM1=2
DLIM2=1
fi
if [ "$2" != "var" ]; then
SUBA=$(get_file_value $LATEFILE "SIM${TMPPROP}=")
replace_fn "SIM${TMPPROP}" "\"$SUBA\"" "\"$TMPVALUE\"" $LATEFILE
fi
done
VARDESCRIPTION=""
if [ $1 != "none" ]; then
VARDESCRIPTION="${VARNAME}-user $VARRELEASE $VARID $VARINCREMENTAL release-keys"
fi
if [ "$2" != "var" ]; then
replace_fn SIMDESCRIPTION "\"$SIMDESCRIPTION\"" "\"$VARDESCRIPTION\"" $LATEFILE
fi
# Load module values
. $LATEFILE
}
# ======================== Device simulation functions ========================
# Edit the simulation props
dev_sim_edit() {
if [ "$FINGERPRINTENB" == 1 -o "$PRINTMODULE" == 0 ] && [ "$PRINTEDIT" == 1 ]; then
if [ "$DEVSIM" == 1 ]; then
log_handler "Editing device simulation props."
for ITEM in $PRINTPARTS; do
TMPPROP=$(get_prop_type $ITEM | tr '[:lower:]' '[:upper:]')
TMPENB=$(get_file_value $LATEFILE "${TMPPROP}SET=")
TMPVALUE=$(get_file_value $LATEFILE "SIM${TMPPROP}=")
if [ "$TMPENB" == 1 ] && [ "$TMPVALUE" ]; then
log_handler "Changing/writing $ITEM."
resetprop -v $ITEM >> $LOGFILE 2>&1
resetprop -nv $ITEM $TMPVALUE >> $LOGFILE 2>&1
else
log_handler "Changing/writing $ITEM is disabled."
fi
done
fi
fi
}
# Enable/disable the option
change_dev_sim() {
if [ $DEVSIM == 0 ]; then
STATETXT="Enabling"
TMPVAL=1
else
STATETXT="Disabling"
TMPVAL=0
2018-04-15 22:05:33 +00:00
fi
2019-02-02 12:37:20 +00:00
log_handler "$STATETXT basic device simulation."
# Enables or disables the setting
replace_fn "DEVSIM" $DEVSIM $TMPVAL $LATEFILE
after_change "$1" "$2"
}
# Change if prop should be simulated or not
change_sim_prop() {
if [ $3 == 1 ]; then
STATETXT="enabled"
else
STATETXT="disabled"
fi
log_handler "Changing device simulation prop $2 to $STATETXT."
TMPPROP=$(get_prop_type $2 | tr '[:lower:]' '[:upper:]')
SUBA=$(get_file_value $LATEFILE "${TMPPROP}SET=")
# Saves new value
replace_fn "${TMPPROP}SET" $SUBA $3 $LATEFILE
after_change "$1" "$4"
}
# Change if description should be simulated or not
change_sim_descr() {
if [ $2 == 1 ]; then
STATETXT="enabled"
else
STATETXT="disabled"
fi
log_handler "Changing device description editing to $STATETXT."
# Saves new value
replace_fn DESCRIPTIONSET $DESCRIPTIONSET $2 $LATEFILE
after_change "$1" "$3"
2018-04-15 22:05:33 +00:00
}
# ======================== Props files functions ========================
# Reset prop files
reset_prop_files() {
log_handler "Resetting prop files$3."
2018-04-19 03:13:40 +00:00
# Changes files
2018-04-15 22:05:33 +00:00
for PROPTYPE in $PROPSLIST; do
2019-02-02 12:37:20 +00:00
log_handler "Disabling prop file editing for '$PROPTYPE'."
2018-03-28 16:39:57 +00:00
PROP=$(get_prop_type $PROPTYPE)
2018-04-15 22:05:33 +00:00
SETPROP=$(echo "SET$PROP" | tr '[:lower:]' '[:upper:]')
2018-04-25 22:17:32 +00:00
replace_fn $SETPROP "true" "false" $LATEFILE
2018-04-15 22:05:33 +00:00
done
2018-04-19 03:13:40 +00:00
# Change fingerprint
2018-04-25 22:17:32 +00:00
replace_fn SETFINGERPRINT "true" "false" $LATEFILE
2018-04-19 03:13:40 +00:00
# Edit settings variables
2018-04-25 22:17:32 +00:00
replace_fn BUILDEDIT 1 0 $LATEFILE
replace_fn DEFAULTEDIT 1 0 $LATEFILE
2018-04-15 22:05:33 +00:00
if [ "$1" != "file" ]; then
after_change_file "$1" "$2"
fi
}
2018-08-07 11:50:01 +00:00
# Editing prop files settings
2018-04-15 22:05:33 +00:00
edit_prop_files() {
log_handler "Modifying prop files$3."
# Checks if editing prop files is enabled
2019-02-02 12:37:20 +00:00
if [ "$BUILDPROPENB" == 0 ]; then
2018-04-15 22:05:33 +00:00
log_handler "Editing build.prop is disabled. Only editing default.prop."
PROPSLIST="
ro.debuggable
ro.secure
"
2018-04-19 03:13:40 +00:00
else
# Checking if the device fingerprint is set by the module
2019-02-02 12:37:20 +00:00
if [ "$FINGERPRINTENB" == 1 ] && [ "$PRINTEDIT" == 1 ]; then
if [ "$(grep "$ORIGFINGERPRINT" $MIRRORLOC/build.prop)" ]; then
2018-04-29 09:14:35 +00:00
log_handler "Enabling prop file editing for device fingerprint."
2018-04-25 22:17:32 +00:00
replace_fn SETFINGERPRINT "false" "true" $LATEFILE
2018-04-19 03:13:40 +00:00
fi
fi
2018-04-15 22:05:33 +00:00
fi
for PROPTYPE in $PROPSLIST; do
log_handler "Checking original file value for '$PROPTYPE'."
PROP=$(get_prop_type $PROPTYPE)
FILEPROP=$(echo "FILE$PROP" | tr '[:lower:]' '[:upper:]')
SETPROP=$(echo "SET$PROP" | tr '[:lower:]' '[:upper:]')
# Check the original file value
PROPVALUE=$(get_file_value $LATEFILE "$FILEPROP=")
if [ -z "$PROPVALUE" ]; then
if [ "$PROPTYPE" == "ro.debuggable" ] || [ "$PROPTYPE" == "ro.secure" ]; then
PROPVALUE=$(get_file_value /default.prop "${PROPTYPE}=")
else
2019-02-02 12:37:20 +00:00
PROPVALUE=$(get_file_value $MIRRORLOC/build.prop "${PROPTYPE}=")
2018-04-15 22:05:33 +00:00
fi
2018-03-28 16:39:57 +00:00
fi
2018-04-15 22:05:33 +00:00
# Checks for default/set values
safe_props $PROPTYPE $PROPVALUE
# Changes file only if necessary
if [ "$SAFE" == 0 ]; then
log_handler "Enabling prop file editing for '$PROPTYPE'."
2018-04-25 22:17:32 +00:00
replace_fn $SETPROP "false" "true" $LATEFILE
2018-04-15 22:05:33 +00:00
elif [ "$SAFE" == 1 ]; then
log_handler "Prop file editing unnecessary for '$PROPTYPE'."
2018-04-25 22:17:32 +00:00
replace_fn $SETPROP "true" "false" $LATEFILE
2018-04-15 22:05:33 +00:00
else
log_handler "Couldn't check safe value for '$PROPTYPE'."
fi
2018-03-28 16:39:57 +00:00
done
2018-04-25 22:17:32 +00:00
replace_fn BUILDEDIT 0 1 $LATEFILE
replace_fn DEFAULTEDIT 0 1 $LATEFILE
2018-04-15 22:05:33 +00:00
if [ "$1" != "file" ]; then
after_change_file "$1" "$2"
fi
2018-03-28 16:39:57 +00:00
}
2018-04-15 22:05:33 +00:00
2018-08-07 11:50:01 +00:00
# Edit the prop files
2018-04-29 09:14:35 +00:00
change_prop_file() {
case $1 in
build)
FNLIST="
ro.build.type
ro.build.tags
ro.build.selinux
"
PROPFILELOC=$MODPATH/system/build.prop
;;
default)
FNLIST="
ro.debuggable
ro.secure
"
PROPFILELOC=/default.prop
;;
esac
for ITEM in $FNLIST; do
PROP=$(get_prop_type $ITEM)
MODULEPROP=$(echo "MODULE${PROP}" | tr '[:lower:]' '[:upper:]')
2018-06-03 16:40:24 +00:00
FILEPROP=$(echo "ORIG${PROP}" | tr '[:lower:]' '[:upper:]')
2018-04-29 09:14:35 +00:00
SETPROP=$(echo "SET${PROP}" | tr '[:lower:]' '[:upper:]')
if [ "$(eval "echo \$$MODULEPROP")" ]; then
SEDVAR="$(eval "echo \$$MODULEPROP")"
else
for P in $SAFELIST; do
2018-05-06 09:57:49 +00:00
if [ "$(get_eq_left "$P")" == "$ITEM" ]; then
SEDVAR=$(get_eq_right "$P")
2018-04-29 09:14:35 +00:00
fi
done
fi
if [ "$(get_file_value $LATEFILE "${SETPROP}=")" == "true" ]; then
replace_fn $ITEM $(eval "echo \$$FILEPROP") $SEDVAR $PROPFILELOC && log_handler "${ITEM}=${SEDVAR}"
fi
done
}
2018-04-15 22:05:33 +00:00
# ======================== MagiskHide Props functions ========================
# Check safe values
safe_props() {
SAFE=""
if [ "$2" ]; then
for P in $SAFELIST; do
2018-05-06 09:57:49 +00:00
if [ "$(get_eq_left "$P")" == "$1" ]; then
if [ "$2" == "$(get_eq_right "$P")" ]; then
2018-04-15 22:05:33 +00:00
SAFE=1
else
SAFE=0
fi
break
fi
done
fi
}
# Find what prop value to change to
change_to() {
CHANGE=""
case "$1" in
ro.debuggable) if [ "$2" == 0 ]; then CHANGE=1; else CHANGE=0; fi
;;
ro.secure) if [ "$2" == 0 ]; then CHANGE=1; else CHANGE=0; fi
;;
ro.build.type) if [ "$2" == "userdebug" ]; then CHANGE="user"; else CHANGE="userdebug"; fi
;;
ro.build.tags) if [ "$2" == "test-keys" ]; then CHANGE="release-keys"; else CHANGE="test-keys"; fi
;;
ro.build.selinux) if [ "$2" == 0 ]; then CHANGE=1; else CHANGE=0; fi
;;
esac
}
# Reset the module prop change
reset_prop() {
# Sets variables
PROP=$(get_prop_type $1)
MODULEPROP=$(echo "MODULE${PROP}" | tr '[:lower:]' '[:upper:]')
REPROP=$(echo "RE${PROP}" | tr '[:lower:]' '[:upper:]')
SUBA=$(get_file_value $LATEFILE "${MODULEPROP}=")
2018-04-29 09:14:35 +00:00
log_handler "Resetting $1 to default system value."
2018-04-15 22:05:33 +00:00
# Saves new module value
2018-04-25 22:17:32 +00:00
replace_fn $MODULEPROP "\"$SUBA\"" "\"\"" $LATEFILE
2018-04-15 22:05:33 +00:00
# Changes prop
2018-04-25 22:17:32 +00:00
replace_fn $REPROP "true" "false" $LATEFILE
2018-04-15 22:05:33 +00:00
# Updates prop change variable in propsconf_late
if [ "$SUBA" ]; then
if [ "$PROPCOUNT" -gt 0 ]; then
PROPCOUNTP=$(($PROPCOUNT-1))
2018-04-25 22:17:32 +00:00
replace_fn PROPCOUNT $PROPCOUNT $PROPCOUNTP $LATEFILE
2018-04-15 22:05:33 +00:00
fi
2018-05-29 07:29:19 +00:00
fi
2019-02-02 12:37:20 +00:00
if [ "$PROPCOUNT" == 0 ]; then
2018-05-29 07:29:19 +00:00
replace_fn PROPEDIT 1 0 $LATEFILE
2018-04-15 22:05:33 +00:00
fi
2019-02-02 12:37:20 +00:00
after_change "$1" "$2"
2018-04-15 22:05:33 +00:00
}
# Use prop value
change_prop() {
# Sets variables
PROP=$(get_prop_type $1)
MODULEPROP=$(echo "MODULE${PROP}" | tr '[:lower:]' '[:upper:]')
REPROP=$(echo "RE${PROP}" | tr '[:lower:]' '[:upper:]')
SUBA=$(get_file_value $LATEFILE "${MODULEPROP}=")
log_handler "Changing $1 to $2."
# Saves new module value
2018-04-25 22:17:32 +00:00
replace_fn $MODULEPROP "\"$SUBA\"" "\"$2\"" $LATEFILE
2018-04-15 22:05:33 +00:00
# Changes prop
2018-04-25 22:17:32 +00:00
replace_fn $REPROP "false" "true" $LATEFILE
2018-04-15 22:05:33 +00:00
# Updates prop change variables in propsconf_late
if [ -z "$SUBA" ]; then
PROPCOUNTP=$(($PROPCOUNT+1))
2018-04-25 22:17:32 +00:00
replace_fn PROPCOUNT $PROPCOUNT $PROPCOUNTP $LATEFILE
2018-04-15 22:05:33 +00:00
fi
2018-04-25 22:17:32 +00:00
replace_fn PROPEDIT 0 1 $LATEFILE
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
after_change "$1" "$3"
2018-04-15 22:05:33 +00:00
}
# Reset all module prop changes
reset_prop_all() {
log_handler "Resetting all props to default values."
for PROPTYPE in $PROPSLIST; do
PROP=$(get_prop_type $PROPTYPE)
MODULEPROP=$(echo "MODULE${PROP}" | tr '[:lower:]' '[:upper:]')
REPROP=$(echo "RE${PROP}" | tr '[:lower:]' '[:upper:]')
SUBA=$(get_file_value $LATEFILE "${MODULEPROP}=")
# Saves new module value
2018-04-25 22:17:32 +00:00
replace_fn $MODULEPROP "\"$SUBA\"" "\"\"" $LATEFILE
2018-04-15 22:05:33 +00:00
# Changes prop
2018-04-25 22:17:32 +00:00
replace_fn $REPROP "true" "false" $LATEFILE
2018-04-15 22:05:33 +00:00
done
2018-04-25 22:17:32 +00:00
# Updates prop change variables in propsconf_late
replace_fn PROPCOUNT $PROPCOUNT 0 $LATEFILE
replace_fn PROPEDIT 1 0 $LATEFILE
2018-05-29 07:29:19 +00:00
2018-04-15 22:05:33 +00:00
after_change "$1"
}
# ======================== Custom Props functions ========================
2018-05-29 07:29:19 +00:00
# Set custom props
custom_edit() {
2019-02-02 12:37:20 +00:00
if [ "$1" ] && [ "$CUSTOMEDIT" == 1 ]; then
2018-09-04 07:55:57 +00:00
TMPLST="$(get_file_value $LATEFILE "${1}=")"
if [ "$TMPLST" ]; then
log_handler "Writing custom props."
for ITEM in $TMPLST; do
log_handler "Changing/writing $(get_eq_left "$ITEM")."
TMPITEM=$( echo $(get_eq_right "$ITEM") | sed 's|_sp_| |g')
resetprop -v $(get_eq_left "$ITEM") >> $LOGFILE 2>&1
resetprop -nv $(get_eq_left "$ITEM") "$TMPITEM" >> $LOGFILE 2>&1
done
fi
2018-05-29 07:29:19 +00:00
fi
}
2018-04-15 22:05:33 +00:00
# Set custom prop value
set_custprop() {
if [ "$2" ]; then
2019-02-02 12:37:20 +00:00
# Reset the prop
reset_custprop "$1" "$(resetprop $1)" "bootstage"
# Set the prop
2018-09-04 07:55:57 +00:00
PROPSBOOTSTAGE="CUSTOMPROPS"
2019-02-02 12:37:20 +00:00
PROPSTXT="default"
2018-09-04 07:55:57 +00:00
if [ "$3" == "post" ]; then
PROPSBOOTSTAGE="CUSTOMPROPSPOST"
2019-02-02 12:37:20 +00:00
PROPSTXT="post-fs-data"
2018-09-04 07:55:57 +00:00
elif [ "$3" == "late" ]; then
PROPSBOOTSTAGE="CUSTOMPROPSLATE"
2019-02-02 12:37:20 +00:00
PROPSTXT="late_start service"
elif [ "$3" == "both" ]; then
PROPSBOOTSTAGE="CUSTOMPROPSPOST CUSTOMPROPSLATE"
PROPSTXT="post-fs-data/late_start service"
2018-09-04 07:55:57 +00:00
fi
2018-06-03 16:40:24 +00:00
TMPVALUE=$(echo "$2" | sed 's| |_sp_|g')
2019-02-02 12:37:20 +00:00
TMPORIG=$(echo "$4" | sed 's| |_sp_|g')
DLIMTMP=1
for ITEM in $PROPSBOOTSTAGE; do
CURRCUSTPROPS=$(get_file_value $LATEFILE "${ITEM}=")
case "$CURRCUSTPROPS" in
*$1*)
TMPCUSTPROPS=$(echo "$CURRCUSTPROPS" | sed "s|${1}=${TMPORIG}|${1}=${TMPVALUE}|")
;;
*)
TMPCUSTPROPS=$(echo "$CURRCUSTPROPS ${1}=${TMPVALUE}" | sed 's|^[ \t]*||')
;;
esac
SORTCUSTPROPS=$(echo $(printf '%s\n' $TMPCUSTPROPS | sort -u))
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
log_handler "Setting custom prop $1 in $(echo $PROPSTXT | cut -f $DLIMTMP -d '/') stage."
replace_fn $ITEM "\"$CURRCUSTPROPS\"" "\"$SORTCUSTPROPS\"" $LATEFILE
replace_fn CUSTOMEDIT 0 1 $LATEFILE
DLIMTMP=$(($DLIMTMP + 1))
done
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
after_change "$1" "$4"
2018-04-15 22:05:33 +00:00
fi
}
# Reset all custom prop values
reset_all_custprop() {
log_handler "Resetting all custom props."
# Removing all custom props
2019-02-02 12:37:20 +00:00
replace_fn CUSTOMPROPS "\"$CUSTOMPROPS\"" "\"\"" $LATEFILE
replace_fn CUSTOMPROPSPOST "\"$CUSTOMPROPSPOST\"" "\"\"" $LATEFILE
replace_fn CUSTOMPROPSLATE "\"$CUSTOMPROPSLATE\"" "\"\"" $LATEFILE
2018-04-25 22:17:32 +00:00
replace_fn CUSTOMEDIT 1 0 $LATEFILE
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
after_change "Resetting all custom props" "$1"
2018-04-15 22:05:33 +00:00
}
# Reset custom prop value
reset_custprop() {
2019-02-02 12:37:20 +00:00
log_handler "Resetting custom prop $1."
PROPSBOOTSTAGE="CUSTOMPROPS CUSTOMPROPSPOST CUSTOMPROPSLATE"
2018-06-03 16:40:24 +00:00
TMPVALUE=$(echo "$2" | sed 's| |_sp_|g')
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
for ITEM in $PROPSBOOTSTAGE; do
CURRCUSTPROPS=$(get_file_value $LATEFILE "${ITEM}=")
TMPCUSTPROPS=$(echo $CURRCUSTPROPS | sed "s|${1}=${TMPVALUE}||" | tr -s " " | sed 's|^[ \t]*||')
# Updating custom props string
replace_fn $ITEM "\"$CURRCUSTPROPS\"" "\"$TMPCUSTPROPS\"" $LATEFILE
done
2018-04-15 22:05:33 +00:00
2019-02-02 12:37:20 +00:00
if [ -z "$CUSTOMPROPS" ] && [ -z "$CUSTOMPROPSPOST" ] && [ -z "$CUSTOMPROPSLATE" ]; then
2018-04-25 22:17:32 +00:00
replace_fn CUSTOMEDIT 1 0 $LATEFILE
2018-04-15 22:05:33 +00:00
fi
2018-09-04 07:55:57 +00:00
if [ "$3" != "bootstage" ]; then
after_change "$1"
fi
}
2018-06-19 09:56:08 +00:00
# ======================== Delete Props functions ========================
# Delete props
prop_del() {
2019-02-02 12:37:20 +00:00
if [ "$DELEDIT" == 1 ]; then
2018-06-19 09:56:08 +00:00
log_handler "Deleting props."
2019-02-02 12:37:20 +00:00
for ITEM in $DELETEPROPS; do
2018-06-19 09:56:08 +00:00
log_handler "Deleting $ITEM."
TMPITEM=$( echo $(get_eq_right "$ITEM") | sed 's|_sp_| |g')
2018-08-07 11:50:01 +00:00
resetprop -v $ITEM >> $LOGFILE 2>&1
2018-11-18 06:31:58 +00:00
case "$ITEM" in
persist*)
resetprop -pv --delete $ITEM >> $LOGFILE 2>&1
;;
*)
resetprop -v --delete $ITEM >> $LOGFILE 2>&1
;;
esac
2018-06-19 09:56:08 +00:00
done
fi
}
# Set prop to delete
set_delprop() {
if [ "$1" ]; then
2019-02-02 12:37:20 +00:00
TMPDELPROPS=$(echo "$DELETEPROPS ${1}" | sed 's|^[ \t]*||')
2018-06-19 09:56:08 +00:00
SORTDELPROPS=$(echo $(printf '%s\n' $TMPDELPROPS | sort -u))
log_handler "Setting prop to delete, $1."
2019-02-02 12:37:20 +00:00
replace_fn DELETEPROPS "\"$DELETEPROPS\"" "\"$SORTDELPROPS\"" $LATEFILE
2018-06-19 09:56:08 +00:00
replace_fn DELEDIT 0 1 $LATEFILE
2019-02-02 12:37:20 +00:00
after_change "Delete $1" "$2"
2018-06-19 09:56:08 +00:00
fi
}
# Reset all props to delete
reset_all_delprop() {
log_handler "Resetting list of props to delete."
# Removing all props to delete
2019-02-02 12:37:20 +00:00
replace_fn DELETEPROPS "\"$DELETEPROPS\"" "\"\"" $LATEFILE
2018-06-19 09:56:08 +00:00
replace_fn DELEDIT 1 0 $LATEFILE
2019-02-02 12:37:20 +00:00
after_change "Delete $1" "$2"
2018-06-19 09:56:08 +00:00
}
# Reset prop to delete
reset_delprop() {
log_handler "Resetting prop to delete, $1."
2019-02-02 12:37:20 +00:00
TMPDELPROPS=$(echo $DELETEPROPS | sed "s|${1}||" | tr -s " " | sed 's|^[ \t]*||')
2018-06-19 09:56:08 +00:00
# Resetting prop to delete
2019-02-02 12:37:20 +00:00
replace_fn DELETEPROPS "\"$DELETEPROPS\"" "\"$TMPDELPROPS\"" $LATEFILE
# Loading new value
. $LATEFILE
if [ -z "$DELETEPROPS" ]; then
2018-06-19 09:56:08 +00:00
replace_fn DELEDIT 1 0 $LATEFILE
fi
2019-02-02 12:37:20 +00:00
after_change "Delete $1" "$2"
2018-06-19 09:56:08 +00:00
}
# ======================== Log collecting functions ========================
# Collects useful logs and info for troubleshooting
collect_logs() {
log_handler "Collecting logs and information."
# Create temporary directory
2018-08-07 11:50:01 +00:00
mkdir -pv $TMPLOGLOC >> $LOGFILE 2>&1
2018-06-19 09:56:08 +00:00
# Saving Magisk and module log files and device original build.prop
for ITEM in $TMPLOGLIST; do
2018-07-01 05:29:20 +00:00
if [ -f "$ITEM" ]; then
case "$ITEM" in
2019-02-02 12:37:20 +00:00
*build.prop*) BPNAME="build_$(echo $ITEM | sed 's|\/build.prop||' | sed 's|.*\/||g').prop"
2018-07-01 05:29:20 +00:00
;;
2019-02-02 12:37:20 +00:00
*) BPNAME=""
2018-07-01 05:29:20 +00:00
;;
esac
2018-08-07 11:50:01 +00:00
cp -af $ITEM ${TMPLOGLOC}/${BPNAME} >> $LOGFILE 2>&1
2018-07-01 05:29:20 +00:00
else
2018-07-26 09:03:13 +00:00
case "$ITEM" in
*/cache)
if [ "$CACHELOC" == "/cache" ]; then
CACHELOCTMP=/data/cache
else
CACHELOCTMP=/cache
fi
ITEMTPM=$(echo $ITEM | sed 's|$CACHELOC|$CACHELOCTMP|')
if [ -f "$ITEMTPM" ]; then
2018-08-07 11:50:01 +00:00
cp -af $ITEMTPM $TMPLOGLOC >> $LOGFILE 2>&1
2018-07-26 09:03:13 +00:00
else
log_handler "$ITEM not available."
fi
;;
2019-02-02 12:37:20 +00:00
*) log_handler "$ITEM not available."
2018-07-26 09:03:13 +00:00
;;
esac
2018-07-01 05:29:20 +00:00
fi
2018-06-19 09:56:08 +00:00
done
# Saving the current prop values
resetprop > $TMPLOGLOC/props.txt
# Package the files
cd $CACHELOC
2018-08-07 11:50:01 +00:00
tar -zcvf propslogs.tar.gz propslogs >> $LOGFILE 2>&1
2018-06-19 09:56:08 +00:00
# Copy package to internal storage
2018-08-07 11:50:01 +00:00
mv -f $CACHELOC/propslogs.tar.gz /storage/emulated/0 >> $LOGFILE 2>&1
2018-09-04 07:55:57 +00:00
2018-06-19 09:56:08 +00:00
# Remove temporary directory
2018-08-07 11:50:01 +00:00
rm -rf $TMPLOGLOC >> $LOGFILE 2>&1
2018-06-19 09:56:08 +00:00
log_handler "Logs and information collected."
2018-07-01 05:29:20 +00:00
if [ "$1" != "issue" ]; then
INPUTTMP=""
menu_header "${C}$1${N}"
echo ""
echo "Logs and information collected."
echo ""
echo "The packaged file has been saved to the"
echo "root of your device's internal storage."
echo ""
echo "Attach the file to a post in the support"
echo "thread @ XDA, with a detailed description"
echo "of your issue."
echo ""
echo -n "Press enter to continue..."
read -r INPUTTMP
case "$INPUTTMP" in
*)
if [ "$2" == "l" ]; then
exit_fn
fi
;;
esac
fi
}
2018-07-19 19:47:43 +00:00
# Log print
log_handler "Functions loaded."