Repository navigation
Expand file tree
/
Copy pathShield-Optimizer.ps1
More file actions
4121 lines (3644 loc) · 184 KB
/
Copy pathShield-Optimizer.ps1
File metadata and controls
4121 lines (3644 loc) · 184 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
param(
[switch]$ForceAdbDownload,
[switch]$LightMode,
[switch]$DarkMode,
[string]$Subnet
)
# Set script-level flags
$Script:ForceAdbDownload = $ForceAdbDownload
$Script:LightMode = $LightMode
$Script:DarkMode = $DarkMode
$Script:Subnet = $Subnet
<#
.SYNOPSIS
Android TV Optimizer
.DESCRIPTION
Supports Nvidia Shield TV, Onn 4K Pro, Chromecast with Google TV, and other Android TV devices.
#>
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# --- PLATFORM DETECTION ---
$Script:Platform = switch ($true) {
$IsWindows { "Windows" }
$IsMacOS { "macOS" }
$IsLinux { "Linux" }
default { if ($env:OS -match "Windows") { "Windows" } else { "Unknown" } }
}
$Script:IsUnix = $Script:Platform -in @("macOS", "Linux")
# --- COLOR SCHEME ---
# Centralized color definitions - change colors in ONE place
$Script:Colors = @{}
function Test-SystemLightMode {
# Returns $true if system is in light mode, $false otherwise
try {
if ($IsMacOS) {
# macOS: Use AppleScript for reliable detection (defaults can be stale)
$script = 'tell application "System Events" to tell appearance preferences to get dark mode'
$darkMode = & osascript -e $script 2>$null
return ($darkMode -eq "false")
}
elseif ($IsWindows) {
# Windows: AppsUseLightTheme = 1 means light, 0 means dark
$regPath = 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'
$theme = (Get-ItemProperty -Path $regPath -Name AppsUseLightTheme -ErrorAction SilentlyContinue).AppsUseLightTheme
return ($theme -eq 1)
}
} catch {}
# Default to dark mode (most common for terminals)
return $false
}
function Initialize-Colors {
# Determine theme: explicit flags take priority, then auto-detect
$useLightMode = $false
if ($Script:LightMode) {
$useLightMode = $true
}
elseif ($Script:DarkMode) {
$useLightMode = $false
}
else {
# Auto-detect system appearance
$useLightMode = Test-SystemLightMode
}
if ($useLightMode) {
# Light background (dark text colors) - high contrast
$Script:Colors = @{
# Semantic colors
Header = "DarkBlue"
SubHeader = "DarkBlue"
Success = "DarkGreen"
Warning = "DarkRed"
Error = "DarkRed"
Info = "Black"
# Text colors
Text = "Black" # Default text
TextDim = "DarkGray" # Secondary/muted text
TextBright = "DarkBlue" # Emphasized text
# UI element colors
Label = "DarkBlue" # Labels like "Device:", "RAM:"
Value = "Black" # Data values
Separator = "DarkGray" # Lines, dividers
# Menu colors
Selected = "DarkBlue" # Selected menu item
Unselected = "DarkGray" # Unselected menu items
Shortcut = "DarkRed" # Keyboard shortcut letters
Bracket = "DarkGray" # Brackets around shortcuts
# Status colors
Active = "DarkGreen"
Disabled = "DarkMagenta"
Missing = "DarkRed"
Installed = "DarkBlue"
NotFound = "DarkGray"
}
# ANSI codes for light mode
$Script:AnsiColors = @{
Text = "30" # Black
TextDim = "90" # Dark Gray
Selected = "34" # Dark Blue
Gray = "90" # Dark Gray
}
} else {
# Dark background (light text colors) - DEFAULT
$Script:Colors = @{
# Semantic colors
Header = "Cyan"
SubHeader = "Blue"
Success = "Green"
Warning = "Yellow"
Error = "Red"
Info = "White"
# Text colors
Text = "White" # Default text
TextDim = "DarkCyan" # Secondary/muted text
TextBright = "Cyan" # Emphasized text
# UI element colors
Label = "Cyan" # Labels like "Device:", "RAM:"
Value = "White" # Data values
Separator = "Blue" # Lines, dividers
# Menu colors
Selected = "Cyan" # Selected menu item
Unselected = "White" # Unselected menu items
Shortcut = "Yellow" # Keyboard shortcut letters
Bracket = "Gray" # Brackets around shortcuts
# Status colors
Active = "Green"
Disabled = "Magenta"
Missing = "Red"
Installed = "Cyan"
NotFound = "Gray"
}
# ANSI codes for dark mode
$Script:AnsiColors = @{
Text = "97" # Bright White
TextDim = "36" # Cyan
Selected = "96" # Bright Cyan
Gray = "37" # Gray
}
}
}
# Initialize colors immediately
Initialize-Colors
# --- CONFIGURATION & DATA MODELS ---
# Device type enum
$Script:DeviceType = @{
Shield = "Shield"
GoogleTV = "GoogleTV"
Unknown = "Unknown"
}
# ============================================================================
# APP LISTS - Hashtable Format for Readability and Maintainability
# ============================================================================
#
# Each app entry is a hashtable with the following properties:
# Package - Android package name (e.g., "com.google.android.feedback")
# Name - Human-readable app name shown in UI
# Method - Default action: "DISABLE" (reversible) or "UNINSTALL" (user-level removal)
# Risk - Risk level: "Safe", "Medium", "High Risk", "Advanced"
# OptimizeDescription - Description shown when optimizing (removing/disabling)
# RestoreDescription - Description shown when restoring
# DefaultOptimize - Default optimize choice: "Y" (yes) or "N" (no/skip)
# DefaultRestore - Default restore choice: "Y" (yes) or "N" (no/skip)
#
# Risk Levels:
# Safe - No negative impact, recommended to disable/remove
# Medium - Minor functionality loss, user preference
# High Risk - May break features, use with caution
# Advanced - For power users only, may break critical functions
# ============================================================================
# Apps common to ALL Android TV devices
$Script:CommonAppList = @(
# --- SAFE: Universal bloatware and telemetry ---
@{ Package = "com.google.android.feedback"; Name = "Google Feedback"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Stops feedback data collection."; RestoreDescription = "Restores Google feedback services."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.android.printspooler"; Name = "Print Spooler"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Disables unused print service."; RestoreDescription = "Restores print service."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.android.gallery3d"; Name = "Android Gallery"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Removes legacy photo viewer."; RestoreDescription = "Restores legacy photo viewer."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
# --- SAFE: Dead/defunct apps ---
@{ Package = "com.google.android.videos"; Name = "Google Play Movies"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Removes defunct app."; RestoreDescription = "Restores defunct app."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.google.android.music"; Name = "Google Play Music"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Removes defunct app."; RestoreDescription = "Restores defunct app."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.Funimation.FunimationNow.androidtv"; Name = "Funimation"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Service shut down April 2024 (merged into Crunchyroll)."; RestoreDescription = "Restores defunct app."; DefaultOptimize = "Y"; DefaultRestore = "N" }
@{ Package = "com.google.stadia.android"; Name = "Stadia"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Service shut down January 2023."; RestoreDescription = "Restores defunct app."; DefaultOptimize = "Y"; DefaultRestore = "N" }
@{ Package = "com.quibi.qlient"; Name = "Quibi"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Service shut down December 2020."; RestoreDescription = "Restores defunct app."; DefaultOptimize = "Y"; DefaultRestore = "N" }
@{ Package = "com.hbo.hbonow"; Name = "HBO Now (legacy)"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Pre-Max HBO app, replaced by com.wbd.stream."; RestoreDescription = "Restores defunct app."; DefaultOptimize = "Y"; DefaultRestore = "N" }
# --- SAFE: Streaming apps (user choice, not bloat) ---
@{ Package = "com.netflix.ninja"; Name = "Netflix"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Netflix."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.amazon.amazonvideo.livingroom"; Name = "Amazon Prime Video"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Prime Video."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.amazon.amazonvideo.livingroom.nvidia"; Name = "Amazon Prime Video (Shield)"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Pre-installed system app - disable only."; RestoreDescription = "Restores Prime Video."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.wbd.stream"; Name = "Max (HBO)"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Max."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.discovery.discoveryplus.androidtv"; Name = "Discovery+"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Discovery+."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.hulu.livingroomplus"; Name = "Hulu"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Hulu."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "tv.twitch.android.app"; Name = "Twitch"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Twitch."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.disney.disneyplus"; Name = "Disney+"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Disney+."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.disney.disneyplus.prod"; Name = "Disney+ (Alt)"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Disney+."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.spotify.tv.android"; Name = "Spotify"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Spotify."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.google.android.youtube.tvmusic"; Name = "YouTube Music"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores YouTube Music."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.apple.atve.androidtv.appletv"; Name = "Apple TV"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Apple TV."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.cbs.ott"; Name = "Paramount+"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Paramount+."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.crunchyroll.crunchyroid"; Name = "Crunchyroll"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Crunchyroll."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "air.com.vudu.air.DownloaderTablet"; Name = "Vudu"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Vudu."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.google.android.youtube.tv"; Name = "YouTube"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores YouTube."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.google.android.youtube.tvkids"; Name = "YouTube Kids"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores YouTube Kids."; DefaultOptimize = "N"; DefaultRestore = "N" }
# --- SAFE: Canadian streaming apps ---
@{ Package = "ca.bellmedia.crave"; Name = "Crave"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Canadian streaming app."; RestoreDescription = "Restores Crave."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "ca.bell.tv"; Name = "Bell Fibe TV"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Bell TV app."; RestoreDescription = "Restores Bell Fibe TV."; DefaultOptimize = "N"; DefaultRestore = "N" }
# --- SAFE: Free ad-supported streaming (FAST) ---
@{ Package = "tv.pluto.android"; Name = "Pluto TV"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Free streaming app."; RestoreDescription = "Restores Pluto TV."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.tubitv"; Name = "Tubi"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Free streaming app."; RestoreDescription = "Restores Tubi."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.peacocktv.peacockandroid"; Name = "Peacock"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Peacock."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.sling"; Name = "Sling TV"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Sling TV."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.philo.philo"; Name = "Philo"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Philo."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.fubo.firetv.screen"; Name = "fuboTV"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores fuboTV."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.haystack.android"; Name = "Haystack News"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "News streaming app."; RestoreDescription = "Restores Haystack News."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.plexapp.android"; Name = "Plex"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Plex."; DefaultOptimize = "N"; DefaultRestore = "N" }
# --- SAFE: Premium streaming add-ons ---
@{ Package = "com.starz.starzplay.android"; Name = "STARZ"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores STARZ."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.showtime.standalone"; Name = "Showtime"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores Showtime."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.amcplus.amcfiretv"; Name = "AMC+"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores AMC+."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.britbox.us"; Name = "BritBox"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores BritBox."; DefaultOptimize = "N"; DefaultRestore = "N" }
@{ Package = "com.epix.epixnow.google"; Name = "MGM+"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Streaming App."; RestoreDescription = "Restores MGM+."; DefaultOptimize = "N"; DefaultRestore = "N" }
# --- MEDIUM: Minor functionality impact ---
@{ Package = "com.android.dreams.basic"; Name = "Basic Daydream"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Disables basic screensaver."; RestoreDescription = "Restores basic screensaver."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.google.android.tv.remote.service"; Name = "Virtual Remote Keyboard"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Disables virtual remote keyboard that auto-activates."; RestoreDescription = "Restores virtual remote keyboard functionality."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.android.providers.tv"; Name = "Live Channels Provider"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Breaks Watch Next / Continue Watching channels for Apple TV, Netflix, Disney+, etc. Also breaks Pandora and the Live Channels app."; RestoreDescription = "Restores Watch Next channel support and Live Channels."; DefaultOptimize = "N"; DefaultRestore = "Y" }
# --- HIGH RISK: May break features ---
@{ Package = "com.google.android.katniss"; Name = "Google Assistant"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Breaks voice search."; RestoreDescription = "Restores voice search."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.google.android.apps.mediashell"; Name = "Chromecast Built-in"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Breaks casting to device."; RestoreDescription = "Restores Chromecast."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.google.android.tts"; Name = "Google Text-to-Speech"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Breaks accessibility features."; RestoreDescription = "Restores text-to-speech."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.google.android.play.games"; Name = "Google Play Games"; Method = "DISABLE"; Risk = "Medium Risk"
OptimizeDescription = "May break cloud saves."; RestoreDescription = "Restores Play Games."; DefaultOptimize = "N"; DefaultRestore = "Y" }
# --- HOME HANDLERS: Use Launcher Wizard instead ---
@{ Package = "com.google.android.tungsten.setupwraith"; Name = "Setup Wraith (HOME)"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "HOME handler! Use Launcher Wizard instead."; RestoreDescription = "Restores setup wizard HOME handler."; DefaultOptimize = "N"; DefaultRestore = "Y" }
)
# NVIDIA Shield-specific apps
$Script:ShieldAppList = @(
# --- SAFE: Shield telemetry ---
@{ Package = "com.nvidia.stats"; Name = "Nvidia Telemetry"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Stops Nvidia data collection."; RestoreDescription = "Restores Nvidia telemetry."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.nvidia.diagtools"; Name = "Nvidia Diagnostics"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Stops diagnostic logging."; RestoreDescription = "Restores diagnostic tools."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.nvidia.feedback"; Name = "Nvidia Feedback"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Stops Nvidia feedback collection."; RestoreDescription = "Restores Nvidia feedback."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.google.android.tvrecommendations"; Name = "Sponsored Content"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Removes Sponsored / Top Picks rows on the stock Google TV home. Also removes the home-screen Watch Next rows that surface Apple TV / Netflix Continue Watching. No effect if you've switched to a custom launcher."; RestoreDescription = "Restores sponsored and Watch Next rows on stock launcher."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
# --- MEDIUM: Shield-specific services ---
@{ Package = "com.nvidia.osc"; Name = "Nvidia OSC"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Background optimization service."; RestoreDescription = "Restores optimization service."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.nvidia.shieldtech.hooks"; Name = "Nvidia System Hooks"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Shield-specific system hooks."; RestoreDescription = "Restores system hooks."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.nvidia.tegrazone3"; Name = "Nvidia Games"; Method = "DISABLE"; Risk = "Medium Risk"
OptimizeDescription = "May break GeForce NOW."; RestoreDescription = "Restores Nvidia Games app."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.nvidia.nvgamecast"; Name = "Nvidia GameStream"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "GameStream casting service."; RestoreDescription = "Restores GameStream."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.google.android.backdrop"; Name = "Ambient Mode"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Disables ambient/screensaver."; RestoreDescription = "Restores ambient mode."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.google.android.speech.pumpkin"; Name = "Google Speech Services"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Breaks voice dictation."; RestoreDescription = "Restores speech services."; DefaultOptimize = "N"; DefaultRestore = "Y" }
# --- HIGH RISK: Critical Shield services ---
@{ Package = "com.nvidia.ota"; Name = "Nvidia System Updater"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Stops Shield OS updates."; RestoreDescription = "Restores system updates."; DefaultOptimize = "N"; DefaultRestore = "Y" }
@{ Package = "com.plexapp.mediaserver.smb"; Name = "Plex Media Server"; Method = "DISABLE"; Risk = "Advanced"
OptimizeDescription = "Breaks local Plex hosting."; RestoreDescription = "Restores Plex Server."; DefaultOptimize = "N"; DefaultRestore = "Y" }
# --- LAUNCHER: Use Launcher Wizard ---
@{ Package = "com.google.android.tvlauncher"; Name = "Stock Launcher"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Requires custom launcher first!"; RestoreDescription = "Restores stock home screen."; DefaultOptimize = "N"; DefaultRestore = "Y" }
)
# Google TV-specific apps (Onn 4K, Chromecast, etc.)
$Script:GoogleTVAppList = @(
# --- SAFE: Google TV bloatware ---
@{ Package = "com.walmart.otto"; Name = "Walmart App"; Method = "UNINSTALL"; Risk = "Safe"
OptimizeDescription = "Removes Walmart bloatware."; RestoreDescription = "Restores Walmart app."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
@{ Package = "com.google.android.leanbacklauncher.recommendations"; Name = "Home Recommendations"; Method = "DISABLE"; Risk = "Safe"
OptimizeDescription = "Removes extra recommendation rows (older Android TV launcher only). No effect on custom or Google TV launchers."; RestoreDescription = "Restores home recommendations."; DefaultOptimize = "Y"; DefaultRestore = "Y" }
# --- MEDIUM: Setup/calibration tools ---
@{ Package = "com.google.android.tungsten.overscan"; Name = "Overscan Calibrator"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Post-setup overscan tool."; RestoreDescription = "Restores overscan calibrator."; DefaultOptimize = "N"; DefaultRestore = "Y" }
# --- MEDIUM: Onn/Amlogic-specific ---
@{ Package = "com.droidlogic.launcher.provider"; Name = "Droidlogic Launcher Provider"; Method = "DISABLE"; Risk = "Medium"
OptimizeDescription = "Onn launcher data provider. Disable with launcher."; RestoreDescription = "Restores Onn launcher provider."; DefaultOptimize = "N"; DefaultRestore = "Y" }
# --- LAUNCHER: Use Launcher Wizard ---
@{ Package = "com.google.android.apps.tv.launcherx"; Name = "Google TV Home"; Method = "DISABLE"; Risk = "High Risk"
OptimizeDescription = "Use Launcher Wizard to safely disable!"; RestoreDescription = "Restores Google TV home."; DefaultOptimize = "N"; DefaultRestore = "Y" }
)
$Script:PerfList = @(
@{Key="window_animation_scale"; Name="Animation Speed"; Desc="Controls UI transition speed."; OptVal="0.5"; RestVal="1.0"}
)
$Script:Launchers = @(
@{Name="Projectivy Launcher"; Pkg="com.spocky.projengmenu"},
@{Name="FLauncher"; Pkg="me.efesser.flauncher"},
@{Name="ATV Launcher"; Pkg="com.sweech.launcher"},
@{Name="Wolf Launcher"; Pkg="com.wolf.firelauncher"},
@{Name="AT4K Launcher"; Pkg="com.overdevs.at4k"},
@{Name="Dispatch Launcher"; Pkg="com.spauldhaliwal.dispatch"}
)
# --- DEVICE DETECTION ---
# Detect device type based on brand and model
function Get-DeviceType ($Target) {
try {
$brand = (& $Script:AdbPath -s $Target shell getprop ro.product.brand 2>&1 | Out-String).Trim().ToLower()
$model = (& $Script:AdbPath -s $Target shell getprop ro.product.model 2>&1 | Out-String).Trim().ToLower()
$device = (& $Script:AdbPath -s $Target shell getprop ro.product.device 2>&1 | Out-String).Trim().ToLower()
# NVIDIA Shield detection
if ($brand -eq "nvidia" -or $model -match "shield" -or $device -match "foster|darcy|mdarcy|sif") {
return $Script:DeviceType.Shield
}
# Onn (Walmart) detection
if ($brand -eq "onn" -or $model -match "onn" -or $device -match "ott_") {
return $Script:DeviceType.GoogleTV
}
# Chromecast / Google TV detection
if ($brand -eq "google" -or $model -match "chromecast|sabrina|boreal") {
return $Script:DeviceType.GoogleTV
}
# Generic Google TV detection - check for launcherx
$hasLauncherX = & $Script:AdbPath -s $Target shell pm list packages com.google.android.apps.tv.launcherx 2>&1 | Out-String
if ($hasLauncherX -match "launcherx") {
return $Script:DeviceType.GoogleTV
}
# Default to Unknown
return $Script:DeviceType.Unknown
}
catch {
return $Script:DeviceType.Unknown
}
}
# Get device-friendly name
function Get-DeviceTypeName ($Type) {
switch ($Type) {
"Shield" { return "Nvidia Shield" }
"GoogleTV" { return "Google TV" }
default { return "Android TV" }
}
}
# Get combined app list for device type
function Get-AppListForDevice ($Type) {
$combined = @()
# Add common apps first
$combined += $Script:CommonAppList
# Add device-specific apps
switch ($Type) {
"Shield" {
$combined += $Script:ShieldAppList
}
"GoogleTV" {
$combined += $Script:GoogleTVAppList
}
default {
# For unknown devices, include both but skip the launchers
foreach ($app in $Script:ShieldAppList) {
if ($app.Package -notmatch "tvlauncher") { $combined += ,$app }
}
foreach ($app in $Script:GoogleTVAppList) {
if ($app.Package -notmatch "launcherx") { $combined += ,$app }
}
}
}
return $combined
}
# Show device profile information
function Show-DeviceProfile ($Target, $DeviceInfo) {
Write-Header "Device Profile"
$typeName = Get-DeviceTypeName $DeviceInfo.Type
Write-Host " Device: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$($DeviceInfo.Name)" -ForegroundColor $Script:Colors.Value
Write-Host " Model: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$($DeviceInfo.Model)" -ForegroundColor $Script:Colors.Value
Write-Host " Profile: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$typeName" -ForegroundColor $Script:Colors.Warning
Write-Host " Serial: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$($DeviceInfo.Serial)" -ForegroundColor $Script:Colors.TextDim
# Get Android version and additional info
try {
$androidVer = (& $Script:AdbPath -s $Target shell getprop ro.build.version.release 2>&1 | Out-String).Trim()
Write-Host " Android: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$androidVer" -ForegroundColor $Script:Colors.Value
$sdkVer = (& $Script:AdbPath -s $Target shell getprop ro.build.version.sdk 2>&1 | Out-String).Trim()
Write-Host " SDK: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$sdkVer" -ForegroundColor $Script:Colors.Value
$buildId = (& $Script:AdbPath -s $Target shell getprop ro.build.id 2>&1 | Out-String).Trim()
Write-Host " Build: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$buildId" -ForegroundColor $Script:Colors.Value
} catch {}
# Show which app list will be used
$appList = Get-AppListForDevice $DeviceInfo.Type
Write-Host " Apps: " -NoNewline -ForegroundColor $Script:Colors.Label
Write-Host "$($appList.Count) apps in optimization list" -ForegroundColor $Script:Colors.Success
Write-Host ""
# Offer to show full app profile
$showFull = Read-Toggle -Prompt "Show full app profile?" -Options @("YES", "NO") -DefaultIndex 1
if ($showFull -eq 0) {
Write-SubHeader "App Profile for $typeName"
# Group apps by risk level
$safeApps = $appList | Where-Object { $_.Risk -eq "Safe" }
$mediumApps = $appList | Where-Object { $_.Risk -match "Medium" }
$highApps = $appList | Where-Object { $_.Risk -match "High|Advanced" }
Write-Host ""
Write-Host " Safe ($($safeApps.Count) apps):" -ForegroundColor $Script:Colors.Success
foreach ($app in $safeApps) {
$defStr = if ($app.DefaultOptimize -eq "Y") { "[Y]" } else { "[N]" }
Write-Host " $defStr $($app.Name)" -ForegroundColor $Script:Colors.Text
}
Write-Host ""
Write-Host " Medium Risk ($($mediumApps.Count) apps):" -ForegroundColor $Script:Colors.Warning
foreach ($app in $mediumApps) {
$defStr = if ($app.DefaultOptimize -eq "Y") { "[Y]" } else { "[N]" }
Write-Host " $defStr $($app.Name)" -ForegroundColor $Script:Colors.Text
}
Write-Host ""
Write-Host " High Risk / Advanced ($($highApps.Count) apps):" -ForegroundColor $Script:Colors.Error
foreach ($app in $highApps) {
$defStr = if ($app.DefaultOptimize -eq "Y") { "[Y]" } else { "[N]" }
Write-Host " $defStr $($app.Name)" -ForegroundColor $Script:Colors.Text
}
Write-Host ""
Write-Host " Legend: [Y] = Default Yes, [N] = Default No/Skip" -ForegroundColor $Script:Colors.Separator
Write-Host ""
}
}
# --- UTILITY FUNCTIONS ---
function Write-Header ($Text) { Write-Host "`n=== $Text ===" -ForegroundColor $Script:Colors.Header }
function Write-SubHeader ($Text){ Write-Host "`n--- $Text ---" -ForegroundColor $Script:Colors.SubHeader }
function Write-Success ($Text) { Write-Host " [OK] $Text" -ForegroundColor $Script:Colors.Success }
function Write-Warn ($Text) { Write-Host " [!!] $Text" -ForegroundColor $Script:Colors.Warning }
function Write-ErrorMsg ($Text) { Write-Host " [ERROR] $Text" -ForegroundColor $Script:Colors.Error }
function Write-Info ($Text) { Write-Host " [INFO] $Text" -ForegroundColor $Script:Colors.Info }
function Write-Dim ($Text) { Write-Host " $Text" -ForegroundColor $Script:Colors.TextDim }
function Write-Separator { Write-Host "`n────────────────────────────────────────────────────────────────────────────────`n" -ForegroundColor $Script:Colors.Separator }
# --- HELPER FUNCTIONS FOR DRY CODE ---
# Vital thresholds for color coding (centralized configuration)
$Script:VitalThresholds = @{
Temperature = @{ Warning = 50; Critical = 70; Normal = "Green"; NormalAnsi = "92" }
RAM = @{ Warning = 70; Critical = 85; Normal = "Green"; NormalAnsi = "92" }
Storage = @{ Warning = 75; Critical = 90; Normal = "Green"; NormalAnsi = "92" }
AppMemory = @{ Warning = 100; Critical = 200; Normal = "White"; NormalAnsi = "97" }
}
# Check if a package exists in a package list string (handles exact matching)
function Test-PackageInList {
param(
[string]$PackageList,
[string]$Package
)
return $PackageList -match "package:$([regex]::Escape($Package))(\r|\n|$)"
}
# Check if a package name is a user app (vs system process)
function Test-AppPackage {
param([string]$Package)
return ($Package -match "^com\." -or $Package -match "^tv\." -or $Package -match "^me\.")
}
# Parse temperature from thermal service output
function Get-ParsedTemperature {
param([string]$ThermalOutput)
if (-not $ThermalOutput) { return "N/A" }
# Prioritize HAL temperatures (live) over cached
if ($ThermalOutput -match "(?s)Current temperatures from HAL:.*?mValue=([\d\.]+).*?mName=CPU") {
return [math]::Round([float]$matches[1], 1)
}
# Fallback patterns for other devices
if ($ThermalOutput -match "mValue=([\d\.]+).*mName=CPU\d*,") {
return [math]::Round([float]$matches[1], 1)
}
elseif ($ThermalOutput -match "mValue=([\d\.]+).*mName=soc_thermal") {
return [math]::Round([float]$matches[1], 1)
}
elseif ($ThermalOutput -match "Temperature\{mValue=([\d\.]+),.*mType=0") {
return [math]::Round([float]$matches[1], 1)
}
return "N/A"
}
# Parse RAM info from meminfo output
function Get-ParsedRamInfo {
param([string]$MemInfoOutput)
$Total = 0; $Free = 0; $Swap = 0
if ($MemInfoOutput) {
if ($MemInfoOutput -match "Total RAM:\s+([0-9,]+)\s*K") {
$Total = [math]::Round(($matches[1] -replace ",","") / 1024, 0)
}
if ($MemInfoOutput -match "Free RAM:\s+([0-9,]+)\s*K") {
$Free = [math]::Round(($matches[1] -replace ",","") / 1024, 0)
}
if ($MemInfoOutput -match "ZRAM:.*used for\s+([0-9,]+)\s*K") {
$Swap = [math]::Round(($matches[1] -replace ",","") / 1024, 0)
}
}
if ($Total -eq 0) { $Total = 2048 }
$Used = $Total - $Free
$Percent = if ($Total -gt 0) { [math]::Round(($Used / $Total) * 100, 0) } else { 0 }
return @{
Total = $Total
Free = $Free
Used = $Used
Swap = $Swap
Percent = $Percent
}
}
# Get PowerShell color name for vital metrics
function Get-VitalColor {
param(
[string]$Type,
[float]$Value
)
$thresholds = $Script:VitalThresholds[$Type]
if (-not $thresholds) { return "White" }
if ($Value -gt $thresholds.Critical) { return "Red" }
elseif ($Value -gt $thresholds.Warning) { return "Yellow" }
else { return $thresholds.Normal }
}
# Get ANSI color code for vital metrics (for console escape sequences)
function Get-VitalAnsiColor {
param(
[string]$Type,
[float]$Value
)
$thresholds = $Script:VitalThresholds[$Type]
if (-not $thresholds) { return "97" } # White
if ($Value -gt $thresholds.Critical) { return "91" } # Red
elseif ($Value -gt $thresholds.Warning) { return "93" } # Yellow
else { return $thresholds.NormalAnsi }
}
# Extract subnet from gateway IP (e.g., "192.168.1.1" -> "192.168.1")
function Get-SubnetFromGateway {
param([string]$Gateway)
$octets = $Gateway -split '\.'
return "$($octets[0]).$($octets[1]).$($octets[2])"
}
# Categorize uninstall errors for user-friendly messages
function Get-UninstallErrorReason ($Output) {
if ($Output -match "Broken pipe") {
return "Protected system app - cannot be removed"
}
if ($Output -match "not installed for") {
return "App not installed for this user"
}
if ($Output -match "DELETE_FAILED_INTERNAL_ERROR") {
return "Internal error - app may be in use"
}
return "Unknown error"
}
function Invoke-AdbCommand {
param(
[string]$Target,
[string]$Command,
[switch]$Silent
)
try {
$output = & $Script:AdbPath -s $Target shell $Command 2>&1
$outputStr = ($output | Out-String).Trim()
# Check for common ADB error patterns
$hasError = $outputStr -match "Exception|Error|Failure|failed|not found|inaccessible"
if ($hasError -and -not $Silent) {
return @{ Success = $false; Output = $outputStr; Error = $outputStr }
}
return @{ Success = $true; Output = $outputStr; Error = $null }
}
catch {
return @{ Success = $false; Output = ""; Error = $_.Exception.Message }
}
}
# Build a {package -> MB} map from a single `dumpsys meminfo` call.
# Sums all processes that share a base package (e.g. com.example, com.example:worker).
# Returns an empty hashtable on any failure so callers can lookup safely.
function Get-AppMemoryMap {
param([string]$Target)
$map = @{}
try {
$mem = & $Script:AdbPath -s $Target shell "dumpsys meminfo" 2>&1 | Out-String
$inSection = $false
foreach ($line in ($mem -split "`n")) {
if ($line -match "Total PSS by process:") { $inSection = $true; continue }
if ($inSection -and $line -match "^\s*$") { break }
if ($inSection -and $line -match "^\s*([\d,]+)K:\s+([a-zA-Z0-9_.]+)") {
$kb = [int]($matches[1] -replace ",", "")
$pkg = $matches[2]
if ($map.ContainsKey($pkg)) { $map[$pkg] += $kb } else { $map[$pkg] = $kb }
}
}
} catch {}
# Convert KB sums to MB rounded
$result = @{}
foreach ($k in $map.Keys) {
$result[$k] = [math]::Round($map[$k] / 1024, 1)
}
return $result
}
# Get the device's current display mode and HDR capability.
# Returns @{ Resolution; RefreshRate; HdrTypes; AudioDevice } — any field may be empty.
# Verified against a Shield (Android 11): the active modeId is in DisplayDeviceInfo,
# and the supportedModes list maps id->{width,height,fps}.
function Get-DisplayMode ($Target) {
$info = @{ Resolution = $null; RefreshRate = $null; HdrTypes = $null; AudioDevice = $null }
try {
$disp = & $Script:AdbPath -s $Target shell "dumpsys display" 2>&1 | Out-String
# Active modeId
$activeId = $null
if ($disp -match "modeId\s+(\d+)") { $activeId = [int]$matches[1] }
# Find the supportedModes entry matching the active id
if ($activeId -and $disp -match "id=$activeId,\s*width=(\d+),\s*height=(\d+),\s*fps=([\d.]+)") {
$info.Resolution = "$($matches[1])x$($matches[2])"
$fps = [double]$matches[3]
$info.RefreshRate = "{0:F2} Hz" -f $fps
}
# HDR support
if ($disp -match "mSupportedHdrTypes=\[([0-9,\s]*)\]") {
$rawTypes = $matches[1].Trim()
if ($rawTypes) {
$names = @()
foreach ($t in ($rawTypes -split ",")) {
switch ($t.Trim()) {
"1" { $names += "Dolby Vision" }
"2" { $names += "HDR10" }
"3" { $names += "HLG" }
"4" { $names += "HDR10+" }
}
}
if ($names.Count -gt 0) { $info.HdrTypes = $names -join ", " }
}
if (-not $info.HdrTypes) { $info.HdrTypes = "SDR only" }
}
} catch {}
# Audio output device — best-effort, format varies by build
try {
$audio = & $Script:AdbPath -s $Target shell "dumpsys audio" 2>&1 | Out-String
if ($audio -match "(?im)^\s*Devices:\s*(\w+)") {
$info.AudioDevice = $matches[1].ToUpper()
}
} catch {}
return $info
}
# Get top memory-consuming apps (returns array of @{Name; Package; MB})
function Get-TopMemoryApps {
param([string]$Target, [int]$Count = 5)
$apps = @()
try {
# dumpsys meminfo outputs sorted by PSS - parse the summary section
$mem = & $Script:AdbPath -s $Target shell "dumpsys meminfo" 2>&1 | Out-String
# Look for lines in "Total PSS by process:" section
# Format: "123,456K: com.example.app (pid 1234)"
$inSection = $false
foreach ($line in ($mem -split "`n")) {
if ($line -match "Total PSS by process:") { $inSection = $true; continue }
if ($inSection -and $line -match "^\s*$") { break } # Empty line ends section
if ($inSection -and $line -match "^\s*([\d,]+)K:\s+([a-zA-Z0-9_.]+)") {
$kb = [int]($matches[1] -replace ",", "")
$pkg = $matches[2]
# Skip system processes, focus on apps
if (Test-AppPackage -Package $pkg) {
$apps += @{ Package = $pkg; MB = [math]::Round($kb / 1024, 1) }
if ($apps.Count -ge $Count) { break }
}
}
}
} catch {}
return $apps
}
function Get-ScriptDirectory {
if ($PSScriptRoot -and $PSScriptRoot -ne "") {
return $PSScriptRoot
}
return (Get-Location).Path
}
# --- CROSS-PLATFORM ADB HELPERS ---
function Get-AdbConfig {
$config = @{
BinaryName = "adb"
ExtraFiles = @()
DownloadUrl = ""
}
switch ($Script:Platform) {
"Windows" {
$config.BinaryName = "adb.exe"
$config.ExtraFiles = @("AdbWinApi.dll", "AdbWinUsbApi.dll")
$config.DownloadUrl = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
}
"macOS" {
$config.BinaryName = "adb"
$config.ExtraFiles = @()
$config.DownloadUrl = "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip"
}
"Linux" {
$config.BinaryName = "adb"
$config.ExtraFiles = @()
$config.DownloadUrl = "https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
}
default {
# Fallback to Windows
$config.BinaryName = "adb.exe"
$config.ExtraFiles = @("AdbWinApi.dll", "AdbWinUsbApi.dll")
$config.DownloadUrl = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
}
}
return $config
}
function Stop-AdbProcess {
if ($Script:IsUnix) {
# Unix: use pkill or killall
try {
$null = & pkill -f "adb" 2>&1
} catch {
try {
$null = & killall adb 2>&1
} catch {}
}
} else {
# Windows: use Stop-Process
try {
Stop-Process -Name "adb" -Force -ErrorAction SilentlyContinue
} catch {}
}
}
function Check-Adb {
$ScriptDir = Get-ScriptDirectory
$adbConfig = Get-AdbConfig
$AdbExe = Join-Path $ScriptDir $adbConfig.BinaryName
$Script:AdbPath = ""
# Force download if flag is set - skip all checks and download fresh
if ($Script:ForceAdbDownload) {
Write-Warn "Forcing ADB re-download..."
# Kill ADB server first so files aren't locked
if (Test-Path $AdbExe) {
try { & $AdbExe kill-server 2>$null } catch {}
}
Stop-AdbProcess
Start-Sleep -Milliseconds 500
Remove-Item $AdbExe -Force -ErrorAction SilentlyContinue
foreach ($extraFile in $adbConfig.ExtraFiles) {
Remove-Item (Join-Path $ScriptDir $extraFile) -Force -ErrorAction SilentlyContinue
}
# Fall through to download section
}
elseif (Test-Path $AdbExe) {
$Script:AdbPath = $AdbExe
}
elseif (Get-Command $adbConfig.BinaryName -ErrorAction SilentlyContinue) {
$Script:AdbPath = (Get-Command $adbConfig.BinaryName).Source
}
if ($Script:AdbPath -eq "") {
if (-not $Script:ForceAdbDownload) { Write-Warn "ADB missing. Downloading..." }
$Url = $adbConfig.DownloadUrl
$Zip = Join-Path $ScriptDir "adb_temp.zip"
$Ext = Join-Path $ScriptDir "adb_temp_extract"
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $Url -OutFile $Zip -UseBasicParsing
Expand-Archive -Path $Zip -DestinationPath $Ext -Force
Move-Item (Join-Path $Ext "platform-tools" $adbConfig.BinaryName) $ScriptDir -Force
foreach ($extraFile in $adbConfig.ExtraFiles) {
Move-Item (Join-Path $Ext "platform-tools" $extraFile) $ScriptDir -Force
}
Remove-Item $Zip -Force; Remove-Item $Ext -Recurse -Force
# Make executable on Unix
if ($Script:IsUnix) {
& chmod +x $AdbExe
}
$Script:AdbPath = $AdbExe
Write-Success "ADB Installed."
} catch { Write-ErrorMsg "ADB Setup Failed."; Exit }
} else { Write-Success "Found ADB." }
}
function Restart-AdbServer {
Write-Info "Restarting ADB server..."
try {
& $Script:AdbPath kill-server 2>$null
Start-Sleep -Milliseconds 500
& $Script:AdbPath start-server 2>$null
Write-Success "ADB server restarted."
}
catch {
Write-ErrorMsg "Failed to restart ADB server."
}
Start-Sleep -Milliseconds 500
}
function Disconnect-Device {
param([string]$Serial)
Write-Info "Disconnecting $Serial..."
try {
& $Script:AdbPath disconnect $Serial 2>$null
Write-Success "Disconnected."
}
catch {
Write-ErrorMsg "Failed to disconnect."
}
}
function Connect-PinPairing {
Write-Header "PIN PAIRING (Android 11+ / Google TV)"
Write-Host ""
Write-Host " On your TV:" -ForegroundColor $Script:Colors.Label
Write-Host " [EXPERIMENTAL] For newer Chromecasts and Google TV devices." -ForegroundColor $Script:Colors.Warning
Write-Host " (Shield TV uses standard Network Debugging - use 'Connect IP' instead)" -ForegroundColor $Script:Colors.Warning
Write-Host ""
Write-Host " 1. Go to Settings > System > Developer Options" -ForegroundColor $Script:Colors.Text
Write-Host " 2. Enable 'USB Debugging'" -ForegroundColor $Script:Colors.Text
Write-Host " 3. Enable 'Network Debugging'" -ForegroundColor $Script:Colors.Text
Write-Host " 4. Tap 'Pair device with pairing code'" -ForegroundColor $Script:Colors.Text
Write-Host " 5. Note the IP, pairing port, and 6-digit PIN shown" -ForegroundColor $Script:Colors.Text
Write-Host ""
# Step 1: Get IP address
$ip = Read-Host "Enter IP address (e.g., 192.168.1.100)"
if (-not (Test-ValidIP $ip)) {
Write-ErrorMsg "Invalid IP address format: $ip"
return $false
}
# Step 2: Get pairing port
$pairingPort = Read-Host "Enter pairing port (shown on TV screen)"
if (-not ($pairingPort -match "^\d+$")) {
Write-ErrorMsg "Invalid port number: $pairingPort"
return $false
}
# Step 3: Get pairing code
$pairingCode = Read-Host "Enter 6-digit pairing code"
if (-not ($pairingCode -match "^\d{6}$")) {
Write-ErrorMsg "Pairing code must be 6 digits: $pairingCode"
return $false
}
# Step 4: Pair
Write-Host ""
Write-Info "Pairing with ${ip}:${pairingPort}..."
$pairResult = & $Script:AdbPath pair "${ip}:${pairingPort}" $pairingCode 2>&1 | Out-String
if ($pairResult -match "Successfully paired|paired successfully") {
Write-Success "Paired successfully!"
Write-Host ""
# Step 5: Connect
$connPort = Read-Host "Enter connection port (shown on TV, different from pairing port)"
if (-not ($connPort -match "^\d+$")) {
Write-ErrorMsg "Invalid port number: $connPort"
return $false
}
Write-Info "Connecting to ${ip}:${connPort}..."
$connResult = & $Script:AdbPath connect "${ip}:${connPort}" 2>&1 | Out-String
if ($connResult -match "connected|already connected") {
Write-Success "Connected to ${ip}:${connPort}!"
return $true
} else {