-
Notifications
You must be signed in to change notification settings - Fork 97
/
port.sh
executable file
·1515 lines (1335 loc) · 83.2 KB
/
port.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# hyperOS_port project
# For A-only and V/A-B (not tested) Devices
# Based on Android 13
# Test Base ROM: A-only Mi 10/PRO/Ultra (MIUI 14 Latset stockrom)
# Test Port ROM: Mi 14/Pro OS1.0.9-1.0.25 Mi 13/PRO OS1.0 23.11.09-23.11.10 DEV
build_user="Bruce Teng"
build_host=$(hostname)
# 底包和移植包为外部参数传入
baserom="$1"
portrom="$2"
work_dir=$(pwd)
tools_dir=${work_dir}/bin/$(uname)/$(uname -m)
export PATH=$(pwd)/bin/$(uname)/$(uname -m)/:$(pwd)/otatools/bin:$PATH
# Import functions
source functions.sh
shopt -s expand_aliases
if [[ "$OSTYPE" == "darwin"* ]]; then
yellow "检测到Mac,设置alias" "macOS detected,setting alias"
alias sed=gsed
alias tr=gtr
alias grep=ggrep
alias du=gdu
alias date=gdate
#alias find=gfind
fi
check unzip aria2c 7z zip java zipalign python3 zstd bc xmlstarlet
# 移植的分区,可在 bin/port_config 中更改
port_partition=$(grep "partition_to_port" bin/port_config |cut -d '=' -f 2)
#super_list=$(grep "super_list" bin/port_config |cut -d '=' -f 2)
repackext4=$(grep "repack_with_ext4" bin/port_config |cut -d '=' -f 2)
pack_method=$(grep "pack_method" bin/port_config | cut -d '=' -f 2)
nfc_fix_type=$(grep "nfc_fix_type" bin/port_config |cut -d '=' -f 2)
if [[ ${repackext4} == true ]]; then
pack_type=EXT
fi
# 检查为本地包还是链接
if [ ! -f "${baserom}" ] && [ "$(echo $baserom |grep http)" != "" ];then
blue "底包为一个链接,正在尝试下载" "Download link detected, start downloding.."
aria2c --max-download-limit=1024M --file-allocation=none -s10 -x10 -j10 ${baserom}
baserom=$(basename ${baserom} | sed 's/\?t.*//')
if [ ! -f "${baserom}" ];then
error "下载错误" "Download error!"
fi
elif [ -f "${baserom}" ];then
green "底包: ${baserom}" "BASEROM: ${baserom}"
else
error "底包参数错误" "BASEROM: Invalid parameter"
exit
fi
if [ ! -f "${portrom}" ] && [ "$(echo ${portrom} |grep http)" != "" ];then
blue "移植包为一个链接,正在尝试下载" "Download link detected, start downloding.."
aria2c --max-download-limit=1024M --file-allocation=none -s10 -x10 -j10 ${portrom}
portrom=$(basename ${portrom} | sed 's/\?t.*//')
if [ ! -f "${portrom}" ];then
error "下载错误" "Download error!"
fi
elif [ -f "${portrom}" ];then
green "移植包: ${portrom}" "PORTROM: ${portrom}"
else
error "移植包参数错误" "PORTROM: Invalid parameter"
exit
fi
if [ "$(echo $baserom |grep _multi_)" != "" ];then
device_code=$(basename $baserom |cut -d '_' -f 3)
elif [ "$(echo $baserom |grep miui_)" != "" ] || [ "$(echo $baserom |grep xiaomi.eu_)" != "" ];then
device_code=$(basename $baserom |cut -d '_' -f 2)
else
device_code="YourDevice"
fi
blue "正在检测ROM底包" "Validating BASEROM.."
if unzip -l ${baserom} | grep -q "payload.bin"; then
baserom_type="payload"
green "检测到payload.bin文件" "Found payload.bin file"
super_list="vendor mi_ext odm odm_dlkm system system_dlkm vendor_dlkm product product_dlkm system_ext"
elif unzip -l ${baserom} | grep -q "br$";then
baserom_type="br"
green "检测到broli文件" "Found broli file"
elif unzip -l ${baserom} | grep -q "images/super.img*"; then
green "检测到super.img.*文件" "Found super.img.* files"
is_base_rom_eu=true
else
error "底包中未发现payload.bin以及br文件,请使用MIUI官方包后重试" "payload.bin/new.br not found, please use HyperOS official OTA zip package."
exit
fi
blue "开始检测ROM移植包" "Validating PORTROM.."
case "${portrom}" in
*.zip)
if unzip -l "${portrom}" | grep -q "payload.bin"; then
green "检测到payload.bin文件" "Found payload.bin file"
elif [[ "${portrom}" == *"xiaomi.eu"* ]] && (unzip -l ${baserom} | grep -q "images/super.img*") ; then
green "检测到super.img.*文件" "Found super.img.* files"
is_eu_rom=true
else
error "目标移植包不是有效的ZIP文件,请检查文件格式。" "The target port package is not a valid ZIP file, please check the file format."
exit
fi
;;
*.tgz)
# FIXME: Checking if the .tgz contains super.img is very time-consuming, so just skip it here for now.
green "跳过检查tgz" "Skip validating tgz file"
portrom_type="fastboot"
;;
*)
error "目标移植包不是有效的ZIP或TGZ文件,请检查文件格式。" "The target port package is not a valid ZIP or TGZ file, please check the file format."
;;
esac
green "ROM初步检测通过" "ROM validation passed."
if [[ "$portrom" =~ SHENNONG|HOUJI ]]; then
is_shennong_houji_port=true
else
is_shennong_houji_port=false
fi
blue "正在清理文件" "Cleaning up.."
for i in ${port_partition};do
[ -d ./${i} ] && rm -rf ./${i}
done
sudo rm -rf app
sudo rm -rf tmp
sudo rm -rf config
sudo rm -rf build/baserom/
sudo rm -rf build/portrom/
find . -type d -name 'hyperos_*' |xargs rm -rf
green "文件清理完毕" "Files cleaned up."
mkdir -p build/baserom/images/
mkdir -p build/portrom/images/
# 提取分区
if [[ ${baserom_type} == 'payload' ]];then
blue "正在提取底包 [payload.bin]" "Extracting files from BASEROM [payload.bin]"
payload-dumper --out build/baserom/images/ $baserom
green "底包 [payload.bin] 提取完毕" "[payload.bin] extracted."
elif [[ ${baserom_type} == 'br' ]];then
blue "正在提取底包 [new.dat.br]" "Extracting files from BASEROM [*.new.dat.br]"
unzip ${baserom} -d build/baserom > /dev/null 2>&1 || error "解压底包 [new.dat.br]时出错" "Extracting [new.dat.br] error"
green "底包 [new.dat.br] 提取完毕" "[new.dat.br] extracted."
elif [[ ${is_base_rom_eu} == true ]];then
blue "正在提取底包 [super.img]" "Extracting files from BASETROM [super.img]"
unzip ${baserom} 'images/*' -d build/baserom > /dev/null 2>&1 ||error "解压移植包 [super.img] 时出错" "Extracting [super.img] error"
blue "合并super.img* 到super.img" "Merging super.img.* into super.img"
simg2img build/baserom/images/super.img.* build/baserom/images/super.img
rm -rf build/baserom/images/super.img.*
mv build/baserom/images/super.img build/baserom/super.img
green "底包 [super.img] 提取完毕" "[super.img] extracted."
mv build/baserom/images/boot.img build/baserom/
mkdir -p build/baserom/firmware-update
mv build/baserom/images/* build/baserom/firmware-update
if [[ -f build/baserom/firmware-update/cust.img.0 ]];then
simg2img build/baserom/firmware-update/cust.img.* build/baserom/firmware-update/cust.img
rm -rf build/baserom/firmware-update/cust.img.*
fi
fi
if [[ ${is_eu_rom} == true ]];then
blue "正在提取移植包 [super.img]" "Extracting files from PORTROM [super.img]"
unzip ${portrom} 'images/super.img.*' -d build/portrom > /dev/null 2>&1 ||error "解压移植包 [super.img] 时出错" "Extracting [super.img] error"
blue "合并super.img* 到super.img" "Merging super.img.* into super.img"
simg2img build/portrom/images/super.img.* build/portrom/images/super.img
rm -rf build/portrom/images/super.img.*
mv build/portrom/images/super.img build/portrom/super.img
green "移植包 [super.img] 提取完毕" "[super.img] extracted."
elif [[ ${portrom_type} == "fastboot" ]];then
blue "正在提取移植包 [super.img]" "Extracting files from PORTROM [super.img]"
mkdir -p tmp/image
tar -xzf ${portrom} -C tmp/image ||error "解压移植包 [super.img] 时出错" "Extracting [super.img] error"
superimg=$(find tmp -type f -name "super.img")
mv ${superimg} build/portrom/images/super.img.sparse
simg2img build/portrom/images/super.img.sparse build/portrom/super.img
rm -rf build/portrom/images/super.img.sparse
green "移植包 [super.img] 提取完毕" "[super.img] extracted."
else
blue "正在提取移植包 [payload.bin]" "Extracting files from PORTROM [payload.bin]"
payload-dumper --partitions system,product,system_ext,mi_ext --out build/portrom/images/ $portrom
green "移植包 [payload.bin] 提取完毕" "[payload.bin] extracted."
fi
if [[ ${is_base_rom_eu} == true ]];then
blue "开始分解底包 [super.img]" "Unpacking BASEROM [super.img]"
super_list=$(python3 bin/lpunpack.py --info build/baserom/super.img | grep "super:" | awk '{ print $5 }')
for i in ${super_list}; do
if [[ $i == *_a ]];then
i=${i%_a}
python3 bin/lpunpack.py -p ${i}_a build/baserom/super.img build/baserom/images >/dev/null 2>&1
mv build/baserom/images/${i}_a.img build/baserom/images/${i}.img
else
python3 bin/lpunpack.py -p ${i} build/baserom/super.img build/baserom/images >/dev/null 2>&1
fi
done
super_list=$(echo $super_list | sed 's/_a//g')
elif [[ ${baserom_type} == 'br' ]];then
super_list=$(cat build/baserom/dynamic_partitions_op_list | grep "add " | awk '{ print $2 }')
blue "开始分解底包 [new.dat.br]" "Unpacking BASEROM[new.dat.br]"
for i in ${super_list}; do
${tools_dir}/brotli -d build/baserom/$i.new.dat.br >/dev/null 2>&1
sudo python3 ${tools_dir}/sdat2img.py build/baserom/$i.transfer.list build/baserom/$i.new.dat build/baserom/images/$i.img >/dev/null 2>&1
rm -rf build/baserom/$i.new.dat* build/baserom/$i.transfer.list build/baserom/$i.patch.*
done
fi
source_img_type=$($tools_dir/gettype -i build/baserom/images/system.img)
if [[ $source_img_type == "erofs" ]] && [[ $repackext4 != true ]];then
pack_type="EROFS"
else
pack_type="EXT"
fi
for part in system system_dlkm system_ext product product_dlkm mi_ext ;do
extract_partition build/baserom/images/${part}.img build/baserom/images
done
# Move those to portrom folder. We need to pack those imgs into final port rom
for image in vendor odm vendor_dlkm odm_dlkm;do
if [ -f build/baserom/images/${image}.img ];then
mv -f build/baserom/images/${image}.img build/portrom/images/${image}.img
# Extracting vendor at first, we need to determine which super parts to pack from Baserom fstab.
extract_partition build/portrom/images/${image}.img build/portrom/images/
fi
done
# Extract the partitions list that need to pack into the super.img
super_list=$(sed '/^#/d;/^\//d;/overlay/d;/^$/d' build/portrom/images/vendor/etc/fstab.qcom \
| awk '{ print $1}' | sort | uniq)
# 分解镜像
green "开始提取逻辑分区镜像" "Starting extract portrom partition from img"
for part in ${super_list};do
# Skip already extraced parts from BASEROM
if [[ ! -d build/portrom/images/${part} ]]; then
if [[ ${is_eu_rom} == true ]];then
blue "PORTROM super.img 提取 [${part}] 分区..." "Extracting [${part}] from PORTROM super.img"
blue "lpunpack.py PORTROM super.img ${part}_a"
python3 bin/lpunpack.py -p ${part}_a build/portrom/super.img build/portrom/images
mv build/portrom/images/${part}_a.img build/portrom/images/${part}.img
elif [[ ${portrom_type} == "fastboot" ]];then
blue "PORTROM super.img 提取 [${part}] 分区..." "Extracting [${part}] from PORTROM super.img"
blue "lpunpack.py PORTROM super.img ${part}_a"
python3 bin/lpunpack.py -p ${part}_a build/portrom/super.img build/portrom/images
mv build/portrom/images/${part}_a.img build/portrom/images/${part}.img
fi
extract_partition "${work_dir}/build/portrom/images/${part}.img" "${work_dir}/build/portrom/images/"
else
yellow "跳过从PORTORM提取分区[${part}]" "Skip extracting [${part}] from PORTROM"
fi
done
rm -rf config
blue "正在获取ROM参数" "Fetching ROM build prop."
# 安卓版本
base_android_version=$(< build/baserom/images/system/system/build.prop grep "ro.system.build.version.release" |awk 'NR==1' |cut -d '=' -f 2)
port_android_version=$(< build/portrom/images/system/system/build.prop grep "ro.system.build.version.release" |awk 'NR==1' |cut -d '=' -f 2)
green "安卓版本: 底包为[Android ${base_android_version}], 移植包为 [Android ${port_android_version}]" "Android Version: BASEROM:[Android ${base_android_version}], PORTROM [Android ${port_android_version}]"
# SDK版本
base_android_sdk=$(< build/portrom/images/vendor/build.prop grep "ro.vendor.build.version.sdk" |awk 'NR==1' |cut -d '=' -f 2)
port_android_sdk=$(< build/portrom/images/system/system/build.prop grep "ro.system.build.version.sdk" |awk 'NR==1' |cut -d '=' -f 2)
green "SDK 版本: 底包为 [SDK ${base_android_sdk}], 移植包为 [SDK ${port_android_sdk}]" "SDK Verson: BASEROM: [SDK ${base_android_sdk}], PORTROM: [SDK ${port_android_sdk}]"
# ROM版本
base_rom_version=$(< build/portrom/images/vendor/build.prop grep "ro.vendor.build.version.incremental" |awk 'NR==1' |cut -d '=' -f 2)
#HyperOS版本号获取
port_mios_version_incremental=$(< build/portrom/images/mi_ext/etc/build.prop grep "ro.mi.os.version.incremental" | awk 'NR==1' | cut -d '=' -f 2)
#替换机型代号,比如小米10:UNBCNXM -> UJBCNXM
port_device_code=$(echo $port_mios_version_incremental | cut -d "." -f 5)
if [[ $port_android_version == "14" ]];then
base_device_code=U$(echo $base_rom_version | cut -d "." -f 5 | cut -c 2-)
elif [[ $port_android_version == "15" ]];then
base_device_code=V$(echo $base_rom_version | cut -d "." -f 5 | cut -c 2-)
fi
if [[ $port_mios_version_incremental == *DEV* ]];then
yellow "检测到开发板,跳过修改版本代码" "Dev deteced,skip replacing codename"
port_rom_version="$(echo $port_mios_version_incremental)"
else
port_rom_version=$(echo $port_mios_version_incremental | sed "s/$port_device_code/$base_device_code/")
fi
green "ROM 版本: 底包为 [${base_rom_version}], 移植包为 [${port_rom_version}]" "ROM Version: BASEROM: [${base_rom_version}], PORTROM: [${port_rom_version}] "
# 代号
#base_rom_code=$(< build/portrom/images/vendor/build.prop grep "ro.product.vendor.device" |awk 'NR==1' |cut -d '=' -f 2)
base_rom_code=$(basename build/baserom/images/product/etc/device_features/*.xml .xml)
port_rom_code=$(< build/portrom/images/product/etc/build.prop grep "ro.product.product.name" |awk 'NR==1' |cut -d '=' -f 2)
green "机型代号: 底包为 [${base_rom_code}], 移植包为 [${port_rom_code}]" "Device Code: BASEROM: [${base_rom_code}], PORTROM: [${port_rom_code}]"
port_release_codename=$(< build/portrom/images/system/system/build.prop grep "ro.build.version.release_or_codename" | awk 'NR=1' | cut -d '=' -f 2)
if grep -q "ro.build.ab_update=true" build/portrom/images/vendor/build.prop; then
is_ab_device=true
else
is_ab_device=false
fi
baseAospFrameworkResOverlay=$(find build/baserom/images/product -type f -name "AospFrameworkResOverlay.apk")
portAospFrameworkResOverlay=$(find build/portrom/images/product -type f -name "AospFrameworkResOverlay.apk")
if [ -f "${baseAospFrameworkResOverlay}" ] && [ -f "${portAospFrameworkResOverlay}" ];then
blue "正在替换 [AospFrameworkResOverlay.apk]" "Replacing [AospFrameworkResOverlay.apk]"
cp -rf ${baseAospFrameworkResOverlay} ${portAospFrameworkResOverlay}
fi
baseMiuiFrameworkResOverlay=$(find build/baserom/images/product -type f -name "MiuiFrameworkResOverlay.apk")
portMiuiFrameworkResOverlay=$(find build/portrom/images/product -type f -name "MiuiFrameworkResOverlay.apk")
if [ -f "${baseMiuiFrameworkResOverlay}" ] && [ -f "${portMiuiFrameworkResOverlay}" ];then
blue "正在替换 [MiuiFrameworkResOverlay.apk]" "Replacing [MiuiFrameworkResOverlay.apk]"
cp -rf ${baseMiuiFrameworkResOverlay} ${portMiuiFrameworkResOverlay}
fi
#baseAospWifiResOverlay=$(find build/baserom/images/product -type f -name "AospWifiResOverlay.apk")
##portAospWifiResOverlay=$(find build/portrom/images/product -type f -name "AospWifiResOverlay.apk")
#if [ -f ${baseAospWifiResOverlay} ] && [ -f ${portAospWifiResOverlay} ];then
# blue "正在替换 [AospWifiResOverlay.apk]"
# cp -rf ${baseAospWifiResOverlay} ${portAospWifiResOverlay}
#fi
baseDevicesAndroidOverlay=$(find build/baserom/images/product -type f -name "DevicesAndroidOverlay.apk")
portDevicesAndroidOverlay=$(find build/portrom/images/product -type f -name "DevicesAndroidOverlay.apk")
if [ -f "${baseDevicesAndroidOverlay}" ] && [ -f "${portDevicesAndroidOverlay}" ];then
blue "正在替换 [DevicesAndroidOverlay.apk]" "Replacing [DevicesAndroidOverlay.apk]"
cp -rf ${baseDevicesAndroidOverlay} ${portDevicesAndroidOverlay}
fi
baseDevicesOverlay=$(find build/baserom/images/product -type f -name "DevicesOverlay.apk")
portDevicesOverlay=$(find build/portrom/images/product -type f -name "DevicesOverlay.apk")
if [ -f "${baseDevicesOverlay}" ] && [ -f "${portDevicesOverlay}" ];then
blue "正在替换 [DevicesOverlay.apk]" "Replacing [DevicesOverlay.apk]"
cp -rf ${baseDevicesOverlay} ${portDevicesOverlay}
fi
baseSettingsRroDeviceHideStatusBarOverlay=$(find build/baserom/images/product -type f -name "SettingsRroDeviceHideStatusBarOverlay.apk")
portSettingsRroDeviceHideStatusBarOverlay=$(find build/portrom/images/product -type f -name "SettingsRroDeviceHideStatusBarOverlay.apk")
if [ -f "${baseSettingsRroDeviceHideStatusBarOverlay}" ] && [ -f "${portSettingsRroDeviceHideStatusBarOverlay}" ];then
blue "正在替换 [SettingsRroDeviceHideStatusBarOverlay.apk]" "Replacing [SettingsRroDeviceHideStatusBarOverlay.apk]"
cp -rf ${baseSettingsRroDeviceHideStatusBarOverlay} ${portSettingsRroDeviceHideStatusBarOverlay}
fi
baseMiuiBiometricResOverlay=$(find build/baserom/images/product -type f -name "MiuiBiometricResOverlay.apk")
portMiuiBiometricResOverlay=$(find build/portrom/images/product -type f -name "MiuiBiometricResOverlay.apk")
if [ -f "${baseMiuiBiometricResOverlay}" ] && [ -f "${portMiuiBiometricResOverlay}" ];then
blue "正在替换 [MiuiBiometricResOverlay.apk]" "Replacing [MiuiBiometricResOverlay.apk]"
cp -rf ${baseMiuiBiometricResOverlay} ${portMiuiBiometricResOverlay}
fi
# displayconfig id
rm -rf build/portrom/images/product/etc/displayconfig/display_id*.xml
cp -rf build/baserom/images/product/etc/displayconfig/display_id*.xml build/portrom/images/product/etc/displayconfig/
# device_features
blue "Copying device_features"
rm -rf build/portrom/images/product/etc/device_features/*
cp -rf build/baserom/images/product/etc/device_features/* build/portrom/images/product/etc/device_features/
#device_info
if [[ ${is_eu_rom} == "true" ]];then
cp -rf build/baserom/images/product/etc/device_info.json build/portrom/images/product/etc/device_info.json
fi
baseMiSound=$(find build/baserom/images/product -type d -name "MiSound")
portMiSound=$(find build/portrom/images/product -type d -name "MiSound")
if [ -d "${baseMiSound}" ] && [ -d "${portMiSound}" ];then
blue "正在替换 MiSound" "Replacing stock MiSound"
rm -rf ./${portMiSound}/*
cp -rf ./${baseMiSound}/* ${portMiSound}/
fi
# 人脸
baseMiuiBiometric=$(find build/baserom/images/product/app -type d -name "*Biometric*")
portMiuiBiometric=$(find build/portrom/images/product/app -type d -name "*Biometric*")
if [ -d "${baseMiuiBiometric}" ] && [ -d "${portMiuiBiometric}" ];then
yellow "查找MiuiBiometric" "Searching and Replacing MiuiBiometric.."
rm -rf ./${portMiuiBiometric}/*
cp -rf ./${baseMiuiBiometric}/* ${portMiuiBiometric}/
else
if [ -d "${baseMiuiBiometric}" ] && [ ! -d "${portMiuiBiometric}" ];then
blue "未找到MiuiBiometric,替换为原包" "MiuiBiometric is missing, copying from base..."
cp -rf ${baseMiuiBiometric} build/portrom/images/product/app/
fi
fi
# 修复AOD问题
targetDevicesAndroidOverlay=$(find build/portrom/images/product -type f -name "DevicesAndroidOverlay.apk")
if [[ -f "${targetDevicesAndroidOverlay}" ]]; then
mkdir tmp/
filename=$(basename $targetDevicesAndroidOverlay)
yellow "修复息屏和屏下指纹问题" "Fixing AOD issue: $filename ..."
targetDir=$(echo "$filename" | sed 's/\..*$//')
bin/apktool/apktool d $targetDevicesAndroidOverlay -o tmp/$targetDir -f > /dev/null 2>&1
search_pattern="com\.miui\.aod\/com\.miui\.aod\.doze\.DozeService"
replacement_pattern="com\.android\.systemui\/com\.android\.systemui\.doze\.DozeService"
for xml in $(find tmp/$targetDir -type f -name "*.xml");do
sed -i "s/$search_pattern/$replacement_pattern/g" $xml
done
bin/apktool/apktool b tmp/$targetDir -o tmp/$filename > /dev/null 2>&1 || error "apktool 打包失败" "apktool mod failed"
cp -rf tmp/$filename $targetDevicesAndroidOverlay
rm -rf tmp
fi
# Fix boot up frame drop issue.
targetAospFrameworkResOverlay=$(find build/portrom/images/product -type f -name "AospFrameworkResOverlay.apk")
if [[ -f "${targetAospFrameworkResOverlay}" ]]; then
if [[ ! -d tmp ]]; then
mkdir tmp
fi
filename=$(basename $targetAospFrameworkResOverlay)
yellow "Change defaultPeakRefreshRate: $filename ..."
targetDir=$(echo "$filename" | sed 's/\..*$//')
bin/apktool/apktool d $targetAospFrameworkResOverlay -o tmp/$targetDir -f > /dev/null 2>&1
for xml in $(find tmp/$targetDir -type f -name "integers.xml");do
# magic: Change DefaultPeakRefrshRate to 60
xmlstarlet ed -L -u "//integer[@name='config_defaultPeakRefreshRate']/text()" -v 60 $xml
done
if [[ $port_android_version == "15" ]]; then
blue "Fix VanillaIceCream brightness"
for xml in $(find tmp/$targetDir -type f -name "*.xml");do
sed -i "s/config_screenBrightnessDim\"/config_screenBrightnessDim_hyper\"/g" $xml
sed -i "s/config_screenBrightnessSettingDefault\"/config_screenBrightnessSettingDefault_hyper\"/g" $xml
sed -i "s/config_screenBrightnessSettingMaximum\"/config_screenBrightnessSettingMaximum_hyper\"/g" $xml
sed -i "s/config_screenBrightnessSettingMinimum\"/config_screenBrightnessSettingMinimum_hyper\"/g" $xml
done
fi
bin/apktool/apktool b tmp/$targetDir -o tmp/$filename > /dev/null 2>&1 || error "apktool 打包失败" "apktool mod failed"
cp -rf tmp/$filename $targetAospFrameworkResOverlay
fi
sourceMiuiFrameworkTelephonyResOverlay=$(find build/baserom/images/product -type f -name "MiuiFrameworkTelephonyResOverlay.apk")
targetMiuiFrameworkTelephonyResOverlay=$(find build/portrom/images/product -type f -name "MiuiFrameworkTelephonyResOverlay.apk")
if [ -f "${sourceMiuiFrameworkTelephonyResOverlay}" ] && [ -f "${targetMiuiFrameworkTelephonyResOverlay}" ];then
cp -rfv $sourceMiuiFrameworkTelephonyResOverlay $targetMiuiFrameworkTelephonyResOverlay
elif [ -f "${sourceMiuiFrameworkTelephonyResOverlay}" ] && [ ! -f "${targetMiuiFrameworkTelephonyResOverlay}" ];then
cp -rfv $sourceMiuiFrameworkTelephonyResOverlay build/portrom/images/product/overlay/
elif [ ! -f "{$sourceMiuiFrameworkTelephonyResOverlay}" ] && [ -f "${targetMiuiFrameworkTelephonyResOverlay}" ];then
rm -rfv $targetMiuiFrameworkTelephonyResOverlay
fi
#其他机型可能没有default.prop
for prop_file in $(find build/portrom/images/vendor/ -name "*.prop"); do
vndk_version=$(< "$prop_file" grep "ro.vndk.version" | awk "NR==1" | cut -d '=' -f 2)
if [ -n "$vndk_version" ]; then
yellow "ro.vndk.version为$vndk_version" "ro.vndk.version found in $prop_file: $vndk_version"
break
fi
done
base_vndk=$(find build/baserom/images/system_ext/apex -type f -name "com.android.vndk.v${vndk_version}.apex")
port_vndk=$(find build/portrom/images/system_ext/apex -type f -name "com.android.vndk.v${vndk_version}.apex")
if [ ! -f "${port_vndk}" ]; then
yellow "apex不存在,从原包复制" "target apex is missing, copying from baserom"
cp -rf "${base_vndk}" "build/portrom/images/system_ext/apex/"
fi
if [ $(grep -c "sm8250" "build/portrom/images/vendor/build.prop") -ne 0 ]; then
## Fix the drop frame issus
echo "ro.surface_flinger.enable_frame_rate_override=false" >> build/portrom/images/vendor/build.prop
echo "ro.vendor.display.mode_change_optimize.enable=true" >> build/portrom/images/vendor/build.prop
if [[ $port_android_version == "15" ]];then
{
echo " ro.miui.affinity.sfui=4-7"
echo "ro.miui.affinity.sfre=4-7"
echo "ro.miui.affinity.sfuireset=4-7"
echo "persist.sys.miui_animator_sched.bigcores=4-7"
echo "persist.sys.miui_animator_sched.big_prime_cores=4-7"
echo "persist.vendor.display.miui.composer_boost=4-7"
} >> build/portrom/images/product/etc/build.prop
else
sed -i "s/persist.sys.miui_animator_sched.bigcores=.*/persist.sys.miui_animator_sched.bigcores=4-6/" build/portrom/images/product/etc/build.prop
sed -i "s/persist.sys.miui_animator_sched.big_prime_cores=.*/persist.sys.miui_animator_sched.big_prime_cores=4-7/" build/portrom/images/product/etc/build.prop
{
echo "persist.sys.miui.sf_cores=4-7"
echo "persist.sys.minfree_def=73728,92160,110592,154832,482560,579072"
echo "persist.sys.minfree_6g=73728,92160,110592,258048,663552,903168"
echo "persist.sys.minfree_8g=73728,92160,110592,387072,1105920,1451520"
echo "persist.vendor.display.miui.composer_boost=4-7"
} >> build/portrom/images/product/etc/build.prop
fi
fi
# props from k60
echo "persist.vendor.mi_sf.optimize_for_refresh_rate.enable=1" >> build/portrom/images/vendor/build.prop
echo "ro.vendor.mi_sf.ultimate.perf.support=true" >> build/portrom/images/vendor/build.prop
#echo "debug.sf.set_idle_timer_ms=1100" >> build/portrom/images/vendor/build.prop
#echo "ro.surface_flinger.set_touch_timer_ms=200" >> build/portrom/images/vendor/build.prop
# https://source.android.com/docs/core/graphics/multiple-refresh-rate
echo "ro.surface_flinger.use_content_detection_for_refresh_rate=false" >> build/portrom/images/vendor/build.prop
echo "ro.surface_flinger.set_touch_timer_ms=0" >> build/portrom/images/vendor/build.prop
echo "ro.surface_flinger.set_idle_timer_ms=0" >> build/portrom/images/vendor/build.prop
#解决开机报错问题
targetVintf=$(find build/portrom/images/system_ext/etc/vintf -type f -name "manifest.xml")
if [ -f "$targetVintf" ]; then
# Check if the file contains $vndk_version
if grep -q "<version>$vndk_version</version>" "$targetVintf"; then
yellow "${vndk_version}已存在,跳过修改" "The file already contains the version $vndk_version. Skipping modification."
else
# If it doesn't contain $vndk_version, then add it
ndk_version="<vendor-ndk>\n <version>$vndk_version</version>\n </vendor-ndk>"
sed -i "/<\/vendor-ndk>/a$ndk_version" "$targetVintf"
yellow "添加成功" "Version $vndk_version added to $targetVintf"
fi
else
blue "File $targetVintf not found."
fi
if [[ ${port_rom_code} == "sheng" ]] || [[ ${port_android_version} == "15" ]];then
blue "Skip StrongToast UI fix"
elif [[ ${port_rom_code} == "houji" ]] || [[ ${port_rom_code} == "shennong" ]] ;then
blue "左侧挖孔灵动岛修复" "StrongToast UI fix"
patch_smali "MiuiSystemUI.apk" "MIUIStrongToast\$2.smali" "const\/4 v7\, 0x0" "iget-object v7\, v1\, Lcom\/android\/systemui\/toast\/MIUIStrongToast;->mRLLeft:Landroid\/widget\/RelativeLayout;\\n\\tinvoke-virtual {v7}, Landroid\/widget\/RelativeLayout;->getLeft()I\\n\\tmove-result v7\\n\\tint-to-float v7,v7"
else
blue "左侧挖孔灵动岛修复" "StrongToast UI fix"
patch_smali "MiuiSystemUI.apk" "MIUIStrongToast\$2.smali" "const\/4 v9\, 0x0" "iget-object v9\, v1\, Lcom\/android\/systemui\/toast\/MIUIStrongToast;->mRLLeft:Landroid\/widget\/RelativeLayout;\\n\\tinvoke-virtual {v9}, Landroid\/widget\/RelativeLayout;->getLeft()I\\n\\tmove-result v9\\n\\tint-to-float v9,v9"
fi
if [[ ${is_eu_rom} == "true" ]];then
patch_smali "miui-services.jar" "SystemServerImpl.smali" ".method public constructor <init>()V/,/.end method" ".method public constructor <init>()V\n\t.registers 1\n\tinvoke-direct {p0}, Lcom\/android\/server\/SystemServerStub;-><init>()V\n\n\treturn-void\n.end method" "regex"
else
if [[ ! -d tmp ]];then
mkdir -p tmp/
fi
blue "开始移除 Android 签名校验" "Disalbe Android 14 Apk Signature Verfier"
mkdir -p tmp/services/
cp -rf build/portrom/images/system/system/framework/services.jar tmp/services.jar
java -jar bin/apktool/APKEditor.jar d -f -i tmp/services.jar -o tmp/services > /dev/null 2>&1
target_method='getMinimumSignatureSchemeVersionForTargetSdk'
old_smali_dir=""
declare -a smali_dirs
while read -r smali_file; do
smali_dir=$(echo "$smali_file" | cut -d "/" -f 3)
if [[ $smali_dir != $old_smali_dir ]]; then
smali_dirs+=("$smali_dir")
fi
method_line=$(grep -n "$target_method" "$smali_file" | cut -d ':' -f 1)
register_number=$(tail -n +"$method_line" "$smali_file" | grep -m 1 "move-result" | tr -dc '0-9')
move_result_end_line=$(awk -v ML=$method_line 'NR>=ML && /move-result /{print NR; exit}' "$smali_file")
orginal_line_number=$method_line
replace_with_command="const/4 v${register_number}, 0x0"
{ sed -i "${orginal_line_number},${move_result_end_line}d" "$smali_file" && sed -i "${orginal_line_number}i\\${replace_with_command}" "$smali_file"; } && blue "${smali_file} 修改成功" "${smali_file} patched"
old_smali_dir=$smali_dir
done < <(find tmp/services/smali/*/com/android/server/pm/ tmp/services/smali/*/com/android/server/pm/pkg/parsing/ -maxdepth 1 -type f -name "*.smali" -exec grep -H "$target_method" {} \; | cut -d ':' -f 1)
target_canJoinSharedUserId_method='canJoinSharedUserId'
find tmp/services/ -type f -name "ReconcilePackageUtils.smali" | while read smali_file; do
cp -rfv $smali_file tmp/
method_line=$(grep -n "$target_canJoinSharedUserId_method" "$smali_file" | cut -d ':' -f 1)
register_number=$(tail -n +"$method_line" "$smali_file" | grep -m 1 "move-result" | tr -dc '0-9')
move_result_end_line=$(awk -v ML=$method_line 'NR>=ML && /move-result /{print NR; exit}' "$smali_file")
replace_with_command="const/4 v${register_number}, 0x1"
{ sed -i "${method_line},${move_result_end_line}d" "$smali_file" && sed -i "${method_line}i\\${replace_with_command}" "$smali_file"; }
done
java -jar bin/apktool/APKEditor.jar b -f -i tmp/services -o tmp/services_patched.jar > /dev/null 2>&1
cp -rf tmp/services_patched.jar build/portrom/images/system/system/framework/services.jar
fi
# 主题防恢复
if [ -f build/portrom/images/system/system/etc/init/hw/init.rc ];then
sed -i '/on boot/a\'$'\n'' chmod 0731 \/data\/system\/theme' build/portrom/images/system/system/etc/init/hw/init.rc
fi
if [[ ${is_eu_rom} == true ]];then
rm -rf build/portrom/images/product/app/Updater
baseXGoogle=$(find build/baserom/images/product/ -type d -name "HotwordEnrollmentXGoogleHEXAGON*")
portXGoogle=$(find build/portrom/images/product/ -type d -name "HotwordEnrollmentXGoogleHEXAGON*")
if [ -d "${baseXGoogle}" ] && [ -d "${portXGoogle}" ];then
yellow "查找并替换HotwordEnrollmentXGoogleHEXAGON_WIDEBAND.apk" "Searching and Replacing HotwordEnrollmentXGoogleHEXAGON_WIDEBAND.apk.."
rm -rf ./${portXGoogle}/*
cp -rf ./${baseXGoogle}/* ${portXGoogle}/
else
if [ -d "${baseXGoogle}" ] && [ ! -d "${portXGoogle}" ];then
blue "未找到HotwordEnrollmentXGoogleHEXAGON_WIDEBAND.apk,替换为原包" "HotwordEnrollmentXGoogleHEXAGON_WIDEBAND.apk is missing, copying from base..."
cp -rf ${baseXGoogle} build/portrom/images/product/priv-app/
fi
fi
else
yellow "删除多余的App" "Debloating..."
# List of apps to be removed
debloat_apps=("MSA" "mab" "Updater" "MiuiUpdater" "MiService" "MIService" "SoterService" "Hybrid" "AnalyticsCore")
for debloat_app in "${debloat_apps[@]}"; do
# Find the app directory
app_dir=$(find build/portrom/images/product -type d -name "*$debloat_app*")
# Check if the directory exists before removing
if [[ -d "$app_dir" ]]; then
yellow "删除目录: $app_dir" "Removing directory: $app_dir"
rm -rf "$app_dir"
fi
done
rm -rf build/portrom/images/product/etc/auto-install*
rm -rf build/portrom/images/product/data-app/*GalleryLockscreen* >/dev/null 2>&1
mkdir -p tmp/app
kept_data_apps=("MIUISecurityManager" "MIUIThemeStore" "DownloadProviderUi" "VirtualSim" "ThirdAppAssistant" "GameCenter" "Video" "Weather" "DeskClock" "Gallery" "SoundRecorder" "ScreenRecorder" "Calculator" "CleanMaster" "Calendar" "Compass" "Notes" "MediaEditor" "Scanner" "SpeechEngine" "wps-lite")
for app in "${kept_data_apps[@]}"; do
mv build/portrom/images/product/data-app/*"${app}"* tmp/app/ >/dev/null 2>&1
done
rm -rf build/portrom/images/product/data-app/*
cp -rf tmp/app/* build/portrom/images/product/data-app
rm -rf tmp/app
rm -rf build/portrom/images/system/verity_key
rm -rf build/portrom/images/vendor/verity_key
rm -rf build/portrom/images/product/verity_key
rm -rf build/portrom/images/system/recovery-from-boot.p
rm -rf build/portrom/images/vendor/recovery-from-boot.p
rm -rf build/portrom/images/product/recovery-from-boot.p
rm -rf build/portrom/images/product/media/theme/miui_mod_icons/com.google.android.apps.nbu*
rm -rf build/portrom/images/product/media/theme/miui_mod_icons/dynamic/com.google.android.apps.nbu*
fi
# build.prop 修改
blue "正在修改 build.prop" "Modifying build.prop"
#
#change the locale to English
export LC_ALL=en_US.UTF-8
buildDate=$(date -u +"%a %b %d %H:%M:%S UTC %Y")
buildUtc=$(date +%s)
for i in $(find build/portrom/images -type f -name "build.prop");do
blue "正在处理 ${i}" "modifying ${i}"
sed -i "s/ro.build.date=.*/ro.build.date=${buildDate}/g" ${i}
sed -i "s/ro.build.date.utc=.*/ro.build.date.utc=${buildUtc}/g" ${i}
sed -i "s/ro.odm.build.date=.*/ro.odm.build.date=${buildDate}/g" ${i}
sed -i "s/ro.odm.build.date.utc=.*/ro.odm.build.date.utc=${buildUtc}/g" ${i}
sed -i "s/ro.vendor.build.date=.*/ro.vendor.build.date=${buildDate}/g" ${i}
sed -i "s/ro.vendor.build.date.utc=.*/ro.vendor.build.date.utc=${buildUtc}/g" ${i}
sed -i "s/ro.system.build.date=.*/ro.system.build.date=${buildDate}/g" ${i}
sed -i "s/ro.system.build.date.utc=.*/ro.system.build.date.utc=${buildUtc}/g" ${i}
sed -i "s/ro.product.build.date=.*/ro.product.build.date=${buildDate}/g" ${i}
sed -i "s/ro.product.build.date.utc=.*/ro.product.build.date.utc=${buildUtc}/g" ${i}
sed -i "s/ro.system_ext.build.date=.*/ro.system_ext.build.date=${buildDate}/g" ${i}
sed -i "s/ro.system_ext.build.date.utc=.*/ro.system_ext.build.date.utc=${buildUtc}/g" ${i}
sed -i "s/ro.product.device=.*/ro.product.device=${base_rom_code}/g" ${i}
sed -i "s/ro.product.product.name=.*/ro.product.product.name=${base_rom_code}/g" ${i}
sed -i "s/ro.product.odm.device=.*/ro.product.odm.device=${base_rom_code}/g" ${i}
sed -i "s/ro.product.vendor.device=.*/ro.product.vendor.device=${base_rom_code}/g" ${i}
sed -i "s/ro.product.system.device=.*/ro.product.system.device=${base_rom_code}/g" ${i}
sed -i "s/ro.product.board=.*/ro.product.board=${base_rom_code}/g" ${i}
sed -i "s/ro.product.system_ext.device=.*/ro.product.system_ext.device=${base_rom_code}/g" ${i}
sed -i "s/persist.sys.timezone=.*/persist.sys.timezone=Asia\/Shanghai/g" ${i}
#全局替换device_code
if [[ $port_mios_version_incremental != *DEV* ]];then
sed -i "s/$port_device_code/$base_device_code/g" ${i}
fi
# 添加build user信息
sed -i "s/ro.build.user=.*/ro.build.user=${build_user}/g" ${i}
if [[ ${is_eu_rom} == "true" ]];then
sed -i "s/ro.product.mod_device=.*/ro.product.mod_device=${base_rom_code}_xiaomieu_global/g" ${i}
sed -i "s/ro.build.host=.*/ro.build.host=xiaomi.eu/g" ${i}
else
sed -i "s/ro.product.mod_device=.*/ro.product.mod_device=${base_rom_code}/g" ${i}
sed -i "s/ro.build.host=.*/ro.build.host=${build_host}/g" ${i}
fi
sed -i "s/ro.build.characteristics=tablet/ro.build.characteristics=nosdcard/g" ${i}
sed -i "s/ro.config.miui_multi_window_switch_enable=true/ro.config.miui_multi_window_switch_enable=false/g" ${i}
sed -i "s/ro.config.miui_desktop_mode_enabled=true/ro.config.miui_desktop_mode_enabled=false/g" ${i}
sed -i "/ro.miui.density.primaryscale=.*/d" ${i}
sed -i "/persist.wm.extensions.enabled=true/d" ${i}
done
#sed -i -e '$a\'$'\n''persist.adb.notify=0' build/portrom/images/system/system/build.prop
#sed -i -e '$a\'$'\n''persist.sys.usb.config=mtp,adb' build/portrom/images/system/system/build.prop
#sed -i -e '$a\'$'\n''persist.sys.disable_rescue=true' build/portrom/images/system/system/build.prop
#sed -i -e '$a\'$'\n''persist.miui.extm.enable=0' build/portrom/images/system/system/build.prop
# 屏幕密度修修改
for prop in $(find build/baserom/images/product build/baserom/images/system -type f -name "build.prop");do
base_rom_density=$(< "$prop" grep "ro.sf.lcd_density" |awk 'NR==1' |cut -d '=' -f 2)
if [ "${base_rom_density}" != "" ];then
green "底包屏幕密度值 ${base_rom_density}" "Screen density: ${base_rom_density}"
break
fi
done
# 未在底包找到则默认440,如果是其他值可自己修改
[ -z ${base_rom_density} ] && base_rom_density=440
found=0
for prop in $(find build/portrom/images/product build/portrom/images/system -type f -name "build.prop");do
if grep -q "ro.sf.lcd_density" ${prop};then
sed -i "s/ro.sf.lcd_density=.*/ro.sf.lcd_density=${base_rom_density}/g" ${prop}
found=1
fi
sed -i "s/persist.miui.density_v2=.*/persist.miui.density_v2=${base_rom_density}/g" ${prop}
done
if [ $found -eq 0 ]; then
blue "未找到ro.fs.lcd_density,build.prop新建一个值$base_rom_density" "ro.fs.lcd_density not found, create a new value ${base_rom_density} "
echo "ro.sf.lcd_density=${base_rom_density}" >> build/portrom/images/product/etc/build.prop
fi
echo "ro.miui.cust_erofs=0" >> build/portrom/images/product/etc/build.prop
#vendorprop=$(find build/portrom/images/vendor -type f -name "build.prop")
#odmprop=$(find build/baserom/images/odm -type f -name "build.prop" |awk 'NR==1')
#if [ "$(< $vendorprop grep "sys.haptic" |awk 'NR==1')" != "" ];then
# blue "复制 haptic prop 到 odm"
# < $vendorprop grep "sys.haptic" >>${odmprop}
#fi
#Fix: mi10 boot stuck at the first screen
sed -i "s/persist\.sys\.millet\.cgroup1/#persist\.sys\.millet\.cgroup1/" build/portrom/images/vendor/build.prop
#Fix:Fingerprint issue encountered on OS V1.0.18
echo "vendor.perf.framepacing.enable=false" >> build/portrom/images/vendor/build.prop
# Millet fix
blue "修复Millet" "Fix Millet"
millet_netlink_version=$(grep "ro.millet.netlink" build/baserom/images/product/etc/build.prop | cut -d "=" -f 2)
if [[ -n "$millet_netlink_version" ]]; then
update_netlink "$millet_netlink_version" "build/portrom/images/product/etc/build.prop"
else
blue "原包未发现ro.millet.netlink值,请手动赋值修改(默认为29)" "ro.millet.netlink property value not found, change it manually(29 by default)."
millet_netlink_version=29
update_netlink "$millet_netlink_version" "build/portrom/images/product/etc/build.prop"
fi
# add advanced texture
if ! is_property_exists persist.sys.background_blur_supported build/portrom/images/product/etc/build.prop; then
echo "persist.sys.background_blur_supported=true" >> build/portrom/images/product/etc/build.prop
echo "persist.sys.background_blur_version=2" >> build/portrom/images/product/etc/build.prop
else
sed -i "s/persist.sys.background_blur_supported=.*/persist.sys.background_blur_supported=true/" build/portrom/images/product/etc/build.prop
fi
echo "persist.sys.perf.cgroup8250.stune=true" >> build/portrom/images/product/etc/build.prop
unlock_device_feature "Whether support AI Display" "bool" "support_AI_display"
unlock_device_feature "device support screen enhance engine" "bool" "support_screen_enhance_engine"
unlock_device_feature "Whether suppot Android Flashlight Controller" "bool" "support_android_flashlight"
unlock_device_feature "Whether support SR for image display" "bool" "support_SR_for_image_display"
unlock_device_feature "whether the device aod need grayscale" "bool" "is_aod_need_grayscale"
unlock_device_feature "whether the device supports aod fullscreen mode" "bool" "support_aod_fullscreen"
unlock_device_feature "whether the device supports aod aon mode" "bool" "support_aod_aon"
# Unlock MEMC; unlocking the screen enhance engine is a prerequisite.
# This feature add additional frames to videos to make content appear smooth and transitions lively.
if grep -q "ro.vendor.media.video.frc.support" build/portrom/images/vendor/build.prop ;then
sed -i "s/ro.vendor.media.video.frc.support=.*/ro.vendor.media.video.frc.support=true/" build/portrom/images/vendor/build.prop
else
echo "ro.vendor.media.video.frc.support=true" >> build/portrom/images/vendor/build.prop
fi
# Game splashscreen speed up
echo "debug.game.video.speed=true" >> build/portrom/images/product/etc/build.prop
echo "debug.game.video.support=true" >> build/portrom/images/product/etc/build.prop
# Enable Xiaomi extm dm_opt feature
echo "persist.miui.extm.dm_opt.enable=true" >> build/portrom/images/product/etc/build.prop
# Unlock Smart fps
maxFps=$(xmlstarlet sel -t -v "//integer-array[@name='fpsList']/item" build/portrom/images/product/etc/device_features/${base_rom_code}.xml | sort -nr | head -n 1)
if [ -z "$maxFps" ]; then
maxFps=90
fi
unlock_device_feature "whether support fps change " "bool" "support_smart_fps"
unlock_device_feature "smart fps value" "integer" "smart_fps_value" "${maxFps}"
if [[ ${base_rom_code} == "munch" ]];then
unlock_device_feature "whether support dc backlight " "bool" "support_dc_backlight"
unlock_device_feature "whether backlight bit switch " "bool" "support_backlight_bit_switch"
fi
patch_smali "PowerKeeper.apk" "DisplayFrameSetting.smali" "unicorn" "umi"
if [[ ${is_eu_rom} == true ]];then
patch_smali "MiSettings.apk" "NewRefreshRateFragment.smali" "const-string v1, \"btn_preferce_category\"" "const-string v1, \"btn_preferce_category\"\n\n\tconst\/16 p1, 0x1"
else
patch_smali "MISettings.apk" "NewRefreshRateFragment.smali" "const-string v1, \"btn_preferce_category\"" "const-string v1, \"btn_preferce_category\"\n\n\tconst\/16 p1, 0x1"
fi
# Unlock eyecare mode
unlock_device_feature "default rhythmic eyecare mode" "integer" "default_eyecare_mode" "2"
unlock_device_feature "default texture for paper eyecare" "integer" "paper_eyecare_default_texture" "0"
# Unlock Celluar Sharing feature
targetFrameworkExtRes=$(find build/portrom/images/system_ext -type f -name "framework-ext-res.apk")
if [[ -f "${targetFrameworkExtRes}" ]] && [[ ${port_android_version} != "15" ]]; then
mkdir tmp/ > /dev/null 2>&1
java -jar bin/apktool/APKEditor.jar d -i $targetFrameworkExtRes -o tmp/framework-ext-res -f > /dev/null 2>&1
if grep -r config_celluar_shared_support tmp/framework-ext-res/ ; then
yellow "开启通信共享功能" "Enable Celluar Sharing feature"
for xml in $(find tmp/framework-ext-res -name "*.xml");do
sed -i 's|<bool name="config_celluar_shared_support">false</bool>|<bool name="config_celluar_shared_support">true</bool>|g' "$xml"
done
#rm -rf tmp
fi
filename=$(basename $targetFrameworkExtRes)
java -jar bin/apktool/APKEditor.jar b -i tmp/framework-ext-res -o tmp/$filename -f> /dev/null 2>&1 || error "apktool 打包失败" "apktool mod failed"
cp -rf tmp/$filename $targetFrameworkExtRes
fi
targetMiLinkOS2APK=$(find build/portrom -type f -name "MiLinkOS2CN.apk")
if [[ -f "${targetMiLinkOS2APK}" ]];then
cp -rf $targetMiLinkOS2APK tmp/$(basename $targetMiLinkOS2APK).bak
java -jar bin/apktool/APKEditor.jar d -i $targetMiLinkOS2APK -o tmp/MiLinkOS2 -f > /dev/null 2>&1
targetsmali=$(find tmp/MiLinkOS2 -name "HMindManager.smali")
python3 bin/patchmethod.py -d tmp/MiLinkOS2 -k "isSupportCapability() context == null" -return true
python3 bin/patchmethod.py $targetsmali J -return true
java -jar bin/apktool/APKEditor.jar b -i tmp/MiLinkOS2 -o $targetMiLinkOS2APK -f > /dev/null 2>&1
fi
targetMIUIThemeManagerAPK=$(find build/portrom -type f -name "MIUIThemeManager.apk")
if [[ -f "${targetMIUIThemeManagerAPK}" ]];then
cp -rf $targetMIUIThemeManagerAPK tmp/$(basename $targetMIUIThemeManagerAPK).bak
java -jar bin/apktool/APKEditor.jar d -i $targetMIUIThemeManagerAPK -o tmp/MIUIThemeManager -f > /dev/null 2>&1
targetsmali=$(find tmp/ -name "o1t.smali" -path "*/basemodule/utils/*")
python3 bin/patchmethod.py $targetsmali mcp -return true
java -jar bin/apktool/APKEditor.jar b -i tmp/MIUIThemeManager -o $targetMIUIThemeManagerAPK -f > /dev/null 2>&1
fi
targetSettingsAPK=$(find build/portrom -type f -name "Settings.apk")
if [[ -f "${targetSettingsAPK}" ]];then
cp -rf $targetSettingsAPK tmp/$(basename $targetSettingsAPK).bak
java -jar bin/apktool/APKEditor.jar d -i $targetSettingsAPK -o tmp/Settings -f > /dev/null 2>&1
targetsmali=$(find tmp/ -type f -path "*/com/android/settings/InternalDeviceUtils.smali")
python3 bin/patchmethod.py $targetsmali isAiSupported -return true
java -jar bin/apktool/APKEditor.jar b -i tmp/Settings -o $targetSettingsAPK -f > /dev/null 2>&1
fi
if [[ ${port_rom_code} == "munch_cn" ]];then
# Add missing camera permission android.permission.TURN_SCREEN_ON
# this missing permission will cause device stuck on boot with higher custom Camera(eg: 5.2.0.XX) integrated
sed -i 's|<permission name="android.permission.SYSTEM_CAMERA" />|<permission name="android.permission.SYSTEM_CAMERA" />\n\t\t<permission name="android.permission.TURN_SCREEN_ON" />|' build/portrom/images/product/etc/permissions/privapp-permissions-product.xml
fi
#自定义替换
#Add perfect icons
blue "Integrating perfect icons"
git clone --depth=1 https://github.com/pzcn/Perfect-Icons-Completion-Project.git icons &>/dev/null
for pkg in "$work_dir"/build/portrom/images/product/media/theme/miui_mod_icons/dynamic/*; do
if [[ -d "$work_dir"/icons/icons/$pkg ]]; then
rm -rf "$work_dir"/icons/icons/$pkg
fi
done
rm -rf "$work_dir"/icons/icons/com.xiaomi.scanner
mv "$work_dir"/build/portrom/images/product/media/theme/default/icons "$work_dir"/build/portrom/images/product/media/theme/default/icons.zip
rm -rf "$work_dir"/build/portrom/images/product/media/theme/default/dynamicicons
mkdir -p "$work_dir"/icons/res
mv "$work_dir"/icons/icons "$work_dir"/icons/res/drawable-xxhdpi
cd "$work_dir"/icons
zip -qr "$work_dir"/build/portrom/images/product/media/theme/default/icons.zip res
cd "$work_dir"/icons/themes/Hyper/
zip -qr "$work_dir"/build/portrom/images/product/media/theme/default/dynamicicons.zip layer_animating_icons
cd "$work_dir"/icons/themes/common/
zip -qr "$work_dir"/build/portrom/images/product/media/theme/default/dynamicicons.zip layer_animating_icons
mv "$work_dir"/build/portrom/images/product/media/theme/default/icons.zip "$work_dir"/build/portrom/images/product/media/theme/default/icons
mv "$work_dir"/build/portrom/images/product/media/theme/default/dynamicicons.zip "$work_dir"/build/portrom/images/product/media/theme/default/dynamicicons
rm -rf "$work_dir"/icons
cd "$work_dir"
# Optimize prop from K40s
if ! is_property_exists ro.miui.surfaceflinger_affinity build/portrom/images/product/etc/build.prop; then
echo "ro.miui.surfaceflinger_affinity=true" >> build/portrom/images/product/etc/build.prop
fi
#自定义替换
sourceAnimationZIP=$(find build/baserom/images/product -type f -name "bootanimation.zip")
targetAnimationZIP=$(find build/portrom/images/product -type f -name "bootanimation.zip")
cp -rf $sourceAnimationZIP $targetAnimationZIP
if [[ -d "devices/common" ]];then
commonCamera=$(find devices/common -type f -name "MiuiCamera.apk")
targetCamera=$(find build/portrom/images/product -type d -name "MiuiCamera")
targetNQNfcNci=$(find build/portrom/images/system/system build/portrom/images/product build/portrom/images/system_ext -type d -name "NQNfcNci*")
if [[ $nfc_fix_type == "legacy" ]];then
if [[ -d "${targetNQNfcNci}" ]];then
rm -rf $targetNQNfcNci
fi
find build/portrom/images/ -name "com.nxp.nfc.nq.jar" -type f -delete
find build/portrom/images/ -name "com.xiaomi.nfc.jar" -type f -delete
unzip -oq devices/common/nfc_legacy.zip -d build/portrom/images/
elif [[ $nfc_fix_type == "a14" ]]; then
unzip -oq devices/common/nfc_a14.zip -d build/portrom/images/
echo "ro.vendor.nfc.dispatch_optim=1" >> build/portrom/images/vendor/build.prop
elif [[ ${port_android_version} == "15" ]]; then
unzip -oq devices/common/nfc_a15.zip -d build/portrom/images/
echo "ro.vendor.nfc.dispatch_optim=1" >> build/portrom/images/vendor/build.prop
fi
if [[ $base_rom_code == "munch" ]] && [[ ${port_android_version} == "15" ]]; then
sourceCamera=$(find build/baserom/images/ -type f -name "MiuiCamera.apk")
targetCamera=$(find build/portrom/images/ -type d -name "MiuiCamera")
cp -rf $sourceCamera $targetCamera/
else
if [[ ${base_android_version} == "13" ]] && [[ -f "${commonCamera}" ]];then
yellow "替换相机为10S HyperOS A13 相机,MI10可用, thanks to 酷安 @PedroZ" "Replacing a compatible MiuiCamera.apk verson 4.5.003000.2"
if [[ -d "${targetCamera}" ]];then
rm -rf $targetCamera/*
fi
cp -rf $commonCamera $targetCamera
fi
fi
fi
#Devices/机型代码/overaly 按照镜像的目录结构,可直接替换目标。
if [[ -d "devices/${base_rom_code}/overlay" ]]; then
cp -rf devices/${base_rom_code}/overlay/* build/portrom/images/
else
yellow "devices/${base_rom_code}/overlay 未找到" "devices/${base_rom_code}/overlay not found"
fi
for zip in $(find devices/${base_rom_code}/ -name "*.zip"); do
if unzip -l $zip | grep -q "anykernel.sh" ;then
blue "检查到第三方内核压缩包 $zip [AnyKernel类型]" "Custom Kernel zip $zip detected [Anykernel]"
if echo $zip | grep -q ".*-KSU" ; then
unzip $zip -d tmp/anykernel-ksu/ > /dev/null 2>&1
elif echo $zip | grep -q ".*-NoKSU" ; then
unzip $zip -d tmp/anykernel-noksu/ > /dev/null 2>&1
else
unzip $zip -d tmp/anykernel/ > /dev/null 2>&1
fi
fi
done
for anykernel_dir in tmp/anykernel*; do
if [ -d "$anykernel_dir" ]; then
blue "开始整合第三方内核进boot.img" "Start integrating custom kernel into boot.img"
kernel_file=$(find "$anykernel_dir" -name "Image" -exec readlink -f {} +)
dtb_file=$(find "$anykernel_dir" -name "dtb" -exec readlink -f {} +)
dtbo_img=$(find "$anykernel_dir" -name "dtbo.img" -exec readlink -f {} +)
if [[ "$anykernel_dir" == *"-ksu"* ]]; then
cp $dtbo_img ${work_dir}/devices/$base_rom_code/dtbo_ksu.img
patch_kernel_to_bootimg "$kernel_file" "$dtb_file" "boot_ksu.img"
blue "生成内核boot_boot_ksu.img完毕" "New boot_ksu.img generated"
elif [[ "$anykernel_dir" == *"-noksu"* ]]; then
cp $dtbo_img ${work_dir}/devices/$base_rom_code/dtbo_noksu.img
patch_kernel_to_bootimg "$kernel_file" "$dtb_file" "boot_noksu.img"
blue "生成内核boot_noksu.img" "New boot_noksu.img generated"
else
cp $dtbo_img ${work_dir}/devices/$base_rom_code/dtbo_custom.img
patch_kernel_to_bootimg "$kernel_file" "$dtb_file" "boot_custom.img"
blue "生成内核boot_custom.img完毕" "New boot_custom.img generated"
fi
fi
rm -rf $anykernel_dir
done
#添加erofs文件系统fstab
if [ ${pack_type} == "EROFS" ];then