-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv6.sh
More file actions
executable file
·1271 lines (1101 loc) · 49.6 KB
/
v6.sh
File metadata and controls
executable file
·1271 lines (1101 loc) · 49.6 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
#!/usr/bin/env bash
set -euo pipefail
if ! command -v adb >/dev/null 2>&1; then
echo -e "\033[0;31mADB is required but not installed. Please install ADB and ensure it's in your PATH.\033[0m"
exit 1
fi
# Global variable for selected device
SELECTED_DEVICE=""
CAP_ROTATION_WINDOW_CMD=0
CAP_NIGHT_MODE_CMD=0
CAP_FIXED_PERFORMANCE_MODE_CMD=0
ACTION_PARTIAL_SUCCESS=10
ACTION_HANDLED_FAILURE=11
# Default color definitions (can be overridden by config.ini)
BOLD='\033[1m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
RESET='\033[0m'
# --- Function Definitions ---
run_adb() {
adb -s "$SELECTED_DEVICE" "$@"
}
run_menu_action() {
local status
set +e
"$@"
status=$?
set -e
if [ $status -eq $ACTION_PARTIAL_SUCCESS ] || [ $status -eq $ACTION_HANDLED_FAILURE ]; then
return $status
fi
if [ $status -ne 0 ]; then
echo
echo -e "${RED}Action failed with exit code ${status}.${RESET}"
echo -e "${YELLOW}Some properties require root, are read-only on your device, or are unsupported on this Android build.${RESET}"
fi
return $status
}
get_secure_setting_value() {
local key value
key=$1
value=$(run_adb shell settings get secure "$key" 2>/dev/null | tr -d '\r' || true)
if [ "$value" = "null" ]; then
value=""
fi
printf '%s\n' "$value"
}
get_system_setting_value() {
local key value
key=$1
value=$(run_adb shell settings get system "$key" 2>/dev/null | tr -d '\r' || true)
if [ "$value" = "null" ]; then
value=""
fi
printf '%s\n' "$value"
}
run_step() {
local description status
description=$1
shift
set +e
"$@"
status=$?
set -e
if [ $status -eq 0 ]; then
echo -e "${GREEN}✓ ${description}${RESET}"
else
echo -e "${RED}✗ ${description} (exit ${status})${RESET}"
fi
return $status
}
run_step_summary() {
local action_name success_count failure_count
action_name=$1
success_count=$2
failure_count=$3
if [ $failure_count -eq 0 ]; then
echo -e "${GREEN}✓ ${action_name} completed successfully${RESET}"
return 0
fi
if [ $success_count -gt 0 ]; then
echo -e "${YELLOW}${action_name} partially completed: ${success_count} succeeded, ${failure_count} failed.${RESET}"
return $ACTION_PARTIAL_SUCCESS
fi
echo -e "${RED}${action_name} failed: all ${failure_count} steps failed.${RESET}"
return $ACTION_HANDLED_FAILURE
}
load_config_vars() {
local config_file="${1:-config.ini}"
if [ ! -f "$config_file" ]; then
echo -e "${RED}Configuration file '$config_file' not found.${RESET}" >&2
return 1
fi
# Only load simple KEY=VALUE assignments and ignore section headers/comments.
source <(sed -n '/^[[:space:]]*[A-Za-z_][A-Za-z0-9_]*[[:space:]]*=/p' "$config_file" | sed 's/^[[:space:]]*//; s/[[:space:]]*=[[:space:]]*/=/')
}
probe_shell_help_contains() {
local command_text pattern output status
command_text=$1
pattern=$2
set +e
output=$(run_adb shell "$command_text" 2>/dev/null | tr -d '\r')
status=$?
set -e
if [ $status -eq 0 ] && printf '%s\n' "$output" | grep -q "$pattern"; then
return 0
fi
return 1
}
normalize_config_vars() {
local value
if [ -z "${window_animation_scale:-}" ]; then
value=$(run_adb shell settings get global window_animation_scale 2>/dev/null | tr -d '\r' || true)
window_animation_scale="${value:-1.0}"
fi
if [ -z "${transition_animation_scale:-}" ]; then
value=$(run_adb shell settings get global transition_animation_scale 2>/dev/null | tr -d '\r' || true)
transition_animation_scale="${value:-1.0}"
fi
if [ -z "${animator_duration_scale:-}" ]; then
value=$(run_adb shell settings get global animator_duration_scale 2>/dev/null | tr -d '\r' || true)
animator_duration_scale="${value:-1.0}"
fi
if [ -z "${density:-}" ]; then
value=$(run_adb shell wm density 2>/dev/null | grep -oE '[0-9]+' | head -1 || true)
density="${value:-420}"
fi
if [ -z "${screen_off_timeout:-}" ]; then
value=$(run_adb shell settings get system screen_off_timeout 2>/dev/null | tr -d '\r' || true)
screen_off_timeout="${value:-15000}"
fi
if [ -z "${screen_brightness:-}" ]; then
value=$(run_adb shell settings get system screen_brightness 2>/dev/null | tr -d '\r' || true)
screen_brightness="${value:-128}"
fi
if [ -z "${screen_brightness_mode:-}" ]; then
value=$(run_adb shell settings get system screen_brightness_mode 2>/dev/null | tr -d '\r' || true)
screen_brightness_mode="${value:-0}"
fi
if [ -z "${font_scale:-}" ]; then
value=$(run_adb shell settings get system font_scale 2>/dev/null | tr -d '\r' || true)
font_scale="${value:-1.0}"
fi
if [ -z "${clock_seconds:-}" ]; then
value=$(get_secure_setting_value clock_seconds)
clock_seconds="${value:-0}"
fi
if [ -z "${icon_blacklist:-}" ]; then
value=$(get_secure_setting_value icon_blacklist)
icon_blacklist="${value:-}"
fi
if [ -z "${status_bar_show_battery_percent:-}" ]; then
value=$(get_system_setting_value status_bar_show_battery_percent)
status_bar_show_battery_percent="${value:-0}"
fi
if [ -z "${show_touches:-}" ]; then
value=$(get_system_setting_value show_touches)
show_touches="${value:-0}"
fi
if [ -z "${pointer_location:-}" ]; then
value=$(get_system_setting_value pointer_location)
pointer_location="${value:-0}"
fi
if [ -z "${force_gpu_rendering:-}" ]; then
value=$(run_adb shell settings get global force_gpu_rendering 2>/dev/null | tr -d '\r' || true)
force_gpu_rendering="${value:-0}"
fi
if [ -z "${profile_gpu_rendering:-}" ]; then
value=$(run_adb shell getprop debug.hwui.profile 2>/dev/null | tr -d '\r' || true)
profile_gpu_rendering="${value:-false}"
fi
if [ -z "${debug_gpu_overdraw:-}" ]; then
value=$(run_adb shell getprop debug.hwui.overdraw 2>/dev/null | tr -d '\r' || true)
debug_gpu_overdraw="${value:-false}"
fi
if [ -z "${stay_on_while_plugged_in:-}" ]; then
value=$(run_adb shell settings get global stay_on_while_plugged_in 2>/dev/null | tr -d '\r' || true)
stay_on_while_plugged_in="${value:-0}"
fi
if [ -z "${accelerometer_rotation:-}" ]; then
value=$(run_adb shell settings get system accelerometer_rotation 2>/dev/null | tr -d '\r' || true)
accelerometer_rotation="${value:-1}"
fi
if [ -z "${user_rotation:-}" ]; then
value=$(run_adb shell settings get system user_rotation 2>/dev/null | tr -d '\r' || true)
user_rotation="${value:-0}"
fi
Prefix="${Prefix:-android_settings_}"
}
detect_device_capabilities() {
CAP_ROTATION_WINDOW_CMD=0
CAP_NIGHT_MODE_CMD=0
CAP_FIXED_PERFORMANCE_MODE_CMD=0
probe_shell_help_contains "cmd window help" "set-allowed-display-rotations" && CAP_ROTATION_WINDOW_CMD=1
probe_shell_help_contains "cmd uimode help" "night" && CAP_NIGHT_MODE_CMD=1
probe_shell_help_contains "cmd power help" "set-fixed-performance-mode-enabled" && CAP_FIXED_PERFORMANCE_MODE_CMD=1
}
check_and_select_device() {
echo -e "${BLUE}Checking for connected devices...${RESET}"
mapfile -t DEVICE_LIST < <(adb devices | awk '$2 == "device" {print $1}')
DEVICE_COUNT=${#DEVICE_LIST[@]}
if [ $DEVICE_COUNT -eq 0 ]; then
echo -e "${RED}No devices connected. Please connect a device and try again.${RESET}"
exit 1
elif [ $DEVICE_COUNT -eq 1 ]; then
SELECTED_DEVICE=${DEVICE_LIST[0]}
echo -e "${GREEN}✓ Using device: $SELECTED_DEVICE${RESET}"
else
echo -e "${YELLOW}Multiple devices found:${RESET}"
for i in "${!DEVICE_LIST[@]}"; do
DEVICE=${DEVICE_LIST[$i]}
MODEL=$(adb -s "$DEVICE" shell getprop ro.product.model 2>/dev/null | tr -d '\r')
echo -e " ${BOLD}$((i + 1))${RESET}. $DEVICE ${YELLOW}($MODEL)${RESET}"
done
while true; do
echo -ne "${BOLD}Select device (1-$DEVICE_COUNT): ${RESET}"
read -r selection
if [[ $selection =~ ^[0-9]+$ ]] && [ $selection -ge 1 ] && [ $selection -le $DEVICE_COUNT ]; then
SELECTED_DEVICE=${DEVICE_LIST[$((selection - 1))]}
echo -e "${GREEN}✓ Selected device: $SELECTED_DEVICE${RESET}"
break
else
echo -e "${RED}Invalid selection. Please try again.${RESET}"
fi
done
fi
detect_device_capabilities
echo
}
create_config_if_missing() {
CONFIG_FILE="config.ini"
if [ ! -f "$CONFIG_FILE" ]; then
echo -e "${YELLOW}Configuration file not found. Creating a default config.ini...${RESET}"
save_settings_to_config # Generate config from current device state
echo -e "${GREEN}✓ Default config.ini created from current device settings.${RESET}"
echo -e "${YELLOW}You can now edit this file to create a custom default profile.${RESET}"
echo
fi
}
save_settings_to_config() {
CONFIG_FILE="config.ini"
echo -e "${BLUE}Saving current device settings to ${CONFIG_FILE}...${RESET}"
{
echo "# Android Optimizer Configuration Profile"
echo "# Edit these values to define the script's default behavior."
echo
echo "[Animation]"
echo "window_animation_scale=$(run_adb shell settings get global window_animation_scale)"
echo "transition_animation_scale=$(run_adb shell settings get global transition_animation_scale)"
echo "animator_duration_scale=$(run_adb shell settings get global animator_duration_scale)"
echo
echo "[Display]"
echo "density=$(run_adb shell wm density | grep -oE '[0-9]+' | head -1)"
echo "screen_off_timeout=$(run_adb shell settings get system screen_off_timeout | tr -d '\r')"
echo "screen_brightness=$(run_adb shell settings get system screen_brightness | tr -d '\r')"
echo "screen_brightness_mode=$(run_adb shell settings get system screen_brightness_mode | tr -d '\r')"
echo "font_scale=$(run_adb shell settings get system font_scale | tr -d '\r')"
echo
echo "[StatusBar]"
echo "clock_seconds=$(get_secure_setting_value clock_seconds)"
echo "icon_blacklist=$(get_secure_setting_value icon_blacklist)"
echo "status_bar_show_battery_percent=$(get_system_setting_value status_bar_show_battery_percent)"
echo
echo "[InputDebug]"
echo "show_touches=$(get_system_setting_value show_touches)"
echo "pointer_location=$(get_system_setting_value pointer_location)"
echo
echo "[HardwareAcceleration]"
echo "force_gpu_rendering=$(run_adb shell settings get global force_gpu_rendering)"
echo "profile_gpu_rendering=$(run_adb shell getprop debug.hwui.profile)"
echo "debug_gpu_overdraw=$(run_adb shell getprop debug.hwui.overdraw)"
echo
echo "[Power]"
echo "stay_on_while_plugged_in=$(run_adb shell settings get global stay_on_while_plugged_in | tr -d '\r')"
echo
echo "[Rotation]"
echo "accelerometer_rotation=$(run_adb shell settings get system accelerometer_rotation)"
echo "user_rotation=$(run_adb shell settings get system user_rotation)"
echo
echo "[Backup]"
echo "Prefix=android_settings_"
echo
echo "[Colors]"
echo "BOLD='\033[1m'"
echo "GREEN='\033[0;32m'"
echo "BLUE='\033[0;34m'"
echo "CYAN='\033[0;36m'"
echo "YELLOW='\033[0;33m'"
echo "RED='\033[0;31m'"
echo "RESET='\033[0m'"
} > "$CONFIG_FILE"
echo -e "${GREEN}✓ Settings saved to ${CONFIG_FILE}${RESET}"
}
load_config_to_device() {
echo -e "${YELLOW}Applying all settings from config.ini to device...${RESET}"
load_config_vars config.ini
normalize_config_vars
# Apply settings
run_adb shell settings put global window_animation_scale "$window_animation_scale"
run_adb shell settings put global transition_animation_scale "$transition_animation_scale"
run_adb shell settings put global animator_duration_scale "$animator_duration_scale"
run_adb shell wm density "$density"
run_adb shell settings put system screen_off_timeout "$screen_off_timeout"
run_adb shell settings put system screen_brightness_mode "$screen_brightness_mode"
run_adb shell settings put system screen_brightness "$screen_brightness"
run_adb shell settings put system font_scale "$font_scale"
run_adb shell settings put secure clock_seconds "$clock_seconds"
run_adb shell settings put system status_bar_show_battery_percent "$status_bar_show_battery_percent"
run_adb shell settings put system show_touches "$show_touches"
run_adb shell settings put system pointer_location "$pointer_location"
if [ -n "$icon_blacklist" ]; then
run_adb shell settings put secure icon_blacklist "$icon_blacklist"
else
run_adb shell settings delete secure icon_blacklist
fi
run_adb shell settings put global force_gpu_rendering "$force_gpu_rendering"
run_adb shell setprop debug.hwui.profile "$profile_gpu_rendering"
run_adb shell setprop debug.hwui.overdraw "$debug_gpu_overdraw"
run_adb shell settings put global stay_on_while_plugged_in "$stay_on_while_plugged_in"
run_adb shell settings put system accelerometer_rotation "$accelerometer_rotation"
run_adb shell settings put system user_rotation "$user_rotation"
echo -e "${GREEN}✓ All settings from config.ini have been applied.${RESET}"
echo -e "${BOLD}A reboot may be required for some changes to take full effect.${RESET}"
}
get_animation_settings() {
echo -e "${BOLD}Current Animation Settings:${RESET}"
echo -e "Window animation scale: ${GREEN}$(run_adb shell settings get global window_animation_scale)${RESET}"
echo -e "Transition animation scale: ${GREEN}$(run_adb shell settings get global transition_animation_scale)${RESET}"
echo -e "Animator duration scale: ${GREEN}$(run_adb shell settings get global animator_duration_scale)${RESET}"
}
get_dpi_info() {
local current_dpi default_dpi current_brightness brightness_mode brightness_mode_label current_font_scale clock_seconds_value clock_seconds_label blacklist_value wifi_icon_label mobile_icon_label tethering_icon_label bluetooth_icon_label vpn_icon_label data_saver_icon_label airplane_icon_label battery_percent_value battery_percent_label show_touches_value show_touches_label pointer_location_value pointer_location_label
current_dpi=$(run_adb shell wm density | grep -oE '[0-9]+' | head -1)
default_dpi=$(run_adb shell getprop ro.sf.lcd_density)
current_brightness=$(run_adb shell settings get system screen_brightness | tr -d '\r')
brightness_mode=$(run_adb shell settings get system screen_brightness_mode | tr -d '\r')
current_font_scale=$(run_adb shell settings get system font_scale | tr -d '\r')
clock_seconds_value=$(get_secure_setting_value clock_seconds)
blacklist_value=$(get_secure_setting_value icon_blacklist)
battery_percent_value=$(get_system_setting_value status_bar_show_battery_percent)
show_touches_value=$(get_system_setting_value show_touches)
pointer_location_value=$(get_system_setting_value pointer_location)
case "$brightness_mode" in
0) brightness_mode_label="Manual";;
1) brightness_mode_label="Adaptive";;
*) brightness_mode_label="Unknown ($brightness_mode)";;
esac
case "$clock_seconds_value" in
1) clock_seconds_label="Shown";;
0|"") clock_seconds_label="Hidden";;
*) clock_seconds_label="Unknown ($clock_seconds_value)";;
esac
case ",$blacklist_value," in
*,wifi,*) wifi_icon_label="Hidden";;
*) wifi_icon_label="Shown";;
esac
case ",$blacklist_value," in
*,mobile,*) mobile_icon_label="Hidden";;
*) mobile_icon_label="Shown";;
esac
case ",$blacklist_value," in
*,hotspot,*) tethering_icon_label="Hidden";;
*) tethering_icon_label="Shown";;
esac
case ",$blacklist_value," in
*,bluetooth,*) bluetooth_icon_label="Hidden";;
*) bluetooth_icon_label="Shown";;
esac
case ",$blacklist_value," in
*,vpn,*) vpn_icon_label="Hidden";;
*) vpn_icon_label="Shown";;
esac
case ",$blacklist_value," in
*,data_saver,*) data_saver_icon_label="Hidden";;
*) data_saver_icon_label="Shown";;
esac
case ",$blacklist_value," in
*,airplane,*) airplane_icon_label="Hidden";;
*) airplane_icon_label="Shown";;
esac
case "$battery_percent_value" in
1) battery_percent_label="Shown";;
0|"") battery_percent_label="Hidden";;
*) battery_percent_label="Unknown ($battery_percent_value)";;
esac
case "$show_touches_value" in
1) show_touches_label="Enabled";;
0|"") show_touches_label="Disabled";;
*) show_touches_label="Unknown ($show_touches_value)";;
esac
case "$pointer_location_value" in
1) pointer_location_label="Enabled";;
0|"") pointer_location_label="Disabled";;
*) pointer_location_label="Unknown ($pointer_location_value)";;
esac
echo -e "${BOLD}Display Information:${RESET}"
echo -e "Current DPI: ${GREEN}$current_dpi${RESET}"
echo -e "Default DPI: ${GREEN}$default_dpi${RESET}"
echo -e "Brightness: ${GREEN}$current_brightness${RESET} ${YELLOW}(0-255)${RESET}"
echo -e "Brightness mode: ${GREEN}$brightness_mode_label${RESET}"
echo -e "Font scale: ${GREEN}$current_font_scale${RESET}"
echo -e "Clock seconds: ${GREEN}$clock_seconds_label${RESET}"
echo -e "Wi-Fi icon: ${GREEN}$wifi_icon_label${RESET}"
echo -e "Mobile icon: ${GREEN}$mobile_icon_label${RESET}"
echo -e "Tethering icon: ${GREEN}$tethering_icon_label${RESET}"
echo -e "Bluetooth icon: ${GREEN}$bluetooth_icon_label${RESET}"
echo -e "VPN icon: ${GREEN}$vpn_icon_label${RESET}"
echo -e "Data Saver icon: ${GREEN}$data_saver_icon_label${RESET}"
echo -e "Airplane icon: ${GREEN}$airplane_icon_label${RESET}"
echo -e "Battery percentage: ${GREEN}$battery_percent_label${RESET}"
echo -e "Show touches: ${GREEN}$show_touches_label${RESET}"
echo -e "Pointer location: ${GREEN}$pointer_location_label${RESET}"
}
get_hw_acceleration_status() {
echo -e "${BOLD}Hardware Acceleration Status:${RESET}"
echo -e "HW Rendering: ${GREEN}$(run_adb shell getprop debug.hwui.render_dirty_regions 2>/dev/null | tr -d '\r')${RESET}"
echo -e "GPU Acceleration: ${GREEN}$(run_adb shell getprop ro.config.hw_quickpoweron 2>/dev/null | tr -d '\r')${RESET}"
echo -e "Force GPU Rendering: ${GREEN}$(run_adb shell settings get global force_gpu_rendering 2>/dev/null | tr -d '\r')${RESET}"
echo -e "UI Hardware Acceleration: ${GREEN}$(run_adb shell getprop persist.sys.ui.hw 2>/dev/null | tr -d '\r')${RESET}"
}
get_device_info() {
echo -e "${BOLD}Device Information:${RESET}"
echo -e "Device ID: ${GREEN}$SELECTED_DEVICE${RESET}"
echo -e "Device Model: ${GREEN}$(run_adb shell getprop ro.product.model)${RESET}"
echo -e "Android Version: ${GREEN}$(run_adb shell getprop ro.build.version.release)${RESET}"
echo -e "SDK Version: ${GREEN}$(run_adb shell getprop ro.build.version.sdk)${RESET}"
echo -e "Screen Resolution: ${GREEN}$(run_adb shell wm size)${RESET}"
}
get_full_device_info() {
local manufacturer brand device_name android_version sdk_version security_patch
local build_id build_type abi_list serial battery_line battery_level battery_status
local mem_total mem_available storage_line uptime_seconds uptime_human ip_address
manufacturer=$(run_adb shell getprop ro.product.manufacturer | tr -d '\r')
brand=$(run_adb shell getprop ro.product.brand | tr -d '\r')
device_name=$(run_adb shell getprop ro.product.model | tr -d '\r')
android_version=$(run_adb shell getprop ro.build.version.release | tr -d '\r')
sdk_version=$(run_adb shell getprop ro.build.version.sdk | tr -d '\r')
security_patch=$(run_adb shell getprop ro.build.version.security_patch | tr -d '\r')
build_id=$(run_adb shell getprop ro.build.display.id | tr -d '\r')
build_type=$(run_adb shell getprop ro.build.type | tr -d '\r')
abi_list=$(run_adb shell getprop ro.product.cpu.abilist | tr -d '\r')
serial=$(run_adb shell getprop ro.serialno | tr -d '\r')
battery_line=$(run_adb shell dumpsys battery | tr -d '\r')
battery_level=$(printf '%s\n' "$battery_line" | sed -n 's/.*level: \([0-9]\+\).*/\1/p' | head -1)
battery_status=$(printf '%s\n' "$battery_line" | sed -n 's/.*status: \([0-9]\+\).*/\1/p' | head -1)
mem_total=$(run_adb shell "awk '/MemTotal/ {print \$2 \" kB\"}' /proc/meminfo" | tr -d '\r')
mem_available=$(run_adb shell "awk '/MemAvailable/ {print \$2 \" kB\"}' /proc/meminfo" | tr -d '\r')
storage_line=$(run_adb shell df -h /data 2>/dev/null | tail -1 | tr -d '\r')
uptime_seconds=$(run_adb shell cut -d. -f1 /proc/uptime | tr -d '\r')
ip_address=$(run_adb shell "ip -4 addr show wlan0 2>/dev/null | awk '/inet / {print \$2}' | cut -d/ -f1" | tr -d '\r')
if [ -n "$uptime_seconds" ] && [[ "$uptime_seconds" =~ ^[0-9]+$ ]]; then
uptime_human="$((uptime_seconds / 86400))d $(((uptime_seconds % 86400) / 3600))h $(((uptime_seconds % 3600) / 60))m"
else
uptime_human="Unknown"
fi
case "$battery_status" in
2) battery_status="Charging";;
3) battery_status="Discharging";;
4) battery_status="Not charging";;
5) battery_status="Full";;
*) battery_status="Unknown";;
esac
[ -z "$ip_address" ] && ip_address="Unavailable"
echo -e "${BOLD}Full Device Information:${RESET}"
echo -e "Device ID: ${GREEN}$SELECTED_DEVICE${RESET}"
echo -e "Serial: ${GREEN}$serial${RESET}"
echo -e "Manufacturer: ${GREEN}$manufacturer${RESET}"
echo -e "Brand: ${GREEN}$brand${RESET}"
echo -e "Model: ${GREEN}$device_name${RESET}"
echo -e "Android Version: ${GREEN}$android_version${RESET}"
echo -e "SDK Version: ${GREEN}$sdk_version${RESET}"
echo -e "Security Patch: ${GREEN}$security_patch${RESET}"
echo -e "Build ID: ${GREEN}$build_id${RESET}"
echo -e "Build Type: ${GREEN}$build_type${RESET}"
echo -e "CPU ABIs: ${GREEN}$abi_list${RESET}"
echo -e "Screen Resolution: ${GREEN}$(run_adb shell wm size | tr -d '\r')${RESET}"
echo -e "Battery Level: ${GREEN}${battery_level:-Unknown}%${RESET}"
echo -e "Battery Status: ${GREEN}$battery_status${RESET}"
echo -e "Memory Total: ${GREEN}${mem_total:-Unknown}${RESET}"
echo -e "Memory Available: ${GREEN}${mem_available:-Unknown}${RESET}"
echo -e "Storage (/data): ${GREEN}${storage_line:-Unavailable}${RESET}"
echo -e "Uptime: ${GREEN}$uptime_human${RESET}"
echo -e "Wi-Fi IP: ${GREEN}$ip_address${RESET}"
}
get_rotation_settings() {
ACCELEROMETER_ROTATION=$(run_adb shell settings get system accelerometer_rotation | tr -d '\r')
USER_ROTATION=$(run_adb shell settings get system user_rotation | tr -d '\r')
[ "$ACCELEROMETER_ROTATION" == "1" ] && ACCELEROMETER_ROTATION_STATUS="Enabled" || ACCELEROMETER_ROTATION_STATUS="Disabled"
case "$USER_ROTATION" in
"0") USER_ROTATION_VALUE="Portrait (0°)";;
"1") USER_ROTATION_VALUE="Landscape (90°)";;
"2") USER_ROTATION_VALUE="Upside down (180°)";;
"3") USER_ROTATION_VALUE="Landscape reversed (270°)";;
*) USER_ROTATION_VALUE="Unknown ($USER_ROTATION)";;
esac
echo -e "${BOLD}Current Rotation Settings:${RESET}"
echo -e "Auto-Rotation: ${GREEN}$ACCELEROMETER_ROTATION_STATUS${RESET}"
echo -e "Current Fixed Rotation: ${GREEN}$USER_ROTATION_VALUE${RESET}"
}
set_animation_scale() {
SCALE=$1
echo -e "${BLUE}Setting all animation scales to ${SCALE}x...${RESET}"
run_adb shell settings put global window_animation_scale "$SCALE"
run_adb shell settings put global transition_animation_scale "$SCALE"
run_adb shell settings put global animator_duration_scale "$SCALE"
echo -e "${GREEN}✓ Animation scales set to ${SCALE}x${RESET}"
}
set_custom_dpi() {
get_dpi_info
echo -n -e "${BOLD}Enter new DPI value: ${RESET}"
read -r new_dpi
if [[ "$new_dpi" =~ ^[0-9]+$ ]]; then
echo -e "${BLUE}Setting device DPI to $new_dpi...${RESET}"
run_adb shell wm density "$new_dpi"
echo -e "${GREEN}✓ DPI set to $new_dpi${RESET}"
echo -e "${BOLD}Note: You may need to restart your device for changes to take full effect${RESET}"
else
echo -e "${RED}Invalid DPI value. Please enter a number.${RESET}"
fi
}
reset_dpi() {
echo -e "${BLUE}Resetting DPI to device default...${RESET}"
run_adb shell wm density reset
echo -e "${GREEN}✓ DPI reset to default${RESET}"
echo -e "${BOLD}Note: You may need to restart your device for changes to take full effect${RESET}"
}
set_screen_timeout() {
local timeout_seconds timeout_millis
timeout_seconds=$1
timeout_millis=$((timeout_seconds * 1000))
echo -e "${BLUE}Setting screen timeout to ${timeout_seconds} seconds...${RESET}"
run_adb shell settings put system screen_off_timeout "$timeout_millis"
echo -e "${GREEN}✓ Screen timeout set to ${timeout_seconds} seconds${RESET}"
}
set_custom_screen_timeout() {
local timeout_seconds
echo -n -e "${BOLD}Enter screen timeout in seconds: ${RESET}"
read -r timeout_seconds
if [[ "$timeout_seconds" =~ ^[0-9]+$ ]] && [ "$timeout_seconds" -gt 0 ]; then
set_screen_timeout "$timeout_seconds"
else
echo -e "${RED}Invalid timeout value. Please enter a positive whole number.${RESET}"
fi
}
set_brightness_mode() {
local brightness_mode brightness_mode_label
brightness_mode=$1
case "$brightness_mode" in
0) brightness_mode_label="manual";;
1) brightness_mode_label="adaptive";;
*) brightness_mode_label="unknown";;
esac
echo -e "${BLUE}Setting brightness mode to ${brightness_mode_label}...${RESET}"
run_adb shell settings put system screen_brightness_mode "$brightness_mode"
echo -e "${GREEN}✓ Brightness mode set to ${brightness_mode_label}${RESET}"
}
set_brightness() {
local brightness_level
brightness_level=$1
echo -e "${BLUE}Setting brightness to ${brightness_level}...${RESET}"
run_adb shell settings put system screen_brightness_mode 0
run_adb shell settings put system screen_brightness "$brightness_level"
echo -e "${GREEN}✓ Brightness set to ${brightness_level}${RESET}"
}
set_custom_brightness() {
local brightness_level
echo -n -e "${BOLD}Enter brightness value (0-255): ${RESET}"
read -r brightness_level
if [[ "$brightness_level" =~ ^[0-9]+$ ]] && [ "$brightness_level" -ge 0 ] && [ "$brightness_level" -le 255 ]; then
set_brightness "$brightness_level"
else
echo -e "${RED}Invalid brightness value. Please enter a whole number from 0 to 255.${RESET}"
fi
}
set_font_scale() {
local scale_value
scale_value=$1
echo -e "${BLUE}Setting font scale to ${scale_value}...${RESET}"
run_adb shell settings put system font_scale "$scale_value"
echo -e "${GREEN}✓ Font scale set to ${scale_value}${RESET}"
}
set_custom_font_scale() {
local scale_value
echo -n -e "${BOLD}Enter font scale (example: 1.15): ${RESET}"
read -r scale_value
if [[ "$scale_value" =~ ^[0-9]+(\.[0-9]+)?$ ]] && awk "BEGIN {exit !($scale_value > 0)}"; then
set_font_scale "$scale_value"
else
echo -e "${RED}Invalid font scale. Please enter a positive number.${RESET}"
fi
}
set_stay_awake_mode() {
local plug_value mode_label
plug_value=$1
case "$plug_value" in
0) mode_label="disabled";;
3) mode_label="AC and USB";;
7) mode_label="AC, USB, and wireless";;
*) mode_label="custom ($plug_value)";;
esac
echo -e "${BLUE}Setting stay-awake mode to ${mode_label}...${RESET}"
run_adb shell settings put global stay_on_while_plugged_in "$plug_value"
echo -e "${GREEN}✓ Stay-awake mode set to ${mode_label}${RESET}"
}
set_clock_seconds() {
local clock_value clock_label
clock_value=$1
case "$clock_value" in
0) clock_label="hidden";;
1) clock_label="shown";;
*) clock_label="custom ($clock_value)";;
esac
echo -e "${BLUE}Setting status bar clock seconds to ${clock_label}...${RESET}"
run_adb shell settings put secure clock_seconds "$clock_value"
echo -e "${GREEN}✓ Status bar clock seconds ${clock_label}${RESET}"
}
set_status_bar_icon_visibility() {
local icon_name icon_label show_value blacklist_value updated_blacklist item
local filtered_items=()
icon_name=$1
icon_label=$2
show_value=$3
blacklist_value=$(get_secure_setting_value icon_blacklist)
IFS=',' read -r -a current_items <<< "$blacklist_value"
for item in "${current_items[@]}"; do
[ -z "$item" ] && continue
[ "$item" = "$icon_name" ] && continue
filtered_items+=("$item")
done
if [ "$show_value" -eq 0 ]; then
filtered_items+=("$icon_name")
fi
updated_blacklist=""
for item in "${filtered_items[@]}"; do
if [ -n "$updated_blacklist" ]; then
updated_blacklist="${updated_blacklist},${item}"
else
updated_blacklist="$item"
fi
done
echo -e "${BLUE}Updating ${icon_label} icon visibility...${RESET}"
if [ -n "$updated_blacklist" ]; then
run_adb shell settings put secure icon_blacklist "$updated_blacklist"
else
run_adb shell settings delete secure icon_blacklist
fi
if [ "$show_value" -eq 1 ]; then
echo -e "${GREEN}✓ ${icon_label} icon shown${RESET}"
else
echo -e "${GREEN}✓ ${icon_label} icon hidden${RESET}"
fi
}
set_system_toggle() {
local setting_key setting_label setting_value enabled_label disabled_label
setting_key=$1
setting_label=$2
setting_value=$3
enabled_label=${4:-enabled}
disabled_label=${5:-disabled}
echo -e "${BLUE}Updating ${setting_label}...${RESET}"
run_adb shell settings put system "$setting_key" "$setting_value"
if [ "$setting_value" -eq 1 ]; then
echo -e "${GREEN}✓ ${setting_label} ${enabled_label}${RESET}"
else
echo -e "${GREEN}✓ ${setting_label} ${disabled_label}${RESET}"
fi
}
enable_all_rotations() {
if [ "$CAP_ROTATION_WINDOW_CMD" -ne 1 ]; then
echo -e "${YELLOW}This device does not support 'cmd window set-allowed-display-rotations'.${RESET}"
return 1
fi
echo -e "${BLUE}Enabling all screen rotations (including upside-down)...${RESET}"
run_adb shell cmd window set-allowed-display-rotations 0,1,2,3
echo -e "${GREEN}✓ All screen rotations enabled${RESET}"
}
disable_upside_down_rotation() {
if [ "$CAP_ROTATION_WINDOW_CMD" -ne 1 ]; then
echo -e "${YELLOW}This device does not support 'cmd window set-allowed-display-rotations'.${RESET}"
return 1
fi
echo -e "${BLUE}Disabling upside-down rotation...${RESET}"
run_adb shell cmd window set-allowed-display-rotations 0,1,3
echo -e "${GREEN}✓ Upside-down rotation disabled${RESET}"
}
set_specific_rotation() {
ROTATION=$1
case "$ROTATION" in
"0") ROTATION_NAME="Portrait (0°)";;
"1") ROTATION_NAME="Landscape (90°)";;
"2") ROTATION_NAME="Upside down (180°)";;
"3") ROTATION_NAME="Landscape reversed (270°)";;
esac
echo -e "${BLUE}Setting rotation to ${ROTATION_NAME}...${RESET}"
run_adb shell settings put system accelerometer_rotation 0
run_adb shell settings put system user_rotation "$ROTATION"
echo -e "${GREEN}✓ Rotation set to ${ROTATION_NAME}${RESET}"
}
toggle_auto_rotation() {
CURRENT_AUTO_ROTATION=$(run_adb shell settings get system accelerometer_rotation | tr -d '\r')
if [ "$CURRENT_AUTO_ROTATION" == "1" ]; then
run_adb shell settings put system accelerometer_rotation 0
echo -e "${GREEN}✓ Auto-rotation disabled${RESET}"
else
run_adb shell settings put system accelerometer_rotation 1
echo -e "${GREEN}✓ Auto-rotation enabled${RESET}"
fi
}
enable_all_hw_acceleration() {
local success_count failure_count
success_count=0
failure_count=0
echo -e "${BLUE}Enabling all hardware acceleration features...${RESET}"
run_step "Enable HWUI dirty region rendering" run_adb shell setprop debug.hwui.render_dirty_regions true && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Enable persist.sys.ui.hw" run_adb shell setprop persist.sys.ui.hw 1 && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Enable force GPU rendering" run_adb shell settings put global force_gpu_rendering 1 && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step_summary "Hardware acceleration enable" "$success_count" "$failure_count"
echo -e "${BOLD}Note: A device restart is recommended for changes to take full effect${RESET}"
}
disable_all_hw_acceleration() {
local success_count failure_count
success_count=0
failure_count=0
echo -e "${BLUE}Disabling all hardware acceleration features...${RESET}"
run_step "Disable HWUI dirty region rendering" run_adb shell setprop debug.hwui.render_dirty_regions false && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Disable persist.sys.ui.hw" run_adb shell setprop persist.sys.ui.hw 0 && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Disable force GPU rendering" run_adb shell settings put global force_gpu_rendering 0 && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step_summary "Hardware acceleration disable" "$success_count" "$failure_count"
echo -e "${BOLD}Note: A device restart is recommended for changes to take full effect${RESET}"
}
reset_hw_acceleration() {
local success_count failure_count
success_count=0
failure_count=0
echo -e "${BLUE}Resetting hardware acceleration to device defaults...${RESET}"
run_step "Reset HWUI dirty region rendering" run_adb shell setprop debug.hwui.render_dirty_regions "" && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Reset persist.sys.ui.hw" run_adb shell setprop persist.sys.ui.hw "" && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Delete force GPU rendering override" run_adb shell settings delete global force_gpu_rendering && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Disable GPU profile rendering" run_adb shell setprop debug.hwui.profile false && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step "Disable GPU overdraw debug" run_adb shell setprop debug.hwui.overdraw false && success_count=$((success_count + 1)) || failure_count=$((failure_count + 1))
run_step_summary "Hardware acceleration reset" "$success_count" "$failure_count"
echo -e "${BOLD}Note: A device restart is recommended for changes to take full effect${RESET}"
}
toggle_gpu_profile() {
CURRENT_STATUS=$(run_adb shell getprop debug.hwui.profile)
if [[ "$CURRENT_STATUS" == "true" || "$CURRENT_STATUS" == "visual_bars" ]]; then
run_adb shell setprop debug.hwui.profile false
echo -e "${GREEN}✓ GPU Profile Rendering disabled${RESET}"
else
run_adb shell setprop debug.hwui.profile true
echo -e "${GREEN}✓ GPU Profile Rendering enabled (bars on screen)${RESET}"
fi
}
toggle_gpu_overdraw() {
CURRENT_STATUS=$(run_adb shell getprop debug.hwui.overdraw)
if [[ "$CURRENT_STATUS" == "true" || "$CURRENT_STATUS" == "show" ]]; then
run_adb shell setprop debug.hwui.overdraw false
echo -e "${GREEN}✓ GPU Overdraw Debugging disabled${RESET}"
else
run_adb shell setprop debug.hwui.overdraw true
echo -e "${GREEN}✓ GPU Overdraw Debugging enabled (colors on screen)${RESET}"
fi
}
reboot_device() {
echo -e "${YELLOW}Rebooting device $SELECTED_DEVICE...${RESET}"
run_adb reboot
echo -e "${GREEN}✓ Reboot command sent${RESET}"
echo -e "${BOLD}Device is now restarting...${RESET}"
echo -e "${BLUE}Please wait for the device to reconnect before continuing${RESET}"
echo -n -e "${YELLOW}Would you like to wait for the device to reconnect? (y/n) ${RESET}"
read -r wait_response
if [[ "$wait_response" =~ ^[Yy]$ ]]; then
echo -e "${BLUE}Waiting for device to reconnect...${RESET}"
run_adb wait-for-device
echo -e "${GREEN}✓ Device reconnected!${RESET}"
else
echo -e "${YELLOW}Exiting. You'll need to restart this script after your device has rebooted.${RESET}"
exit 0
fi
}
backup_settings() {
load_config_vars config.ini
normalize_config_vars
BACKUP_FILE="${Prefix}$(date +%Y%m%d_%H%M%S).bak"
echo -e "${BLUE}Performing a full backup of all known settings to ${BACKUP_FILE}...${RESET}"
save_settings_to_config # Use the same logic to ensure all settings are captured
mv config.ini "$BACKUP_FILE"
echo -e "${GREEN}✓ Full backup complete: ${BACKUP_FILE}${RESET}"
create_config_if_missing # Recreate a default config to continue working
}
change_device() {
check_and_select_device
}
get_selected_device_model() {
local model status
set +e
model=$(run_adb shell getprop ro.product.model 2>/dev/null | tr -d '\r')
status=$?
set -e
if [ $status -ne 0 ] || [ -z "$model" ]; then
echo "Unknown device"
else
echo "$model"
fi
}
restore_settings() {
local backup_files=()
shopt -s nullglob
backup_files=(*.bak)
shopt -u nullglob
if [ ${#backup_files[@]} -eq 0 ]; then
echo -e "${YELLOW}No backup files found in the current directory.${RESET}"
return 1
fi
echo -e "${BLUE}Select a backup file to restore:${RESET}"
select BACKUP_FILE in "${backup_files[@]}"; do
if [ -n "$BACKUP_FILE" ] && [ -f "$BACKUP_FILE" ]; then
break
else
echo -e "${RED}Invalid selection. Please try again.${RESET}"
fi
done
echo -e "${YELLOW}Restoring all settings from ${BACKUP_FILE}...${RESET}"
cp "$BACKUP_FILE" config.ini
load_config_to_device
echo -e "${GREEN}✓ All settings restored from ${BACKUP_FILE}${RESET}"
}
handle_info() {
case $1 in
1) get_animation_settings;;
2) get_dpi_info;;
3) get_device_info;;
4) get_hw_acceleration_status;;
5) get_rotation_settings;;
esac
}
handle_animation() {
case $1 in
6) set_animation_scale 1.0;;
7) set_animation_scale 0.9;;
8) set_animation_scale 0.75;;
9)
echo -n -e "${BOLD}Enter custom scale (e.g., 0.5): ${RESET}"
read -r custom_scale
if [[ "$custom_scale" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
set_animation_scale "$custom_scale"
else
echo -e "${RED}Invalid scale. Please enter a number.${RESET}"
fi
;;
10) set_animation_scale 0.0;;