forked from toraidl/coloros_port
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathport.sh
More file actions
executable file
·2567 lines (2202 loc) · 133 KB
/
port.sh
File metadata and controls
executable file
·2567 lines (2202 loc) · 133 KB
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
# ColorOS_port project
# For A-only and V/A-B (not tested) Devices
# Based on Android 14
# Test Base ROM: OnePlus 8T (ColorOS_14.0.0.600)
# Test Port ROM: OnePlus 12 (ColorOS_14.0.0.810), OnePlus ACE3V(ColorOS_14.0.1.621) Realme GT Neo5 240W(RMX3708_14.0.0.800)
build_user="Juniper"
build_host=$(hostname)"@lemonadeports"
# 底包和移植包为外部参数传入
baserom="$1"
portrom="$2"
portrom2="$3"
portparts="$4"
work_dir=$(pwd)
tools_dir=${work_dir}/bin/$(uname)/$(uname -m)
globalise=false
export PATH=$(pwd)/bin/$(uname)/$(uname -m)/:$(pwd)/otatools/bin/:$PATH
# Import functions
source functions.sh
check unzip aria2c 7z zip java python3 zstd bc xmlstarlet
# 可在 bin/port_config 中更改
port_partition=$(grep "partition_to_port" bin/port_config |cut -d '=' -f 2)
super_list=$(grep "possible_super_list" bin/port_config |cut -d '=' -f 2)
repackext4=$(grep "repack_with_ext4" bin/port_config |cut -d '=' -f 2)
super_extended=$(grep "super_extended" bin/port_config |cut -d '=' -f 2)
pack_method=$(grep "pack_method" bin/port_config | cut -d '=' -f 2)
if [[ ${repackext4} == true ]]; then
pack_type=EXT
else
pack_type=EROFS
fi
if [ ${globalise} == true ] && [ ! $portrom2 ];then
error "A second rom was not entered. Please use a ColorOS global rom with the same major version as your primary rom."
exit
fi
# 检查为本地包还是链接
if [ ! -f "${baserom}" ] && [ "$(echo $baserom |grep http)" != "" ];then
blue "底包为一个链接,正在尝试下载" "Download link detected, start downloading.."
aria2c -c --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 downloading.."
if [ "$(/usr/bin/echo $portrom | grep downloadCheck)" != "" ];then
blue "downloadCheck link detected! Redirecting..."
portrom=$(curl -Lsv -I --compressed -H "userId: oplus-ota|16002018" -H "User-Agent: okhttp/3.12.12" -H "Accept: */*" -H "Connection: Keep-Alive" "${portrom}" 2>&1 | grep -i "< location:" | awk '{print $3}' | tr -d '\r')
fi
aria2c -c --max-download-limit=1024M --file-allocation=none -s10 -x10 -j10 ${portrom}
portrom=$(basename ${portrom} | sed 's/\.zip.*/.zip/')
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 ColorOS_)" != "" ];then
device_code=$(basename $baserom |cut -d '_' -f 2)
else
device_code="op8t"
fi
blue "正在检测ROM底包" "Validating BASEROM.."
# 检测底包类型
if unzip -l "${baserom}" | grep -q "payload.bin"; then
baserom_type="payload"
oplus_hex_nv_id=$(unzip -p "${baserom}" META-INF/com/android/metadata 2>/dev/null | grep "oplus_hex_nv_id=" | cut -d= -f2)
elif unzip -l "${baserom}" | grep -Eq "br$"; then
baserom_type="br"
oplus_hex_nv_id=$(unzip -p "${baserom}" META-INF/com/android/metadata 2>/dev/null | grep "oplus_hex_nv_id=" | cut -d= -f2)
elif unzip -l "${baserom}" | grep -Eq "\.img$"; then
baserom_type="img"
else
error "底包中未发现 payload.bin、br 或 img 文件,请使用官方ROM包后重试" \
"payload.bin / *.br / *.img not found, please use official OTA or fastboot package."
exit 1
fi
green "检测到底包类型: ${baserom_type}" "Detected base package type: ${baserom_type}"
echo $portrom2
if [ ! -f "${portrom2}" ] && [ "$(echo ${portrom2} |grep http)" != "" ];then
blue "移植包为一个链接,正在尝试下载" "Download link detected, start downloading.."
if [ "$(/usr/bin/echo $portrom2 | grep downloadCheck)" != "" ];then
blue "downloadCheck link detected! Redirecting..."
portrom2=$(curl -Lsv -I --compressed -H "userId: oplus-ota|16002018" -H "User-Agent: okhttp/3.12.12" -H "Accept: */*" -H "Connection: Keep-Alive" "${portrom2}" 2>&1 | grep -i "< location:" | awk '{print $3}' | tr -d '\r')
fi
aria2c -c --max-download-limit=1024M --file-allocation=none -s10 -x10 -j10 ${portrom2}
portrom2=$(basename ${portrom2} | sed 's/\.zip.*/.zip/')
if [ ! -f "${portrom2}" ];then
error "下载错误" "Download error!"
fi
fi
blue "开始检测ROM移植包" "Validating PORTROM.."
echo $portrom2
# 检测移植包类型
if unzip -l "${portrom}" | grep -q "payload.bin"; then
portrom_type="payload"
elif unzip -l "${portrom}" | grep -Eq "\.img$"; then
portrom_type="img"
else
error "目标移植包中未发现 payload.bin 或 img 文件,请使用包含 system.img 的官方ROM包作为移植包" \
"payload.bin or *.img not found, please use an official ROM package containing system.img as PORTROM."
exit 1
fi
# 提取版本信息(仅当有 metadata 时)
if unzip -l "${portrom}" | grep -q "META-INF/com/android/metadata"; then
version_name=$(unzip -p "${portrom}" META-INF/com/android/metadata 2>/dev/null | grep "version_name=" | cut -d= -f2)
ota_version=$(unzip -p "${portrom}" META-INF/com/android/metadata 2>/dev/null | grep "ota_version=" | cut -d= -f2)
else
version_name="$(basename ${portrom%.*})"
ota_version="V16.0.0"
fi
green "ROM初步检测通过,类型: ${portrom_type}" "ROM validation passed. Type: ${portrom_type}"
[[ -n "${version_name}" ]] && echo "版本名: ${version_name}"
if [[ -n $portrom2 ]];then
mix_port=true
fi
if [[ -n $portparts ]];then
mix_port_part=($portparts)
else
mix_port_part=("my_stock" "my_region" "my_manifest" "my_product")
fi
if [[ $mix_port == true ]];then
blue "混合移植包模式"
blue "开始检测第二个移植包" "Validating PORTROM.."
if unzip -l ${portrom2} | grep -q "payload.bin"; then
green "第二个ROM初步检测通过" "ROM validation passed."
portrom2_type="payload"
version_name2=$(unzip -p ${portrom2} META-INF/com/android/metadata | grep "version_name=" | cut -d = -f2)
elif unzip -l "${portrom2}" | grep -Eq "\.img$"; then
portrom2_type="img"
version_name2="$(basename "${portrom2%.*}")"
else
error "目标移植包中未发现 payload.bin 或 img 文件,请使用包含 system.img 的官方ROM包作为移植包" \
"payload.bin or *.img not found, please use an official ROM package containing system.img as PORTROM."
exit 1
fi
fi
green "ROM初步检测通过" "ROM validation passed."
blue "正在清理文件" "Cleaning up.."
rm -rf app
rm -rf tmp
rm -rf config
rm -rf build/baserom/
rm -rf build/portrom/
find . -type d -name 'ColorOS_*' |xargs rm -rf
green "文件清理完毕" "Files cleaned up."
mkdir -p build/baserom/images/
mkdir -p build/portrom/images/
mkdir tmp
export TMPDIR=$work_dir/tmp/
# ===== 提取底包 =====
if [[ ${baserom_type} == 'payload' ]]; then
blue "正在提取底包 [payload.bin]" "Extracting files from BASEROM [payload.bin]"
payload_dumper -o 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 -q "${baserom}" -d build/baserom || \
error "解压底包 [new.dat.br]时出错" "Extracting [new.dat.br] error"
green "底包 [new.dat.br] 解压完毕" "[new.dat.br] extracted."
blue "开始分解底包 [new.dat.br]" "Unpacking BASEROM [new.dat.br]"
# 修复带数字的文件名问题
for file in build/baserom/*; do
filename=$(basename -- "$file")
extension="${filename##*.}"
name="${filename%.*}"
if [[ $name =~ [0-9] ]]; then
new_name=$(echo "$name" | sed 's/[0-9]\+\(\.[^0-9]\+\)/\1/g' | sed 's/\.\./\./g')
mv -fv "$file" "build/baserom/${new_name}.${extension}"
fi
done
# 转换为 .img
for i in ${super_list}; do
if [[ -f build/baserom/${i}.new.dat.br ]]; then
${tools_dir}/brotli -d build/baserom/${i}.new.dat.br >/dev/null 2>&1
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.*
fi
done
green "底包 [new.dat.br] 分解完毕" "[new.dat.br] unpack complete."
elif [[ ${baserom_type} == 'img' ]]; then
blue "检测到底包类型为 [img]" "Extracting BASEROM containing .img files"
mkdir -p build/baserom/images/
unzip -q "${baserom}" -d build/baserom/tmp/ || \
error "解压底包时出错" "Extracting BASEROM error"
# 移动所有 img 文件
find build/baserom/tmp/ -type f -name "*.img" -exec mv -fv {} build/baserom/images/ \;
rm -rf build/baserom/tmp/
green "底包 [*.img] 提取完毕" "[*.img] extracted."
else
error "未知底包类型: ${baserom_type}" "Unknown base package type: ${baserom_type}"
exit 1
fi
# ===== 提取移植包 =====
if [[ -n ${version_name} ]] && [[ -d build/${version_name} ]]; then
blue "检测到已存在解压的移植包cache文件夹 ${version_name},从中复制" \
"Cached ${version_name} folder detected, copying..."
IFS=',' read -ra PARTS <<< "$port_partition"
for i in "${PARTS[@]}"; do
cp -rfv "build/${version_name}/${i}.img" build/portrom/images/
done
else
mkdir -p build/${version_name}/ build/portrom/images/
if [[ ${portrom_type} == 'payload' ]]; then
blue "正在提取移植包 [payload.bin]" "Extracting PORTROM [payload.bin]"
payload_dumper -i "${port_partition}" -o "build/${version_name}/" "${portrom}"
cp -rfv build/${version_name}/*.img build/portrom/images/
green "移植包 [payload.bin] 提取完毕" "[payload.bin] extracted."
elif [[ ${portrom_type} == 'img' ]]; then
blue "检测到移植包类型为 [img]" "Extracting PORTROM containing .img files"
# 将逗号分隔的分区名转为数组
IFS=',' read -ra PARTS <<< "$port_partition"
# 构建解压参数
declare -a unzip_targets=()
for part in "${PARTS[@]}"; do
unzip_targets+=("${part}.img" "${part}_a.img" "${part}_b.img")
done
blue "正在选择性解压移植包中的img文件" "Extracting specific img files from PORTROM"
# 仅解压指定分区的img文件
unzip -q "${portrom}" "${unzip_targets[@]}" -d "build/${version_name}/" || \
error "解压指定 img 文件失败,请检查包中是否包含 ${port_partition}" \
"Failed to extract specified img files from PORTROM."
green "指定分区镜像解压完成" "Selected partitions extracted successfully."
find "build/${version_name}/" -type f -name "*.img" -exec cp -fv {} build/portrom/images/ \;
green "移植包 [*.img] 提取完毕" "[*.img] extracted."
else
error "未知移植包类型: ${portrom_type}" "Unknown port package type: ${portrom_type}"
exit 1
fi
fi
if [[ -n ${version_name2} ]] && [[ -d build/${version_name2} ]];then
blue "检测到已存在解压的第二个移植包cache文件夹${version_name2},从中复制" "cached ${version_name2} folder detected, copying"
#IFS=',' read -ra PARTS <<< "$port_partition" # 用逗号分割为数组
for i in "${mix_port_part[@]}"; do
# if [[ -f build/${version_name}/${i}_patched.img ]];then
# skip_list2+=("$i")
# cp -rfv build/${version_name}/${i}_patched.img build/portrom/images/${i}.img
#else
cp -rfv build/${version_name2}/${i}.img build/portrom/images/
#fi
done
elif [[ -n ${version_name2} ]];then
if [[ ${portrom2_type} == 'payload' ]]; then
blue "正在提取移植包 [payload.bin]" "Extracting files from PORTROM [payload.bin]"
mkdir -p build/${version_name2}/
payload_dumper -i ${port_partition} -o build/${version_name2}/ $portrom2
for i in "${mix_port_part[@]}"; do
cp -rfv build/${version_name2}/${i}.img build/portrom/images/
done
elif [[ ${portrom2_type} == 'img' ]]; then
blue "检测到移植包2类型为 [img]" "Extracting PORTROM containing .img files"
# 将逗号分隔的分区名转为数组
IFS=',' read -ra PARTS <<< "$port_partition"
# 构建解压参数
declare -a unzip_targets=()
for part in "${PARTS[@]}"; do
unzip_targets+=("${part}.img" "${part}_a.img" "${part}_b.img")
done
blue "正在选择性解压移植包中的img文件" "Extracting specific img files from PORTROM"
# 仅解压指定分区的img文件
unzip -q "${portrom2}" "${unzip_targets[@]}" -d "build/${version_name2}/" || \
error "解压指定 img 文件失败,请检查包中是否包含 ${port_partition}" \
"Failed to extract specified img files from PORTROM."
green "指定分区镜像解压完成" "Selected partitions extracted successfully."
find "build/${version_name2}/" -type f -name "*.img" -exec cp -fv {} build/portrom/images/ \;
green "移植包 [*.img] 提取完毕" "[*.img] extracted."
fi
fi
if [[ -n ${version_name} ]] && [[ -n ${version_name2} ]];then
app_patch_folder=${version_name2}
elif [[ -n ${version_name} ]];then
app_patch_folder=${version_name}
fi
for part in system product system_ext my_product my_manifest;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 my_company my_preload system_dlkm vendor_dlkm my_engineering;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
if [ ! -d build/portrom/images/system_dlkm ];then
super_list="system system_ext vendor product my_product odm my_engineering my_stock my_heytap my_carrier my_region my_bigball my_manifest my_company my_preload"
fi
# Extract the partitions list that need to pack into the super.img
#super_list=$(sed '/^#/d;/^\//d;/overlay/d;/^$/d;/\^loop/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_list1 或 skip_list2 中
# if [[ " ${skip_list1[@]} " =~ " ${part} " ]] || [[ " ${skip_list2[@]} " =~ " ${part} " ]]; then
# yellow "跳过分区 [${part}],已通过patched镜像复用" "Skip [${part}], already reused from patched image"
# continue
# fi
# Skip already extracted parts from BASEROM
if [[ ! -d build/portrom/images/${part} ]]; then
blue "提取 [${part}] 分区..." "Extracting [${part}]"
(
extract_partition "${work_dir}/build/portrom/images/${part}.img" "${work_dir}/build/portrom/images/" && \
rm -rf "${work_dir}/build/baserom/images/${part}.img"
) &
else
yellow "跳过从PORTROM提取分区[${part}]" "Skip extracting [${part}] from PORTROM"
fi
done
wait
rm -rf config
blue "正在获取ROM参数" "Fetching ROM build prop."
# 安卓版本
base_android_version=$(< build/baserom/images/system/system/build.prop grep "ro.build.version.release" |awk 'NR==1' |cut -d '=' -f 2)
port_android_version=$(< build/portrom/images/system/system/build.prop grep "ro.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/baserom/images/system/system/build.prop grep "ro.system.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 Version: BASEROM: [SDK ${base_android_sdk}], PORTROM: [SDK ${port_android_sdk}]"
# ROM版本
base_rom_version=$(< build/baserom/images/my_manifest/build.prop grep "ro.build.display.ota" | awk 'NR==1' | cut -d '=' -f 2 | cut -d "_" -f 2-)
port_rom_version=$(< build/portrom/images/my_manifest/build.prop grep "ro.build.display.ota" | awk 'NR==1' | cut -d '=' -f 2 | cut -d "_" -f 2-)
green "ROM 版本: 底包为 [${base_rom_version}], 移植包为 [${port_rom_version}]" "ROM Version: BASEROM: [${base_rom_version}], PORTROM: [${port_rom_version}] "
#ColorOS版本号获取
base_device_code=$(< build/baserom/images/my_manifest/build.prop grep "ro.oplus.version.my_manifest" | awk 'NR==1' | cut -d '=' -f 2 | cut -d "_" -f 1)
port_device_code=$(< build/portrom/images/my_manifest/build.prop grep "ro.oplus.version.my_manifest" | awk 'NR==1' | cut -d '=' -f 2 | cut -d "_" -f 1)
green "机型代号: 底包为 [${base_device_code}], 移植包为 [${port_device_code}]" "Device Code: BASEROM: [${base_device_code}], PORTROM: [${port_device_code}]"
# 代号
base_product_device=$(< build/baserom/images/my_manifest/build.prop grep "ro.product.device" |awk 'NR==1' |cut -d '=' -f 2)
port_product_device=$(< build/portrom/images/my_manifest/build.prop grep "ro.product.device" |awk 'NR==1' |cut -d '=' -f 2)
green "Product机型: 底包为 [${base_product_device}], 移植包为 [${port_product_device}]" "Product Device: BASEROM: [${base_product_device}], PORTROM: [${port_product_device}]"
base_product_name=$(< build/baserom/images/my_manifest/build.prop grep "ro.product.name" |awk 'NR==1' |cut -d '=' -f 2)
port_product_name=$(< build/portrom/images/my_manifest/build.prop grep "ro.product.name" |awk 'NR==1' |cut -d '=' -f 2)
green "Product名称: 底包为 [${base_product_name}], 移植包为 [${port_product_name}]" "Product Name: BASEROM: [${base_product_name}], PORTROM: [${port_product_name}]"
base_product_model=$(< build/baserom/images/my_manifest/build.prop grep "ro.product.model" |awk 'NR==1' |cut -d '=' -f 2)
port_product_model=$(< build/portrom/images/my_manifest/build.prop grep "ro.product.model" |awk 'NR==1' |cut -d '=' -f 2)
green "Product型号: 底包为 [${base_product_model}], 移植包为 [${port_product_model}]" "Product Model: BASEROM: [${base_product_model}], PORTROM: [${port_product_model}]"
if grep -q "ro.vendor.oplus.market.name" build/baserom/images/my_manifest/build.prop;then
base_market_name=$(< build/baserom/images/my_manifest/build.prop grep "ro.vendor.oplus.market.name" |awk 'NR==1' |cut -d '=' -f 2)
else
base_market_name=$(< build/portrom/images/odm/build.prop grep "ro.vendor.oplus.market.name" |awk 'NR==1' |cut -d '=' -f 2)
fi
port_market_name=$(grep -r --include="*.prop" --exclude-dir="odm" "ro.vendor.oplus.market.name" build/portrom/images/ | head -n 1 | awk "NR==1" | cut -d "=" -f2)
green "市场名称: 底包为 [${base_market_name}], 移植包为 [${port_market_name}]" "Market Name: BASEROM: [${base_market_name}], PORTROM: [${port_market_name}]"
base_my_product_type=$(< build/baserom/images/my_product/build.prop grep "ro.oplus.image.my_product.type" |awk 'NR==1' |cut -d '=' -f 2)
port_my_product_type=$(< build/portrom/images/my_product/build.prop grep "ro.oplus.image.my_product.type" |awk 'NR==1' |cut -d '=' -f 2)
green "my_product类型: 底包为 [${base_my_product_type}], 移植包为 [${port_my_product_type}]" "My_Product Type: BASEROM: [${base_my_product_type}], PORTROM: [${port_my_product_type}]"
target_display_id=$(< build/portrom/images/my_manifest/build.prop grep "ro.build.display.id=" |awk 'NR==1' |cut -d '=' -f 2 | sed "s/$port_device_code/$base_device_code/g")
target_display_id_show=$(< build/portrom/images/my_manifest/build.prop grep "ro.build.display.id.show" |awk 'NR==1' |cut -d '=' -f 2 | sed "s/$port_device_code/$base_device_code/g")
base_vendor_brand=$(< build/baserom/images/my_manifest/build.prop grep "ro.product.vendor.brand" |awk 'NR==1' |cut -d '=' -f 2)
port_vendor_brand=$(< build/portrom/images/my_manifest/build.prop grep "ro.product.vendor.brand" |awk 'NR==1' |cut -d '=' -f 2)
base_product_first_api_level=$(< build/baserom/images/my_manifest/build.prop grep "ro.product.first_api_level" |awk 'NR==1' |cut -d '=' -f 2)
port_product_first_api_level=$(< build/portrom/images/my_manifest/build.prop grep "ro.product.first_api_level" |awk 'NR==1' |cut -d '=' -f 2)
base_device_family=$(< build/baserom/images/my_product/build.prop grep "ro.build.device_family" |awk 'NR==1' |cut -d '=' -f 2)
target_device_family=$(< build/portrom/images/my_product/build.prop grep "ro.build.device_family" |awk 'NR==1' |cut -d '=' -f 2)
# Security Patch Date
portrom_version_security_patch=$(< build/portrom/images/my_manifest/build.prop grep "ro.build.version.security_patch" |awk 'NR==1' |cut -d '=' -f 2 )
port_oplusrom_version=$(< build/portrom/images/my_product/build.prop grep "ro.build.version.oplusrom.confidential" |awk 'NR==1' |cut -d '=' -f 2 )
#regionmark=$(< build/portrom/images/my_bigball/etc/region/build.prop grep "ro.vendor.oplus.regionmark" |awk 'NR==1' |cut -d '=' -f 2)
regionmark=$(find build/portrom/images/ -name build.prop -exec grep -m1 "ro.vendor.oplus.regionmark=" {} \; -quit | cut -d '=' -f2)
base_regionmark=$(find build/baserom/images/ -name build.prop -exec grep -m1 "ro.vendor.oplus.regionmark=" {} \; -quit | cut -d '=' -f2)
if [ -z "$base_regionmark" ]; then
base_regionmark=$(find build/baserom/images/ -name build.prop -exec grep -m1 "ro.oplus.image.my_region.type=" {} \; -quit | cut -d '=' -f2 | cut -d '_' -f1)
fi
vendor_cpu_abilist32=$(< build/portrom/images/vendor/build.prop grep "ro.vendor.product.cpu.abilist32" |awk 'NR==1' |cut -d '=' -f 2 )
base_area=$(grep -r --include="*.prop" --exclude-dir="odm" "ro.oplus.image.system_ext.area" build/baserom/images/ | head -n1 | cut -d "=" -f2 | tr -d '\r')
base_brand=$(grep -r --include="*.prop" --exclude-dir="odm" "ro.oplus.image.system_ext.brand" build/baserom/images/ | head -n1 | cut -d "=" -f2 | tr -d '\r')
baseIsColorOSCN=false
baseIsOOS=false
baseIsRealmeUI=false
if [[ "$base_area" == "domestic" && "$base_brand" != "realme" ]]; then
baseIsColorOSCN=true
elif [[ "$base_brand" == "realme" ]];then
baseIsRealmeUI=true
elif [[ "$base_area" == "gdpr" && "$base_brand" == "oneplus" ]]; then
baseIsOOS=true
fi
port_area=$(grep -r --include="*.prop" --exclude-dir="odm" "ro.oplus.image.system_ext.area" build/portrom/images/ | head -n1 | cut -d "=" -f2 | tr -d '\r')
port_brand=$(grep -r --include="*.prop" --exclude-dir="odm" "ro.oplus.image.system_ext.brand" build/portrom/images/ | head -n1 | cut -d "=" -f2 | tr -d '\r')
portIsColorOSGlobal=false
portIsOOS=false
portIsColorOS=false
portIsRealmeUI=false
port_oplusrom_version=$(get_oplusrom_version)
port_oplusrom_confidential_version=$(< build/portrom/images/my_manifest/build.prop grep "ro.build.version.oplusrom.confidential" |awk 'NR==1' |cut -d '=' -f 2)
if [[ "$port_brand" == "realme" ]];then
portIsRealmeUI=true
fi
if [[ "$port_area" == "gdpr" && "$port_brand" != "oneplus" ]]; then
portIsColorOSGlobal=true
elif [[ "$port_area" == "gdpr" && "$port_brand" == "oneplus" ]]; then
portIsOOS=true
else
portIsColorOS=true
fi
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
if [[ ! -f build/portrom/images/system/system/bin/app_process32 && -n "$vendor_cpu_abilist32" ]]; then
blue "64bit only portrom detected. convert vendor to 64bit-only"
sed -i "s/ro.vendor.product.cpu.abilist=.*/ro.vendor.product.cpu.abilist=arm64-v8a/g" build/portrom/images/vendor/build.prop
sed -i "s/ro.vendor.product.cpu.abilist32=.*/ro.vendor.product.cpu.abilist32=/g" build/portrom/images/vendor/build.prop
sed -i "s/ro.zygote=.*/ro.zygote=zygote64/g" build/portrom/images/vendor/default.prop
#cp -rfv devices/32-libs/* build/portrom/images/
fi
if [[ -f devices/${base_product_device}/config ]];then
source devices/${base_product_device}/config
fi
#rm -rf build/portrom/images/my_manifest
#cp -rf build/baserom/images/my_manifest build/portrom/images/
#cp -rf build/baserom/images/config/my_manifest_* build/portrom/images/config/
sed -i "s/ro.build.display.id=.*/ro.build.display.id=${target_display_id}/g" build/portrom/images/my_manifest/build.prop
sed -i "s/ro.product.first_api_level=.*/ro.product.first_api_level=${base_product_first_api_level}/g" build/portrom/images/my_manifest/build.prop
if ! grep -q "ro.build.display.id.show" build/portrom/images/my_manifest/build.prop ;then
echo "ro.build.display.id.show=$target_display_id_show" >> build/portrom/images/my_manifest/build.prop
else
sed -i "s/ro.build.display.id.show=.*/ro.build.display.id.show=${target_display_id_show}/g" build/portrom/images/my_manifest/build.prop
fi
sed -i '/ro.build.version.release=/d' build/portrom/images/my_manifest/build.prop
sed -i "s/ro.vendor.oplus.market.name=.*/ro.vendor.oplus.market.name=${base_market_name}/g" build/portrom/images/my_manifest/build.prop
sed -i "s/ro.vendor.oplus.market.enname=.*/ro.vendor.oplus.market.enname=${base_market_name}/g" build/portrom/images/my_manifest/build.prop
sed -i '/ro.oplus.watermark.betaversiononly.enable=/d' build/portrom/images/my_manifest/build.prop
BASE_PROP="build/baserom/images/my_manifest/build.prop"
PORT_PROP="build/portrom/images/my_manifest/build.prop"
KEYS="\.name= \.model= \.manufacturer= \.device= \.brand= \.my_product.type="
for k in $KEYS; do
grep "$k" "$BASE_PROP" | while IFS='=' read -r key value; do
if [[ "$key" == "ro.product.vendor.brand" ]]; then
# 特殊处理:强制写 OPPO
sed -i "s|^$key=.*|$key=OPPO|" "$PORT_PROP"
elif grep -q "^$key=" "$PORT_PROP"; then
sed -i "s|^$key=.*|$key=$value|" "$PORT_PROP"
fi
done
done
# OOS 16 mixed port
if [[ -n $vendor_cpu_abilist32 ]] ;then
sed -i "/ro.zygote=zygote64/d" build/portrom/images/my_manifest/build.prop
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
for prop in $(find build/portrom/images -name "build.prop");do
sed -i "s/ro.build.version.security_patch=.*/ro.build.version.security_patch=${portrom_version_security_patch}/g" $prop
done
old_face_unlock_app=$(find build/baserom/images/my_product -name "OPFaceUnlock.apk")
if [[ -f build/${app_patch_folder}/patched/services.jar ]];then
blue "复制已经处理过的services.jar"
cp -rfv build/${app_patch_folder}/patched/services.jar build/portrom/images/system/system/framework/services.jar
elif [[ -f build/portrom/images/system/system/framework/services.jar ]];then
if [[ ! -d tmp ]];then
mkdir -p tmp/
fi
mkdir -p tmp/services/
cp -rf build/portrom/images/system/system/framework/services.jar tmp/services.jar
framework_res=$(find build/portrom/images/ -type f -name "framework-res.apk")
extra_args=""
if [[ -f $framework_res ]];then
extra_args="-framework $framework_res"
fi
java -jar bin/apktool/APKEditor.jar d -f -i tmp/services.jar -o tmp/services
smalis=("ScanPackageUtils")
methods=("--assertMinSignatureSchemeIsValid")
for (( i=0; i<${#smalis[@]}; i++ )); do
smali="${smalis[i]}"
method="${methods[i]}"
target_file=$(find tmp/services -type f -name "${smali}.smali")
echo "smali is $smali"
echo "target_file is $target_file"
if [[ -f $target_file ]]; then
for single_method in $method; do
python3 bin/patchmethod.py $target_file $single_method && echo "${target_file} patched successfully"
done
fi
done
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")
original_line_number=$method_line
replace_with_command="const/4 v${register_number}, 0x0"
{ sed -i "${original_line_number},${move_result_end_line}d" "$smali_file" && sed -i "${original_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)
ALLOW_NON_PRELOADS_SYSTEM_SHAREDUIDS='ALLOW_NON_PRELOADS_SYSTEM_SHAREDUIDS'
find tmp/services/ -type f -name "ReconcilePackageUtils.smali" | while read smali_file; do
match_line=$(grep -n "sput-boolean .*${ALLOW_NON_PRELOADS_SYSTEM_SHAREDUIDS}" "$smali_file" | head -n 1)
if [[ -n "$match_line" ]]; then
line_number=$(echo "$match_line" | cut -d ':' -f 1)
reg=$(echo "$match_line" | sed -n 's/.*sput-boolean \([^,]*\),.*/\1/p')
echo "Found in $smali_file at line $line_number using register $reg"
# 在该行前插入 const/4 vX, 0x1
sed -i "${line_number}i\ const/4 $reg, 0x1" "$smali_file"
echo "→ Patched successfully in $smali_file"
else
echo "× Not found in $smali_file"
fi
done
java -jar bin/apktool/APKEditor.jar b -f -i tmp/services -o build/${app_patch_folder}/patched/services.jar
cp -rfv build/${app_patch_folder}/patched/services.jar build/portrom/images/system/system/framework/services.jar
fi
if [[ -f build/${app_patch_folder}/patched/framework.jar ]];then
blue "复制已经处理过的framework.jar"
cp -rfv build/${app_patch_folder}/patched/framework.jar build/portrom/images/system/system/framework/framework.jar
else
cp -rf build/portrom/images/system/system/framework/framework.jar tmp/framework.jar
if [[ -f devices/common/0001-core-framework-Introduce-OplusPropsHookUtils-V6.patch ]]; then
java -jar bin/apktool/APKEditor.jar d -f -i tmp/framework.jar -o tmp/framework -no-dex-debug
pushd tmp/framework
[[ -d .git ]] && rm -rf .git
git init
git config user.name "patchuser"
git config user.email "patchuser@example.com"
git add . > /dev/null 2>&1
git commit -m "Initial smali source" > /dev/null 2>&1
echo "🔧 应用 patch 文件 0001-core-framework-Introduce-OplusPropsHookUtils-V6.patch ..."
git apply ${work_dir}/devices/common/0001-core-framework-Introduce-OplusPropsHookUtils-V6.patch && echo "✅ Patch 应用成功" || echo "❌ Patch 应用失败"
popd
java -jar bin/apktool/APKEditor.jar b -f -i tmp/framework -o build/${app_patch_folder}/patched/framework.jar
cp -rfv build/${app_patch_folder}/patched/framework.jar build/portrom/images/system/system/framework/framework.jar
else
echo "⚠️ 0001-core-framework-Introduce-OplusPropsHookUtils-V6.patch不存在,跳过补丁应用"
fi
fi
# Kaorios Toolbox
if [[ ${portIsOOS} == true ]];then
blue "Implement Kaorios Toolbox"
git clone https://github.com/Wuang26/Kaorios-Toolbox.git tmp/kaorios
wget -O tmp/KaoriosToolbox.apk https://github.com/Wuang26/Kaorios-Toolbox/releases/download/V1.0.9/KaoriosToolbox-V1.0.9.apk
wget -O tmp/privapp_whitelist_com.kousei.kaorios.xml https://github.com/Wuang26/Kaorios-Toolbox/releases/download/V1.0.9/com.kousei.kaorios.xml
cp -rf build/portrom/images/system/system/framework/framework.jar tmp/kaorios/Toolbox-patcher/framework.jar
pushd tmp/kaorios/Toolbox-patcher/
chmod +x scripts/patcher.sh
./scripts/patcher.sh framework.jar
popd
cp -rf tmp/kaorios/Toolbox-patcher/framework_patched.jar build/portrom/images/system/system/framework/framework.jar
mkdir build/portrom/images/system_ext/priv-app/KaoriosToolbox
cp -rf tmp/KaoriosToolbox.apk build/portrom/images/system_ext/priv-app/KaoriosToolbox/
cp -rf tmp/privapp_whitelist_com.kousei.kaorios.xml build/portrom/images/system_ext/etc/permissions/
chmod 755 build/portrom/images/system_ext/priv-app/KaoriosToolbox
chmod 644 build/portrom/images/system_ext/etc/permissions/privapp_whitelist_com.kousei.kaorios.xml
chmod 644 build/portrom/images/system_ext/priv-app/KaoriosToolbox/KaoriosToolbox.apk
echo "# Kaorios Toolbox required props" >> build/portrom/images/system/system/build.prop
echo "persist.sys.kaorios=kousei" >> build/portrom/images/system/system/build.prop
echo "ro.control_privapp_permissions=" >> build/portrom/images/system/system/build.prop
fi
targetOplusService=$(find build/portrom/images/ -name "oplus-services.jar")
if [[ -f build/${app_patch_folder}/patched/oplus-services.jar ]];then
blue "复制已经处理过的oplus-services.jar"
cp -rfv build/${app_patch_folder}/patched/oplus-services.jar $targetOplusService
elif [[ -f $targetOplusService ]];then
blue "Removing GSM Restriction"
cp -rf $targetOplusService tmp/$(basename $targetOplusService).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetOplusService -o tmp/OplusService
targetSmali=$(find tmp -type f -name "OplusBgSceneManager.smali")
python3 bin/patchmethod.py $targetSmali "-isGmsRestricted"
java -jar bin/apktool/APKEditor.jar b -f -i tmp/OplusService -o build/${app_patch_folder}/patched/oplus-services.jar
cp -rfv build/${app_patch_folder}/patched/oplus-services.jar $targetOplusService
fi
if [[ ${base_device_family} == "OPSM8250" ]] || [[ ${base_device_family} == "OPSM8350" ]]; then
blue "修复ColorOS15/OxygenOS15 人脸识解锁问题" "COS15/OOS15: Fix Face Unlock for SM8250/8350"
#pushd tmp/services
#patch -p1 < ${work_dir}/devices/${base_product_device}/0001-face-unlock-fix-for-op8t.patch
#popd
if [[ -f devices/common/face_unlock_fix_common.zip ]];then
rm -rf build/portrom/images/vendor/overlay/*
unzip -o devices/common/face_unlock_fix_common.zip -d ${work_dir}/build/portrom/images/
fi
if [[ -f $old_face_unlock_app ]]; then
unzip -o ${work_dir}/devices/${base_product_device}/face_unlock_fix.zip -d ${work_dir}/build/portrom/images/
rm -rf build/portrom/images/odm/lib/vendor.oneplus.faceunlock.hal@1.0.so
rm -rf build/portrom/images/odm/bin/hw/vendor.oneplus.faceunlock.hal@1.0-service
rm -rf build/portrom/images/odm/lib/vendor.oneplus.faceunlock.hal-V1-ndk_platform.so
rm -rf build/portrom/images/odm/etc/vintf/manifest/manifest_opfaceunlock.xml
rm -rf build/portrom/images/odm/etc/init/vendor.oneplus.faceunlock.hal@1.0-service.rc
rm -rf build/portrom/images/odm/lib64/vendor.oneplus.faceunlock.hal@1.0.so
rm -rf build/portrom/images/odm/lib64/vendor.oneplus.faceunlock.hal-V1-ndk_platform.so
fi
fi
if [[ ${base_android_version} == 13 ]] && [[ ${port_android_version} == 14 ]];then
if [[ -f devices/common/a13_base_fix.zip ]];then
unzip -o devices/common/a13_base_fix.zip -d ${work_dir}/build/portrom/images/
rm -rfv build/portrom/images/odm/bin/hw/vendor.oplus.hardware.charger@1.0-service \
build/portrom/images/odm/bin/hw/vendor.oplus.hardware.wifi@1.1-service \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.charger@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.felica@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.midas@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.wifi@1.1-service-qcom.rc \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_charger.xml \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_felica.xml \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_midas.xml \
build/portrom/images/odm/etc/vintf/manifest/oplus_wifi_service_device.xml \
build/portrom/images/odm/framework/vendor.oplus.hardware.wifi-V1.1-java.jar \
build/portrom/images/odm/lib64/vendor.oplus.hardware.felica@1.0-impl.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.felica@1.0.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.wifi@1.1.so \
build/portrom/images/odm/overlay/CarrierConfigOverlay.*.apk
fi
fi
if [[ ${port_android_version} -ge 15 ]]; then
if [[ ${base_device_family} == "OPSM8250" ]] && [[ ${base_android_version} != 13 ]];then
unzip -o devices/common/ril_fix_sm8250.zip -d ${work_dir}/build/portrom/images/
rm -rf build/portrom/images/odm/lib/libmindroid-app.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.subsys_radio-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.subsys-V1-ndk_platform.so
elif [[ ${base_device_family} == "OPSM8350" ]];then
unzip -o devices/common/ril_fix_sm8350.zip -d ${work_dir}/build/portrom/images/
rm -rf build/portrom/images/odm/lib/libmindroid-app.so \
build/portrom/images/odm/lib/libmindroid-framework.so \
build/portrom/images/odm/lib/vendor.oplus.hardware.subsys_radio-V1-ndk_platform.so \
build/portrom/images/odm/lib/vendor.oplus.hardware.subsys-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.subsys_radio-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.subsys-V1-ndk_platform.so
fi
if [[ ${base_android_version} == 14 ]]; then
charger_v3=$(find build/portrom/images/odm/bin/hw/ -type f -name "vendor.oplus.hardware.charger-V3-service")
if [[ -f $charger_v3 ]];then
unzip -o devices/common/charger-v6-update.zip -d ${work_dir}/build/portrom/images/
rm -rf build/portrom/images/odm/bin/hw/vendor.oplus.hardware.charger-V3-service \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.charger-V3-service.rc \
build/portrom/images/odm/lib/vendor.oplus.hardware.charger-V3-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.charger-V3-ndk_platform.so
fi
elif [[ ${base_android_version} == 13 ]];then
#Ril Fix
unzip -o devices/common/ril_fix_a13_to_a15.zip -d ${work_dir}/build/portrom/images/
#Ril Fix for OxygenOS firmware (IN2013/IN2023)
if ! grep -q "persist.vendor.radio.virtualcomm" build/portrom/images/odm/build.prop;then
echo "persist.vendor.radio.virtualcomm=1" >> build/portrom/images/odm/build.prop
fi
rm -rf build/portrom/images/odm/bin/hw/vendor.oplus.hardware.charger@1.0-service \
build/portrom/images/odm/bin/hw/vendor.oplus.hardware.wifi@1.1-service \
build/portrom/images/odm/etc/init/vendor.oneplus.faceunlock.hal@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.charger@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.felica@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.midas@1.0-service.rc \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.wifi@1.1-service-qcom.rc \
build/portrom/images/odm/etc/vintf/manifest/manifest_opfaceunlock.xml \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_charger.xml \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_cryptoeng_hidl.xml \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_felica.xml \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_midas.xml \
build/portrom/images/odm/etc/vintf/manifest/oplus_wifi_service_device.xml \
build/portrom/images/odm/framework/vendor.oplus.hardware.wifi-V1.1-java.jar \
build/portrom/images/odm/lib/vendor.oneplus.faceunlock.hal@1.0.so \
build/portrom/images/odm/lib/vendor.oneplus.faceunlock.hal-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oneplus.faceunlock.hal@1.0.so \
build/portrom/images/odm/lib64/vendor.oneplus.faceunlock.hal-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.felica@1.0-impl.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.felica@1.0.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.subsys_radio-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.subsys-V1-ndk_platform.so \
build/portrom/images/odm/lib64/vendor.oplus.hardware.wifi@1.1.so
#Nfc Fix
unzip -o devices/common/nfc_fix_for_a13.zip -d ${work_dir}/build/portrom/images/
rm -rf build/portrom/images/odm/bin/hw/vendor.oplus.hardware.nfc@1.0-service \
build/portrom/images/odm/etc/init/vendor.oplus.hardware.nfc@1.0-service.rc \
build/portrom/images/odm/etc/vintf/manifest/manifest_oplus_nfc.xml \
build/portrom/images/odm/lib/vendor.oplus.hardware.nfc@1.0.so
if [[ -f devices/common/cryptoeng_fix_a13.zip ]];then
# Fix Privacy related features(App lock、App hide)
unzip -o devices/common/cryptoeng_fix_a13.zip -d ${work_dir}/build/portrom/images/
fi
fi
fi
if [[ ! -f build/portrom/images/vendor/lib64/vendor.oplus.hardware.radio-V2-ndk_platform.so ]] && [[ ${base_device_family} == "OPSM8350" ]];then
blue "Fixing RIL..."
unzip -o devices/common/ril_fix_A16_SM8350.zip -d ${work_dir}/build/portrom/images/vendor/
rm -rf build/portrom/images/vendor/*/vendor.oplus.hardware.radio-V1-ndk_platform.so
fi
echo "ro.surface_flinger.game_default_frame_rate_override=120" >> build/portrom/images/vendor/default.prop
#Unlock AI Call
#targetAICallAssistant=$(find build/portrom/images/ -name "HeyTapSpeechAssist.apk")
if [[ -f build/${app_patch_folder}/patched/HeyTapSpeechAssist.apk ]]; then
blue "复制已经处理过的HeyTapSpeechAssist.apk"
cp -rfv build/${app_patch_folder}/patched/HeyTapSpeechAssist.apk $targetAICallAssistant
elif [[ -f $targetAICallAssistant ]];then
blue "Unlock AI Call"
cp -rf $targetAICallAssistant tmp/$(basename $targetAICallAssistant).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetAICallAssistant -o tmp/HeyTapSpeechAssist $extra_args
targetSmali=$(find tmp -type f -name "AiCallCommonBean.smali")
python3 bin/patchmethod_v2.py $targetSmali getSupportAiCall -return true
find tmp/HeyTapSpeechAssist -type f -name "*.smali" -exec sed -i "s/sget-object \([vp][0-9]\+\), Landroid\/os\/Build;->MODEL:Ljava\/lang\/String;/const-string \1, \"PLG110\"/g" {} +
java -jar bin/apktool/APKEditor.jar b -f -i tmp/HeyTapSpeechAssist -o build/${app_patch_folder}/patched/HeyTapSpeechAssist.apk $extra_args
cp -rfv build/${app_patch_folder}/patched/HeyTapSpeechAssist.apk $targetAICallAssistant
fi
# patch_smali_with_apktool "HeyTapSpeechAssist.apk" "com/heytap/speechassist/aicall/setting/config/AiCallCommonBean.smali" ".method public final getSupportAiCall()Z/,/.end method" ".method public final getSupportAiCall()Z\n\t.locals 1\n\tconst\/4 v0, 0x1\n\treturn v0\n.end method" "regex"
ota_patched=false
if [[ $regionmark == "CN" ]];then
cp -rf devices/common/OTA_CN.apk build/portrom/images/system_ext/app/OTA/OTA.apk && ota_patched=true
else
cp -rf devices/common/OTA_IN.apk build/portrom/images/system_ext/app/OTA/OTA.apk && ota_patched=true
fi
if [[ $ota_patched == "false" ]];then
# Remove OTA dm-verity
targetOTA=$(find build/portrom/images/ -name "OTA.apk")
if [[ -f build/${app_patch_folder}/patched/OTA.apk ]]; then
blue "复制已经处理过的OTA.apk"
cp -rfv build/${app_patch_folder}/patched/OTA.apk $targetOTA
elif [[ -f $targetOTA ]];then
blue "Removing OTA dm-verity"
cp -rf $targetOTA tmp/$(basename $targetOTA).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetOTA -o tmp/OTA $extra_args
targetSmali=$(find tmp -type f -path "*/com/oplus/common/a.smali")
python3 bin/patchmethod_v2.py -d tmp/OTA -k ro.boot.vbmeta.device_state locked -return false
java -jar bin/apktool/APKEditor.jar b -f -i tmp/OTA -o build/${app_patch_folder}/patched/OTA.apk $extra_args
cp -rfv build/${app_patch_folder}/patched/OTA.apk $targetOTA
fi
fi
EXTENDED_MODELS=("PJF110" "PEEM00" "PEDM00" "LE2120" "LE2121" "LE2123" "KB2000" "KB2001" "KB2005" "KB2003" "LE2110" "LE2111" "LE2112" "LE2113" "IN2010" "IN2011" "IN2012" "IN2013" "IN2020" "IN2021" "IN2022" "IN2023")
targetAIUnit=$(find build/portrom/images/ -name "AIUnit.apk")
MODEL=PLG110
#PKZ110 Reno 14 Pro
#CPH2723 OnePlus 13s
#CPH2671 #Oppo Find N5 Global
#CPH2749 OnePlus 15
[[ $regionmark != CN ]] && MODEL=CPH2745
if [[ -f build/${app_patch_folder}/patched/AIUnit.apk ]]; then
blue "复制已经处理过的OTA.apk"
cp -rfv build/${app_patch_folder}/patched/AIUnit.apk $targetAIUnit
elif [[ -f $targetAIUnit ]];then
blue "Unlock High-End AI features, Device Model: $MODEL"
cp -rf $targetAIUnit tmp/$(basename $targetAIUnit).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetAIUnit -o tmp/AIUnit $extra_args
find tmp/AIUnit -type f -name "*.smali" -exec sed -i "s/sget-object \([vp][0-9]\+\), Landroid\/os\/Build;->MODEL:Ljava\/lang\/String;/const-string \1, \"$MODEL\"/g" {} +
targetSmali=$(find tmp -type f -name "UnitConfig.smali")
python3 bin/patchmethod_v2.py $targetSmali isAllWhiteConditionMatch
python3 bin/patchmethod_v2.py $targetSmali isWhiteConditionsMatch
python3 bin/patchmethod_v2.py $targetSmali isSupport
unit_config_list=$(find tmp/AIUnit -type f -name "unit_config_list.json")
jq --arg models_str "${EXTENDED_MODELS[*]}" '
# 定义数组变量
($models_str | split(" ")) as $new_models
|
# 开始对输入 JSON 数组执行 map
map(
if has("whiteModels") and (.whiteModels | type) == "string" then
.whiteModels as $current |
if $current == "" then
.whiteModels = ($new_models | join(","))
else
($current | split(",")) as $existing_models |
($new_models | map(select(. as $m | $existing_models | index($m) == null))) as $unique_models |
if ($unique_models | length) > 0 then
.whiteModels = $current + "," + ($unique_models | join(","))
else . end
end
else . end
|
if has("minAndroidApi") then .minAndroidApi = 30 else . end
)
' $unit_config_list > ${unit_config_list}.bak && mv ${unit_config_list}.bak ${unit_config_list}
java -jar bin/apktool/APKEditor.jar b -f -i tmp/AIUnit -o build/${app_patch_folder}/patched/AIUnit.apk $extra_args
cp -rfv build/${app_patch_folder}/patched/AIUnit.apk $targetAIUnit
fi
if [[ $port_android_version == 16 ]] && [[ $base_android_version -lt 15 ]] ;then
# workaround fix AI Eraser
cp build/portrom/images/odm/lib64/libaiboost.so build/portrom/images/my_product/lib64/libaiboost.so
# sed -i 's|^/odm/lib64/libaiboost\.so.*$|/odm/lib64/libaiboost\.so u:object_r:same_process_hal_file:s0|' build/portrom/images/config/odm_file_contexts
# echo "/(vendor|odm)/lib(64)?/libaiboost\.so u:object_r:same_process_hal_file:s0" >> build/portrom/images/vendor/etc/selinux/vendor_file_contexts
fi
if [[ -f devices/common/xeutoolbox.zip ]] && [[ $base_android_version -lt 15 ]] && [[ ${portIsColorOSGlobal} != true ]];then
blue "Integrated Xiami EU xeutoolbox"
# this causes OOS/Cos 16.0.1 boot into bootloader
#python3 bin/insert_selinux_policy.py build/portrom/images/system_ext/etc/selinux/system_ext_sepolicy.cil --config ${work_dir}/devices/common/xeu_toolbox_policy.json
#echo "/system_ext/xbin/xeu_toolbox u:object_r:xeu_toolbox_exec:s0" >> build/portrom/images/system_ext/etc/selinux/system_ext_file_contexts
echo "/system_ext/xbin/xeu_toolbox u:object_r:toolbox_exec:s0" >> build/portrom/images/config/system_ext_file_contexts
echo "/system_ext/xbin/xeu_toolbox u:object_r:toolbox_exec:s0" >> build/portrom/images/system_ext/etc/selinux/system_ext_file_contexts
echo "(allow init toolbox_exec (file ((execute_no_trans))))" >> build/portrom/images/system_ext/etc/selinux/system_ext_sepolicy.cil
unzip -o devices/common/xeutoolbox.zip -d build/portrom/images/
elif [[ $base_android_version -lt 15 ]];then
targetGallery=$(find build/portrom/images/ -name "OppoGallery2.apk")
if [[ -f build/${app_patch_folder}/patched/OppoGallery2.apk ]]; then
blue "复制已经处理过的OppoGallery2"
cp -rfv build/${app_patch_folder}/patched/OppoGallery2.apk $targetGallery
elif [[ -f $targetGallery ]];then
blue "Unlock AI Editor"
cp -rf $targetGallery tmp/$(basename $targetGallery).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetGallery -o tmp/Gallery $extra_args
python3 bin/patchmethod_v2.py -d tmp/Gallery -k "const-string.*\"ro.product.first_api_level\"" -hook " const/16 reg, 0x22"
java -jar bin/apktool/APKEditor.jar b -f -i tmp/Gallery -o build/${app_patch_folder}/patched/OppoGallery2.apk $extra_args
cp -rfv build/${app_patch_folder}/patched/OppoGallery2.apk $targetGallery
fi
fi
if [[ ${base_device_family} == "OPSM8250" ]] || [[ ${base_device_family} == "OPSM8350" ]];then
# Patch Battery Health Maximum capacity
targetBattery=$(find build/portrom/images/ -name "Battery.apk")
if [[ -f build/${app_patch_folder}/patched/Battery.apk ]]; then
blue "复制已经处理过的Battery"
cp -rfv build/${app_patch_folder}/patched/Battery.apk $targetBattery
elif [[ -f $targetBattery ]];then
blue "Patch Battery Health Maximum capacity"
cp -rf $targetBattery tmp/$(basename $targetBattery).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetBattery -o tmp/Battery $extra_args
python3 bin/patchmethod_v2.py -d tmp/Battery/ -k "getUIsohValue" -m devices/common/patch_battery_soh.txt
java -jar bin/apktool/APKEditor.jar b -f -i tmp/Battery -o build/${app_patch_folder}/patched/Battery.apk $extra_args
cp -rfv build/${app_patch_folder}/patched/Battery.apk $targetBattery
fi
fi
targetSettings=$(find build/portrom/images/ -name "Settings.apk")
if [[ ${regionmark} != "CN" ]] && [[ ${base_product_model} != "IN20*" ]];then
if [[ -f $targetSettings ]];then
blue "Charging info in Settings"
cp -rf $targetSettings tmp/$(basename $targetSettings).bak
java -jar bin/apktool/APKEditor.jar d -f -i $targetSettings -o tmp/Settings $extra_args
targetSmali=$(find tmp -type f -name "DeviceChargeInfoController.smali")
python3 bin/patchmethod_v2.py $targetSmali isPreferenceSupport
java -jar bin/apktool/APKEditor.jar b -f -i tmp/Settings -o $targetSettings $extra_args