now checking if the service became a zombie every time we receive a stop request, instead of trying to guess the problematic cases (attempting to fix the Priviliged Options again)
This commit is contained in:
parent
430ce1f97e
commit
ed1ed176c9
3 changed files with 32 additions and 22 deletions
|
|
@ -23,24 +23,19 @@ import io.github.sspanak.tt9.util.SystemSettings;
|
||||||
public class TraditionalT9 extends MainViewHandler {
|
public class TraditionalT9 extends MainViewHandler {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Handler backgroundTasks = new Handler(Looper.getMainLooper());
|
private final Handler backgroundTasks = new Handler(Looper.getMainLooper());
|
||||||
private final Handler deathDetector = new Handler(Looper.getMainLooper());
|
private final Handler zombieDetector = new Handler(Looper.getMainLooper());
|
||||||
|
private int zombieChecks = 0;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onEvaluateInputViewShown() {
|
public boolean onEvaluateInputViewShown() {
|
||||||
super.onEvaluateInputViewShown();
|
super.onEvaluateInputViewShown();
|
||||||
|
if (!SystemSettings.isTT9Active(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
setInputField(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
setInputField(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
||||||
|
return shouldBeVisible();
|
||||||
if (!shouldBeVisible()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SystemSettings.isTT9Enabled(this)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
onDeath();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -129,8 +124,6 @@ public class TraditionalT9 extends MainViewHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onStart(InputConnection connection, EditorInfo field) {
|
protected boolean onStart(InputConnection connection, EditorInfo field) {
|
||||||
deathDetector.removeCallbacksAndMessages(null);
|
|
||||||
|
|
||||||
if (!super.onStart(connection, field)) {
|
if (!super.onStart(connection, field)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -174,6 +167,10 @@ public class TraditionalT9 extends MainViewHandler {
|
||||||
backgroundTasks.removeCallbacksAndMessages(null);
|
backgroundTasks.removeCallbacksAndMessages(null);
|
||||||
backgroundTasks.postDelayed(this::runBackgroundTasks, SettingsStore.WORD_BACKGROUND_TASKS_DELAY);
|
backgroundTasks.postDelayed(this::runBackgroundTasks, SettingsStore.WORD_BACKGROUND_TASKS_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (zombieChecks == 0) {
|
||||||
|
startZombieCheck();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -181,19 +178,32 @@ public class TraditionalT9 extends MainViewHandler {
|
||||||
* On Android 11 the IME is sometimes not killed when the user switches to a different one.
|
* On Android 11 the IME is sometimes not killed when the user switches to a different one.
|
||||||
* Here we attempt to detect if we are disabled, then hide and kill ourselves.
|
* Here we attempt to detect if we are disabled, then hide and kill ourselves.
|
||||||
*/
|
*/
|
||||||
private void onDeath() {
|
private void startZombieCheck() {
|
||||||
if (SystemSettings.isTT9Active(this)) {
|
if (!SystemSettings.isTT9Active(this)) {
|
||||||
Logger.w("onDeath", "===> Still active, rescheduling");
|
onDeath();
|
||||||
deathDetector.postDelayed(this::onDeath, SettingsStore.ZOMBIE_CHECK_INTERVAL);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++zombieChecks < SettingsStore.ZOMBIE_CHECK_MAX) {
|
||||||
|
zombieDetector.postDelayed(this::startZombieCheck, SettingsStore.ZOMBIE_CHECK_INTERVAL);
|
||||||
} else {
|
} else {
|
||||||
deathDetector.removeCallbacksAndMessages(null);
|
Logger.d("startZombieCheck", "Not a zombie after " + zombieChecks + " checks");
|
||||||
|
zombieChecks = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void onDeath() {
|
||||||
|
if (currentInputConnection == null) {
|
||||||
|
Logger.w("onDeath", "===> Already dead. Nothing to do.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.w("onDeath", "===> Killing self");
|
Logger.w("onDeath", "===> Killing self");
|
||||||
requestHideSelf(0);
|
requestHideSelf(0);
|
||||||
onStop();
|
setInputField(null, null);
|
||||||
backgroundTasks.removeCallbacksAndMessages(null);
|
backgroundTasks.removeCallbacksAndMessages(null);
|
||||||
|
zombieDetector.removeCallbacksAndMessages(null);
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ public class SettingsStore extends SettingsUI {
|
||||||
public final static int WORD_FREQUENCY_NORMALIZATION_DIVIDER = 100; // normalized frequency = WORD_FREQUENCY_MAX / WORD_FREQUENCY_NORMALIZATION_DIVIDER
|
public final static int WORD_FREQUENCY_NORMALIZATION_DIVIDER = 100; // normalized frequency = WORD_FREQUENCY_MAX / WORD_FREQUENCY_NORMALIZATION_DIVIDER
|
||||||
public final static int WORD_PAIR_MAX = 1000;
|
public final static int WORD_PAIR_MAX = 1000;
|
||||||
public final static int WORD_PAIR_MAX_WORD_LENGTH = 6;
|
public final static int WORD_PAIR_MAX_WORD_LENGTH = 6;
|
||||||
public final static int ZOMBIE_CHECK_INTERVAL = 666; // ms
|
public final static int ZOMBIE_CHECK_INTERVAL = 1500; // ms
|
||||||
|
public final static int ZOMBIE_CHECK_MAX = 2;
|
||||||
|
|
||||||
/************* hacks *************/
|
/************* hacks *************/
|
||||||
public final static int PREFERENCES_CLICK_DEBOUNCE_TIME = 250; // ms
|
public final static int PREFERENCES_CLICK_DEBOUNCE_TIME = 250; // ms
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ public class SystemSettings {
|
||||||
inputManager = inputManager == null ? (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE) : inputManager;
|
inputManager = inputManager == null ? (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE) : inputManager;
|
||||||
packageName = packageName == null ? context.getPackageName() : packageName;
|
packageName = packageName == null ? context.getPackageName() : packageName;
|
||||||
|
|
||||||
|
|
||||||
for (final InputMethodInfo imeInfo : inputManager.getEnabledInputMethodList()) {
|
for (final InputMethodInfo imeInfo : inputManager.getEnabledInputMethodList()) {
|
||||||
if (packageName.equals(imeInfo.getPackageName()) && imeInfo.getId().equals(defaultIME)) {
|
if (packageName.equals(imeInfo.getPackageName()) && imeInfo.getId().equals(defaultIME)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue