am 7345059f: Merge "Make ExpandableBinaryDictionary usable for offdevice tests."

* commit '7345059fa611b2566e69349f9c93ecb9d3e3c6d2':
  Make ExpandableBinaryDictionary usable for offdevice tests.
main
Keisuke Kuroyanagi 2013-12-13 08:28:26 -08:00 committed by Android Git Automerger
commit 7ae55b63cd
4 changed files with 29 additions and 4 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -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,

View File

@ -137,6 +137,7 @@ public class PrioritizedSerialExecutor {
public void shutdown() {
synchronized(mLock) {
mIsShutdown = true;
mThreadPoolExecutor.shutdown();
}
}