Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
Merge PR #69: launcher: show a VPN badge on the network pill
Gathin23eb2a08014db3
diff --cc launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex 78ce0d9b5,5fc644145..9af6f614b--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@@ -67,15 -69,10 +70,16 @@@ public class MainActivity extends Activprivate int ambientColor;private boolean heroShown;private TextView greeting;+ private View btnInputs;private TextView btnWifi;+ private TextView shamsiDate;+ private boolean shamsi;+ private String vpnApp;private SpringAnimation springX, springY;private float glassTargetX, glassTargetY;+ // How far the grid has scrolled the glass. springY works without it, in grid content space, so a+ // scroll moves the glass in lockstep with its tile instead of becoming a moving spring target.+ private float glassScrollShift;private boolean glassShown;// Static so they survive the activity being destroyed while another app is open (low-memory TVs,// or Developer options → "Don't keep activities"); they only reset when the process dies.@@@ -97,18 -94,18 +101,30 @@@handler.post(MainActivity.this::updateWifiLabel);}};+ /** Shows the Inputs pill once the TV registers an input: at boot HDMI inputs can appear after Home is shown. */+ private final TvInputManager.TvInputCallback inputCallback = new TvInputManager.TvInputCallback() {+ @Override+ public void onInputAdded(String inputId) {+ updateInputsButton();+ }++ @Override+ public void onInputRemoved(String inputId) {+ updateInputsButton();+ }+ };+ /** Listens for any VPN coming up or going down, even one this app's traffic is excluded from. */+ private final ConnectivityManager.NetworkCallback vpnCallback = new ConnectivityManager.NetworkCallback() {+ @Override+ public void onAvailable(@NonNull Network network) {+ handler.post(MainActivity.this::updateWifiLabel);+ }++ @Override+ public void onLost(@NonNull Network network) {+ handler.post(MainActivity.this::updateWifiLabel);+ }+ };private final Runnable minuteTick = new Runnable() {@Overridepublic void run() {@@@ -138,14 -135,7 +154,15 @@@ambientGlow.setGradientRadius((r - l) * 0.62f));greeting = findViewById(R.id.greeting);btnWifi = findViewById(R.id.btnWifi);+ shamsiDate = findViewById(R.id.shamsiDate);+ shamsi = getResources().getBoolean(R.bool.shamsi_date);+ if (shamsi) {+ shamsiDate.setVisibility(View.VISIBLE);+ TextView date = findViewById(R.id.date);+ date.setTextSize(11f);+ date.setPadding(0, (int) (4 * density), 0, 0);+ }+ vpnApp = getString(R.string.vpn_app).trim();grid = findViewById(R.id.grid);grid.setLayoutManager(new GridLayoutManager(this, COLUMNS));@@@ -195,10 -175,14 +212,14 @@@s.setSpring(new SpringForce().setStiffness(260f).setDampingRatio(0.58f));}- View btnInputs = findViewById(R.id.btnInputs);+ btnInputs = findViewById(R.id.btnInputs);View btnSettings = findViewById(R.id.btnSettings);btnInputs.setOnClickListener(v -> showInputs());- btnWifi.setOnClickListener(v -> open(new Intent(Settings.ACTION_WIFI_SETTINGS)));+ btnWifi.setOnClickListener(v -> openNetworkPill());+ btnWifi.setOnLongClickListener(v -> {+ open(new Intent(Settings.ACTION_WIFI_SETTINGS));+ return true;+ });btnSettings.setOnClickListener(v -> open(new Intent(Settings.ACTION_SETTINGS)));// Keep focus on the top bar at its ends and at the top: Android's focus finder would otherwise@@@ -224,9 -204,13 +245,15 @@@});ConnectivityManager cm = getSystemService(ConnectivityManager.class);- if (cm != null) cm.registerDefaultNetworkCallback(networkCallback);+ TvInputManager tim = (TvInputManager) getSystemService(TV_INPUT_SERVICE);+ if (tim != null) tim.registerCallback(inputCallback, handler);+ if (cm != null) {+ cm.registerDefaultNetworkCallback(networkCallback);+ cm.registerNetworkCallback(new NetworkRequest.Builder()+ .addTransportType(NetworkCapabilities.TRANSPORT_VPN)+ .removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)+ .build(), vpnCallback);+ }}@Override@@@ -265,9 -248,10 +292,12 @@@protected void onDestroy() {super.onDestroy();ConnectivityManager cm = getSystemService(ConnectivityManager.class);- if (cm != null) cm.unregisterNetworkCallback(networkCallback);+ TvInputManager tim = (TvInputManager) getSystemService(TV_INPUT_SERVICE);+ if (tim != null) tim.unregisterCallback(inputCallback);+ if (cm != null) {+ cm.unregisterNetworkCallback(networkCallback);+ cm.unregisterNetworkCallback(vpnCallback);+ }}@Override@@@ -465,24 -454,25 +509,40 @@@}} catch (Exception ignored) {}- btnWifi.setText(text);+ if (vpn) {+ // Network name, then a green lock-and-VPN capsule drawn in place of the word "VPN".+ String badge = getString(R.string.vpn);+ SpannableString label = new SpannableString(text + " " + badge);+ label.setSpan(new VpnBadge(getDrawable(R.drawable.ic_lock), density),+ text.length() + 1, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);+ btnWifi.setText(label);+ } else {+ btnWifi.setText(text);+ }+ }++ /** The network pill opens the VPN app when one is configured and installed, otherwise Wi-Fi settings. */+ private void openNetworkPill() {+ Intent i = vpnApp.isEmpty() ? null : getPackageManager().getLeanbackLaunchIntentForPackage(vpnApp);+ if (i == null && !vpnApp.isEmpty()) i = getPackageManager().getLaunchIntentForPackage(vpnApp);+ open(i != null ? i : new Intent(Settings.ACTION_WIFI_SETTINGS));}+ /** Hides the Inputs pill when it would have nothing to list: streaming boxes have no HDMI-in, AV or tuner. */+ private void updateInputsButton() {+ boolean any = !liveTvPkg.isEmpty() && getPackageManager().getLeanbackLaunchIntentForPackage(liveTvPkg) != null;+ TvInputManager tim = (TvInputManager) getSystemService(TV_INPUT_SERVICE);+ if (!any && tim != null) {+ for (TvInputInfo info : tim.getTvInputList()) {+ if (info.isPassthroughInput()) {+ any = true;+ break;+ }+ }+ }+ btnInputs.setVisibility(any ? View.VISIBLE : View.GONE);+ }+private void open(Intent i) {i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);try {diff --cc launcher/app/src/main/res/values/config.xmlindex 9ec77e3e3,4e133c897..d92065120--- a/launcher/app/src/main/res/values/config.xml+++ b/launcher/app/src/main/res/values/config.xml@@@ -22,9 -22,9 +22,12 @@@<!-- The TV's Live TV / tuner app, offered at the end of the Inputs menu. Leave empty to omit. --><string name="live_tv_package" translatable="false">com.mediatek.wwtv.tvcenter</string>+ <!-- Show the Solar Hijri (Shamsi) date used in Iran and Afghanistan, e.g. "27 Mehr 1405", above the+ Gregorian date. -->+ <bool name="shamsi_date">false</bool>+ <!-- Optional VPN app the network pill opens (hold the pill for Wi-Fi settings), e.g. the package of the+ VPN you use. Empty: the pill opens Wi-Fi settings. The VPN badge shows for any VPN either way. -->+ <string name="vpn_app" translatable="false"></string><!-- Tiles per row in the grid; the dock always has this many slots. --><integer name="columns">4</integer>