Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37503590 authored by Dan Zivkovic's avatar Dan Zivkovic
Browse files

Kill+restart tasks before/after decoder init.

Bug 19625976.

Change-Id: I6d8b0d2b0a77ccda1bfc914501cf568b92862980
parent bd1bc406
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -26,12 +26,17 @@ import com.android.inputmethod.latin.settings.SettingsValues;
public class StatsUtilsManager {

    private static final StatsUtilsManager sInstance = new StatsUtilsManager();
    private static StatsUtilsManager sTestInstance = null;

    /**
     * @return the singleton instance of {@link StatsUtilsManager}.
     */
    public static StatsUtilsManager getInstance() {
        return sInstance;
        return sTestInstance != null ? sTestInstance : sInstance;
    }

    public static void setTestInstance(final StatsUtilsManager testInstance) {
        sTestInstance = testInstance;
    }

    public void onCreate(final Context context, final DictionaryFacilitator dictionaryFacilitator) {
+10 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import com.android.inputmethod.annotations.UsedForTesting;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

@@ -74,6 +73,16 @@ public class ExecutorUtils {
        return sExecutorService;
    }

    public static void killTasks() {
        getBackgroundExecutor().shutdownNow();
        try {
            getBackgroundExecutor().awaitTermination(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            Log.wtf(TAG, "Failed to shut down background task.");
            throw new IllegalStateException("Failed to shut down background task.");
        }
    }

    public static Runnable chain(final Runnable... runnables) {
        return new RunnableChain(runnables);
    }