Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ jobs:
-PversionName=${{ steps.v.outputs.versionName }} \
-PversionCode=${{ steps.v.outputs.versionCode }} \
--stacktrace
# Publishing gate: stores (Myket, Cafe Bazar, Play) reject signed-less
# APKs, so fail the job instead of shipping one.
set -- app/build/outputs/apk/release/*.apk
for APK in "$@"; do
case "$APK" in
*unsigned*)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Updates use an incompatible signing key

When the configured keystore is valid but uses a certificate different from the store’s registered signing certificate, the filename-only gate accepts a correctly signed APK even when its certificate differs from the one registered for the package, so the workflow publishes an update that the store rejects.

Verify each APK’s signing certificate against a pinned expected fingerprint before collecting or publishing it.

Prompt for AI agents
In `.github/workflows/release.yml` at line 81:

**Updates use an incompatible signing key**

When the configured keystore is valid but uses a certificate different from the store’s registered signing certificate, the filename-only gate accepts a correctly signed APK even when its certificate differs from the one registered for the package, so the workflow publishes an update that the store rejects.

Verify each APK’s signing certificate against a pinned expected fingerprint before collecting or publishing it.

echo "::error::unsigned release APK ($APK) — signing secrets are missing or wrong"
exit 1
;;
esac
done
[ -e "$1" ] || { echo "::error::no release APK produced"; exit 1; }
echo "signed release APK(s): $#"

- name: Collect APK
id: apk
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboardHidden"
android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
27 changes: 22 additions & 5 deletions app/src/main/java/com/erfanbagheri/controlix/L10n.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@ import java.util.Locale
private const val LANG_PREFS = "controlix_lang"
private const val LANG_KEY = "lang"

/** "" = follow the system/per-app locale; "en"/"fa" = in-app override. */
/** "": follow the system/per-app locale; "en"/"fa": in-app override. */
private var forcedLang: String = ""

/**
* Compose-observable mirror of [forcedLang]. `tr()` resolves through a plain
* module field, so nothing recomposes when the language changes; the theme
* reads this to re-derive typography and layout direction in place instead of
* waiting for the next cold start.
*/
private val langState = androidx.compose.runtime.mutableStateOf("")

/** The language the composition should render with — read inside @Composable. */
fun languageState(): String = langState.value

private fun setForcedLang(lang: String) {
forcedLang = lang
langState.value = lang
}

private var rawContext: Context? = null
private var appContext: Context? = null

Expand All @@ -33,7 +49,7 @@ private var appContext: Context? = null
*/
fun l10nApply(base: Context): Context {
val lang = base.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).getString(LANG_KEY, "").orEmpty()
forcedLang = lang
setForcedLang(lang)
// Rebuild the tr() context from scratch. The system per-app language switch
// (localeConfig) never calls setLanguage, so this is the only place that can
// notice it — and `base` is the one object carrying the *new* locale.
Expand Down Expand Up @@ -75,8 +91,9 @@ private fun wrapLocale(base: Context, lang: String): Context {
fun l10nInit(context: Context) {
val raw = context.applicationContext
rawContext = raw
forcedLang = raw.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).getString(LANG_KEY, "").orEmpty()
appContext = wrapLocale(raw, forcedLang)
val saved = raw.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).getString(LANG_KEY, "").orEmpty()
setForcedLang(saved)
appContext = wrapLocale(raw, saved)
}

/**
Expand All @@ -88,7 +105,7 @@ fun setLanguage(lang: String) {
// commit(): recreate() below re-reads this pref synchronously —
// apply() races and the old locale wins until a cold restart.
raw.getSharedPreferences(LANG_PREFS, Context.MODE_PRIVATE).edit().putString(LANG_KEY, lang).commit()
forcedLang = lang
setForcedLang(lang)
appContext = wrapLocale(raw, lang)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ data class AcSelection(val tempC: Int, val mode: AcMode, val power: Boolean) {

/** Modes offered by the pad; unsupported modes stay disabled. */
fun presetModes(): List<AcMode> = AcMode.entries.toList()

/**
* How many preset modes a remote must carry before the mode row
* shows presets at all. A remote with a bare `Mode` cycle key
* supports none of the five presets individually — it just walks
* its own list — so the row would render five dead buttons.
*/
const val MODE_ROW_MIN_SUPPORTED: Int = 1
}
}

