Merge "Log interrupted tasks in AOSP."

main
Dan Zivkovic 2015-04-02 22:15:18 +00:00 committed by Android (Google) Code Review
commit 915b1ed34a
5 changed files with 16 additions and 9 deletions

View File

@ -650,7 +650,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
reloadDictionaryIfRequired();
final String dictName = mDictName;
final File dictFile = mDictFile;
final AsyncResultHolder<DictionaryStats> result = new AsyncResultHolder<>();
final AsyncResultHolder<DictionaryStats> result =
new AsyncResultHolder<>("DictionaryStats");
asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() {
@Override
public void run() {
@ -724,7 +725,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/
public WordProperty[] getWordPropertiesForSyncing() {
reloadDictionaryIfRequired();
final AsyncResultHolder<WordProperty[]> result = new AsyncResultHolder<>();
final AsyncResultHolder<WordProperty[]> result =
new AsyncResultHolder<>("WordPropertiesForSync");
asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() {
@Override
public void run() {

View File

@ -1436,7 +1436,7 @@ public final class InputLogic {
return;
}
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>();
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>("Suggest");
mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER,
new OnGetSuggestedWordsCallback() {
@Override

View File

@ -209,7 +209,7 @@ public class SettingsValues {
prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE,
defaultKeyPreviewDismissEndScale);
mDisplayOrientation = res.getConfiguration().orientation;
mAppWorkarounds = new AsyncResultHolder<>();
mAppWorkarounds = new AsyncResultHolder<>("AppWorkarounds");
final PackageInfo packageInfo = TargetPackageInfoGetterTask.getCachedPackageInfo(
mInputAttributes.mTargetApplicationPackageName);
if (null != packageInfo) {

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.latin.utils;
import android.util.Log;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -29,9 +31,11 @@ public class AsyncResultHolder<E> {
private final Object mLock = new Object();
private E mResult;
private final String mTag;
private final CountDownLatch mLatch;
public AsyncResultHolder() {
public AsyncResultHolder(final String tag) {
mTag = tag;
mLatch = new CountDownLatch(1);
}
@ -61,6 +65,7 @@ public class AsyncResultHolder<E> {
try {
return mLatch.await(timeOut, TimeUnit.MILLISECONDS) ? mResult : defaultValue;
} catch (InterruptedException e) {
Log.w(mTag, "get() : Interrupted after " + timeOut + " ms");
return defaultValue;
}
}

View File

@ -45,27 +45,27 @@ public class AsyncResultHolderTests extends AndroidTestCase {
}
public void testGetWithoutSet() {
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(DEFAULT_VALUE, resultValue);
}
public void testGetBeforeSet() {
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS + MARGIN_IN_MILLISECONDS);
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(DEFAULT_VALUE, resultValue);
}
public void testGetAfterSet() {
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
holder.set(SET_VALUE);
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(SET_VALUE, resultValue);
}
public void testGetBeforeTimeout() {
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>();
final AsyncResultHolder<Integer> holder = new AsyncResultHolder<>("Test");
setAfterGivenTime(holder, SET_VALUE, TIMEOUT_IN_MILLISECONDS - MARGIN_IN_MILLISECONDS);
final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS);
assertEquals(SET_VALUE, resultValue);