-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcustomize.sh
1435 lines (1367 loc) · 39 KB
/
customize.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
# space
ui_print " "
# var
UID=`id -u`
[ ! "$UID" ] && UID=0
FIRARCH=`grep_get_prop ro.bionic.arch`
SECARCH=`grep_get_prop ro.bionic.2nd_arch`
ABILIST=`grep_get_prop ro.product.cpu.abilist`
if [ ! "$ABILIST" ]; then
ABILIST=`grep_get_prop ro.system.product.cpu.abilist`
fi
if [ "$FIRARCH" == arm64 ]\
&& ! echo "$ABILIST" | grep -q arm64-v8a; then
if [ "$ABILIST" ]; then
ABILIST="$ABILIST,arm64-v8a"
else
ABILIST=arm64-v8a
fi
fi
if [ "$FIRARCH" == x64 ]\
&& ! echo "$ABILIST" | grep -q x86_64; then
if [ "$ABILIST" ]; then
ABILIST="$ABILIST,x86_64"
else
ABILIST=x86_64
fi
fi
if [ "$SECARCH" == arm ]\
&& ! echo "$ABILIST" | grep -q armeabi; then
if [ "$ABILIST" ]; then
ABILIST="$ABILIST,armeabi"
else
ABILIST=armeabi
fi
fi
if [ "$SECARCH" == arm ]\
&& ! echo "$ABILIST" | grep -q armeabi-v7a; then
if [ "$ABILIST" ]; then
ABILIST="$ABILIST,armeabi-v7a"
else
ABILIST=armeabi-v7a
fi
fi
if [ "$SECARCH" == x86 ]\
&& ! echo "$ABILIST" | grep -q x86; then
if [ "$ABILIST" ]; then
ABILIST="$ABILIST,x86"
else
ABILIST=x86
fi
fi
ABILIST32=`grep_get_prop ro.product.cpu.abilist32`
if [ ! "$ABILIST32" ]; then
ABILIST32=`grep_get_prop ro.system.product.cpu.abilist32`
fi
if [ "$SECARCH" == arm ]\
&& ! echo "$ABILIST32" | grep -q armeabi; then
if [ "$ABILIST32" ]; then
ABILIST32="$ABILIST32,armeabi"
else
ABILIST32=armeabi
fi
fi
if [ "$SECARCH" == arm ]\
&& ! echo "$ABILIST32" | grep -q armeabi-v7a; then
if [ "$ABILIST32" ]; then
ABILIST32="$ABILIST32,armeabi-v7a"
else
ABILIST32=armeabi-v7a
fi
fi
if [ "$SECARCH" == x86 ]\
&& ! echo "$ABILIST32" | grep -q x86; then
if [ "$ABILIST32" ]; then
ABILIST32="$ABILIST32,x86"
else
ABILIST32=x86
fi
fi
if [ ! "$ABILIST32" ]; then
[ -f /system/lib/libandroid.so ] && ABILIST32=true
fi
# log
if [ "$BOOTMODE" != true ]; then
FILE=/data/media/"$UID"/$MODID\_recovery.log
ui_print "- Log will be saved at $FILE"
exec 2>$FILE
ui_print " "
fi
# optionals
OPTIONALS=/data/media/"$UID"/optionals.prop
if [ ! -f $OPTIONALS ]; then
touch $OPTIONALS
fi
# debug
if [ "`grep_prop debug.log $OPTIONALS`" == 1 ]; then
ui_print "- The install log will contain detailed information"
set -x
ui_print " "
fi
# recovery
if [ "$BOOTMODE" != true ]; then
MODPATH_UPDATE=`echo $MODPATH | sed 's|modules/|modules_update/|g'`
rm -f $MODPATH/update
rm -rf $MODPATH_UPDATE
fi
# run
. $MODPATH/function.sh
# info
MODVER=`grep_prop version $MODPATH/module.prop`
MODVERCODE=`grep_prop versionCode $MODPATH/module.prop`
ui_print " ID=$MODID"
ui_print " Version=$MODVER"
ui_print " VersionCode=$MODVERCODE"
if [ "$KSU" == true ]; then
ui_print " KSUVersion=$KSU_VER"
ui_print " KSUVersionCode=$KSU_VER_CODE"
ui_print " KSUKernelVersionCode=$KSU_KERNEL_VER_CODE"
sed -i 's|#k||g' $MODPATH/post-fs-data.sh
else
ui_print " MagiskVersion=$MAGISK_VER"
ui_print " MagiskVersionCode=$MAGISK_VER_CODE"
fi
ui_print " "
# dolby
if [ "`grep_prop misound.dolby $OPTIONALS`" == 0 ]; then
DOLBY=false
else
DOLBY=true
fi
# architecture
if [ "$ABILIST" ]; then
ui_print "- $ABILIST architecture"
ui_print " "
fi
NAME=arm64-v8a
NAME2=armeabi-v7a
if ! echo "$ABILIST" | grep -Eq "$NAME|$NAME2"; then
if [ "$BOOTMODE" == true ]; then
ui_print "! This ROM doesn't support $NAME"
ui_print " nor $NAME2 architecture"
else
ui_print "! This Recovery doesn't support $NAME"
ui_print " nor $NAME2 architecture"
ui_print " Try to install via Magisk app instead"
fi
ui_print " Mi Sound EQ will not work"
ui_print " except this ROM has built-in misoundfx"
ui_print " "
fi
if ! echo "$ABILIST" | grep -q $NAME; then
rm -rf `find $MODPATH/system -type d -name *64*`
if [ $DOLBY == true ]; then
ui_print "! Unsupported Dolby Atmos"
ui_print " "
fi
DOLBY=false
if [ "$BOOTMODE" != true ]; then
ui_print "! This Recovery doesn't support $NAME architecture"
ui_print " Try to install via Magisk app instead"
ui_print " "
fi
fi
if ! echo "$ABILIST" | grep -q $NAME2; then
rm -rf $MODPATH/system*/lib\
$MODPATH/system*/vendor/lib
if [ "$BOOTMODE" != true ]; then
ui_print "! This Recovery doesn't support $NAME2 architecture"
ui_print " Try to install via Magisk app instead"
ui_print " "
fi
fi
# sdk
NUM=26
if [ "$API" -lt $NUM ]; then
ui_print "! Unsupported SDK $API."
ui_print " You have to upgrade your Android version"
ui_print " at least SDK $NUM to use this module."
abort
else
ui_print "- SDK $API"
if [ $DOLBY == true ] && [ "$API" -lt 30 ]; then
ui_print " ! Unsupported Dolby Atmos."
DOLBY=false
fi
ui_print " "
fi
# miuicore
if [ ! -d /data/adb/modules/MiuiCore ]; then
ui_print "! Miui Core Magisk Module is not installed."
ui_print " MiSound app will not be working without"
ui_print " Miui Core Magisk Module except you are in Miui ROM!"
ui_print " "
else
rm -f /data/adb/modules/MiuiCore/remove
rm -f /data/adb/modules/MiuiCore/disable
fi
# recovery
mount_partitions_in_recovery
# magisk
magisk_setup
# path
SYSTEM=`realpath $MIRROR/system`
VENDOR=`realpath $MIRROR/vendor`
PRODUCT=`realpath $MIRROR/product`
SYSTEM_EXT=`realpath $MIRROR/system_ext`
ODM=`realpath $MIRROR/odm`
MY_PRODUCT=`realpath $MIRROR/my_product`
# create
if [ $DOLBY == true ]; then
mkdir -p $MODPATH/system_dolby/etc/vintf
NAMES="vendor.dolby.hardware.dms@1.0-service
vendor.dolby_sp.hardware.dmssp@2.0-service
vendor.dolby_v3_6.hardware.dms360@2.0-service"
for NAME in $NAMES; do
if [ -f $VENDOR/bin/hw/$NAME ]; then
touch $MODPATH/system_dolby/vendor/bin/hw/$NAME
fi
done
if [ -d $ODM/bin/hw ] || [ -d $VENDOR/odm/bin/hw ]; then
mkdir -p $MODPATH/system_dolby/vendor/odm/bin/hw
fi
NAMES="vendor.dolby.hardware.dms@1.0-service
vendor.dolby.hardware.dms@2.0-service
vendor.dolby_sp.hardware.dmssp@2.0-service
vendor.dolby_v3_6.hardware.dms360@2.0-service"
for NAME in $NAMES; do
if [ -f $ODM/bin/hw/$NAME ]\
|| [ -f $VENDOR/odm/bin/hw/$NAME ]; then
touch $MODPATH/system_dolby/vendor/odm/bin/hw/$NAME
fi
done
fi
# check
if [ $DOLBY == true ]\
&& [ "`grep_prop dolby.mod $OPTIONALS`" != 1 ]; then
ui_print "- Checking in-built Dolby apps..."
FILE=`find /system/app /system/priv-app /product/app\
/product/priv-app /product/preinstall /system_ext/app\
/system_ext/priv-app /vendor/app /vendor/euclid/product/app\
-type f -name XiaomyDolby.apk -o -name DolbyManager.apk`
if [ "$FILE" ]; then
ui_print " Detected"
ui_print "$FILE"
ui_print " You need to use dolby.mod=1 to use the Dolby Atmos,"
ui_print " otherwise the Dolby Atmos will not work. Please check"
ui_print " Optionals at README."
fi
ui_print " "
fi
# check
if [ $DOLBY == true ]; then
FILE=/bin/hw/vendor.dolby.media.c2@1.0-service
if [ -f $SYSTEM$FILE ] || [ -f $VENDOR$FILE ]\
|| [ -f $ODM$FILE ] || [ -f $SYSTEM_EXT$FILE ]\
|| [ -f $PRODUCT$FILE ]; then
ui_print "! Dolby Atmos maybe conflicting with your"
ui_print " $FILE"
ui_print " causes your internal storage mount failure"
ui_print " "
fi
fi
# .aml.sh
mv -f $MODPATH/aml.sh $MODPATH/.aml.sh
# function
check_function_2() {
if [ -f $MODPATH/system_support$DIR/$LIB ]; then
ui_print "- Checking"
ui_print "$NAME"
ui_print " function at"
ui_print "$FILE"
ui_print " Please wait..."
if ! grep -q $NAME $FILE; then
ui_print " Function not found."
ui_print " Replaces /system$DIR/$LIB systemlessly."
mv -f $MODPATH/system_support$DIR/$LIB $MODPATH/system$DIR
[ "$MES" ] && ui_print "$MES"
fi
ui_print " "
fi
}
check_function() {
if [ -d $MODPATH/system_support/vendor$DIR/hw ]; then
ui_print "- Checking"
ui_print "$NAME"
ui_print " function at"
ui_print "$FILE"
ui_print " Please wait..."
if grep -q $NAME $FILE; then
ui_print " "
else
ui_print " Function not found."
ui_print " Replaces /vendor$DIR/hw/*audio*.so systemlessly."
mv -f $MODPATH/system_support/vendor$DIR/hw $MODPATH/system/vendor$DIR
[ "$MES" ] && ui_print "$MES"
ui_print " "
fi
fi
}
# check
if [ $DOLBY == true ]; then
ui_print "- Activating Dolby Atmos..."
ui_print " "
NAME=_ZN7android23sp_report_stack_pointerEv
if [ "$IS64BIT" == true ]; then
DIR=/lib64
FILE=$VENDOR$DIR/hw/*audio*.so
check_function
fi
if [ "$ABILIST32" ]; then
DIR=/lib
FILE=$VENDOR$DIR/hw/*audio*.so
check_function
fi
NAME=_ZN7android8hardware23getOrCreateCachedBinderEPNS_4hidl4base4V1_05IBaseE
DES=vendor.dolby.hardware.dms@2.0.so
LIB=libhidlbase.so
if [ "$IS64BIT" == true ]; then
DIR=/lib64
LISTS=`strings $MODPATH/system_dolby/vendor$DIR/$DES | grep ^lib | grep .so`
FILE=`for LIST in $LISTS; do echo $SYSTEM$DIR/$LIST; done`
check_function_2
fi
if [ "$ABILIST32" ]; then
DIR=/lib
LISTS=`strings $MODPATH/system_dolby/vendor$DIR/$DES | grep ^lib | grep .so`
FILE=`for LIST in $LISTS; do echo $SYSTEM$DIR/$LIST; done`
check_function_2
fi
MODNAME2='Mi Sound and Dolby Atmos Redmi K40'
sed -i "s|$MODNAME|$MODNAME2|g" $MODPATH/module.prop
MODNAME=$MODNAME2
cp -rf $MODPATH/system_dolby/* $MODPATH/system
sed -i 's|ro.vendor.audio.dolby.dax.support false|ro.vendor.audio.dolby.dax.support true|g' $MODPATH/service.sh
if [ "`grep_prop dolby.rhode $OPTIONALS`" == 1 ]; then
ui_print "- Using libswdap.so from Moto G52 (rhode)"
cp -rf $MODPATH/system_rhode/* $MODPATH/system
sed -i 's|resetprop -n ro.product.brand|#resetprop -n ro.product.brand|g' $MODPATH/service.sh
sed -i 's|resetprop -n ro.product.device|#resetprop -n ro.product.device|g' $MODPATH/service.sh
sed -i 's|resetprop -n ro.product.manufacturer|#resetprop -n ro.product.manufacturer|g' $MODPATH/service.sh
sed -i 's|#ddap_proxy|dap|g' $MODPATH/.aml.sh
ui_print " "
else
sed -i 's|#ddap_proxy|dap_proxy|g' $MODPATH/.aml.sh
fi
sed -i 's|#d||g' $MODPATH/.aml.sh
sed -i 's|#d||g' $MODPATH/*.sh
fi
# check
FILE=$VENDOR/lib/soundfx/libmisoundfx.so
FILE2=$ODM/lib/soundfx/libmisoundfx.so
FILE3=$VENDOR/lib64/soundfx/libmisoundfx.so
FILE4=$ODM/lib64/soundfx/libmisoundfx.so
if [ -f $FILE ] || [ -f $FILE2 ] || [ -f $FILE3 ]\
|| [ -f $FILE4 ]; then
ui_print "- Built-in misoundfx is detected."
rm -f `find $MODPATH/system/vendor -type f -name *misound*`
ui_print " "
else
if [ ! -e /dev/socket/audio_hw_socket ]; then
ui_print "! Unsupported audio_hw_socket."
ui_print " Mi Sound EQ will not be working with this device"
if [ $DOLBY == true ]; then
ui_print " but you can still use the Dolby Atmos EQ."
fi
ui_print " "
fi
NAME=_ZN7android23sp_report_stack_pointerEv
if [ "$IS64BIT" == true ]; then
DIR=/lib64
FILE=$VENDOR$DIR/hw/*audio*.so
check_function
fi
if [ "$ABILIST32" ]; then
DIR=/lib
FILE=$VENDOR$DIR/hw/*audio*.so
check_function
fi
fi
# sepolicy
FILE=$MODPATH/sepolicy.rule
DES=$MODPATH/sepolicy.pfsd
if [ "`grep_prop sepolicy.sh $OPTIONALS`" == 1 ]\
&& [ -f $FILE ]; then
mv -f $FILE $DES
fi
# mod ui
if [ "`grep_prop mod.ui $OPTIONALS`" == 1 ]; then
APP=MiSound
FILE=/data/media/"$UID"/$APP.apk
DIR=`find $MODPATH/system -type d -name $APP`
ui_print "- Using modified UI apk..."
if [ -f $FILE ]; then
cp -f $FILE $DIR
chmod 0644 $DIR/$APP.apk
ui_print " Applied"
else
ui_print " ! There is no $FILE file."
ui_print " Please place the apk to your internal storage first"
ui_print " and reflash!"
fi
ui_print " "
fi
# function
extract_lib() {
for APP in $APPS; do
FILE=`find $MODPATH/system -type f -name $APP.apk`
if [ -f `dirname $FILE`/extract ]; then
ui_print "- Extracting..."
DIR=`dirname $FILE`/lib/"$ARCHLIB"
mkdir -p $DIR
rm -rf $TMPDIR/*
DES=lib/"$ABILIB"/*
unzip -d $TMPDIR -o $FILE $DES
cp -f $TMPDIR/$DES $DIR
ui_print " "
fi
done
}
# extract
APPS="`ls $MODPATH/system/priv-app`
`ls $MODPATH/system/app`"
ARCHLIB=arm64
ABILIB=arm64-v8a
extract_lib
ARCHLIB=arm
if echo "$ABILIST" | grep -q armeabi-v7a; then
ABILIB=armeabi-v7a
extract_lib
elif echo "$ABILIST" | grep -q armeabi; then
ABILIB=armeabi
extract_lib
else
ABILIB=armeabi-v7a
extract_lib
fi
ARCHLIB=x64
ABILIB=x86_64
extract_lib
ARCHLIB=x86
ABILIB=x86
extract_lib
rm -f `find $MODPATH/system -type f -name extract`
# cleaning
ui_print "- Cleaning..."
if [ $DOLBY == true ]; then
PKGS=`cat $MODPATH/package-dolby.txt`
if [ "`grep_prop dolby.mod $OPTIONALS`" == 1 ]; then
rm -f /data/vendor/dolby/dap_sqlite3.db
sed -i 's|dax_sqlite3.db|dap_sqlite3.db|g' $MODPATH/uninstall.sh
else
rm -f /data/vendor/dolby/dax_sqlite3.db
fi
else
PKGS=`cat $MODPATH/package.txt`
fi
if [ "$BOOTMODE" == true ]; then
for PKG in $PKGS; do
FILE=`find /data/app -name *$PKG*`
if [ "$FILE" ]; then
RES=`pm uninstall $PKG 2>/dev/null`
fi
done
fi
rm -rf $MODPATH/system_dolby $MODPATH/system_rhode\
$MODPATH/system_support $MODPATH/unused
remove_sepolicy_rule
ui_print " "
# function
conflict() {
for NAME in $NAMES; do
DIR=/data/adb/modules_update/$NAME
if [ -f $DIR/uninstall.sh ]; then
sh $DIR/uninstall.sh
fi
rm -rf $DIR
DIR=/data/adb/modules/$NAME
rm -f $DIR/update
touch $DIR/remove
FILE=/data/adb/modules/$NAME/uninstall.sh
if [ -f $FILE ]; then
sh $FILE
rm -f $FILE
fi
rm -rf /metadata/magisk/$NAME\
/mnt/vendor/persist/magisk/$NAME\
/persist/magisk/$NAME\
/data/unencrypted/magisk/$NAME\
/cache/magisk/$NAME\
/cust/magisk/$NAME
done
}
conflict_disable() {
for NAME in $NAMES; do
DIR=/data/adb/modules_update/$NAME
touch $DIR/disable
DIR=/data/adb/modules/$NAME
touch $DIR/disable
done
}
# conflict
NAMES=diracmisoundfxRemover
conflict_disable
if [ $DOLBY == true ]; then
if [ "`grep_prop dolby.mod $OPTIONALS`" == 1 ]; then
NAMES="dolbyatmos DolbyAudio DolbyAtmos MotoDolby
DolbyAtmos360 DolbyAtmosSP"
else
NAMES="dolbyatmos DolbyAudio DolbyAtmos MotoDolby
DolbyAtmos360 DolbyAtmosSP dsplus Dolby"
fi
conflict
NAMES=SoundEnhancement
FILE=/data/adb/modules/$NAMES/module.prop
if grep -q 'and Dolby Atmos' $FILE; then
conflict
fi
NAMES=DolbyAtmosSpatialSound
FILE=/data/adb/modules/$NAMES/module.prop
if grep -q 'Dolby Atmos and' $FILE; then
conflict
fi
fi
# function
cleanup() {
if [ -f $DIR/uninstall.sh ]; then
sh $DIR/uninstall.sh
fi
DIR=/data/adb/modules_update/$MODID
if [ -f $DIR/uninstall.sh ]; then
sh $DIR/uninstall.sh
fi
}
# cleanup
DIR=/data/adb/modules/$MODID
FILE=$DIR/module.prop
PREVMODNAME=`grep_prop name $FILE`
if [ "`grep_prop data.cleanup $OPTIONALS`" == 1 ]; then
sed -i 's|^data.cleanup=1|data.cleanup=0|g' $OPTIONALS
ui_print "- Cleaning-up $MODID data..."
cleanup
ui_print " "
elif [ -d $DIR ]\
&& [ "$PREVMODNAME" != "$MODNAME" ]; then
ui_print "- Different module name is detected"
ui_print " Cleaning-up $MODID data..."
cleanup
ui_print " "
fi
# function
permissive_2() {
sed -i 's|#2||g' $MODPATH/post-fs-data.sh
}
permissive() {
FILE=/sys/fs/selinux/enforce
SELINUX=`cat $FILE`
if [ "$SELINUX" == 1 ]; then
if ! setenforce 0; then
echo 0 > $FILE
fi
SELINUX=`cat $FILE`
if [ "$SELINUX" == 1 ]; then
ui_print " Your device can't be turned to Permissive state."
ui_print " Using Magisk Permissive mode instead."
permissive_2
else
if ! setenforce 1; then
echo 1 > $FILE
fi
sed -i 's|#1||g' $MODPATH/post-fs-data.sh
fi
else
sed -i 's|#1||g' $MODPATH/post-fs-data.sh
fi
}
backup() {
if [ ! -f $FILE.orig ] && [ ! -f $FILE.bak ]; then
ui_print "- Checking free space..."
SIZE=`du $FILE | sed "s|$FILE||g"`
SIZE=$(( $SIZE + 1 ))
INFO=`df $FILE`
FREE=`echo "$INFO" | awk 'NR==3{print $3}'`
if [ ! "$FREE" ]; then
FREE=`echo "$INFO" | awk 'NR==2{print $4}'`
fi
ui_print "$INFO"
ui_print " Free space = $FREE KiB"
ui_print " Free space required = $SIZE KiB"
ui_print " "
if [ "$FREE" -ge "$SIZE" ]; then
cp -af $FILE $FILE.orig
if [ -f $FILE.orig ]; then
ui_print "- Created"
ui_print "$FILE.orig"
ui_print " This file will not be restored automatically even you"
ui_print " have uninstalled this module."
else
ui_print "- Failed to create"
ui_print "$FILE.orig"
ui_print " The partition is Read-Only"
fi
ui_print " "
fi
fi
}
patch_manifest() {
if [ -f $FILE ]; then
backup
if [ -f $FILE.orig ] || [ -f $FILE.bak ]; then
ui_print "- Patching"
ui_print "$FILE"
ui_print " directly..."
sed -i '/<manifest/a\
<hal format="hidl">\
<name>vendor.dolby.hardware.dms</name>\
<transport>hwbinder</transport>\
<fqname>@2.0::IDms/default</fqname>\
</hal>' $FILE
ui_print " "
fi
fi
}
eim_dir_warning() {
ui_print "! It seems Magisk early init mount directory is not"
ui_print " activated yet. Please reinstall Magisk via Magisk app"
ui_print " (not via Recovery)."
ui_print " "
}
early_init_mount_dir() {
if echo $MAGISK_VER | grep -Eq 'delta|kitsune'\
&& [ "`grep_prop dolby.skip.early $OPTIONALS`" != 1 ]; then
check_data
get_flags > /dev/null 2>&1
if [ "$BOOTMODE" == true ]; then
if [ "$MAGISK_VER_CODE" -ge 26000 ]; then
PREINITDEVICE=`grep_prop PREINITDEVICE $INTERNALDIR/config`
if [ ! "$PREINITDEVICE" ]; then
eim_dir_warning
fi
fi
if [ -L $MIRROR/early-mount ]; then
EIMDIR=`readlink $MIRROR/early-mount`
[ "${EIMDIR:0:1}" != "/" ] && EIMDIR="$MIRROR/$EIMDIR"
fi
fi
if [ ! "$EIMDIR" ]; then
if ! $ISENCRYPTED; then
EIMDIR=/data/adb/early-mount.d
elif [ -d /data/unencrypted ]\
&& ! grep ' /data ' /proc/mounts | grep -q dm-\
&& grep ' /data ' /proc/mounts | grep -q ext4; then
EIMDIR=/data/unencrypted/early-mount.d
elif grep ' /cache ' /proc/mounts | grep -q ext4; then
EIMDIR=/cache/early-mount.d
elif grep ' /metadata ' /proc/mounts | grep -q ext4; then
EIMDIR=/metadata/early-mount.d
elif grep ' /persist ' /proc/mounts | grep -q ext4; then
EIMDIR=/persist/early-mount.d
elif grep ' /mnt/vendor/persist ' /proc/mounts | grep -q ext4; then
EIMDIR=/mnt/vendor/persist/early-mount.d
elif grep ' /cust ' /proc/mounts | grep -q ext4; then
EIMDIR=/cust/early-mount.d
fi
fi
if [ ! "$EIMDIR" ]\
&& [ "$MAGISK_VER_CODE" -ge 26000 ]; then
if [ -d /data/unencrypted ]\
&& ! grep ' /data ' /proc/mounts | grep -q dm-\
&& grep ' /data ' /proc/mounts | grep -q f2fs; then
EIMDIR=/data/unencrypted/early-mount.d
elif grep ' /cache ' /proc/mounts | grep -q f2fs; then
EIMDIR=/cache/early-mount.d
elif grep ' /metadata ' /proc/mounts | grep -q f2fs; then
EIMDIR=/metadata/early-mount.d
elif grep ' /persist ' /proc/mounts | grep -q f2fs; then
EIMDIR=/persist/early-mount.d
elif grep ' /mnt/vendor/persist ' /proc/mounts | grep -q f2fs; then
EIMDIR=/mnt/vendor/persist/early-mount.d
elif grep ' /cust ' /proc/mounts | grep -q f2fs; then
EIMDIR=/cust/early-mount.d
fi
fi
if [ "$EIMDIR" ]; then
if [ -d ${EIMDIR%/early-mount.d} ]; then
EIM=true
mkdir -p $EIMDIR
ui_print "- Your early init mount directory is"
ui_print " $EIMDIR"
ui_print " Any file stored to this directory will not be deleted"
ui_print " even you have uninstalled this module."
else
EIM=false
ui_print "- Unable to find early init mount directory ${EIMDIR%/early-mount.d}"
fi
ui_print " "
else
EIM=false
ui_print "- Unable to find early init mount directory"
ui_print " "
fi
else
EIM=false
fi
}
eim_cache_warning() {
if echo $EIMDIR | grep -q cache; then
ui_print " Please do not ever wipe your /cache"
ui_print " as long as this module is installed!"
ui_print " If your /cache is wiped for some reasons,"
ui_print " then you need to uninstall this module and reboot first,"
ui_print " then reinstall this module afterwards"
ui_print " to get this module working correctly."
fi
}
patch_manifest_eim() {
if [ $EIM == true ]; then
SRC=$SYSTEM/etc/vintf/manifest.xml
if [ -f $SRC ]; then
DIR=$EIMDIR/system/etc/vintf
DES=$DIR/manifest.xml
mkdir -p $DIR
if [ ! -f $DES ]; then
cp -af $SRC $DIR
fi
if ! grep -A2 vendor.dolby.hardware.dms $DES | grep -q 2.0; then
ui_print "- Patching"
ui_print "$DES"
sed -i '/<manifest/a\
<hal format="hidl">\
<name>vendor.dolby.hardware.dms</name>\
<transport>hwbinder</transport>\
<fqname>@2.0::IDms/default</fqname>\
</hal>' $DES
eim_cache_warning
ui_print " "
fi
else
EIM=false
fi
fi
}
# permissive
if [ "`grep_prop permissive.mode $OPTIONALS`" == 1 ]; then
ui_print "- Using device Permissive mode."
rm -f $MODPATH/sepolicy.rule
permissive
ui_print " "
elif [ "`grep_prop permissive.mode $OPTIONALS`" == 2 ]; then
ui_print "- Using Magisk Permissive mode."
rm -f $MODPATH/sepolicy.rule
permissive_2
ui_print " "
fi
# remount
if [ $DOLBY == true ]; then
remount_rw
fi
# early init mount dir
if [ $DOLBY == true ]; then
early_init_mount_dir
fi
# patch manifest.xml
if [ $DOLBY == true ]; then
FILE="$INTERNALDIR/mirror/*/etc/vintf/manifest.xml
$INTERNALDIR/mirror/*/*/etc/vintf/manifest.xml
/*/etc/vintf/manifest.xml /*/*/etc/vintf/manifest.xml
$INTERNALDIR/mirror/*/etc/vintf/manifest/*.xml
$INTERNALDIR/mirror/*/*/etc/vintf/manifest/*.xml
/*/etc/vintf/manifest/*.xml /*/*/etc/vintf/manifest/*.xml"
if [ "`grep_prop dolby.skip.vendor $OPTIONALS`" != 1 ]\
&& ! grep -A2 vendor.dolby.hardware.dms $FILE | grep -q 2.0; then
FILE=$VENDOR/etc/vintf/manifest.xml
patch_manifest
fi
if [ "`grep_prop dolby.skip.system $OPTIONALS`" != 1 ]\
&& ! grep -A2 vendor.dolby.hardware.dms $FILE | grep -q 2.0; then
FILE=$SYSTEM/etc/vintf/manifest.xml
patch_manifest
fi
if [ "`grep_prop dolby.skip.system_ext $OPTIONALS`" != 1 ]\
&& ! grep -A2 vendor.dolby.hardware.dms $FILE | grep -q 2.0; then
FILE=$SYSTEM_EXT/etc/vintf/manifest.xml
patch_manifest
fi
if ! grep -A2 vendor.dolby.hardware.dms $FILE | grep -q 2.0; then
patch_manifest_eim
if [ $EIM == false ]; then
sed -i 's|#s||g' $MODPATH/service.sh
ui_print "- Using systemless manifest.xml patch."
ui_print " On some ROMs, it causes bugs or even makes bootloop"
ui_print " because not allowed to restart hwservicemanager."
ui_print " You can fix this by using Magisk Delta/Kitsune Mask."
ui_print " "
fi
fi
fi
# remount
if [ $DOLBY == true ]; then
remount_ro
fi
# function
hide_oat() {
for APP in $APPS; do
REPLACE="$REPLACE
`find $MODPATH/system -type d -name $APP | sed "s|$MODPATH||g"`/oat"
done
}
replace_dir() {
if [ -d $DIR ] && [ ! -d $MODPATH$MODDIR ]; then
REPLACE="$REPLACE $MODDIR"
fi
}
hide_app() {
for APP in $APPS; do
DIR=$SYSTEM/app/$APP
MODDIR=/system/app/$APP
replace_dir
DIR=$SYSTEM/priv-app/$APP
MODDIR=/system/priv-app/$APP
replace_dir
DIR=$PRODUCT/app/$APP
MODDIR=/system/product/app/$APP
replace_dir
DIR=$PRODUCT/priv-app/$APP
MODDIR=/system/product/priv-app/$APP
replace_dir
DIR=$MY_PRODUCT/app/$APP
MODDIR=/system/product/app/$APP
replace_dir
DIR=$MY_PRODUCT/priv-app/$APP
MODDIR=/system/product/priv-app/$APP
replace_dir
DIR=$PRODUCT/preinstall/$APP
MODDIR=/system/product/preinstall/$APP
replace_dir
DIR=$SYSTEM_EXT/app/$APP
MODDIR=/system/system_ext/app/$APP
replace_dir
DIR=$SYSTEM_EXT/priv-app/$APP
MODDIR=/system/system_ext/priv-app/$APP
replace_dir
DIR=$VENDOR/app/$APP
MODDIR=/system/vendor/app/$APP
replace_dir
DIR=$VENDOR/euclid/product/app/$APP
MODDIR=/system/vendor/euclid/product/app/$APP
replace_dir
done
}
# hide
APPS="`ls $MODPATH/system/priv-app`
`ls $MODPATH/system/app`"
hide_oat
APPS="$APPS MusicFX"
hide_app
if [ $DOLBY == true ]; then
APPS="DaxUI MotoDolbyDax3 MotoDolbyV3 OPSoundTuner
DolbyAtmos AudioEffectCenter DolbySound"
hide_app
fi
# hide
if [ "`grep_prop hide.parts $OPTIONALS`" == 1 ]; then
APPS="XiaomiParts ZenfoneParts ZenParts GalaxyParts
KharaMeParts DeviceParts PocoParts LineageParts"
ui_print "- Hides Parts app"
hide_app
ui_print " "
fi
# stream mode
FILE=$MODPATH/.aml.sh
PROP=`grep_prop stream.mode $OPTIONALS`
if echo "$PROP" | grep -q m; then
ui_print "- Activating music stream..."
sed -i 's|#m||g' $FILE
sed -i 's|musicstream=|musicstream=true|g' $MODPATH/acdb.conf
sed -i 's|music_stream false|music_stream true|g' $MODPATH/service.sh
ui_print " The sound effect will always be enabled"
ui_print " and cannot be disabled by on/off togglers"
ui_print " "
else
APPS=AudioFX
hide_app
fi
if echo "$PROP" | grep -q r; then
ui_print "- Activating ring stream..."
sed -i 's|#r||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q a; then
ui_print "- Activating alarm stream..."
sed -i 's|#a||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q s; then
ui_print "- Activating system stream..."
sed -i 's|#s||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q v; then
ui_print "- Activating voice_call stream..."
sed -i 's|#v||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q n; then
ui_print "- Activating notification stream..."
sed -i 's|#n||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q b; then
ui_print "- Activating bluetooth_sco stream..."
sed -i 's|#b||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q f; then
ui_print "- Activating dtmf stream..."
sed -i 's|#f||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q e; then
ui_print "- Activating enforced_audible stream..."
sed -i 's|#e||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q y; then
ui_print "- Activating accessibility stream..."
sed -i 's|#y||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q t; then
ui_print "- Activating tts stream..."
sed -i 's|#t||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q i; then
ui_print "- Activating assistant stream..."
sed -i 's|#i||g' $FILE
ui_print " "
fi
if echo "$PROP" | grep -q c; then
ui_print "- Activating call_assistant stream..."
sed -i 's|#c||g' $FILE
ui_print " "
fi
if [ "`grep_prop dolby.game $OPTIONALS`" != 0 ]; then
sed -i 's|#p||g' $FILE
sed -i 's|#g||g' $FILE
sed -i 's|#x||g' $FILE
else
ui_print "- Does not use Dolby/Mi Sound Game patch & rerouting stream"
ui_print " "
fi
# function
dolby_settings() {
FILE=$MODPATH/system/vendor/etc/dolby/dax-default.xml
PROP=`grep_prop dolby.bass $OPTIONALS`
if [ "$PROP" == true ]; then
ui_print "- Changing all bass-enhancer-enable value to true"
sed -i 's|bass-enhancer-enable value="false"|bass-enhancer-enable value="true"|g' $FILE
elif [ "$PROP" == false ]; then