diff options
author | 2014-10-30 11:33:39 -0700 | |
---|---|---|
committer | 2014-11-26 11:17:24 -0800 | |
commit | 12d63820d459edd71a46fa2495fea98b3c785f2d (patch) | |
tree | b313f90ca6f9cf65d46cb2b7f2807834357b1990 /java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java | |
parent | 4195567d24e89b36d23fac89a01ca9459d5b7c47 (diff) | |
download | latinime-12d63820d459edd71a46fa2495fea98b3c785f2d.tar.gz latinime-12d63820d459edd71a46fa2495fea98b3c785f2d.tar.xz latinime-12d63820d459edd71a46fa2495fea98b3c785f2d.zip |
Hook for fetching sync content from UserHistoryDict
Add API to ExpandableBinaryDictionary to dump content
from a given dictionary. We use this for dumping data
for sync process.
Refactored UserHistoryDictionaryTests to scrap out the util
methods for testing. These utility methods would be used
for testing sync + user dictionary code in LatinIMEGoogleTests
Bug:18106539
Change-Id: I357f9192ea1bd69a526d0b620c25616a2e8e9d5b
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index d9d22e0fc..0b61dc18b 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -77,6 +77,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { private static final int DICTIONARY_FORMAT_VERSION = FormatSpec.VERSION4; + private static final WordProperty[] DEFAULT_WORD_PROPERTIES_FOR_SYNC = + new WordProperty[0] /* default */; + /** The application context. */ protected final Context mContext; @@ -802,4 +805,38 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } }); } + + /** + * Returns dictionary content required for syncing. + */ + public WordProperty[] getWordPropertiesForSyncing() { + reloadDictionaryIfRequired(); + final AsyncResultHolder<WordProperty[]> result = new AsyncResultHolder<>(); + asyncExecuteTaskWithLock(mLock.readLock(), "sync-read", new Runnable() { + @Override + public void run() { + final ArrayList<WordProperty> wordPropertyList = new ArrayList<>(); + final BinaryDictionary binaryDictionary = getBinaryDictionary(); + if (binaryDictionary == null) { + return; + } + int token = 0; + do { + // TODO: We need a new API that returns *new* un-synced data. + final BinaryDictionary.GetNextWordPropertyResult result = + binaryDictionary.getNextWordProperty(token); + final WordProperty wordProperty = result.mWordProperty; + if (wordProperty == null) { + break; + } + wordPropertyList.add(wordProperty); + token = result.mNextToken; + } while (token != 0); + result.set(wordPropertyList.toArray(new WordProperty[wordPropertyList.size()])); + } + }); + // TODO: Figure out the best timeout duration for this API. + return result.get(DEFAULT_WORD_PROPERTIES_FOR_SYNC, + TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS); + } } |