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
8c40109f49
commit
611ee9926a
@ -343,6 +343,7 @@ bool AdbUtils::enableAdbIMEKeyboard(const QString &deviceId) {
|
|||||||
// Проверяем, установлен ли ADB Keyboard
|
// Проверяем, установлен ли ADB Keyboard
|
||||||
QString installedList;
|
QString installedList;
|
||||||
startProcess(adb, {"-s", deviceId, "shell", "pm", "list", "packages", "com.android.adbkeyboard"}, &installedList);
|
startProcess(adb, {"-s", deviceId, "shell", "pm", "list", "packages", "com.android.adbkeyboard"}, &installedList);
|
||||||
|
bool freshlyInstalled = false;
|
||||||
if (!installedList.contains("com.android.adbkeyboard")) {
|
if (!installedList.contains("com.android.adbkeyboard")) {
|
||||||
const QString apkPath = QCoreApplication::applicationDirPath() + "/assets/ADBKeyboard.apk";
|
const QString apkPath = QCoreApplication::applicationDirPath() + "/assets/ADBKeyboard.apk";
|
||||||
qDebug() << "[AdbUtils] ADB Keyboard not installed, installing from:" << apkPath;
|
qDebug() << "[AdbUtils] ADB Keyboard not installed, installing from:" << apkPath;
|
||||||
@ -352,6 +353,7 @@ bool AdbUtils::enableAdbIMEKeyboard(const QString &deviceId) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qDebug() << "[AdbUtils] ADB Keyboard installed successfully";
|
qDebug() << "[AdbUtils] ADB Keyboard installed successfully";
|
||||||
|
freshlyInstalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Пакет мог быть отключён производителем (pm disable-user).
|
// Пакет мог быть отключён производителем (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;
|
QString out, err;
|
||||||
if (!startProcess(adb, {"-s", deviceId, "shell", "ime", "enable", imeId}, &out, &err)) {
|
if (startProcess(adb, {"-s", deviceId, "shell", "ime", "enable", imeId}, &out, &err)) {
|
||||||
qWarning() << "[AdbUtils] ime enable failed:" << err.trimmed();
|
qDebug() << "[AdbUtils] ime enable:" << out.trimmed();
|
||||||
return false;
|
imeEnabled = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
qDebug() << "[AdbUtils] ime enable:" << out.trimmed();
|
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 должен появиться в списке разрешённых
|
// Верификация: IME должен появиться в списке разрешённых
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user