From 12d63820d459edd71a46fa2495fea98b3c785f2d Mon Sep 17 00:00:00 2001 From: Jatin Matani Date: Thu, 30 Oct 2014 11:33:39 -0700 Subject: 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 --- .../latin/ExpandableBinaryDictionary.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java') 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 result = new AsyncResultHolder<>(); + asyncExecuteTaskWithLock(mLock.readLock(), "sync-read", new Runnable() { + @Override + public void run() { + final ArrayList 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); + } } -- cgit v1.2.3-83-g751a