Offline voice recognition in Google keyboard is don't-blink fast, but ironically it doesn't work after I've blocked Gboard in iptables (afwall) -- it sits forever in "
Initializing...". If however I turn off wifi and mobile data, then voice recognition starts up right away --
even faster than when the network is up and allowed. It's a question of special annoyance how Gboard has world class offline recognition yet still forces the user wait a variable fraction of a second in order to phone home, every, time, it, activates. Anyways, this set of observations led me to believe XPL might help close the gap between afwall and gboard. Unfortunately the existing
example Internet.Offline hook targets
android.net.NetworkInfo, which was deprecated in API 29, and my device is on 33 (Android 13). That example hook was being triggered, but not having the "everything's off" effect. A couple guesses later produced this working replacement, targeting the replacement
NetworkCapabilities API:
JSON:
{
"script": [
{
"name": "backlitpetals.NetworkCapabilities.hasCapability",
"code": "function after(hook, param)\n local result = param:getResult()\n if result == false then\n return false\n end\n\n param:setResult(false)\n return true\nend"
}
],
"definition": [
{
"builtin": false,
"collection": "backlitpetals",
"group": "Internet.Offline",
"name": "NetworkCapabilities.hasCapability",
"author": "backlitpetals",
"version": 0,
"description": "Fake offline for API 29 and later.",
"className": "android.net.NetworkCapabilities",
"methodName": "hasCapability",
"parameterTypes": [
"int"
],
"returnType": "boolean",
"minSdk": 21,
"maxSdk": 999,
"minApk": 0,
"maxApk": 2147483647,
"enabled": true,
"optional": false,
"usage": true,
"notify": false,
"luaScript": "@backlitpetals.NetworkCapabilities.hasCapability"
}
]
}
I will enjoy this the dozen times a day I click the Gboard microphone button and it responds on the order of the local cpu rather whatever crappy network I happen to be on. Cheers XPL!
EDITs: copy+style