Merge "Make ExpandableBinaryDictionary usable for offdevice tests."
This commit is contained in:
commit
7345059fa6
4 changed files with 29 additions and 4 deletions
|
@ -33,6 +33,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.utils.StringUtils;
|
import com.android.inputmethod.latin.utils.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -83,6 +84,11 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
loadDictionary();
|
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) {
|
private synchronized void registerObserver(final Context context) {
|
||||||
// Perform a managed query. The Activity will handle closing and requerying the cursor
|
// Perform a managed query. The Activity will handle closing and requerying the cursor
|
||||||
// when needed.
|
// when needed.
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
|
@ -181,6 +180,19 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
return executor;
|
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,
|
private static AbstractDictionaryWriter getDictionaryWriter(final Context context,
|
||||||
final boolean isDynamicPersonalizationDictionary) {
|
final boolean isDynamicPersonalizationDictionary) {
|
||||||
if (isDynamicPersonalizationDictionary) {
|
if (isDynamicPersonalizationDictionary) {
|
||||||
|
@ -504,7 +516,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
* dictionary exists, this method will generate one.
|
* dictionary exists, this method will generate one.
|
||||||
*/
|
*/
|
||||||
protected void loadDictionary() {
|
protected void loadDictionary() {
|
||||||
mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = SystemClock.uptimeMillis();
|
mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = System.currentTimeMillis();
|
||||||
reloadDictionaryIfRequired();
|
reloadDictionaryIfRequired();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,7 +612,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
* the current binary dictionary from file.
|
* the current binary dictionary from file.
|
||||||
*/
|
*/
|
||||||
protected void setRequiresReload(final boolean requiresRebuild) {
|
protected void setRequiresReload(final boolean requiresRebuild) {
|
||||||
final long time = SystemClock.uptimeMillis();
|
final long time = System.currentTimeMillis();
|
||||||
mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = time;
|
mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = time;
|
||||||
mDictNameDictionaryUpdateController.mLastUpdateRequestTime = time;
|
mDictNameDictionaryUpdateController.mLastUpdateRequestTime = time;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -648,7 +660,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final long time = SystemClock.uptimeMillis();
|
final long time = System.currentTimeMillis();
|
||||||
final boolean dictionaryFileExists = dictionaryFileExists();
|
final boolean dictionaryFileExists = dictionaryFileExists();
|
||||||
if (mDictNameDictionaryUpdateController.isOutOfDate()
|
if (mDictNameDictionaryUpdateController.isOutOfDate()
|
||||||
|| !dictionaryFileExists) {
|
|| !dictionaryFileExists) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import com.android.inputmethod.compat.UserDictionaryCompatUtils;
|
||||||
import com.android.inputmethod.latin.utils.LocaleUtils;
|
import com.android.inputmethod.latin.utils.LocaleUtils;
|
||||||
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -78,6 +79,11 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
||||||
this(context, locale, false);
|
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,
|
public UserBinaryDictionary(final Context context, final Locale locale,
|
||||||
final boolean alsoUseMoreRestrictiveLocales) {
|
final boolean alsoUseMoreRestrictiveLocales) {
|
||||||
super(context, getDictNameWithLocale(NAME, locale), locale, Dictionary.TYPE_USER,
|
super(context, getDictNameWithLocale(NAME, locale), locale, Dictionary.TYPE_USER,
|
||||||
|
|
|
@ -137,6 +137,7 @@ public class PrioritizedSerialExecutor {
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
synchronized(mLock) {
|
synchronized(mLock) {
|
||||||
mIsShutdown = true;
|
mIsShutdown = true;
|
||||||
|
mThreadPoolExecutor.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue