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

View File

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

View File

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

View File

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

View File

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