Improve ADB Keyboard activation reliability:
- Add retries for `ime enable` to handle delayed IME registration after installation. - Introduce flag to distinguish newly installed keyboards for adaptive retry logic.
This commit is contained in:
parent
cc5a4ed15b
commit
f5be380292
@ -343,6 +343,7 @@ bool AdbUtils::enableAdbIMEKeyboard(const QString &deviceId) {
|
||||
// Проверяем, установлен ли ADB Keyboard
|
||||
QString installedList;
|
||||
startProcess(adb, {"-s", deviceId, "shell", "pm", "list", "packages", "com.android.adbkeyboard"}, &installedList);
|
||||
bool freshlyInstalled = false;
|
||||
if (!installedList.contains("com.android.adbkeyboard")) {
|
||||
const QString apkPath = QCoreApplication::applicationDirPath() + "/assets/ADBKeyboard.apk";
|
||||
qDebug() << "[AdbUtils] ADB Keyboard not installed, installing from:" << apkPath;
|
||||
@ -352,6 +353,7 @@ bool AdbUtils::enableAdbIMEKeyboard(const QString &deviceId) {
|
||||
return false;
|
||||
}
|
||||
qDebug() << "[AdbUtils] ADB Keyboard installed successfully";
|
||||
freshlyInstalled = true;
|
||||
}
|
||||
|
||||
// Пакет мог быть отключён производителем (pm disable-user).
|
||||
@ -365,14 +367,28 @@ bool AdbUtils::enableAdbIMEKeyboard(const QString &deviceId) {
|
||||
}
|
||||
}
|
||||
|
||||
// ime enable
|
||||
{
|
||||
// ime enable с retry: сразу после 'pm install' InputMethodManagerService
|
||||
// может ещё не подхватить новый IME и возвращать "Unknown input method ... cannot be enabled".
|
||||
// Ретраим до появления IME в списке всех зарегистрированных (ime list -a).
|
||||
const int enableAttempts = freshlyInstalled ? 10 : 3;
|
||||
bool imeEnabled = false;
|
||||
QString lastErr;
|
||||
for (int attempt = 0; attempt < enableAttempts; ++attempt) {
|
||||
QString out, err;
|
||||
if (!startProcess(adb, {"-s", deviceId, "shell", "ime", "enable", imeId}, &out, &err)) {
|
||||
qWarning() << "[AdbUtils] ime enable failed:" << err.trimmed();
|
||||
return false;
|
||||
}
|
||||
if (startProcess(adb, {"-s", deviceId, "shell", "ime", "enable", imeId}, &out, &err)) {
|
||||
qDebug() << "[AdbUtils] ime enable:" << out.trimmed();
|
||||
imeEnabled = true;
|
||||
break;
|
||||
}
|
||||
lastErr = err.trimmed();
|
||||
qDebug() << "[AdbUtils] ime enable attempt" << attempt + 1 << "/" << enableAttempts
|
||||
<< "failed:" << lastErr << "— ждём, пока IMMS перечитает IME";
|
||||
QThread::msleep(1000);
|
||||
}
|
||||
if (!imeEnabled) {
|
||||
qWarning() << "[AdbUtils] ime enable failed after" << enableAttempts
|
||||
<< "attempts. Last error:" << lastErr;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Верификация: IME должен появиться в списке разрешённых
|
||||
|
||||
Loading…
Reference in New Issue
Block a user