From 5a53505fe4c0ae5d04bfcb3612908d3c93be90b1 Mon Sep 17 00:00:00 2001 From: Dan Zivkovic Date: Thu, 2 Apr 2015 14:47:36 -0700 Subject: [PATCH] Log interrupted tasks in AOSP. Bug 19987461. Change-Id: Ia2714f555146f8f31a6d8c61f555d2b6fecdab7d --- .../inputmethod/latin/ExpandableBinaryDictionary.java | 6 ++++-- .../android/inputmethod/latin/inputlogic/InputLogic.java | 2 +- .../inputmethod/latin/settings/SettingsValues.java | 2 +- .../inputmethod/latin/utils/AsyncResultHolder.java | 7 ++++++- .../inputmethod/latin/utils/AsyncResultHolderTests.java | 8 ++++---- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 37899d21e..907095746 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -650,7 +650,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { reloadDictionaryIfRequired(); final String dictName = mDictName; final File dictFile = mDictFile; - final AsyncResultHolder result = new AsyncResultHolder<>(); + final AsyncResultHolder 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 result = new AsyncResultHolder<>(); + final AsyncResultHolder result = + new AsyncResultHolder<>("WordPropertiesForSync"); asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() { @Override public void run() { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index cf4064b72..ed4810c64 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1407,7 +1407,7 @@ public final class InputLogic { return; } - final AsyncResultHolder holder = new AsyncResultHolder<>(); + final AsyncResultHolder holder = new AsyncResultHolder<>("Suggest"); mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() { @Override diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index d112e7200..94573a6d5 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -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) { diff --git a/java/src/com/android/inputmethod/latin/utils/AsyncResultHolder.java b/java/src/com/android/inputmethod/latin/utils/AsyncResultHolder.java index 952ac2a62..1525f2d56 100644 --- a/java/src/com/android/inputmethod/latin/utils/AsyncResultHolder.java +++ b/java/src/com/android/inputmethod/latin/utils/AsyncResultHolder.java @@ -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 { 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 { try { return mLatch.await(timeOut, TimeUnit.MILLISECONDS) ? mResult : defaultValue; } catch (InterruptedException e) { + Log.w(mTag, "get() : Interrupted after " + timeOut + " ms"); return defaultValue; } } diff --git a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java index 170d64383..c214b5fd0 100644 --- a/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java +++ b/tests/src/com/android/inputmethod/latin/utils/AsyncResultHolderTests.java @@ -45,27 +45,27 @@ public class AsyncResultHolderTests extends AndroidTestCase { } public void testGetWithoutSet() { - final AsyncResultHolder holder = new AsyncResultHolder<>(); + final AsyncResultHolder holder = new AsyncResultHolder<>("Test"); final int resultValue = holder.get(DEFAULT_VALUE, TIMEOUT_IN_MILLISECONDS); assertEquals(DEFAULT_VALUE, resultValue); } public void testGetBeforeSet() { - final AsyncResultHolder holder = new AsyncResultHolder<>(); + final AsyncResultHolder 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 holder = new AsyncResultHolder<>(); + final AsyncResultHolder 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 holder = new AsyncResultHolder<>(); + final AsyncResultHolder 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);