Make ExpandableBinaryDictionary usable for offdevice tests.

Bug: 11956652
Change-Id: If5a503ef161781818f2efceba542be5a61be6bd1
This commit is contained in:
Keisuke Kuroyanagi 2013-12-13 14:48:43 +09:00
parent 9bd6dac470
commit 9642286c01
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();
}
}