Add ui_print, fix /vendor detection, nicer func names, fix func decl syntax

master
Felix 3 years ago
parent d0dd02e65b
commit 4ec9465172

@ -5,12 +5,13 @@ ui_print(" by");
ui_print(" Gouster4, oshmoun, local__hero & MartinX3");
ui_print("------------------------------------");
ui_print("Mounting system partition...");
run_program("/sbin/mount", "/system");
run_program("/sbin/mkdir", "/mnt/system");
run_program("/sbin/mount", "/dev/block/bootdevice/by-name/system", "/mnt/system");
ui_print("Mounting vendor partition (may fail) ...");
run_program("/sbin/mount", "/vendor");
ui_print("Mounting oem partition (may fail) ...");
run_program("/sbin/mount", "/oem");
ui_print("Tweaking build.prop files and patching manifest...");
ui_print("Running patch script...");
package_extract_dir("tmp", "/tmp");
set_perm(0, 0, 0777, "/tmp/patch_dualsim.sh");
run_program("/tmp/patch_dualsim.sh");

@ -1,23 +1,51 @@
#!/sbin/sh
# Get file descriptor for output
OUTFD=$(ps | grep -v "grep" | grep -o -E "update-binary(.*)" | cut -d " " -f 3);
# Try looking for a differently named updater binary
if [ -z $OUTFD ]; then
OUTFD=$(ps | grep -v "grep" | grep -o -E "updater(.*)" | cut -d " " -f 3);
fi
# same as ui_print command in updater_script, for example:
#
# ui_print "hello world!"
#
# will output "hello world!" to recovery, while
#
# ui_print
#
# outputs an empty line
ui_print() {
if [ $OUTFD != "" ]; then
echo "ui_print ${1} " 1>&$OUTFD;
echo "ui_print " 1>&$OUTFD;
else
echo "${1}";
fi;
}
system_mount=/mnt/system
vendor_path=/vendor
device_variant=
device_supported=false
default_network=
block_allow_data=
# If we have system-as-root the system is mounted at /system/system in twrp
function check_vendor_on_system() {
echo "Checking whether /vendor is on /system (Pre-Treble)"
# On Android 10, system-as-root means system.img will contain ./system and
# ./vendor.
# /vendor will never be in /system/system/vendor
if [ -f /system/vendor/etc/vintf/manifest.xml ]
check_vendor_on_system() {
ui_print "Checking whether /vendor is on /system (Pre-Treble)"
if [ -f ${system_mount}/vendor/etc/vintf/manifest.xml ]
then
vendor_path=${system_mount}/vendor
elif [ -f ${system_mount}/system/vendor/etc/vintf/manifest.xml ]
then
vendor_path=/system/vendor
vendor_path=${system_mount}/system/vendor
fi
}
function check_oem_as_vendor() {
echo "Checking whether /oem is used as /vendor (Fake Treble)"
check_oem_as_vendor() {
ui_print "Checking whether /oem is used as /vendor (Fake Treble)"
if [ -f /oem/etc/vintf/manifest.xml ]
then
vendor_path=/oem
@ -25,12 +53,14 @@ function check_oem_as_vendor() {
}
# Sanity check - was this patch already flashed?
function check_already_patched() {
echo "Checking if already patched"
check_already_patched() {
ui_print "Checking if already patched"
if [ ! -z "$(cat ${vendor_path}/etc/vintf/manifest.xml | grep slot2)" ]
then
echo "Already patched"
ui_print "Already patched"
exit 0
else
ui_print "Not yet patched"
fi
}
@ -40,8 +70,8 @@ function check_already_patched() {
# Output will be e.g. f8332
# (Not 100% sure about the lowercase f8332 though,
# so use tr to convert to all-lowercase to make sure)
function get_lta_label() {
echo "Mounting LTALabel partition"
get_lta_label() {
ui_print "Mounting LTALabel partition"
mkdir /lta-label
mount -t ext4 /dev/block/bootdevice/by-name/LTALabel /lta-label
device_variant=$(\
@ -53,39 +83,45 @@ function get_lta_label() {
);
umount /lta-label
rm /lta-label
echo "Device variant is ${device_variant}"
ui_print "Device variant is ${device_variant}"
}
function get_default_network_from_device_variant() {
assign_props() {
case ${device_variant} in
# voyager, pioneer, discovery, kirin(2x), mermaid(2x)
h4413|h4113|h4213|i4113|i4193|i4213|i4293)
default_network="9,0"
device_supported=true
;;
# suzu, kagura, dora, keyaki, maple, poplar
f5122|f8332|f8132|g8232|g8142|g8342)
default_network="9,1"
device_supported=true
;;
# apollo, akatsuki(2x), akari(2x)
h8324|h9436|h9493|h8266|h8296)
default_network="9,9"
device_supported=true
;;
# griffin, bahamut
j9110|j9210)
default_network="9,9"
block_allow_data=0
device_supported=true
;;
esac
echo "Setting default_network to $default_network"
}
function set_build_prop_dual_sim_values() {
set_build_prop_dual_sim_values() {
rm -f /tmp/build.prop
ui_print "Setting multisim config to dsds"
echo "persist.vendor.radio.multisim.config=dsds" >> /tmp/build.prop
ui_print "Setting default_network to $default_network"
echo "ro.telephony.default_network=$default_network" >> /tmp/build.prop
if [ ! -z $block_allow_data ]
# kumano devices
then
ui_print "Setting block_allow_data to $block_allow_data"
echo "persist.vendor.radio.block_allow_data=$block_allow_data" >> /tmp/build.prop
fi
@ -97,7 +133,7 @@ function set_build_prop_dual_sim_values() {
model=$(echo ${model} | sed 's/(AOSP)/Dual (AOSP)/')
echo "$model" >> /tmp/build.prop
echo "Substituting props in $vendor_path/build.prop"
ui_print "Substituting props in $vendor_path/build.prop"
# Prevent prop names with spaces in them being split into multiple fields
IFS=$'\n'
@ -110,78 +146,95 @@ function set_build_prop_dual_sim_values() {
done
}
function set_build_prop_device_model_values() {
substitute_in_build_prop() {
sed -i "s/$1/$2/g" ${vendor_path}/build.prop
}
# VINTF manifest patching
# Add a second instance of every needed HAL
function patch_vintf_manifest() {
echo "Patching VINTF manifest"
patch_vintf_manifest() {
ui_print "Patching VINTF manifest"
sed -i -r 's/( +<(fqname|instance)>[^<>]*(slot)[^<>]*)1(<\/[^<>]+>)/\11\4\n\12\4/i' ${vendor_path}/etc/vintf/manifest.xml
sed -i -r 's/( +<(fqname|instance)>[^<>]*(hook|radio|ril|uim)[^<>]*)0(<\/[^<>]+>)/\10\4\n\11\4/i' ${vendor_path}/etc/vintf/manifest.xml
}
ui_print ""
check_vendor_on_system;
check_oem_as_vendor;
check_already_patched;
ui_print "/vendor located at $vendor_path"
get_lta_label;
get_default_network_from_device_variant;
if [ $device_supported = false ]
then
ui_print ""
ui_print "############################################"
ui_print "FAIL: Device $device_variant not supported"
ui_print "Are you trying to flash a single-sim device?"
ui_print "############################################"
ui_print ""
exit 1
fi
check_already_patched;
assign_props;
set_build_prop_dual_sim_values;
# griffin
set_build_prop_device_model_values j8110 j9110;
set_build_prop_device_model_values J8110 J9110;
substitute_in_build_prop j8110 j9110;
substitute_in_build_prop J8110 J9110;
# bahamut
set_build_prop_device_model_values j8210 j9210;
set_build_prop_device_model_values J8210 J9210;
substitute_in_build_prop j8210 j9210;
substitute_in_build_prop J8210 J9210;
# kirin
set_build_prop_device_model_values i3113 i4113;
set_build_prop_device_model_values I3113 I4113;
substitute_in_build_prop i3113 i4113;
substitute_in_build_prop I3113 I4113;
# mermaid
set_build_prop_device_model_values i3213 i4213;
set_build_prop_device_model_values I3213 I4213;
substitute_in_build_prop i3213 i4213;
substitute_in_build_prop I3213 I4213;
# akari
set_build_prop_device_model_values h8216 h8266;
set_build_prop_device_model_values H8216 H8266;
substitute_in_build_prop h8216 h8266;
substitute_in_build_prop H8216 H8266;
# apollo
set_build_prop_device_model_values h8314 h8324;
set_build_prop_device_model_values H8314 H8324;
substitute_in_build_prop h8314 h8324;
substitute_in_build_prop H8314 H8324;
# akatsuki
set_build_prop_device_model_values h8416 h9436;
set_build_prop_device_model_values H8416 H9436;
substitute_in_build_prop h8416 h9436;
substitute_in_build_prop H8416 H9436;
# pioneer
set_build_prop_device_model_values h3113 h4113;
set_build_prop_device_model_values H3113 H4113;
substitute_in_build_prop h3113 h4113;
substitute_in_build_prop H3113 H4113;
# discovery
set_build_prop_device_model_values h3213 h4213;
set_build_prop_device_model_values H3213 H4213;
substitute_in_build_prop h3213 h4213;
substitute_in_build_prop H3213 H4213;
# voyager
set_build_prop_device_model_values h3413 h4413;
set_build_prop_device_model_values H3413 H4413;
substitute_in_build_prop h3413 h4413;
substitute_in_build_prop H3413 H4413;
# maple
set_build_prop_device_model_values g8131 g8142;
set_build_prop_device_model_values G8131 G8142;
substitute_in_build_prop g8131 g8142;
substitute_in_build_prop G8131 G8142;
# poplar
set_build_prop_device_model_values g8341 g8342;
set_build_prop_device_model_values G8341 G8342;
substitute_in_build_prop g8341 g8342;
substitute_in_build_prop G8341 G8342;
# dora
set_build_prop_device_model_values f8131 f8132;
set_build_prop_device_model_values F8131 F8132;
substitute_in_build_prop f8131 f8132;
substitute_in_build_prop F8131 F8132;
# kagura
set_build_prop_device_model_values f8331 f8332;
set_build_prop_device_model_values F8331 F8332;
substitute_in_build_prop f8331 f8332;
substitute_in_build_prop F8331 F8332;
# keyaki
set_build_prop_device_model_values g8231 g8232;
set_build_prop_device_model_values G8231 G8232;
substitute_in_build_prop g8231 g8232;
substitute_in_build_prop G8231 G8232;
# suzu
set_build_prop_device_model_values f5121 f5122;
set_build_prop_device_model_values F5121 F5122;
substitute_in_build_prop f5121 f5122;
substitute_in_build_prop F5121 F5122;
patch_vintf_manifest;

Loading…
Cancel
Save