Expand Down
199 changes: 198 additions & 1 deletion app/src/main/java/com/erfanbagheri/controlix/data/ButtonNames.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package com.erfanbagheri.controlix.data
object ButtonNames {

/** lowercase, keep alphanumerics and +/-. */
private fun norm(s: String): String =
fun norm(s: String): String =
s.lowercase().filter { it.isLetterOrDigit() || it == '+' || it == '-' }

fun power(n: String): Boolean {
Expand Down Expand Up @@ -167,4 +167,201 @@ object ButtonNames {

/** A swing / louver key. */
fun acSwing(n: String): Boolean = norm(n).contains("swing")

// ── Non-TV families (fans, purifiers, humidifiers, heaters, …) ────────
// ponytail: these are label heuristics validated against the DB's own
// vocabulary (see docs/DB.md). Upgrade path: per-brand metadata.

fun speedUp(n: String): Boolean {
val x = norm(n)
return (x.contains("speed") || x.contains("fan")) &&
(x.contains("up") || x.contains("+") || x.contains("faster") || x.contains("higher"))
}
fun speedDown(n: String): Boolean {
val x = norm(n)
return (x.contains("speed") || x.contains("fan")) &&
(x.contains("down") || x.contains("dn") || x.contains("-") || x.contains("slower") || x.contains("lower"))
}
/** A discrete speed/fan level key (SPEED 1, FAN HIGH, LOW, MEDIUM, …). */
fun speedLevel(n: String): Boolean {
val x = norm(n)
if (x == "speed" || x == "fan" || x == "fanonly") return false
if (x.startsWith("speed") || x.startsWith("fan")) {
val tail = x.removePrefix("speed").removePrefix("fan").removePrefix("speed_").removePrefix("fan_").trim()
val levelWords = setOf("low", "med", "medium", "mid", "high", "max", "turbo", "quiet",
"slow", "normal", "1", "2", "3", "4", "5", "6", "7", "8", "9")
return tail in levelWords || tail.all { it.isDigit() }
}
return false
}
/**
* A mode key (Mode, Auto, Turbo, Sleep, Night, Eco, Quiet, Natural, …),
* plus compound mode+duration labels like "Heat_5m" or "Dry_1h": a mode
* word at the front followed by digits and an optional unit.
*/
fun modeKey(n: String): Boolean {
val x = norm(n)
if (x == "mode" || x.startsWith("mode")) return true
if (x in setOf("auto", "turbo", "sleep", "night", "eco", "quiet", "natural", "wind",
"ionizer", "plasma", "purify", "dry", "cool", "heat", "warm", "vent",
"fanonly", "breeze", "nightmode", "moon", "snow", "freeze")) {
return true
}
// mode prefix + a duration tail: Heat_5m, Cool_30, Vent_1h.
val m = compoundTail(n) ?: return false
return setOf("heat", "dry", "vent", "cool", "warm", "auto", "fan", "night", "snow", "freeze")
.any { m.first.startsWith(it) }
}

/**
* A duration tail on a compound label, e.g. 5m / 30 / 1h / 3h in
* "Heat_5m", or null when the label has none.
*/
internal fun compoundTail(n: String): Pair<String, String>? {
val i = n.indexOfAny(charArrayOf('_', '-'))
if (i <= 0) return null
val tail = n.substring(i + 1).trim()
if (tail.isEmpty() || tail.length > 8) return null
val digits = tail.filter { it.isDigit() }
val unit = tail.filterNot { it.isDigit() }.lowercase()
// Digit-less tails are only "on"/"off" ("Vent_On"): a mode toggle, not a duration.
if (digits.isEmpty() && unit !in setOf("on", "off")) return null
if (unit != "" && unit !in setOf("m", "min", "mins", "minute", "h", "hr", "hrs", "hour", "hours", "s", "sec", "on", "off")) return null
return n.substring(0, i).lowercase() to tail
}

/**
* The mode half of a compound label — "heat" for "Heat_5m", "vent" for
* "Vent_On" — or null when the label is not compound.
*
* The pad uses this to group a fan's 22 mode keys by what they actually
* do: Heat / Vent / Dry / HeatDry each get their own row instead of one
* 22-chip wall. Without it every duration variant is a separate-looking
* control and the row is unreadable.
*
* ponytail: grouping is a string split on the first separator, so a brand
* that writes "5mHeat" groups under a junk head. Upgrade path: per-brand
* button maps carrying the real (mode, duration) pair.
*/
fun modeHead(n: String): String? = compoundTail(n)?.first

/**
* The duration half of a compound label — "5m" for "Heat_5m", "On" for
* "Vent_On" — or null when the label is not compound. The pad shows this
* as the chip text once the head has been promoted to the row label, so
* a grouped row reads "Heat: 5m 15m 30m 1h" instead of four "Heat_5m"s.
*/
fun modeTail(n: String): String? = compoundTail(n)?.second

/** An oscillation / swing / rotation / louver key. */
fun oscillate(n: String): Boolean {
val x = norm(n)
return x.contains("osc") || x.contains("rotat") || x.contains("swing") ||
x.contains("louver") || x.contains("turn") || x.contains("wide") ||
x.contains("vertical") || x.contains("horizontal")
}
/** A timer key. */
fun timerKey(n: String): Boolean {
val x = norm(n)
return x.contains("timer") || x == "time" || x.startsWith("hour") || x.contains("ontimer") ||
x.contains("offtimer")
}
/** A light / lamp key. */
fun lightKey(n: String): Boolean {
val x = norm(n)
return x.contains("light") || x.contains("lamp") || x.contains("mood")
}
/** A temperature step up (+) key. */
fun tempUp(n: String): Boolean {
val x = norm(n)
return (x.contains("temp") || x.contains("temperature")) &&
(x.contains("up") || x.contains("+") || x.contains("plus"))
}
/** A temperature step down (−) key. */
fun tempDown(n: String): Boolean {
val x = norm(n)
return (x.contains("temp") || x.contains("temperature")) &&
(x.contains("down") || x.contains("dn") || x.contains("-") || x.contains("minus"))
}
/** A color key (lighting). Multi-word names ("Ice Blue", "Dark Green") match
* on their last word; "R"/"G"/"B"/"W" single letters count. */
fun colorKey(n: String): Boolean {
val words = norm(n).split(' ', '_').filter { it.isNotEmpty() }
return words.any { it in COLORS } && words.size <= 3
}

private val COLORS = setOf(
"red", "green", "blue", "white", "yellow", "orange", "purple", "pink", "cyan",
"lime", "amber", "violet", "indigo", "teal", "aqua", "navy", "rainbow", "warm",
"cool", "neutral", "cozy", "pastel", "r", "g", "b", "w", "c", "y", "o", "p",
)
/** An effect key (lighting). */
fun effectKey(n: String): Boolean {
val x = norm(n)
return x in setOf("flash", "fade", "strobe", "smooth", "jump", "quick", "wave",
"blink", "sparkle", "glow")
}
/** A brightness key. */
fun brightnessKey(n: String): Boolean {
val x = norm(n)
return x.contains("bright") || x.startsWith("dim") || x.contains("darker")
}
/** A humidity / mist key. */
fun humidityKey(n: String): Boolean {
val x = norm(n)
return x.contains("hum") || x.contains("mist") || x.contains("vapor")
}
/** A cleaning / dock / spot key (vacuums). */
fun cleaningKey(n: String): Boolean {
val x = norm(n)
return x.contains("clean") || x.contains("spot") || x.contains("edge") ||
x.contains("suction") || x.contains("spiral") || x.contains("zigzag") ||
x.contains("square") || x.contains("zone")
}
/** A dock / home / return key (vacuums). */
fun dockKey(n: String): Boolean {
val x = norm(n)
return x == "home" || x == "dock" || x.contains("recharge") || x.contains("return")
}
/** A start / stop / pause key (vacuums). */
fun startStopKey(n: String): Boolean {
val x = norm(n)
return x.contains("start") || x.contains("pause") || x == "stop" || x.contains("stopstart")
}
/** An audio source / input key. */
fun audioSourceKey(n: String): Boolean {
val x = norm(n)
return x.contains("source") || x.contains("input") || x.contains("bluetooth") ||
x == "bt" || x.contains("optical") || x.contains("opt") || x.contains("hdmi") ||
x == "aux" || x.contains("usb") || x == "tv" || x == "pc" || x == "fm" ||
x.contains("cd") || x.contains("phono") || x.contains("dvd") || x.contains("sat")
}
/** An audio sound-mode key. */
fun audioModeKey(n: String): Boolean {
val x = norm(n)
return x in setOf("music", "movie", "cinema", "standard", "surround", "night",
"game", "stereo", "theater", "news", "speech", "voice", "nightmode", "sports",
"pop", "rock", "jazz", "classical", "flat", "user")
}
/** A bass / treble key. */
fun bassTrebleKey(n: String): Boolean {
val x = norm(n)
return x.contains("bass") || x.contains("treble") || x.contains("eq") ||
x.contains("equalizer") || x.contains("sub")
}
/** A transport key (playback). */
fun transportKey(n: String): Boolean {
val x = norm(n)
return x.contains("play") || x == "stop" || x.contains("pause") || x == "next" ||
x == "prev" || x.contains("previous") || x.contains("rewind") ||
x.contains("fastforward") || x.contains("forward") || x.contains("record")
}
/** A freeze / blank / aspect key (projectors). */
fun projectorKey(n: String): Boolean {
val x = norm(n)
return x.contains("freeze") || x.contains("blank") || x.contains("aspect") ||
x.contains("keystone") || x.contains("zoom") || x.contains("focus")
}
/** A lock / child-lock key. */
fun lockKey(n: String): Boolean = norm(n).contains("lock")
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/erfanbagheri/controlix/data/PadOverflow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.erfanbagheri.controlix.data

/**
* Splits a pad's keys into the row shown on the pad and the "More keys" sheet.
* Pure data; ordering decisions belong to the caller.
*/
object PadOverflow {
const val VISIBLE_LIMIT = 8

data class Split<T>(val visible: List<T>, val overflow: List<T>)

fun <T> split(keys: List<T>): Split<T> =
if (keys.size <= VISIBLE_LIMIT) {
Split(keys, emptyList())
} else {
Split(keys.take(VISIBLE_LIMIT), keys.drop(VISIBLE_LIMIT))
}

// ponytail: stateless split, no grouping of overflow keys; if a remote ever
// carries >20 keys, group the overflow by its own heading inside the sheet.
}
Loading