Skip to content

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

Merge PR #3540: tools: manage.py set refuses a string the launcher answers with a default

Gathin23bdbde918bc92
diff --cc tools/manage.py
index a44d154c9,729ddd8f0..1299507b6
--- a/tools/manage.py
+++ b/tools/manage.py
@@@ -16,10 -16,10 +16,12 @@@ pushes it with the platform's theme scr
--theme at the project's themes/ or examples/ is refused before anything is written. set reads the value the way
the key's own type in the Keys table needs - true or false for a bool, a JSON list, object or number where the
table says so, the text itself for a string - and refuses one the launcher would ignore or a number outside the
-range the table states. A string whose row names the values it takes (glow_style, glass_style, wallpaper_order,
-clock_format) is held to them, since the launcher answers any other value with its own default. A theme's
-config.json is hand-edited, so one that cannot be read, is not JSON, or is not a JSON object is named before the
-key is written, and a write it cannot make says so instead of ending in a traceback.
+range the table states. A list of keycodes is read the same way one entry at a time, because the launcher's
+intArray() answers a list holding a word or a number under 1 with the built-in default instead of the list.
- A theme's config.json is hand-edited, so one that cannot be read, is not JSON, or is not a
- JSON object is named before the key is written, and a write it cannot make says so instead of ending in a traceback.
++A string whose row names the values it takes (glow_style, glass_style, wallpaper_order, clock_format) is held to
++them, since the launcher answers any other value with its own default. A theme's config.json is hand-edited, so one
++that cannot be read, is not JSON, or is not a JSON object is named before the key is written, and a write it cannot
++make says so instead of ending in a traceback.
set's own arguments are read first: a switch without a value, a --theme without the folder behind it, and a word
left over are answered with the usage line and exit 2 before a theme folder is read or written. list, status,
show, install and remove read their own words the same way, before anything is read from this checkout or asked
@@@ -220,29 -220,41 +222,64 @@@ def number_in_range(key, item, parsed,
return value
+# The Keys-table cell of a list the launcher reads with intArray() - `[83, 176]` for the remote buttons those
+# keys add. A list with anything else in it is answered with the built-in default, not the list.
+KEYCODES = "list of keycodes"
+
+
+def keycode_problem(values):
+ """The first entry intArray() would throw the whole list away for, or None.
+
+ intArray() is `if (!(item instanceof Number)) return fallback; ... if (out[i] < 1) return fallback;`, so one
+ entry that is a word, or a number under 1, gives the launcher config.xml's array instead of the list: the
+ remote buttons the key was meant to add do nothing while set has already reported the list as written.
+ Number.intValue() truncates, so a fraction is read as the whole number below it rather than dropped.
+ """
+ for entry in values:
+ if isinstance(entry, bool) or not isinstance(entry, (int, float)):
+ return f"{entry!r} is not a number"
+ if entry != int(entry):
+ return f"{entry} is not a whole number (the launcher reads it as {int(entry)})"
+ if int(entry) < 1:
+ return f"{int(entry)} is below 1"
+ return None
+
+
+ # The string keys a Keys-table row names the values of, with the one the launcher answers instead and whether its
+ # reader ignores case. Config.glowStyle() is `GLOW_HORIZON.equalsIgnoreCase(value.trim()) ? GLOW_HORIZON :
+ # GLOW_RADIAL` and glassStyle() answers glass to anything else; WallpaperRotation.validOrder() is
+ # `ORDER_SEQUENTIAL.equals(order) || ORDER_SHUFFLE.equals(order)`, so `Sequential` is shuffle; ClockFormat applies
+ # "12" or "24" and lets every other mode follow the TV, which is what `system` means, so a capital in SYSTEM is the
+ # same mode. A value outside these sets is not an error on the TV - the default comes back - so set would report a
+ # switch it left where it was, the dead `"glow_style": "off"` #3429 removed from two themes.
+ ENUMS = {
+ "glow_style": (("radial", "horizon"), "radial", True),
+ "glass_style": (("glass", "rim", "halo"), "glass", True),
+ "clock_format": (("12", "24", "system"), "system", True),
+ "wallpaper_order": (("shuffle", "sequential"), "shuffle", False),
+ }
+
+
+ def enum_value(key, value):
+ """The string as the key's own reader keeps it, or a refusal naming the values it takes.
+
+ The launcher trims every string it reads (`string()`, `v instanceof String ? ((String) v).trim() : fallback`),
+ so the value written is the trimmed one. A key with no closed set - a name, a festival, a locale - is handed
+ back untouched, and so is a number written for a string key (`set greeting_name 42` is the text 42).
+ """
+ rule = ENUMS.get(key)
+ if rule is None:
+ return value
+ values, fallback, ignores_case = rule
+ trimmed = value.strip()
+ kept = trimmed.lower() if ignores_case else trimmed
+ if kept not in values:
+ allowed = ", ".join(values[:-1]) + " or " + values[-1]
+ sys.exit(f"{key} takes {allowed}, so {value!r} is not one the launcher keeps: it answers "
+ f"{fallback} instead, and the theme would change nothing. Nothing was written or pushed.")
+ return trimmed
+
+
def value_as(key, item, text):
"""The argument read the way the key's type needs, or a refusal naming what the key takes."""
kind = declared_kind(item)