From 9642286c0140bf78f11d9229c12a07a3c1ac7ff6 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Fri, 13 Dec 2013 14:48:43 +0900 Subject: [PATCH] Make ExpandableBinaryDictionary usable for offdevice tests. Bug: 11956652 Change-Id: If5a503ef161781818f2efceba542be5a61be6bd1 --- .../latin/ContactsBinaryDictionary.java | 6 ++++++ .../latin/ExpandableBinaryDictionary.java | 20 +++++++++++++++---- .../latin/UserBinaryDictionary.java | 6 ++++++ .../utils/PrioritizedSerialExecutor.java | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java index b6cfcd064..ae41e74e3 100644 --- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java @@ -33,6 +33,7 @@ import android.util.Log; import com.android.inputmethod.latin.utils.StringUtils; +import java.io.File; import java.util.List; import java.util.Locale; @@ -83,6 +84,11 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary { loadDictionary(); } + // Dummy constructor for tests. + public ContactsBinaryDictionary(final Context context, final Locale locale, final File file) { + this(context, locale); + } + private synchronized void registerObserver(final Context context) { // Perform a managed query. The Activity will handle closing and requerying the cursor // when needed. diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 9f5cd162f..7afd657a0 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -17,7 +17,6 @@ package com.android.inputmethod.latin; import android.content.Context; -import android.os.SystemClock; import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; @@ -181,6 +180,19 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { return executor; } + /** + * Shutdowns all executors and removes all executors from the executor map for testing. + */ + @UsedForTesting + public static void shutdownAllExecutors() { + synchronized(sDictNameExecutorMap) { + for (final PrioritizedSerialExecutor executor : sDictNameExecutorMap.values()) { + executor.shutdown(); + sDictNameExecutorMap.remove(executor); + } + } + } + private static AbstractDictionaryWriter getDictionaryWriter(final Context context, final boolean isDynamicPersonalizationDictionary) { if (isDynamicPersonalizationDictionary) { @@ -504,7 +516,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { * dictionary exists, this method will generate one. */ protected void loadDictionary() { - mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = SystemClock.uptimeMillis(); + mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = System.currentTimeMillis(); reloadDictionaryIfRequired(); } @@ -600,7 +612,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { * the current binary dictionary from file. */ protected void setRequiresReload(final boolean requiresRebuild) { - final long time = SystemClock.uptimeMillis(); + final long time = System.currentTimeMillis(); mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = time; mDictNameDictionaryUpdateController.mLastUpdateRequestTime = time; if (DEBUG) { @@ -648,7 +660,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { @Override public void run() { try { - final long time = SystemClock.uptimeMillis(); + final long time = System.currentTimeMillis(); final boolean dictionaryFileExists = dictionaryFileExists(); if (mDictNameDictionaryUpdateController.isOutOfDate() || !dictionaryFileExists) { diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java index 1dc3c54bb..6fc98220f 100644 --- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java @@ -32,6 +32,7 @@ import com.android.inputmethod.compat.UserDictionaryCompatUtils; import com.android.inputmethod.latin.utils.LocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; +import java.io.File; import java.util.Arrays; import java.util.Locale; @@ -78,6 +79,11 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary { this(context, locale, false); } + // Dummy constructor for tests. + public UserBinaryDictionary(final Context context, final Locale locale, final File file) { + this(context, locale); + } + public UserBinaryDictionary(final Context context, final Locale locale, final boolean alsoUseMoreRestrictiveLocales) { super(context, getDictNameWithLocale(NAME, locale), locale, Dictionary.TYPE_USER, diff --git a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java index 201a70d42..b10d08af3 100644 --- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java +++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java @@ -137,6 +137,7 @@ public class PrioritizedSerialExecutor { public void shutdown() { synchronized(mLock) { mIsShutdown = true; + mThreadPoolExecutor.shutdown(); } }