blob: fed3279028f97acfd61a9992143c8bc9b70bbf06 (
plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
|
#!/system/bin/sh
# Copyright (c) 2013-2017 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
export PATH=/system/bin:$PATH
strBakForReplace=".bakforspec"
strExcludeFiles="exclude.list"
strExcludeFolder="exclude"
strForLink=".link"
currentSpec=""
SourceFolder=""
DestFolder=""
BasePath=""
LocalFlag=""
mode=""
strPathDefHosts="/system/vendor/hosts"
strPathForHosts="/system/etc/hosts"
#auditTargetList=("sdm845" "sdm855" "sdm670" "sdm660" "msm8998")
auditTargetList=("sdm845") # [[BEGIN:"ro.platform.audited"="true":END]]
hostsRedirect="false"
targetAudited="false"
funcInstall="installFunc"
funcUnInstall="uninstallFunc"
auditList()
{
target="$1"
if [ "" != "${target}" ]; then
for t in ${auditTargetList[*]}
do
if [ "" != "$t" ]; then
if [ "${target}" == "$t" ]; then
return 1
break
fi
fi
done
fi
return 0
}
auditTarget()
{
auditedProp=`getprop ro.platform.audited`
if [ "true" == "${auditedProp}" ]; then
targetAudited="true"
elif [ "false" != "${auditedProp}" ]; then
if [ -f /sys/devices/soc0/machine ]; then
target=`cat /sys/devices/soc0/machine | tr [:upper:] [:lower:]`
else
target=`getprop ro.board.platform`
fi
auditList $target
if [ "1" == $? ]; then
targetAudited="true"
fi
fi
}
auditProp()
{
step=0;
flag=0;
for line in $(cat $1); do
((index=$step/2))
((flag=$step%2))
if [ 0 -eq ${flag} ]; then
echo "$2.$3${index}=${line}"
else
echo "$2.$4${index}=${line}"
fi
((step=$step+1))
done
}
auditHosts()
{
auditEnabled="$1"
if [ "-audit" == "${auditEnabled}" ] && [ "true" == "${targetAudited}" ]; then
hostsRedirect="true"
fi
}
redirectHosts()
{
funcName="$1"
srcPath="$2"
dstPath="$3"
dstDir="$4"
sFlag="0"
if [ "${strPathDefHosts}" == "${dstPath}" ]; then
if [ "${funcInstall}" == "${funcName}" ]; then
if [ "false" == "${hostsRedirect}" ]
then
sFlag="1"
else
sFlag="2"
fi
elif [ "${funcUnInstall}" == "${funcName}" ]; then
if [ "${srcPath%$strForLink}" == "${srcPath}" ] || [ ! -f $srcPath ]
then
sFlag="1"
else
sFlag="2"
fi
else #UnUsed
sFlag="0"
fi
fi
case "${sFlag}" in
"1")
echo "redirectHosts return from ${funcName} for ${srcPath} ${dstPath} ${dstDir}"
;;
"2")
echo "redirectHosts redirect the ${dstPath} to ${strPathForHosts}"
;;
esac
return "${sFlag}"
}
createFolder()
{
local dirPath=$1
if [ -d "$dirPath" ]
then
echo "Exist $dirPath"
else
createFolder "${dirPath%/*}"
echo "mkdir and chmod $dirPath"
mkdir "$dirPath"
chmod 755 "$dirPath"
fi
}
installFunc()
{
local srcPath=$1
local dstPath=$2
local dstDir="${dstPath%/*}"
createFolder $dstDir
echo "installFunc $srcPath $dstPath $dstDir"
if [ "${dstPath%$strForLink}" != "$dstPath" ]
then
dstPath="${dstPath%$strForLink}"
fi
if [ "$dstPath" == "/system/vendor/default.prop" ] ; then
echo "return installFunc $srcPath $dstPath $dstDir"
return
fi
redirectHosts "${funcInstall}" "$srcPath" "$dstPath" "$dstDir"
case "$?" in
"1")
return
;;
"2")
dstPath=$strPathForHosts
;;
esac
if [ "${srcPath%$strForLink}" != "$srcPath" ]
then
if [ "${dstPath#${BasePath}/system/}" != "${dstPath}" ]
then
if [ -f "${srcPath%$strForLink}" ] || [ -h "${srcPath%$strForLink}" ]
then
if [ -f "$dstPath" ]
then
rm "$dstPath"
fi
mv "${srcPath%$strForLink}" $dstPath
chmod 644 "$dstPath"
fi
else
cp -p "${srcPath%$strForLink}" $dstPath
chmod 644 "$dstPath"
chown system:system "$dstPath"
fi
elif [ -h "$srcPath$strForLink" ]
then
installFunc "$srcPath$strForLink" $dstPath
else
if [ -f "$dstPath" ]
then
if [ -f "$dstPath$strBakForReplace$currentSpec" ]
then
rm "$dstPath$strBakForReplace$currentSpec"
fi
mv $dstPath $dstPath$strBakForReplace$currentSpec
fi
if [ "$mode" == "compiling" ] || [ "$mode" == "running" ]
then
ln -s ${dstPath#$BasePath} "$srcPath$strForLink"
fi
installFunc "$srcPath$strForLink" $dstPath
fi
}
uninstallFunc()
{
local srcPath=$1
local dstPath=$2
echo "uninstallFunc $srcPath $dstPath"
if [ "${dstPath%$strForLink}" != "$dstPath" ]
then
dstPath="${dstPath%$strForLink}"
fi
if [ "$dstPath" == "/system/vendor/default.prop" ] ; then
echo "return uninstallFunc $srcPath $dstPath $dstDir"
return
fi
redirectHosts "${funcUnInstall}" "$srcPath" "$dstPath" "$dstDir"
case "$?" in
"1")
return
;;
"2")
dstPath=$strPathForHosts
;;
esac
if [ "${srcPath%$strForLink}" != "$srcPath" ]
then
if [ "${dstPath#${BasePath}/system/}" != "${dstPath}" ]
then
if [ -f "$dstPath" ] || [ -h "$dstPath" ]
then
if [ -f "${srcPath%$strForLink}" ] || [ -h "${srcPath%$strForLink}" ]
then
rm $dstPath
else
mv $dstPath "${srcPath%$strForLink}"
chmod 644 "${srcPath%$strForLink}"
fi
fi
else
echo "remove $dstPath"
rm $dstPath
fi
if [ -f "$dstPath$strBakForReplace$currentSpec" ]
then
if [ -f "$dstPath" ]
then
rm $dstPath
fi
mv $dstPath$strBakForReplace$currentSpec $dstPath
fi
if [ "$mode" == "compiling" ] || [ "$mode" == "running" ]
then
rm $srcPath
fi
elif [ -h "$srcPath$strForLink" ] || [ -f "$srcPath" ]
then
uninstallFunc "$srcPath$strForLink" $dstPath
else
echo "Finish install"
fi
}
installFolderFunc()
{
local srcPath=$1
local dstPath=$2
for item in `ls -a $srcPath`
do
echo "find item=$item"
if [ "$item" = "." ]
then
echo "current folder"
else
if [ "$item" = ".." ]
then
echo "upfolder"
elif [ "$item" = ".preloadspec" ] || [ "$item" = "$strExcludeFiles" ]
then
echo "specflag"
else
if [ -f "$srcPath/$item" ]
then
installFunc "$srcPath/${item}" "$dstPath/${item}"
elif [ -h "$srcPath/$item" ]
then
installFunc "$srcPath/${item}" "$dstPath/${item}"
else
if [ -d "$srcPath/$item" ]
then
installFolderFunc "$srcPath/${item}" "$dstPath/${item}"
fi
fi
fi
fi
done
}
uninstallFolderFunc()
{
local srcPath=$1
local dstPath=$2
for item in `ls -a $srcPath`
do
echo "uitem=$item"
if [ "$item" = "." ]
then
echo "current folder"
else
if [ "$item" = ".." ]
then
echo "upfolder"
elif [ "$item" = ".preloadspec" ] || [ "$item" = "$strExcludeFiles" ]
then
echo "specflag"
else
if [ -f "$srcPath/$item" ]
then
uninstallFunc "$srcPath/${item}" "$dstPath/${item}"
elif [ -h "$srcPath/$item" ]
then
uninstallFunc "$srcPath/${item}" "$dstPath/${item}"
else
if [ -d "$srcPath/$item" ]
then
uninstallFolderFunc "$srcPath/${item}" "$dstPath/${item}"
fi
fi
fi
fi
done
}
excludeFilesFunc()
{
local srcPath=$1
if [ -f "$srcPath" ]
then
echo "exclude the files in current spec"
while read line
do
if [ -f "$DestFolder/$line" ]
then
local dstPath="$SourceFolder/$strExcludeFolder/$line"
local dstDir="${dstPath%/*}"
createFolder $dstDir
if [ "${line#system/}" != "${line}" ]
then
mv $DestFolder/$line $dstPath
else
cp -p $DestFolder/$line $dstPath
fi
fi
done < "$srcPath"
fi
}
includeFilesFunc()
{
local srcPath=$1
if [ -f "$srcPath" ]
then
echo "restore the files excluded in previous spec"
while read line
do
if [ -f "$SourceFolder/$strExcludeFolder/$line" ]
then
local dstPath="$DestFolder/$line"
if [ "${line#system/}" != "${line}" ]
then
mv "$SourceFolder/$strExcludeFolder/$line" $dstPath
else
cp -p "$SourceFolder/$strExcludeFolder/$line" $dstPath
fi
fi
done < "$srcPath"
fi
}
getCurrentSpec()
{
local specPath=$1
currentSpec=""
if [ -f "$specPath" ]
then
. $specPath
while read line
do
currentSpec=${line#*=}
done < $specPath
fi
}
makeFlagFolder()
{
if [ -d "$DestFolder/data/switch_spec" ]
then
echo "no need to create flag"
else
mkdir "$DestFolder/data/switch_spec"
chmod 770 "$DestFolder/data/switch_spec"
if [ "$mode" != "compiling" ]
then
chown system:system "$DestFolder/data/switch_spec"
fi
fi
}
changeDirMode()
{
local strCurPath=$1
chmod 755 $strCurPath
for item in `ls -a $strCurPath/`
do
if [ "$item" = "." ] || [ "$item" = ".." ]
then
echo ".."
elif [ -f "$strCurPath/$item" ]
then
chmod 644 "$strCurPath/$item"
elif [ -d "$strCurPath/$item" ]
then
changeDirMode "$strCurPath/$item"
else
echo "who is $strCurPath/$item"
fi
done
}
recoveryDataPartition()
{
local specPath=$1
installFolderFunc "$SourceFolder/system/vendor/$currentSpec/data" "$DestFolder/data"
currentSpec="Default"
if [ -f "$specPath" ]
then
# Recovery the data partition for each spec
local x=0
while read line
do
if [ "$x" -ge "1" ]
then
if [ "${line#*=}" != "" ]
then
installFolderFunc "$SourceFolder/system/vendor/${line#*=}/data" "$DestFolder/data"
currentSpec="${line#*=}"
fi
fi
let "x+=1"
done < $specPath
fi
}
prepareActionData()
{
# Mark if user has operated switching by CarrierConfigure app
local iSSwitchByAction="false"
# Copy spec folder from $SwitchData/cache/system/vendor to /cache/temp
if [ -f "$SwitchApp/cache/action" ]
then
mkdir -p "$DestFolder/cache/temp"
local x=0
while read line
do
if [ "$x" -ge "1" ]
then
local specItem="${line#*=}"
echo "specItem="$specItem
echo "SwitchCacheData="$SwitchCacheData
if [ -d "$SwitchData/cache/system/vendor/$specItem" ]
then
cp -rvf "$SwitchData/cache/system/vendor/$specItem" "$DestFolder/cache/temp/"
elif [ -d "$SwitchCacheData/cache/system/vendor/$specItem" ]
then
cp -rvf "$SwitchCacheData/cache/system/vendor/$specItem" "$DestFolder/cache/temp/"
fi
fi
let "x+=1"
done < "$SwitchApp/cache/action"
# Copy action spec list to $SwitchActionFlag
cp -rf "$SwitchApp/cache/action" "$SwitchActionFlag"
iSSwitchByAction="true"
elif [ -f "$DestFolder/cache/action" ]
then
iSSwitchByAction="true"
fi
echo $iSSwitchByAction
}
getNewSpecList()
{
local SwitchFlag=$1
local specList
if [ -f "$SwitchFlag" ]
then
local strNewSpec=""
local newPackCount=0
. "$SwitchFlag"
if [ "$newPackCount" -ge "1" ]
then
local x=0
while read line
do
if [ "$x" -ge "1" ]
then
local specItem="${line#*=}"
specList[$x-1]=$specItem
fi
let "x+=1"
done < $SwitchFlag
else
specList[0]=$strNewSpec
fi
fi
echo ${specList[*]}
}
# Remove all files except folders
removeFilesUnderFolder()
{
local folder=$1
local array
if [ -d "$folder" ]
then
array=(`ls $folder`)
local x=0
while [ "$x" -lt "${#array[@]}" ]
do
if [ -d "$folder/${array[$x]}" ]
then
removeFilesUnderFolder "$folder/${array[$x]}"
elif [ -f "$folder/${array[$x]}" ]
then
echo "Remove file $folder/${array[$x]} ..."
rm -f $folder/${array[$x]}
fi
let "x+=1"
done
fi
}
uninstallOldSpecList()
{
local specPath=$1
local specList
if [ -f "$specPath" ]
then
local x=0
while read line
do
if [ "$x" -ge "1" ]
then
specList[$x-1]="${line#*=}"
fi
let "x+=1"
done < "$specPath"
fi
local x="${#specList[@]}"
while [ "$x" -gt "0" ]
do
let "x-=1"
if [ "$x" -ge "1" ]
then
currentSpec=${specList[$x-1]}
else
currentSpec="Default"
fi
if [ "${specList[$x]}" != "Default" ]
then
uninstallFolderFunc "$SourceFolder/${specList[$x]}" "$DestFolder"
includeFilesFunc "$SourceFolder/${specList[$x]}/$strExcludeFiles"
fi
done
rm -rf $SourceFolder/$strExcludeFolder/*
# Reinstall Default pack
mv -f $DestFolder/system/build.prop.bakforspecDefault $DestFolder/system/build.prop
if [ -f $DestFolder/etc/hosts.bakforspecDefault ]
then
mv -f $DestFolder/etc/hosts.bakforspecDefault $DestFolder/etc/hosts
fi
uninstallFolderFunc "$SourceFolder/Default" "$DestFolder"
if [ "$mode" == "running" ]
then
removeFilesUnderFolder "$DestFolder/data"
fi
installFolderFunc "$SourceFolder/Default" "$DestFolder"
echo "packCount=1" > $specPath
echo "strSpec1=Default" >> $specPath
}
overrideRoProperty()
{
local srcprop=$1
local dstprop=$2
local tempfile=${dstprop%/*}"/temp.prop"
echo "Override ro.* property from $srcprop to $dstprop ..."
while IFS=$'\n' read -r srcline
do
if [ "${srcline:0:1}" != "#" ] && [ "${srcline#*=}" != "${srcline}" ]
then
local flag=0
while IFS=$'\n' read -r dstline
do
if [ "${srcline%%.*}" = "ro" ] && [ "${srcline%%[ =]*}" = "${dstline%%[ =]*}" ]
then
echo "Override $srcline ..."
echo -E $srcline >> $tempfile
else
echo -E $dstline >> $tempfile
fi
done < $dstprop
mv -f $tempfile $dstprop
fi
done < $srcprop
chmod 644 $dstprop
}
installNewSpecList()
{
local specList
specList=(`echo "$@"`)
if [ "${#specList[@]}" -eq "1" ] && [ "${specList[0]}" = "Default" ]
then
echo "Default spec already have been installed, do nothing here!"
else
# Check if the list is ready
local x=0
local y=0
local newList
if [ "${#specList[@]}" -ge "1" ]
then
while [ "$x" -lt "${#specList[@]}" ]
do
if [ "${specList[$x]}" != "" ]
then
# Copy spec folder from /cache/temp to /system/vendor
if [ -d "$DestFolder/cache/temp/${specList[$x]}" ]
then
if [ -d "$SourceFolder/${specList[$x]}" ]
then
rm -rf "$SourceFolder/${specList[$x]}"
fi
cp -rf "$DestFolder/cache/temp/${specList[$x]}" "$SourceFolder/${specList[$x]}"
fi
if [ -d "$SourceFolder/${specList[$x]}" ]
then
newList[$y]=${specList[$x]}
let "y+=1"
fi
fi
let "x+=1"
done
fi
# remove $DestFolder/cache/temp
if [ -d "$DestFolder/cache/temp" ]
then
rm -rf "$DestFolder/cache/temp"
fi
# Install spec as list
if [ "${#newList[@]}" -ge "1" ]
then
# Backup build.prop for Default
cp -f $DestFolder/system/build.prop $DestFolder/system/build.prop.bakforspecDefault
if [ "true" == "${targetAudited}" ]
then
cp -f $DestFolder/etc/hosts $DestFolder/etc/hosts.bakforspecDefault
fi
local x=0
echo "packCount=${#newList[@]}" > $LocalFlag
while [ "$x" -lt "${#newList[@]}" ]
do
excludeFilesFunc "$SourceFolder/${newList[$x]}/$strExcludeFiles"
changeDirMode "$SourceFolder/${newList[$x]}"
installFolderFunc "$SourceFolder/${newList[$x]}" "$DestFolder"
overrideRoProperty "$DestFolder/system/vendor/vendor.prop" "$DestFolder/system/build.prop"
let "x+=1"
currentSpec="${newList[$x-1]}"
echo "strSpec$x=$currentSpec" >> $LocalFlag
done
fi
fi
}
cleanOldSpecs()
{
local specList
specList=(`echo "$@"`)
# When in step 1 of switching mode,
# should ensure that action specs are not cleared.
if [ "$mode" = "switching" ]
then
local actionSpecList
actionSpecList=(`getNewSpecList "$SwitchActionFlag"`)
specList+=("${actionSpecList[@]}")
fi
for item in `ls -a $SourceFolder`
do
if [ "$item" = "Default" ]
then
echo "Default spec, no need remove"
elif [ "$item" = ".." ] || [ "$item" = "." ]
then
echo "Current path"
elif [ -f "$SourceFolder/$item/.preloadspec" ]
then
echo "find $item"
local x=0
local flag=0
while [ "$x" -lt "${#specList[@]}" ]
do
if [ "$item" = "${specList[$x]}" ]
then
flag=1
break
fi
let "x+=1"
done
if [ "$flag" -eq "0" ]
then
rm -rf "$SourceFolder/$item"
fi
fi
done
}
initSwitchingMode()
{
if [ -f "$SwitchModeFlag" ]
then
. "$SwitchModeFlag"
echo "Before mode = $mode"
fi
if [ "$mode" = "" ]
then
if [ "$DestFolder" != "" ]
then
# compiling mode means that switch spec when compiling the source code
# in Android.mk.
mode="compiling"
else
if [ "$(prepareActionData)" = "true" ]
then
# switching mode means that switch spec through CarrierConfigure App or
# SIM Trigger, which includes two steps:
# 1. switch to Default and clean the old specs
# 2. switch to the new spec list
mode="switching"
echo "mode=$mode" > "$SwitchModeFlag"
else
# running mode means that run switch_spec.sh to switch spec
# manully through cmd on DUT.
mode="running"
fi
fi
fi
}
findDependency()
{
local storagePos=$1
local spec=$2
local depend=""
if [ -e $storagePos/$spec/.preloadspec ] ; then
depend=`grep "\(^[^#].*\)Dependency=" $storagePos/$spec/.preloadspec`
depend="${depend##*"Dependency=\""}"
depend="${depend%%\"*}"
fi
echo "${depend##*/}"
}
findAllDependencys()
{
local storagePos=$1
local spec=$2
local depend=""
depend="$(findDependency "$storagePos" "$spec")"
local depends="$depend"
while [ "$depend" != "" ]
do
depend="$(findDependency "$storagePos" "$depend")"
depends=" $depends $depend"
done
echo "$spec $depends"
}
# Used to switch spec in regionalization way
# When "ro.regionalization.support" is true.
regionalizationSwitch()
{
if [ "$(getprop ro.regionalization.support)" != "true" ]
then
return
fi
local storagePos=""
local spec=""
if [ "$#" -eq "2" ]
then
storagePos=$1
spec=$2
else
storagePos="$DestFolder/system/vendor"
fi
# Create spec and prop pointer file if not exist
if [ ! -f "$RegionalizationEnvSpecPath/spec" ]
then
echo "packStorage=$storagePos" > "$RegionalizationEnvSpecPath/spec"
echo "packCount=1" >> "$RegionalizationEnvSpecPath/spec"
echo "strSpec1=Default" >> "$RegionalizationEnvSpecPath/spec"
fi
chmod 666 "$RegionalizationEnvSpecPath/spec"
chown system:system "$RegionalizationEnvSpecPath/spec"
chmod 666 "$RegionalizationEnvSpecPath/devicetype"
chown system:system "$RegionalizationEnvSpecPath/devicetype"
chmod 666 "$RegionalizationEnvSpecPath/mbnversion"
chown system:system "$RegionalizationEnvSpecPath/mbnversion"
chmod 666 "$RegionalizationEnvSpecPath/.not_triggered"
chown system:system "$RegionalizationEnvSpecPath/.not_triggered"
if [ ! -f "$RegionalizationEnvSpecPath/vendor_ro.prop" ]
then
echo "import $storagePos/Default/system/vendor/vendor.prop" > "$RegionalizationEnvSpecPath/vendor_ro.prop"
fi
chmod 644 "$RegionalizationEnvSpecPath/vendor_ro.prop"
chown system:system "$RegionalizationEnvSpecPath/vendor_ro.prop"
if [ ! -f "$RegionalizationEnvSpecPath/vendor_persist.prop" ]
then
echo "import $storagePos/Default/system/vendor/vendor.prop" > "$RegionalizationEnvSpecPath/vendor_persist.prop"
fi
chmod 644 "$RegionalizationEnvSpecPath/vendor_persist.prop"
chown system:system "$RegionalizationEnvSpecPath/vendor_persist.prop"
if [ ! -f "$RegionalizationEnvSpecPath/submask" ]
then
touch "$RegionalizationEnvSpecPath/submask"
fi
chmod 644 "$RegionalizationEnvSpecPath/submask"
chown system:system "$RegionalizationEnvSpecPath/submask"
if [ ! -f "$RegionalizationEnvSpecPath/partition" ]
then
touch "$RegionalizationEnvSpecPath/partition"
fi
chmod 644 "$RegionalizationEnvSpecPath/partition"
chown system:system "$RegionalizationEnvSpecPath/partition"
# Find dependency specs
local specList
if [ "$spec" != "" ]
then
specList=($(findAllDependencys "$storagePos" "$spec"))
echo "Installing ${specList[@]} ... "
fi
# Modify spec files under /persist/speccfg
if [ "${#specList[@]}" -gt 0 ]
then
cat /dev/null > "$RegionalizationEnvSpecPath/spec"
cat /dev/null > "$RegionalizationEnvSpecPath/vendor_ro.prop"
cat /dev/null > "$RegionalizationEnvSpecPath/vendor_persist.prop"
echo "packStorage=$storagePos" >> "$RegionalizationEnvSpecPath/spec"
echo "packCount=${#specList[@]}" >> "$RegionalizationEnvSpecPath/spec"
local x=0
while [ "$x" -lt "${#specList[@]}" ]
do
let "x+=1"
echo "import $storagePos/${specList[$x-1]}/system/vendor/vendor.prop" >> "$RegionalizationEnvSpecPath/vendor_ro.prop"
done
local y=1
while [ "$x" -gt "0" ]
do
echo "strSpec$y=${specList[$x-1]}" >> "$RegionalizationEnvSpecPath/spec"
echo "import $storagePos/${specList[$x-1]}/system/vendor/vendor.prop" >> "$RegionalizationEnvSpecPath/vendor_persist.prop"
let "x-=1"
let "y+=1"
done
fi
}
######Main function start######
if [ "$#" -eq "0" ]
then
RegionalizationEnvSpecPath="$DestFolder/persist/speccfg"
# Just init here
regionalizationSwitch
if [ ! -d "$DestFolder/data/switch_spec" ]
then
if [ "$(getprop ro.regionalization.support)" == "true" ]
then
recoveryDataPartition "$RegionalizationEnvSpecPath/spec"
else
recoveryDataPartition "$DestFolder/system/vendor/speccfg/spec"
fi
makeFlagFolder
fi
elif [ "$#" -eq "1" ]
then
RmFlag="$1"
SpecFile="$DestFolder/cache/action"
# Get the current specs
x=0
newSpecList=""
while read line
do
if [ "$x" -eq "0" ]
then
storagePos="${line#*=}"
echo "storagePos = $storagePos"
fi
if [ "$x" -ge "2" ]
then
specItem="${line#*=}"
newSpecList[$x-2]=$specItem
fi
let "x+=1"
done < "$SpecFile"
# Clean old specs to free $storagePos
if [ "$RmFlag" -eq "1" ]
then
echo "Clean $storagePos ..."
SourceFolder="$DestFolder$storagePos"
cleanOldSpecs "${newSpecList[*]}"
fi
x=0
while [ "$x" -lt "${#newSpecList[@]}" ]
do
if [ "${newSpecList[$x]}" == "" ]
then
let "x+=1"
continue
fi
echo "new spec = ${newSpecList[$x]}"
if [ -d "$DestFolder/cache/temp/system/vendor/${newSpecList[$x]}" ]
then
if [ -d "$DestFolder$storagePos/${newSpecList[$x]}" ]
then
rm -rf "$DestFolder$storagePos/${newSpecList[$x]}"
fi
cp -rf "$DestFolder/cache/temp/system/vendor/${newSpecList[$x]}" "$DestFolder$storagePos/${newSpecList[$x]}"
fi
let "x+=1"
done
if [ -d "$DestFolder/cache/temp" ]
then
rm -rf "$DestFolder/cache/temp"
fi
if [ -f "$SpecFile" ]
then
rm -f "$SpecFile"
fi
elif [ "$#" -eq "2" ]
then
# For adb cmds swtiching when regionalzation env is supported
RegionalizationEnvSpecPath="$DestFolder/persist/speccfg"
storagePos=$1
spec=$2
regionalizationSwitch "$storagePos" "$spec"
else
SourceFolder="$1"
DestFolder="$2"
BasePath="$3"
LocalFlag="$4"
echo "SourceFolder=$SourceFolder DestFolder=$DestFolder BasePath=$BasePath LocalFlag=$LocalFlag"
SwitchApp="$DestFolder/data/data/com.qualcomm.qti.carrierconfigure"
SwitchData="$DestFolder/data/data/com.qualcomm.qti.loadcarrier"
SwitchCacheData="$DestFolder/data/data/com.qualcomm.qti.accesscache"
SwitchModeFlag="$DestFolder/system/vendor/speccfg/mode"
SwitchFlag="$DestFolder/system/vendor/speccfg/spec.new"
SwitchActionFlag="$DestFolder/cache/action"
RmFlag="0"
initSwitchingMode
echo "Current mode = $mode"
# Set the RmFlag for cleaning preset specs
if [ -f "$SwitchApp/cache/rmflag" ]
then
RmFlag="1"
fi
if [ -d "$SourceFolder/$strExcludeFolder" ]
then
echo "no need to create excludefolder"
else
mkdir "$SourceFolder/$strExcludeFolder"
chmod 770 "$SourceFolder/$strExcludeFolder"
fi
if [ "$#" -gt "4" ]
then
newSpecList="$5"
echo "switchToSpec=${newSpecList[0]}"
if [ "$#" -gt "5" ]
then
RmFlag="$6"
fi
else
if [ "$mode" == "compiling" ] && [ -f "$SwitchFlag" ]
then
mkdir -p "$DestFolder/cache"
mv -f $SwitchFlag $SwitchActionFlag
fi
newSpecList=(`getNewSpecList "$SwitchActionFlag"`)
if [ -f "$SwitchModeFlag" ]
then
rm -rf "$SwitchModeFlag"
fi
if [ -f "$SwitchActionFlag" ]
then
rm -rf "$SwitchActionFlag"
fi
fi
auditTarget
if [ "$#" -ge "7" ]; then
auditHosts "$7"
fi
getCurrentSpec "$LocalFlag"
if [ "${#currentSpec}" -eq "0" ]
then
echo "No find spec, but need to install Default"
installFolderFunc "$SourceFolder/Default" "$DestFolder"
currentSpec="Default"
fi
uninstallOldSpecList "$LocalFlag"
if [ "$RmFlag" -eq "1" ]
then
cleanOldSpecs "${newSpecList[*]}"
fi
if [ "${#newSpecList[@]}" -ge "1" ]
then
installNewSpecList "${newSpecList[*]}"
fi
# if [ "$mode" == "compiling" ]
# then
# rm -rf "$DestFolder/cache"
# fi
chmod 644 "$LocalFlag"
chmod 755 "$DestFolder/system/vendor/speccfg"
makeFlagFolder
if [ "$newSpecList" == "ChinaMobile" ]
then
rm -rf /system/media/boot.wav
rm -rf /system/media/shutdown.wav
fi
fi
######Main function end######
|