forked from florisboard/florisboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovision-florisboard.sh
More file actions
executable file
·281 lines (235 loc) · 9.12 KB
/
provision-florisboard.sh
File metadata and controls
executable file
·281 lines (235 loc) · 9.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FLORISBOARD_PACKAGE="dev.patrickgold.florisboard"
FLORISBOARD_APK="${SCRIPT_DIR}/florisboard.apk"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
step() { echo -e "${GREEN}[STEP]${NC} $1"; }
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; }
require_adb() {
if ! command -v adb >/dev/null 2>&1; then
error "adb not found. Install Android SDK Platform-Tools."
exit 1
fi
}
ensure_device() {
local c
c=$(adb devices | awk 'NR>1 && $2=="device" {print $1}' | wc -l | tr -d ' ')
if [ "${c}" -eq 0 ]; then
error "No Android device connected. Enable USB debugging and reconnect."
exit 1
fi
info "Device connected"
}
install_florisboard() {
step "Installing FlorisBoard keyboard"
if [ ! -f "${FLORISBOARD_APK}" ]; then
error "FlorisBoard APK not found: ${FLORISBOARD_APK}"
exit 1
fi
# Install with -r (replace), -d (allow downgrade), -g (grant all runtime permissions)
if adb install -r -d -g "${FLORISBOARD_APK}"; then
info "FlorisBoard installed successfully"
else
error "Failed to install FlorisBoard APK"
exit 1
fi
# Verify installation
if ! adb shell pm list packages | grep -q "${FLORISBOARD_PACKAGE}"; then
error "FlorisBoard package not found after installation"
exit 1
fi
info "FlorisBoard package verified"
}
disable_gboard() {
step "Disabling Gboard keyboard"
# Gboard package names (different versions use different packages)
local gboard_packages=(
"com.google.android.inputmethod.latin"
"com.google.android.gms.inputmethod"
)
local disabled_any=false
for gboard_pkg in "${gboard_packages[@]}"; do
# Check if Gboard package is installed
if adb shell pm list packages | grep -q "${gboard_pkg}"; then
info "Found Gboard package: ${gboard_pkg}"
# Method 1: Disable the package (requires device owner or user approval)
if adb shell pm disable-user --user 0 "${gboard_pkg}" 2>/dev/null; then
info "Disabled Gboard package: ${gboard_pkg}"
disabled_any=true
else
warn "Could not disable Gboard package via pm disable-user: ${gboard_pkg}"
warn "This may require device owner privileges"
warn "Will attempt to disable via IME settings instead"
fi
fi
done
# Also find and disable Gboard IMEs directly
info "Searching for Gboard IMEs to disable..."
local all_imes
all_imes=$(adb shell ime list -a 2>/dev/null || echo "")
if [ -n "${all_imes}" ]; then
local gboard_ime_found=false
while IFS= read -r ime_id; do
[ -z "${ime_id}" ] && continue
ime_id=$(echo "${ime_id}" | tr -d '\r\n' | sed 's/:$//')
# Check if this IME belongs to Gboard
for gboard_pkg in "${gboard_packages[@]}"; do
if echo "${ime_id}" | grep -q "${gboard_pkg}"; then
info "Found Gboard IME: ${ime_id}"
gboard_ime_found=true
# Disable the IME
if adb shell ime disable "${ime_id}" 2>/dev/null; then
info "Disabled Gboard IME: ${ime_id}"
disabled_any=true
else
warn "Failed to disable Gboard IME: ${ime_id}"
fi
fi
done
done <<< "${all_imes}"
if [ "${gboard_ime_found}" = false ]; then
info "No Gboard IMEs found in IME list"
fi
fi
if [ "${disabled_any}" = false ]; then
info "Gboard not found or already disabled"
fi
}
enable_florisboard() {
step "Enabling FlorisBoard keyboard"
# First, list all IMEs (including disabled ones) to find FlorisBoard's service name
info "Checking available IMEs..."
local all_imes
all_imes=$(adb shell ime list -a 2>/dev/null || echo "")
if [ -z "${all_imes}" ]; then
error "Could not retrieve IME list"
return 1
fi
# Find FlorisBoard IME ID from the list
local florisboard_ime_id
florisboard_ime_id=$(echo "${all_imes}" | grep "${FLORISBOARD_PACKAGE}" | head -1 | tr -d '\r\n' | sed 's/:$//' || echo "")
if [ -z "${florisboard_ime_id}" ]; then
warn "FlorisBoard IME not found in IME list"
info "All available IMEs:"
echo "${all_imes}"
warn "FlorisBoard may need to be set up manually in Settings > System > Languages & input"
return 1
fi
info "Found FlorisBoard IME: ${florisboard_ime_id}"
# Get current enabled IMEs from settings (more reliable than ime list)
local current_enabled
current_enabled=$(adb shell settings get secure enabled_input_methods 2>/dev/null | tr -d '\r\n' || echo "")
info "Currently enabled IMEs (from settings): ${current_enabled}"
# Method 1: Directly set enabled_input_methods to only FlorisBoard (most reliable)
# This matches what MainActivity does in Kotlin
info "Setting enabled_input_methods to only FlorisBoard..."
if adb shell settings put secure enabled_input_methods "${florisboard_ime_id}" 2>/dev/null; then
info "Successfully set enabled_input_methods to FlorisBoard only"
else
warn "Failed to set enabled_input_methods via settings"
fi
# Method 2: Also disable all other IMEs using ime disable (for redundancy)
info "Disabling all other enabled input methods via ime command..."
local enabled_imes
enabled_imes=$(adb shell ime list -s 2>/dev/null || echo "")
local disabled_count=0
if [ -n "${enabled_imes}" ]; then
while IFS= read -r ime_id; do
# Skip empty lines
[ -z "${ime_id}" ] && continue
# Remove trailing colon if present
ime_id=$(echo "${ime_id}" | sed 's/:$//')
# Skip FlorisBoard
if [ "${ime_id}" = "${florisboard_ime_id}" ]; then
continue
fi
# Disable this IME
info "Disabling IME: ${ime_id}..."
if adb shell ime disable "${ime_id}" 2>/dev/null; then
info "Disabled IME: ${ime_id}"
disabled_count=$((disabled_count + 1))
else
# Try again - sometimes IME disable needs a retry
sleep 0.5
if adb shell ime disable "${ime_id}" 2>/dev/null; then
info "Disabled IME: ${ime_id} (on retry)"
disabled_count=$((disabled_count + 1))
else
warn "Failed to disable IME: ${ime_id}"
fi
fi
done <<< "${enabled_imes}"
fi
if [ "${disabled_count}" -gt 0 ]; then
info "Disabled ${disabled_count} other input method(s) via ime command"
fi
# Enable FlorisBoard IME explicitly
info "Enabling FlorisBoard IME..."
if adb shell ime enable "${florisboard_ime_id}" 2>/dev/null; then
info "FlorisBoard IME enabled successfully"
else
warn "Failed to enable FlorisBoard IME via adb"
warn "This may require the keyboard to be enabled manually in Settings"
fi
# Verify only FlorisBoard is enabled
local remaining_enabled
remaining_enabled=$(adb shell ime list -s 2>/dev/null | grep -v "${florisboard_ime_id}" | grep -v "^$" | wc -l | tr -d ' ' || echo "0")
if [ "${remaining_enabled}" -gt 0 ]; then
warn "Warning: ${remaining_enabled} other IME(s) are still enabled"
warn "Remaining enabled IMEs:"
adb shell ime list -s 2>/dev/null | grep -v "${florisboard_ime_id}" | while read -r remaining_ime; do
warn " - ${remaining_ime}"
done
else
info "Verified: Only FlorisBoard is enabled"
fi
# Verify enabled_input_methods setting
local verified_enabled
verified_enabled=$(adb shell settings get secure enabled_input_methods 2>/dev/null | tr -d '\r\n' || echo "")
if echo "${verified_enabled}" | grep -q "${florisboard_ime_id}"; then
if [ "${verified_enabled}" = "${florisboard_ime_id}" ]; then
info "Verified: enabled_input_methods contains only FlorisBoard"
else
warn "Warning: enabled_input_methods contains other IMEs: ${verified_enabled}"
# Try to fix it again
adb shell settings put secure enabled_input_methods "${florisboard_ime_id}" 2>/dev/null || true
fi
else
warn "Warning: FlorisBoard not found in enabled_input_methods: ${verified_enabled}"
fi
# Set as default IME (requires device owner or WRITE_SECURE_SETTINGS permission)
info "Setting FlorisBoard as default keyboard..."
if adb shell settings put secure default_input_method "${florisboard_ime_id}" 2>/dev/null; then
info "FlorisBoard set as default keyboard"
else
warn "Failed to set FlorisBoard as default keyboard via settings"
warn "This may require device owner privileges or WRITE_SECURE_SETTINGS permission"
warn "The app will attempt to set it programmatically on launch if it's the device owner"
fi
# Verify it's set as default
local current_default
current_default=$(adb shell settings get secure default_input_method 2>/dev/null | tr -d '\r\n' || echo "")
if [ "${current_default}" = "${florisboard_ime_id}" ]; then
info "Verified: FlorisBoard is now the default keyboard"
else
warn "Default keyboard is: ${current_default}"
warn "Expected: ${florisboard_ime_id}"
fi
}
main() {
require_adb
ensure_device
install_florisboard
disable_gboard
enable_florisboard
step "FlorisBoard provisioning complete"
info "Note: The app will also attempt to set FlorisBoard as default on launch"
}
main "$@"