-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustomize.sh
521 lines (478 loc) · 11.7 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
# 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 " "
# sdk
NUM=17
if [ "$API" -lt $NUM ]; then
ui_print "! Unsupported SDK $API. You have to upgrade your"
ui_print " Android version at least SDK $NUM to use this module."
abort
else
ui_print "- SDK $API"
ui_print " "
fi
# recovery
mount_partitions_in_recovery
# architecture
if [ "$ABILIST" ]; then
ui_print "- $ABILIST architecture"
ui_print " "
fi
NAME=arm64-v8a
NAME2=armeabi-v7a
if ! echo "$ABILIST" | grep -q $NAME; then
rm -rf `find $MODPATH/system -type d -name *64*`
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
if [ "$BOOTMODE" == true ]; then
abort "! This ROM doesn't support $NAME2 architecture"
else
ui_print "! This Recovery doesn't support $NAME2 architecture"
ui_print " Try to install via Magisk app instead"
abort
fi
fi
if ! file /*/bin/hw/*hardware*audio* | grep -q 32-bit; then
ui_print "! This module uses 32 bit audio service only"
ui_print " But this ROM uses 64 bit audio service"
abort
fi
# 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`
# sepolicy
FILE=$MODPATH/sepolicy.rule
DES=$MODPATH/sepolicy.pfsd
if [ "`grep_prop sepolicy.sh $OPTIONALS`" == 1 ]\
&& [ -f $FILE ]; then
mv -f $FILE $DES
fi
# .aml.sh
mv -f $MODPATH/aml.sh $MODPATH/.aml.sh
# mod ui
if [ "`grep_prop mod.ui $OPTIONALS`" == 1 ]; then
APP=Atmos
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
# cleaning
ui_print "- Cleaning..."
PKGS=`cat $MODPATH/package.txt`
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
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
}
# 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
}
# 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
# 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
# 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
else
ui_print "- Does not use Dolby Game patch & rerouting stream"
ui_print " "
fi
# directory
if [ "$API" -le 25 ]; then
ui_print "- /vendor/lib*/soundfx is not supported in SDK 25 and bellow"
ui_print " Using /system/lib*/soundfx instead"
cp -rf $MODPATH/system/vendor/lib* $MODPATH/system
rm -rf $MODPATH/system/vendor/lib*
ui_print " "
fi
# settings
FILE=$MODPATH/system/etc/dlb-default.xml
sed -i 's|dvle=\[1\]|dvle=\[0\]|g' $FILE
# fix sensor
if [ "`grep_prop dolby.fix.sensor $OPTIONALS`" == 1 ]; then
ui_print "- Fixing sensors issue"
ui_print " This causes bootloop in some ROMs"
sed -i 's|#x||g' $MODPATH/service.sh
ui_print " "
fi
# audio rotation
FILE=$MODPATH/service.sh
if [ "`grep_prop audio.rotation $OPTIONALS`" == 1 ]; then
ui_print "- Enables ro.audio.monitorRotation=true"
sed -i '1i\
resetprop -n ro.audio.monitorRotation true\
resetprop -n ro.audio.monitorWindowRotation true' $FILE
ui_print " "
fi
# raw
FILE=$MODPATH/.aml.sh
if [ "`grep_prop disable.raw $OPTIONALS`" == 0 ]; then
ui_print "- Does not disable Ultra Low Latency (Raw) playback"
ui_print " "
else
sed -i 's|#u||g' $FILE
fi
# run
. $MODPATH/copy.sh
. $MODPATH/.aml.sh
# unmount
unmount_mirror