Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

launcher: config knobs for Live TV apps without a leanback entry point, and for TVs with no TvInputManager

xbsheng765be6cd694d
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index 1aa15dac8..ad4d0a26f 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -2,6 +2,7 @@ package com.gathin.tvhome;
import android.app.Activity;
import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -60,6 +61,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
static int COLUMNS = 4;
private static final long MINUTE_MS = 60_000L;
private String liveTvPkg;
+ private String liveTvAction;
+ private String sourcePanelService;
+ private String sourcePanelAction;
private AppAdapter adapter;
private RecyclerView grid;
@@ -142,6 +146,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
density = getResources().getDisplayMetrics().density;
COLUMNS = Math.max(1, getResources().getInteger(R.integer.columns));
liveTvPkg = getString(R.string.live_tv_package).trim();
+ liveTvAction = getString(R.string.live_tv_action).trim();
+ sourcePanelService = getString(R.string.source_panel_service).trim();
+ sourcePanelAction = getString(R.string.source_panel_action).trim();
root = findViewById(R.id.root);
glass = findViewById(R.id.glass);
@@ -534,7 +541,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
/** 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;
+ boolean any = liveTvIntent() != null || !sourcePanelService.isEmpty();
TvInputManager tim = (TvInputManager) getSystemService(TV_INPUT_SERVICE);
if (!any && tim != null) {
for (TvInputInfo info : tim.getTvInputList()) {
@@ -547,6 +554,27 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
btnInputs.setVisibility(any ? View.VISIBLE : View.GONE);
}
+ /** The Live TV app's launch intent: its leanback entry point, or the configured action if it has none. */
+ private Intent liveTvIntent() {
+ if (liveTvPkg.isEmpty()) return null;
+ Intent i = getPackageManager().getLeanbackLaunchIntentForPackage(liveTvPkg);
+ if (i != null || liveTvAction.isEmpty()) return i;
+ Intent byAction = new Intent(liveTvAction).setPackage(liveTvPkg);
+ return getPackageManager().resolveActivity(byAction, 0) != null ? byAction : null;
+ }
+
+ /** The TV's own source-selection panel, for TVs that have no TvInputManager (TCL Android TV 9). */
+ private void openSourcePanel() {
+ Intent i = new Intent(sourcePanelAction);
+ ComponentName c = ComponentName.unflattenFromString(sourcePanelService);
+ if (c != null) i.setComponent(c);
+ try {
+ startService(i);
+ } catch (Exception e) {
+ Toast.makeText(this, R.string.not_available, Toast.LENGTH_SHORT).show();
+ }
+ }
+
private void open(Intent i) {
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
@@ -610,7 +638,11 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
TvContract.buildChannelUriForPassthroughInput(id), "vnd.android.cursor.item/channel")));
}
}
- Intent liveTv = liveTvPkg.isEmpty() ? null : getPackageManager().getLeanbackLaunchIntentForPackage(liveTvPkg);
+ // Nothing to list where there is no TvInputManager: the TV's own source panel switches inputs.
+ if (rows.getChildCount() == 0 && !sourcePanelService.isEmpty()) {
+ addInputRow(rows, popup, R.drawable.ic_input, getString(R.string.inputs), -1, this::openSourcePanel);
+ }
+ Intent liveTv = liveTvIntent();
if (liveTv != null && tunerId != null) {
liveTv = new Intent(Intent.ACTION_VIEW)
.setDataAndType(TvContract.buildChannelUriForPassthroughInput(tunerId), "vnd.android.cursor.item/channel")
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 01750dda1..0c4708de5 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -22,6 +22,17 @@
<!-- 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>
+ <!-- Some TVs give their Live TV app no leanback entry point at all, so `live_tv_package` above
+ resolves to nothing (TCL Android TV 9 on China-market sets is one). This action is then sent
+ to that package instead, and the app starts normally. Leave empty to omit. -->
+ <string name="live_tv_action" translatable="false"></string>
+
+ <!-- TVs with no TvInputManager have no HDMI list to read, but their own source-selection panel
+ still switches inputs (TCL Android TV 9 again). When nothing could be listed, the Inputs menu
+ offers one row that starts this service: component first, then action. Leave empty to omit. -->
+ <string name="source_panel_service" translatable="false"></string>
+ <string name="source_panel_action" translatable="false"></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>