-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvanir
596 lines (572 loc) · 15.4 KB
/
vanir
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
#!/system/xbin/bash
# Nuclearmistake - based on popcornscripts by sonicxml
#export TESTING=1
SDWTF=/sdcard
if [ ! -e /sdcard/vanir.cfg ] && [ -e /data/media/vanir.cfg ]; then
SDWTF=/data/media
fi
menu()
{
[ ! $1 ] && menu_main || menu_$1
}
menu_main()
{
[ ! $TESTING ] && [ ! -e $SDWTF/vanir.cfg ] && echo "$SDWTF/vanir.cfg is missing. Cannot continue."
sectionheader "Main Menu"
echo "1) CPU Tweaks"
echo "2) GPU Overclock"
echo "3) BLX Params"
echo "4) Fast Charge Toggle"
echo "5) Wifi Low-Latency Toggle"
echo "6) Color Control"
echo "7) Sound Control"
echo "8) Memory Mgmt"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) choice="cpu";;
2) choice="gpu";;
3) choice="blx";;
4) choice="fc";;
5) choice="wll";;
6) choice="cc";;
7) choice="sc";;
8) choice="mm";;
[Qq]) echo "Goodbye."; echo; exit 0;;
*) echo "Invalid option" && sleep 1;;
esac
if [ ! -z $choice ]; then
menu $choice
fi
menu
}
menu_sr()
{
sectionheader "Smart Reflex"
. $SDWTF/vanir.cfg
echo "1) MPU"
echo "2) IVA"
echo "3) Core"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) choice="srmpu";;
2) choice="sriva";;
3) choice="srcore";;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_sr; return 0;;
esac
if [ ! -z "$choice" ]; then
menu $choice
fi
menu sr
return 0;
}
menu_srmpu()
{
sectionheader "MPU Smart Reflex"
. $SDWTF/vanir.cfg
prompt srMPU "(0=disabled, 1=enabled--default)" bool
return 0
}
menu_sriva()
{
sectionheader "IVA Smart Reflex"
. $SDWTF/vanir.cfg
prompt srIVA "(0=disabled, 1=enabled--default)" bool
return 0
}
menu_srcore()
{
sectionheader "Core Smart Reflex"
. $SDWTF/vanir.cfg
prompt srCORE "(0=disabled, 1=enabled--default)" bool
return 0
}
menu_sc()
{
sectionheader "Sound Control"
. $SDWTF/vanir.cfg
echo "1) Volume Boost"
echo "2) High Performance"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) menu vb;;
2) menu hp;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_sc; return 0;;
esac
menu sc
return 0;
}
menu_vb()
{
sectionheader "Volume Boost"
. $SDWTF/vanir.cfg
prompt VolBoost "(0=no boost, 1=slight boost, 2=moderate boost, 3=max boost)" num 0 3
return 0
}
menu_hp()
{
sectionheader "High Performance Sound"
. $SDWTF/vanir.cfg
prompt HighPerf "(0=disabled, 1=enabled (may drain battery))" bool
return 0
}
menu_gpu()
{
sectionheader "GPU Control"
. $SDWTF/vanir.cfg
echo "1) GPU Overclock"
echo "2) GPU Governor"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) menu gpu_oc;;
2) menu gpu_gov;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_gpu; return 0;;
esac
menu gpu
return 0;
}
menu_gpu_oc()
{
sectionheader "GPU Overclock"
. $SDWTF/vanir.cfg
prompt gpuOC "(0=307MHz--default, 1=384MHz, 2=512MHz)" num 0 2
return 0
}
menu_gpu_gov()
{
sectionheader "GPU Governor"
. $SDWTF/vanir.cfg
eval curr=$gpuGOV
[ -z "$curr" ] && curr="D"
echo "1) ondemand (default)"
echo "2) performance"
echo "3) powersave"
echo "C: to use current setting"
echo "D: to use the stock value"
echo "Current governor: $curr"
read -p "Enter choice: " val
case $val in
[Cc]) apply; return 0;;
[Dd]) export VAL=; commit $1; return 0;;
[Mm]) return 0;;
[Qq]) exit 0;;
1) export VAL="ondemand";
commit gpuGOV;
apply;;
2) export VAL="performance";
commit gpuGOV;
apply;;
3) export VAL="powersave";
commit gpuGOV;
apply;;
*) echo "Invalid option"; sleep 1; menu_gpu_gov; return 0;;
esac
return 0
}
menu_fc()
{
sectionheader "Force Fast Charge"
echo "(at boot)"
. $SDWTF/vanir.cfg
prompt ffc "(0=disabled--default, 1=enabled)" bool
return 0
}
menu_wll()
{
sectionheader "Wireless Low-latency"
. $SDWTF/vanir.cfg
prompt wll "(0=saves battery--default, 1=lower wireless latency when screen is off (for streaming, etc.))" bool
return 0
}
menu_blx()
{
sectionheader "BLX Params"
. $SDWTF/vanir.cfg
prompt BLX "1-100" num 1 100
return 0
}
menu_cc()
{
sectionheader "Color Control"
. $SDWTF/vanir.cfg
echo "1) Omap Gamma Control"
echo "2) Gamma Offsets"
echo "3) Color Multipliers"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) menu cc1;;
2) menu cc2;;
3) menu cc3;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_cc; return 0;;
esac
menu cc
return 0;
}
menu_cc1()
{
sectionheader "OMAP Gamma"
. $SDWTF/vanir.cfg
prompt OMAPgamma "1-10. (0=lowest contrast, 10=highest contrast, 6=default)" num 1 10
return 0
}
menu_cc2()
{
sectionheader "Gamma Offsets"
. $SDWTF/vanir.cfg
prompt GammaOffset "3 numbers, separated by spaces. Recommended: -6 0 7" multinum 3 -100 100
return 0;
}
menu_cc3()
{
sectionheader "Color Multipliers"
. $SDWTF/vanir.cfg
echo "1) Set multipliers"
echo "2) Enable/disable multipler safety"
echo "M) Return to previous menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) menu cc31;;
2) menu cc32;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1;;
esac
menu cc3
return 0;
}
menu_cc31()
{
sectionheader "Set Multipliers"
. $SDWTF/vanir.cfg
prompt ColorMult "3 three-digit numbers. default: 200 200 200" multinum 3 0 999 10000000
}
menu_cc32()
{
sectionheader "Multiplier Safety"
. $SDWTF/vanir.cfg
prompt ColorSafety "(1=enabled/safe, 0=disabled)" bool
return 0
}
menu_hot()
{
sectionheader "Force Cpu1 on"
. $SDWTF/vanir.cfg
prompt HotPlug "0=force off, 1=force on, D=default (aka unset)" bool
}
menu_cpu()
{
sectionheader "CPU Control"
. $SDWTF/vanir.cfg
echo "1) Frequency Control"
echo "2) Governor Control"
echo "3) Smart Reflex"
echo "4) Force 2nd core online"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) menu freq;;
2) menu gov;;
3) menu sr;;
4) menu hot;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_cpu; return 0;;
esac
menu cpu
return 0;
}
menu_freq()
{
sectionheader "Frequencies"
. $SDWTF/vanir.cfg
echo "1) Set MAX Frequency"
echo "2) Set MIN Frequency"
echo "3) Set SCREEN-OFF-MAX Frequency"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) choice="maxFreq";;
2) choice="minFreq";;
3) choice="maxFreqScreenOff";;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_freq; return 0;;
esac
if [ -z "$choice" ]; then menu freq; fi
. $SDWTF/vanir.cfg
eval curr=\$$choice
[ -z $curr ] && curr="D"
sectionheader "$choice"
echo "C: to use current setting"
echo "D: to use the stock value"
echo "Available frequencies:"
for i in $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies); do
echo "$i"
done
echo "Current $choice: $curr"
read -p "Enter $choice value: " val
export VAL=$val
case $val in
[Cc]) apply; return 0;;
[Dd]) export VAL=; commit $choice; return 0;;
[Mm]) return 0;;
[Qq]) exit 0;;
*)
v=$val;
success=0;
for i in $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies); do
if [ $v = $i ]; then
VAL=$v;
commit $choice;
apply;
success=1;
break;
fi;
done;
if [ $success -eq 0 ]; then
echo "Invalid option"; sleep 1; menu_freq; return 0;
fi;;
esac
return 0;
}
menu_gov()
{
sectionheader "Governor Selection"
. $SDWTF/vanir.cfg
choice="scaleGov"
eval curr=\$$choice
[ -z $curr ] && curr="D"
j=1
for i in $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors); do
echo "$j) $i"
j=$(expr $j + 1)
done
echo "C: to use current setting"
echo "D: to use the stock value"
echo "Current governor: $curr"
read -p "Enter choice: " val
case $val in
[Cc]) apply; return 0;;
[Dd]) export VAL=; commit $1; return 0;;
[Mm]) return 0;;
[Qq]) exit 0;;
[0-9]*)
export VAL=$val
j=1
gov=""
for i in $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors); do
if [ $j -eq $val ]; then
gov=$i
break
fi
j=$(expr $j + 1)
done
export VAL=$gov
commit $choice;
apply;;
*) echo "Invalid option"; sleep 1; menu_gov; return 0;;
esac
return 0;
}
menu_mm()
{
sectionheader "Memory mgmt"
. $SDWTF/vanir.cfg
echo "1) KSM"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) menu zram;;
2) menu ksm;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_mm; return 0;;
esac
menu mm
return 0;
}
menu_ksm()
{
sectionheader "KSM options"
echo "<DANGER WILL ROBINSON>"
. $SDWTF/vanir.cfg
echo "1) Enable/disable"
echo "2) KSM Sleep Time"
echo "3) Pages to scan"
echo "M) Return to main menu"
echo "Q) Quit"
read -p "Enter option: " opt
choice=""
case $opt in
1) sectionheader "KSM enable/disable"; prompt ksmRun "(1=default/allows DVM to merge pages - may increase performance, 0 =doesn't)" bool ;;
2) sectionheader "KSM sleep"; prompt ksmSleep "(ms to sleep between mergings. longer = safer, higher = more efficient merging - default=40001)" num 1000 30000 ;;
3) sectionheader "KSM pages"; prompt ksmPagesToScan "(pages to merge per scan - default=128)" num 64 512 ;;
[Mm]) return 0;;
[Qq]) apply; exit 0;;
*) echo "Invalid option"; sleep 1; menu_ksm; return 0;;
esac
menu ksm
return 0
}
prompt()
{
# $1 = setting name
# $2 = valid input (string)
# $3 = name of val test function
. $SDWTF/vanir.cfg
eval curr=\$$1
[ -z "$curr" ] && curr="D"
echo "C: to use current setting"
echo "D: to use the stock value"
echo "M: return to previous menu"
echo "Q: quit"
echo "Valid settings: $2"
echo "Current Setting: $curr"
read -p "Enter value: " val
export VAL=$val
case $val in
[Cc]) apply; return 0;;
[Dd]) export VAL=; export $1=; commit $1; return 0;;
[Mm]) return 0;;
[Qq]) exit 0;;
*) test $3 $4 $5 $6 $7 $8 $9 && commit $1 $7 && apply && return 0;;
esac
echo "Invalid input. Please try again"
prompt $1 "$2" $3 && return 0
return 1
}
test() { [ -z "$1" ] && return 1; test_$* && return 0; return 1; }
test_bool() { test_num 0 1 && return 0; return 1; }
test_num() { [[ $val =~ [-]*[0-9][0-9]* ]] && test_singlenum $VAL $1 $2 && return 0; return 1; }
test_singlenum() { [[ $1 =~ [-]*[0-9][0-9]* ]] && [ $1 -le $3 ] && [ $1 -ge $2 ] && return 0; return 1; } # $2 = min, $3 = max
test_multinum() { vals=$(echo "$VAL" | wc -w); [ $vals -ne $1 ] && return 1; for i in $VAL; do if ! test_singlenum $i $2 $3; then return 1; fi; done; return 0; }
commit()
{
# $1=name of setting
# $VAL=new value
if [ $(echo "$VAL" | wc -w) -gt 1 ]; then
newval=""
if [ $2 ]; then
for i in $VAL; do
newval="$newval$(expr $i \* $2) "
done
VAL=$newval
fi
export VAL="\"$VAL\""
fi
echo "SETTING $1=$VAL"
sed "s/#$1/$1/g" -i $SDWTF/vanir.cfg
if [ ! "$VAL" ]; then
[ $(cat $SDWTF/vanir.cfg | grep "$1" | wc -l) ] && sed "s/$1=.*/#&/g" -i $SDWTF/vanir.cfg || echo "#$1=" >> $SDWTF/vanir.cfg
export VAL=
return 0
fi
[ $(cat $SDWTF/vanir.cfg | grep "$1" | wc -l) ] && sed "s/$1=.*/$1=$VAL/g" -i $SDWTF/vanir.cfg || echo "$1=$VAL" >> $SDWTF/vanir.cfg
export VAL=
return 0
}
apply()
{
. $SDWTF/vanir.cfg
[ $TESTING ] && echo "APPLYING STUFF" || vanirtweakapply &> /dev/null
return 0
}
sectionheader()
{
total=$(echo " Vanir Tweaks " | wc -c)
title=$(echo "$1" | wc -c)
diff=$(expr $total - $title)
lpadc=$(expr $diff / 2)
rpadc=$(expr $diff - $lpadc)
lpad=""
rpad=""
while [ $lpadc -gt 0 ]; do lpad="$lpad "; lpadc=$(expr $lpadc - 1); done
while [ $rpadc -gt 0 ]; do rpad="$rpad "; rpadc=$(expr $rpadc - 1); done
echo
echo
echo "++++++++++++++++++++++++++++"
echo "+ Vanir Tweaks +"
echo "+$lpad $1 $rpad+"
echo "++++++++++++++++++++++++++++"
}
dovanirflash()
{
echo "This feature requires TWRP recovery to work. Install it if you haven't already."
read -p "Are you sure you want to flash vanir_rom.zip, vanir_gapps.zip, and any zips in /sdcard/vanir_addons/? <Y/n> " doit
case $doit in
[Nn]) echo "canceling"; exit 0;;
*) vanirflash;;
esac
}
disable()
{
export VAL=0
commit enableTweaks
echo "Vanir Tweaks disabled. Reboot required to take effect."
}
enable()
{
export VAL=1
commit enableTweaks
. $SDWTF/vanir.cfg
vanirtweakapply
echo "Vanir Tweaks enabled."
}
showusage()
{
echo "Usage:";
echo " vanir config - displays menu to change tweak settings.";
echo " vanir disable - prevents tweak settings from being applied at boot.";
echo " vanir enable - applies your current settings. All tweaks will auto-apply at boot."
echo " vanir flash - flashes a fresh version of vanir (\"dirty\" -- data UNTOUCHED)"
echo " (REQUIRES TWRP!!)"
echo " ROM ZIP MUST BE COPIED/MOVED TO $SDWTF/vanir_rom.zip"
echo " GAPPS ZIP MUST BE COPIED/MOVED TO $SDWTF/vanir_gapps.zip"
echo " (optional) ADDITIONAL ZIPS TO FLASH MUST BE IN $SDWTF/vanir_addons/"
}
amiroot()
{
ret=`whoami 2>&1`
[ "$ret" = "root" ] && return 0 || [ `echo $ret | egrep "uid 0" | wc -l` -gt 0 ] && return 0 || return 1
}
if [ ! $1 ]; then
showusage
else
case $1 in
"enable") [ $TESTING ] && enable || amiroot && enable || echo "You must run this as root. run: su -c 'vanir enable'";;
"disable") disable;;
"config") [ $TESTING ] && menu || amiroot && menu || echo "You must run this as root. run: su -c 'vanir config'";;
"flash") [ $TESTING ] || dovanirflash;;
"status") . /sdcard/vanir.cfg; if [ -z "$enableTweaks" ] || [ $enableTweaks -eq 0 ]; then echo 0; else echo 1; fi;;
*) showusage;;
esac
fi