Log interrupted tasks in AOSP.

Bug 19987461.

Change-Id: Ia2714f555146f8f31a6d8c61f555d2b6fecdab7d
This commit is contained in:
Dan Zivkovic 2015-04-02 14:47:36 -07:00
parent 87eb7ac29c
commit 5a53505fe4
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

@ -1407,7 +1407,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);