Skip to content

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

Module cards: a decision is for one card name under one key; captions cannot claim endorsement

Gathin2349a42c643248
diff --git a/README.md b/README.md
index 8c82b02ec..4c128569a 100644
--- a/README.md
+++ b/README.md
@@ -260,12 +260,13 @@ choice, an optional caption and a glow colour, placed ahead of the alphabetical
Nothing changes until you say so. When a module is installed the launcher asks once, naming the
app, its package and its signing key, with **Keep hidden** selected by default; Back keeps it hidden
too. Keeping it hidden leaves the app's ordinary tile exactly as before. The answer is remembered for
-that app's signing key, so an update signed with a different key asks again.
+that app's signing key and that card name, so an update signed with a different key, or one that
+renames its card, asks again.
To change your mind, **hold OK on the Settings pill**: the Module cards list shows every installed
card with its package and key, and OK toggles Shown and Hidden. At most eight cards are drawn, in
label order; any further card you set to Shown is listed as over the limit and keeps its ordinary
-tile. Set `module_cards` to `false` in `config.xml` to turn the whole thing off.
+tile. Set `module_cards` to `false` in `config.xml` or a theme's `config.json` to turn the whole thing off.
A card is only a different look for a tile. The launcher never installs or downloads anything,
never loads code from a module, and launches a card exactly as it launches any app.
diff --git a/docs/modules.md b/docs/modules.md
index fa52ca24d..8397b93d9 100644
--- a/docs/modules.md
+++ b/docs/modules.md
@@ -38,8 +38,10 @@ Then create `res/xml/module_card.xml`:
- `label`: 1 to 24 characters, letters, digits, space and `. & + ' -`. Keep it short; it is the
name on the tile and in the top shelf. Words like "verified" or "official", the launcher's own UI
names and input names such as HDMI are refused, and so is a new card whose label (or whose app
- label) is the name of another app installed on the TV (the full list is in the spec).
+ label) is the name of another app installed on the TV (the full list is in the spec). Changing
+ the label in an update makes the owner decide again, so pick it once.
- `caption`: optional, up to 32 characters, shown after the label while the card is focused. The
+ endorsement words refused in labels are refused here too. The
name line under the tile is one line; label and caption together show about 26 characters on a
4 column grid, so keep the caption to a few words.
- `accent`: optional `#RRGGBB`, the glow colour behind the card while it is focused in the dock.
diff --git a/docs/specs/card.md b/docs/specs/card.md
index dfe85accb..3531d2271 100644
--- a/docs/specs/card.md
+++ b/docs/specs/card.md
@@ -70,15 +70,17 @@ and digits removed. "Live TV", "live-tv" and "LIVETV" are the same name.
A label is rejected when:
- it contains `verified` or `official` anywhere: words that imply endorsement are reserved, and
- nothing a module declares is ever presented as endorsed;
+ nothing a module declares is ever presented as endorsed (the same two words are refused in the
+ caption);
- it is one of the names the launcher's own UI uses, in English or in the TV's language:
- `Home`, `Settings`, `Inputs`, `Wi-Fi`, `Live TV`, `Default home`, `Clock`, `tv-vibehack`;
+ `Home`, `Settings`, `Inputs`, `Wi-Fi`, `Live TV`, `Default home`, `Clock`, `cleanyourtv`, `tv-vibehack`;
- it names an input the Inputs menu shows: `HDMI` and anything starting with it, `AV`;
-- while the prompt is due (a new card, or one whose signing key changed): it equals the label of
+- while the prompt is due (a new card, or one whose signing key or label changed): it equals the label of
another app installed on this TV (the names on the home screen), or the app's own label equals
another installed app's label. The module's own app label is fine: a card named "Retro" from an
app named "Retro" is the normal case. Once the owner has answered, the name stays with that card:
- an app installed afterwards with the same label does not displace it;
+ an app installed afterwards with the same label does not displace it. The answer is for that name:
+ a card that changes its label on an update is pending again and goes through these checks anew;
- two cards share a label: the one the owner already decided on keeps the name (the oldest
decision wins), the other is dropped; when neither has a decision, both are dropped and nobody is
asked about a contested name.
@@ -111,11 +113,12 @@ any violation drops that one card, with a log line and no other effect.
digest"). On Android 9 and newer the launcher reads the current signer; on Android 8 it reads
the package's signature. A package signed with more than one certificate is rejected.
3. Decision record. The owner's decision is stored per package in the launcher's private storage
- (`files/cards.json`): package, signer digest, decision (`show` or `hide`), first seen, decided
- at. The file is written atomically and validated strictly when read; a file that does not
+ (`files/cards.json`, format version 2): package, signer digest, the card's folded label, decision
+ (`show` or `hide`), first seen, decided at. The file is written atomically and validated strictly when read; a file that does not
validate is moved to `cards.json.bad` and the launcher continues as if no decision had been made.
The record never leaves the TV (backups are off for the launcher).
-4. Prompt. A card with no record, or whose signer digest differs from its record, is not shown. Once
+4. Prompt. A card with no record, or whose signer digest or folded label differs from its record, is
+ not shown. Once
the grid is laid out and the home screen has focus, with no menu open, the launcher shows one
prompt. It names the app by its own label (control and formatting characters removed, at most 40
characters) and package and the key by the first twelve hex characters of the digest; when the
@@ -126,11 +129,14 @@ any violation drops that one card, with a log line and no other effect.
5. Signer change. A package whose signer digest differs from its record is treated as new: the card
is not shown, and the prompt says the app was updated with a different signing key. The record is
replaced only by the owner's answer, never by the detection alone.
+ Label change. A card whose folded label differs from its record is treated the same way: not
+ shown, and the prompt says the card changed its name. A decision is for one name under one key.
6. Placement. A shown card stands in for every tile of its package: the ordinary tile is not shown
next to it. A package in `hidden_apps` (`config.xml`) shows neither a tile nor a card. A package in
`dock_apps` gets its card in that dock slot. Other cards sort right after the configured dock apps
and before the alphabetical grid, by label. On the default configuration, four dock apps and four
- columns, that is the first grid tile. In the dock, the top shelf shows the label and the glow uses
+ columns, that is the first grid tile. With fewer `dock_apps` than columns, a shown card fills the
+ empty dock slot, since the dock is simply the first row. In the dock, the top shelf shows the label and the glow uses
the accent; in the grid, the name line under the focused tile shows the label and the caption,
as far as they fit on one line. A card uses the app's own banner (or icon) for its artwork.
7. Hide. A hidden card leaves the app's ordinary tile exactly as before: hiding a card never
@@ -142,7 +148,7 @@ any violation drops that one card, with a log line and no other effect.
9. Launch. A card launches the declaring activity by explicit component with no extras and no data,
the same way every tile is launched. No field of a card can name an intent, a URI, a class or a
package. Holding OK on a card opens the app's App info page, like any tile.
-10. Off switch. `module_cards` in `config.xml` (default `true`). When `false` the launcher never looks
+10. Off switch. `module_cards` in `config.xml` or the `config.json` theme overlay (default `true`). When `false` the launcher never looks
for cards, never asks, and the Module cards list only says that none are installed.
## Security
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Cards.java b/launcher/app/src/main/java/com/gathin/tvhome/Cards.java
index 2f085cc62..a08d231e0 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Cards.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Cards.java
@@ -78,7 +78,7 @@ final class Cards {
private static final String[] RESERVED_ANYWHERE = {"verified", "official"};
/** Names the launcher's own UI renders (pills, tiles, the Inputs menu): rejected as a whole label. */
private static final Set<String> RESERVED_EXACT = new HashSet<>(Arrays.asList(
- "tvvibehack", "settings", "inputs", "livetv", "home", "defaulthome", "wifi", "av"));
+ "tvvibehack", "cleanyourtv", "settings", "inputs", "livetv", "home", "defaulthome", "wifi", "av"));
/** "HDMI", "HDMI 1", "HDMI2"... */
private static final String RESERVED_PREFIX = "hdmi";
@@ -87,6 +87,8 @@ final class Cards {
NEW,
/** The record was made for a different signing key: it no longer applies and the prompt is due. */
RESIGNED,
+ /** The card's label changed since the owner decided: the decision was for another name, the prompt is due. */
+ RELABELLED,
SHOWN,
HIDDEN
}
@@ -119,21 +121,27 @@ final class Cards {
}
boolean pending() {
- return state == State.NEW || state == State.RESIGNED;
+ return state == State.NEW || state == State.RESIGNED || state == State.RELABELLED;
}
}
- /** The owner's decision for one package, valid only while the package is signed with this key. */
+ /**
+ * The owner's decision for one package, valid only while the package is signed with this key and
+ * its card keeps the name (folded) it had when the owner decided.
+ */
static final class Record {
final String pkg;
final String digest;
+ /** The card's label as {@link #fold} wrote it at decision time. */
+ final String label;
final String decision;
final long firstSeen;
final long decidedAt;
- Record(String pkg, String digest, String decision, long firstSeen, long decidedAt) {
+ Record(String pkg, String digest, String label, String decision, long firstSeen, long decidedAt) {
this.pkg = pkg;
this.digest = digest;
+ this.label = label;
this.decision = decision;
this.firstSeen = firstSeen;
this.decidedAt = decidedAt;
@@ -297,16 +305,19 @@ final class Cards {
if (d.spec != SPEC_SUPPORTED) throw new CardException("spec " + d.spec + " is not supported (this launcher reads spec " + SPEC_SUPPORTED + ")");
String digest = digest(pm, pkg);
+ String folded = fold(d.label);
Record r = records.get(pkg);
State state;
if (r == null) state = State.NEW;
else if (!r.digest.equals(digest)) state = State.RESIGNED;
+ else if (!r.label.equals(folded)) state = State.RELABELLED; // the owner said yes to another name
else state = DECISION_SHOW.equals(r.decision) ? State.SHOWN : State.HIDDEN;
- boolean pending = state == State.NEW || state == State.RESIGNED;
+ boolean pending = state == State.NEW || state == State.RESIGNED || state == State.RELABELLED;
// Reserved words are policy and always apply. Name collisions only matter while the prompt is
// due: they stop a newcomer from borrowing a name, and never undo a decision the owner made.
- String folded = fold(d.label);
+ // A decided card that changes its label becomes pending again (RELABELLED), so it cannot take
+ // another app's name on an update either.
if (isReserved(folded, uiNames)) throw new CardException("label '" + d.label + "' is reserved");
if (pending && isTaken(folded, pkg, names)) throw new CardException("label '" + d.label + "' is the name of another installed app");
String appLabel = cleanLabel(String.valueOf(ai.applicationInfo.loadLabel(pm)), pkg);
@@ -440,6 +451,8 @@ final class Cards {
if (isReference(caption)) return "caption is a resource reference; write the text itself";
if (!isText(caption)) return "caption has characters outside A-Z a-z 0-9 space . & + ' -";
if (caption.charAt(0) == ' ' || caption.charAt(caption.length() - 1) == ' ') return "caption starts or ends with a space";
+ String folded = fold(caption);
+ for (String word : RESERVED_ANYWHERE) if (folded.contains(word)) return "caption claims endorsement ('" + word + "')";
return null;
}
@@ -577,6 +590,16 @@ final class Cards {
return s != null && s.length() == 64 && isHex(s, true);
}
+ /** A label exactly as {@link #fold} writes it: 1 to LABEL_MAX characters from a-z 0-9. */
+ static boolean isFolded(String s) {
+ if (s == null || s.isEmpty() || s.length() > LABEL_MAX) return false;
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))) return false;
+ }
+ return true;
+ }
+
static String hex(byte[] bytes) {
char[] digits = "0123456789abcdef".toCharArray();
char[] out = new char[bytes.length * 2];
@@ -682,7 +705,7 @@ final class Cards {
Record old = records.get(card.pkg);
long now = System.currentTimeMillis();
long firstSeen = old != null && old.digest.equals(card.digest) ? old.firstSeen : now;
- records.put(card.pkg, new Record(card.pkg, card.digest, show ? DECISION_SHOW : DECISION_HIDE, firstSeen, now));
+ records.put(card.pkg, new Record(card.pkg, card.digest, fold(card.label), show ? DECISION_SHOW : DECISION_HIDE, firstSeen, now));
return save(file, records);
}
@@ -693,10 +716,11 @@ final class Cards {
return file.renameTo(bad) || file.delete();
}
- private static final String HEADER = "{\"version\":1,\"records\":[";
+ private static final String HEADER = "{\"version\":2,\"records\":[";
private static final String FOOTER = "]}";
private static final String F_PACKAGE = "{\"package\":\"";
private static final String F_DIGEST = "\",\"signer_sha256\":\"";
+ private static final String F_LABEL = "\",\"label\":\"";
private static final String F_DECISION = "\",\"decision\":\"";
private static final String F_FIRST_SEEN = "\",\"first_seen\":";
private static final String F_DECIDED_AT = ",\"decided_at\":";
@@ -743,7 +767,9 @@ final class Cards {
String pkg = until(line, at, '"');
if (pkg == null || !isPackageName(pkg) || !take(line, at, F_DIGEST)) return null;
String digest = until(line, at, '"');
- if (digest == null || !isDigest(digest) || !take(line, at, F_DECISION)) return null;
+ if (digest == null || !isDigest(digest) || !take(line, at, F_LABEL)) return null;
+ String label = until(line, at, '"');
+ if (label == null || !isFolded(label) || !take(line, at, F_DECISION)) return null;
String decision = until(line, at, '"');
if (decision == null || !(DECISION_SHOW.equals(decision) || DECISION_HIDE.equals(decision))) return null;
if (!take(line, at, F_FIRST_SEEN)) return null;
@@ -753,7 +779,7 @@ final class Cards {
String decidedAt = until(line, at, '}');
if (decidedAt == null || decidedAt.length() > 18 || !isDigits(decidedAt)) return null;
if (!take(line, at, "}") || at[0] != line.length()) return null;
- return new Record(pkg, digest, decision, Long.parseLong(firstSeen), Long.parseLong(decidedAt));
+ return new Record(pkg, digest, label, decision, Long.parseLong(firstSeen), Long.parseLong(decidedAt));
}
/** Consumes the literal at the cursor, or returns false. */
@@ -784,12 +810,12 @@ final class Cards {
for (int i = 0; i < list.size(); i++) {
Record r = list.get(i);
// Every field is validated before it gets here, so no JSON escaping is ever needed.
- if (!isPackageName(r.pkg) || !isDigest(r.digest)
+ if (!isPackageName(r.pkg) || !isDigest(r.digest) || !isFolded(r.label)
|| !(DECISION_SHOW.equals(r.decision) || DECISION_HIDE.equals(r.decision))
|| r.firstSeen < 0 || r.decidedAt < 0) {
throw new IllegalArgumentException("record for " + r.pkg + " is not valid");
}
- b.append(F_PACKAGE).append(r.pkg).append(F_DIGEST).append(r.digest).append(F_DECISION).append(r.decision)
+ b.append(F_PACKAGE).append(r.pkg).append(F_DIGEST).append(r.digest).append(F_LABEL).append(r.label).append(F_DECISION).append(r.decision)
.append(F_FIRST_SEEN).append(r.firstSeen).append(F_DECIDED_AT).append(r.decidedAt).append('}');
if (i < list.size() - 1) b.append(',');
b.append('\n');
@@ -825,7 +851,7 @@ final class Cards {
if (!isPackageName("io.example.a") || isPackageName("example")) bad.add("package name");
Map<String, Record> one = new TreeMap<>();
String digest = hex(new byte[32]);
- one.put("io.example.a", new Record("io.example.a", digest, DECISION_SHOW, 1, 2));
+ one.put("io.example.a", new Record("io.example.a", digest, "a", DECISION_SHOW, 1, 2));
Map<String, Record> back = decode(encode(one));
if (back == null || back.size() != 1 || back.get("io.example.a").decidedAt != 2) bad.add("store round trip");
if (decode("{}") != null) bad.add("bad store accepted");
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
index f40321079..36c5e9a7c 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -41,6 +41,7 @@ final class Config {
final int columns;
final int rowsBelowDock;
final boolean shamsiDate;
+ final boolean moduleCards;
final String vpnApp;
final boolean showHomeSettingsShortcut;
/** Background colour behind everything, #RRGGBB; black unless a theme says otherwise. */
@@ -53,7 +54,7 @@ final class Config {
private Config(List<String> dockApps, List<String> hiddenApps, String liveTvPackage, String liveTvAction,
String sourcePanelService, String sourcePanelAction, String inputAction,
int columns, int rowsBelowDock,
- boolean shamsiDate, String vpnApp, boolean showHomeSettingsShortcut, int backgroundColor,
+ boolean shamsiDate, boolean moduleCards, String vpnApp, boolean showHomeSettingsShortcut, int backgroundColor,
File wallpaper, boolean overlayApplied) {
this.dockApps = Collections.unmodifiableList(dockApps);
this.hiddenApps = Collections.unmodifiableList(hiddenApps);
@@ -65,6 +66,7 @@ final class Config {
this.columns = columns;
this.rowsBelowDock = rowsBelowDock;
this.shamsiDate = shamsiDate;
+ this.moduleCards = moduleCards;
this.vpnApp = vpnApp;
this.showHomeSettingsShortcut = showHomeSettingsShortcut;
this.backgroundColor = backgroundColor;
@@ -89,6 +91,7 @@ final class Config {
int columns = res.getInteger(R.integer.columns);
int rowsBelow = res.getInteger(R.integer.rows_below_dock);
boolean shamsi = res.getBoolean(R.bool.shamsi_date);
+ boolean moduleCards = res.getBoolean(R.bool.module_cards);
String vpn = res.getString(R.string.vpn_app).trim();
boolean homeSettings = res.getBoolean(R.bool.show_home_settings_shortcut);
int background = 0xFF000000;
@@ -109,6 +112,7 @@ final class Config {
columns = integer(json, "columns", columns, 1, 8);
rowsBelow = integer(json, "rows_below_dock", rowsBelow, 0, 3);
shamsi = bool(json, "shamsi_date", shamsi);
+ moduleCards = bool(json, "module_cards", moduleCards);
vpn = string(json, "vpn_app", vpn);
homeSettings = bool(json, "show_home_settings_shortcut", homeSettings);
background = color(json, "background_color", background);
@@ -119,7 +123,7 @@ final class Config {
if (json != null && json.has("wallpaper") && !bool(json, "wallpaper", true)) wallpaper = null;
return new Config(dock, hidden, liveTv, liveTvAction, panelService, panelAction, inputAction,
- Math.max(1, columns), Math.max(0, rowsBelow), shamsi, vpn, homeSettings, background,
+ Math.max(1, columns), Math.max(0, rowsBelow), shamsi, moduleCards, vpn, homeSettings, background,
wallpaper, applied);
}
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 9ffccf2fb..e91721b0d 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -210,7 +210,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
date.setPadding(0, (int) (4 * density), 0, 0);
}
vpnApp = cfg.vpnApp;
- moduleCards = getResources().getBoolean(R.bool.module_cards);
+ moduleCards = cfg.moduleCards;
hiddenApps = new HashSet<>(cfg.hiddenApps);
grid = findViewById(R.id.grid);
@@ -277,6 +277,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
});
btnSettings.setOnClickListener(v -> open(new Intent(Settings.ACTION_SETTINGS)));
btnSettings.setOnLongClickListener(v -> {
+ if (!moduleCards) return false; // off: a long press does nothing, as before the feature
showModuleCards();
return true;
});
@@ -925,6 +926,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
((TextView) panel.findViewById(R.id.title)).setText(getString(R.string.card_prompt_title, card.appLabel));
((TextView) panel.findViewById(R.id.body)).setText(card.state == Cards.State.RESIGNED
? getString(R.string.card_prompt_resigned, card.appLabel)
+ : card.state == Cards.State.RELABELLED
+ ? getString(R.string.card_prompt_relabelled, card.appLabel)
: getString(R.string.card_prompt_body, card.appLabel));
TextView names = panel.findViewById(R.id.names);
if (Cards.fold(card.label).equals(Cards.fold(card.appLabel))) names.setVisibility(View.GONE);
@@ -951,10 +954,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
decided[0] = true;
cardPrompt = null;
dialog.dismiss();
- CardFeature.run(() -> {
- decideCard(card, v.getId() == R.id.btnShow);
- return null;
- }, null);
+ decideCard(card, v.getId() == R.id.btnShow); // guards its own card calls; the tile reload stays outside
restoreFocus(); // the tiles changed under the prompt; this also chains the next prompt
};
keep.setOnClickListener(choose);
@@ -1062,6 +1062,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
return getString(R.string.card_state_hidden);
case RESIGNED:
return getString(R.string.card_state_new_key);
+ case RELABELLED:
+ return getString(R.string.card_state_new_label);
default:
return getString(R.string.card_state_new);
}
diff --git a/launcher/app/src/main/res/values/strings.xml b/launcher/app/src/main/res/values/strings.xml
index e011aa7de..aa641180e 100644
--- a/launcher/app/src/main/res/values/strings.xml
+++ b/launcher/app/src/main/res/values/strings.xml
@@ -30,7 +30,8 @@
<string name="card_prompt_title">New card from %1$s</string>
<string name="card_prompt_body">%1$s can show a card on your home screen. Keeping it hidden leaves the app\'s normal tile as it is.</string>
<string name="card_prompt_names">The card is named \'%1$s\'. The app is \'%2$s\'.</string>
- <string name="card_prompt_resigned">%1$s was updated with a different signing key. Show its card again?</string>
+ <string name="card_prompt_resigned">%1$s was updated with a different signing key, so your earlier answer no longer applies. Decide again for its card.</string>
+ <string name="card_prompt_relabelled">%1$s changed the name of its card since you decided. Decide again for it.</string>
<string name="card_prompt_hint">You can change this later: hold OK on Settings.</string>
<string name="card_prompt_identity">%1$s, key %2$s</string>
<string name="card_keep_hidden">Keep hidden</string>
@@ -44,4 +45,5 @@
<string name="card_state_hidden">Hidden</string>
<string name="card_state_new">New</string>
<string name="card_state_new_key">New key</string>
+ <string name="card_state_new_label">New name</string>
</resources>
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/CardsTest.java b/launcher/app/src/test/java/com/gathin/tvhome/CardsTest.java
index 6f1c984ed..6e78e6c96 100644
--- a/launcher/app/src/test/java/com/gathin/tvhome/CardsTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/CardsTest.java
@@ -273,7 +273,7 @@ public class CardsTest {
for (int i = 0; i < pkgAndFirstSeen.length; i += 2) {
String pkg = (String) pkgAndFirstSeen[i];
long seen = ((Number) pkgAndFirstSeen[i + 1]).longValue();
- m.put(pkg, new Cards.Record(pkg, DIGEST_A, "show", seen, seen));
+ m.put(pkg, new Cards.Record(pkg, DIGEST_A, "games", "show", seen, seen));
}
return m;
}
@@ -382,10 +382,11 @@ public class CardsTest {
@Test
public void decodeRecordIsExact() {
String line = "{\"package\":\"io.example.a\",\"signer_sha256\":\"" + DIGEST_A
- + "\",\"decision\":\"show\",\"first_seen\":1,\"decided_at\":2}";
+ + "\",\"label\":\"retro\",\"decision\":\"show\",\"first_seen\":1,\"decided_at\":2}";
Cards.Record r = Cards.decodeRecord(line);
assertNotNull(r);
assertEquals("io.example.a", r.pkg);
+ assertEquals("retro", r.label);
assertEquals(1L, r.firstSeen);
assertEquals(2L, r.decidedAt);
assertNull(Cards.decodeRecord(line + " "));
@@ -394,6 +395,9 @@ public class CardsTest {
assertNull(Cards.decodeRecord(line.replace("\"decided_at\":2", "\"decided_at\":")));
assertNull(Cards.decodeRecord(line.replace("\"decided_at\":2", "\"decided_at\":1234567890123456789")));
assertNull(Cards.decodeRecord(line.replace("signer_sha256", "signer")));
+ assertNull(Cards.decodeRecord(line.replace("\"label\":\"retro\"", "\"label\":\"Retro\""))); // not folded
+ assertNull(Cards.decodeRecord(line.replace("\"label\":\"retro\"", "\"label\":\"\"")));
+ assertNull(Cards.decodeRecord(line.replace("\"label\":\"retro\",", "")));
assertNull(Cards.decodeRecord(""));
assertNull(Cards.decodeRecord("{"));
}
@@ -403,17 +407,18 @@ public class CardsTest {
@Test
public void storeRoundTrip() {
Map<String, Cards.Record> in = new TreeMap<>();
- in.put("io.github.udhaykumarbala.retro", new Cards.Record("io.github.udhaykumarbala.retro", DIGEST_B, "show", 1700000000000L, 1700000001000L));
- in.put("io.example.spoof", new Cards.Record("io.example.spoof", DIGEST_A, "hide", 1700000002000L, 1700000003000L));
+ in.put("io.github.udhaykumarbala.retro", new Cards.Record("io.github.udhaykumarbala.retro", DIGEST_B, "retro", "show", 1700000000000L, 1700000001000L));
+ in.put("io.example.spoof", new Cards.Record("io.example.spoof", DIGEST_A, "netflix", "hide", 1700000002000L, 1700000003000L));
String text = Cards.encode(in);
- assertEquals("{\"version\":1,\"records\":[\n"
- + "{\"package\":\"io.example.spoof\",\"signer_sha256\":\"" + DIGEST_A + "\",\"decision\":\"hide\",\"first_seen\":1700000002000,\"decided_at\":1700000003000},\n"
- + "{\"package\":\"io.github.udhaykumarbala.retro\",\"signer_sha256\":\"" + DIGEST_B + "\",\"decision\":\"show\",\"first_seen\":1700000000000,\"decided_at\":1700000001000}\n"
+ assertEquals("{\"version\":2,\"records\":[\n"
+ + "{\"package\":\"io.example.spoof\",\"signer_sha256\":\"" + DIGEST_A + "\",\"label\":\"netflix\",\"decision\":\"hide\",\"first_seen\":1700000002000,\"decided_at\":1700000003000},\n"
+ + "{\"package\":\"io.github.udhaykumarbala.retro\",\"signer_sha256\":\"" + DIGEST_B + "\",\"label\":\"retro\",\"decision\":\"show\",\"first_seen\":1700000000000,\"decided_at\":1700000001000}\n"
+ "]}\n", text);
Map<String, Cards.Record> out = Cards.decode(text);
assertNotNull(out);
assertEquals(2, out.size());
assertEquals("show", out.get("io.github.udhaykumarbala.retro").decision);
+ assertEquals("retro", out.get("io.github.udhaykumarbala.retro").label);
assertEquals(DIGEST_B, out.get("io.github.udhaykumarbala.retro").digest);
assertEquals(1700000000000L, out.get("io.github.udhaykumarbala.retro").firstSeen);
assertEquals(1700000003000L, out.get("io.example.spoof").decidedAt);
@@ -422,7 +427,7 @@ public class CardsTest {
@Test
public void emptyStoreRoundTrip() {
String text = Cards.encode(new TreeMap<>());
- assertEquals("{\"version\":1,\"records\":[\n]}\n", text);
+ assertEquals("{\"version\":2,\"records\":[\n]}\n", text);
Map<String, Cards.Record> out = Cards.decode(text);
assertNotNull(out);
assertTrue(out.isEmpty());
@@ -441,13 +446,13 @@ public class CardsTest {
assertNull(Cards.decode(good.replace("io.example.a", "io.example.a\",\"x\":\"")));
assertNull(Cards.decode(good.replace("io.example.a", "example"))); // no dot
assertNull(Cards.decode(good.replace("io.example.a", "io.1example.a"))); // bad segment
- assertNull(Cards.decode(good.replace("\"version\":1", "\"version\":2")));
+ assertNull(Cards.decode(good.replace("\"version\":2", "\"version\":1"))); // the old format, without labels
assertNull(Cards.decode(good.replace("]}", "")));
assertNull(Cards.decode(good.replace("1700", "-170")));
assertNull(Cards.decode(good + "garbage"));
// Missing comma between records, and the same package twice.
Map<String, Cards.Record> two = one("io.example.a", DIGEST_A, "show");
- two.put("io.example.b", new Cards.Record("io.example.b", DIGEST_B, "hide", 1, 2));
+ two.put("io.example.b", new Cards.Record("io.example.b", DIGEST_B, "b", "hide", 1, 2));
String pair = Cards.encode(two);
assertNotNull(Cards.decode(pair));
assertNull(Cards.decode(pair.replace("},\n", "}\n")));
@@ -459,7 +464,7 @@ public class CardsTest {
Map<String, Cards.Record> many = new TreeMap<>();
for (int i = 0; i < Cards.MAX_RECORDS + 1; i++) {
String pkg = "io.example.p" + i;
- many.put(pkg, new Cards.Record(pkg, DIGEST_A, "hide", i, i));
+ many.put(pkg, new Cards.Record(pkg, DIGEST_A, "card" + i, "hide", i, i));
}
String text = Cards.encode(many); // encode drops the oldest beyond the cap
Map<String, Cards.Record> out = Cards.decode(text);
@@ -513,9 +518,38 @@ public class CardsTest {
assertTrue(bad.delete() && dir.delete());
}
+ @Test
+ public void captionCannotClaimEndorsement() {
+ assertNull(Cards.checkCaption("NES games"));
+ assertNotNull(Cards.checkCaption("Official Netflix app"));
+ assertNotNull(Cards.checkCaption("VERIFIED by Google"));
+ assertNotNull(Cards.checkCaption("ver-ified")); // folding removes the hyphen
+ }
+
+ @Test
+ public void relabelledCardIsPendingAgain() {
+ // A card the owner decided on, whose label then changed, is treated like a new card: it does
+ // not win a name clash, and the clash rule drops both undecided cards.
+ Cards.Card renamed = card("io.example.retro", "Netflix", Cards.State.RELABELLED);
+ Cards.Card other = card("io.example.other", "netflix", Cards.State.NEW);
+ assertTrue(renamed.pending());
+ assertTrue(Cards.resolveClashes(Arrays.asList(renamed, other), recordsFor("io.example.retro", 100)).isEmpty());
+ assertEquals(renamed, Cards.firstPending(Arrays.asList(card("io.example.a", "A", Cards.State.SHOWN), renamed)));
+ }
+
+ @Test
+ public void isFoldedIsStrict() {
+ assertTrue(Cards.isFolded("retro"));
+ assertTrue(Cards.isFolded("nes2"));
+ assertFalse(Cards.isFolded(""));
+ assertFalse(Cards.isFolded("Retro"));
+ assertFalse(Cards.isFolded("re tro"));
+ assertFalse(Cards.isFolded("abcdefghijklmnopqrstuvwxy")); // 25
+ }
+
private static Map<String, Cards.Record> one(String pkg, String digest, String decision) {
Map<String, Cards.Record> m = new TreeMap<>();
- m.put(pkg, new Cards.Record(pkg, digest, decision, 1700000000000L, 1700000000000L));
+ m.put(pkg, new Cards.Record(pkg, digest, "a", decision, 1700000000000L, 1700000000000L));
return m;
}
diff --git a/themes/README.md b/themes/README.md
index 19f25365a..7e3440bb6 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -31,6 +31,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| `columns` | 1 to 8 | Tiles per row; tiles shrink to fit from 5 up |
| `rows_below_dock` | 0 to 3 | Grid rows left visible under the dock |
| `shamsi_date` | bool | Show the Solar Hijri date above the Gregorian one |
+| `module_cards` | bool | Look for module cards and ask about them (`true`); `false` turns the feature off |
| `vpn_app` | string | App the network pill opens when a VPN is configured; also shows a red "VPN off" badge while no VPN is up |
| `show_home_settings_shortcut` | bool | The "Default home" tile, where the TV has a home picker |
| `background_color` | `#RRGGBB` | Colour behind everything; black by default |