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
launcher: repair Coocaa homepage properties at boot
VincentYe123b8ed6e45a79f
diff --git a/examples/skyworth-7s60-a5/README.md b/examples/skyworth-7s60-a5/README.mdindex fb09ee737..963ec3b7f 100644--- a/examples/skyworth-7s60-a5/README.md+++ b/examples/skyworth-7s60-a5/README.md@@ -37,6 +37,11 @@ PY=tools/venv/bin/pythonproperties say. The shim watches for that during the first two minutes after boot and asks`com.tianci.system` to go Home (Coocaa blocks activity starts from background apps). With thestock home disabled, which is the last step, this no longer happens at all.+- **The framework can overwrite the homepage properties at boot** with the literal strings+ `home[0]` / `home[1]`. The Home key then does nothing. While `com.ccos.tv.homepage` is installed,+ the launcher's boot receiver writes the shim back into those properties and opens Home+ (`CoocaaBoot`). It does nothing on a TV where that package is not installed. Coocaa also disables+ third-party boot receivers; opening the launcher re-enables its own.## Install@@ -96,9 +101,10 @@ cannot be read, the Inputs pill opens Coocaa's control center on its source row## Known issues-- Now and then the framework writes the literal strings `home[0]` / `home[1]` into the homepage- properties at boot (it races `com.tianci.system`), and Home stops working. Run the `setprop` line- from step 3 again.+- The framework writes `home[0]` / `home[1]` into the homepage properties on some boots. A launcher+ with `CoocaaBoot` puts the shim back and opens Home; the lines it writes are in+ `/sdcard/Android/data/com.coocaa.tvhome/files/boot.log`. On an older launcher, run the `setprop`+ line from step 3 again.- The TV has no clock battery and starts at 1970-01-01 08:00 until network time arrives a few secondsafter boot, so the launcher's clock can read 08:00 briefly.- `com.coocaa.sky.ccapi` and `com.tianci.user` are Coocaa's payment and account apps: Coocaadiff --git a/launcher/app/src/main/AndroidManifest.xml b/launcher/app/src/main/AndroidManifest.xmlindex 80124b58a..8490b7d1c 100644--- a/launcher/app/src/main/AndroidManifest.xml+++ b/launcher/app/src/main/AndroidManifest.xml@@ -7,6 +7,7 @@<uses-feature android:name="android.hardware.wifi" android:required="false" /><uses-feature android:name="android.hardware.location.gps" android:required="false" />+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><!-- Needed since Android 10 to read the Wi-Fi network name for the network pill. Never requested at@@ -190,6 +191,18 @@<!-- The remote's Input button (KEYCODE_TV or KEYCODE_TV_INPUT) opens the input switcher, and input_key_keycodes andapp_keys (config.xml or a theme) bring back other remote buttons; see InputKeyService. -->+ <!-- Coocaa OS rewrites the homepage properties at boot. This puts them back and opens Home.+ It returns immediately when the Coocaa homepage shim is not installed. -->+ <receiver+ android:name=".CoocaaBoot"+ android:directBootAware="true"+ android:exported="true">+ <intent-filter>+ <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />+ <action android:name="android.intent.action.BOOT_COMPLETED" />+ </intent-filter>+ </receiver>+<serviceandroid:name=".InputKeyService"android:exported="false"diff --git a/launcher/app/src/main/java/com/gathin/tvhome/CoocaaBoot.java b/launcher/app/src/main/java/com/gathin/tvhome/CoocaaBoot.javanew file mode 100644index 000000000..27b26714d--- /dev/null+++ b/launcher/app/src/main/java/com/gathin/tvhome/CoocaaBoot.java@@ -0,0 +1,99 @@+package com.gathin.tvhome;++import android.content.BroadcastReceiver;+import android.content.ComponentName;+import android.content.Context;+import android.content.Intent;+import android.content.pm.PackageManager;+import android.net.Uri;++import java.io.File;+import java.io.FileWriter;+import java.io.IOException;+import java.lang.reflect.Method;++/**+ * Coocaa OS (Skyworth, China) stores Home in persist.service.homepage.* and sometimes overwrites+ * those with the literal strings home[0] / home[1] at boot, after which the Home key does nothing.+ * When the homepage shim is installed, put the properties back and open this launcher.+ */+public class CoocaaBoot extends BroadcastReceiver {++ private static final String SHIM = "com.ccos.tv.homepage";+ private static final String SHIM_ACTIVITY = "com.ccos.tv.homepage.LaunchActivity";+ private static final Uri SYSTEM = Uri.parse("content://com.tianci.provider");++ /** Something on Coocaa disables third-party boot receivers. An app may re-enable its own. */+ static void keepEnabled(Context context) {+ ComponentName self = new ComponentName(context, CoocaaBoot.class);+ PackageManager pm = context.getPackageManager();+ try {+ if (pm.getComponentEnabledSetting(self) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {+ pm.setComponentEnabledSetting(self, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,+ PackageManager.DONT_KILL_APP);+ }+ } catch (RuntimeException ignored) {+ }+ }++ @Override+ public void onReceive(Context context, Intent intent) {+ keepEnabled(context);+ if (!installed(context, SHIM)) return;+ boolean pkg = setProp("persist.service.homepage.pkg", SHIM);+ boolean cls = setProp("persist.service.homepage.cls", SHIM_ACTIVITY);+ log(context, "boot pkgSet=" + pkg + " clsSet=" + cls+ + " now=" + getProp("persist.service.homepage.pkg"));+ try {+ context.getContentResolver().call(SYSTEM, "COMMON", "gotoHomePage", null);+ } catch (RuntimeException e) {+ log(context, "gotoHomePage " + e);+ }+ try {+ context.startActivity(new Intent(context, MainActivity.class)+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED));+ } catch (RuntimeException e) {+ log(context, "start " + e);+ }+ }++ private static boolean installed(Context context, String pkg) {+ try {+ context.getPackageManager().getPackageInfo(pkg, 0);+ return true;+ } catch (PackageManager.NameNotFoundException e) {+ return false;+ }+ }++ private static boolean setProp(String key, String value) {+ try {+ Class<?> c = Class.forName("android.os.SystemProperties");+ Method set = c.getMethod("set", String.class, String.class);+ set.invoke(null, key, value);+ return value.equals(getProp(key));+ } catch (ReflectiveOperationException | RuntimeException e) {+ return false;+ }+ }++ private static String getProp(String key) {+ try {+ Class<?> c = Class.forName("android.os.SystemProperties");+ Method get = c.getMethod("get", String.class);+ Object v = get.invoke(null, key);+ return v == null ? "" : v.toString();+ } catch (ReflectiveOperationException | RuntimeException e) {+ return "";+ }+ }++ private static void log(Context context, String line) {+ File dir = context.getExternalFilesDir(null);+ if (dir == null) return;+ try (FileWriter w = new FileWriter(new File(dir, "boot.log"), true)) {+ w.write(line + "\n");+ } catch (IOException ignored) {+ }+ }+}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex dca4f8424..c07273d8a 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@ -351,6 +351,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);+ CoocaaBoot.keepEnabled(this);setContentView(R.layout.activity_main);density = getResources().getDisplayMetrics().density;// config.xml, overlaid by config.json from a pushed theme (see Config and tools/theme.sh).