From 75e69753b709c19d5a23baf88ec3ac2576ee9c24 Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Tue, 8 Jan 2013 18:36:44 -0800 Subject: [PATCH] [Rlog57b] fix logging of reverts Change-Id: I07c817061a0cc060197e0fea45195ca07a9bf276 --- .../android/inputmethod/latin/LatinIME.java | 2 ++ .../inputmethod/research/ResearchLogger.java | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index df733c55a..8c8a824d8 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2310,6 +2310,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord, mWordComposer.isBatchMode()); + ResearchLogger.getInstance().uncommitCurrentLogUnit(committedWord, + true /* dumpCurrentLogUnit */); } // Don't restart suggestion yet. We'll restart if the user deletes the // separator. diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index f464facf4..5c44af1f2 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -1247,8 +1247,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang public static void mainKeyboardView_setKeyboard(final Keyboard keyboard) { final KeyboardId kid = keyboard.mId; final boolean isPasswordView = kid.passwordInput(); - getInstance().setIsPasswordView(isPasswordView); - getInstance().enqueueEvent(LOGSTATEMENT_MAINKEYBOARDVIEW_SETKEYBOARD, + final ResearchLogger researchLogger = getInstance(); + researchLogger.setIsPasswordView(isPasswordView); + researchLogger.enqueueEvent(LOGSTATEMENT_MAINKEYBOARDVIEW_SETKEYBOARD, KeyboardId.elementIdToName(kid.mElementId), kid.mLocale + ":" + kid.mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), kid.mOrientation, kid.mWidth, KeyboardId.modeName(kid.mMode), kid.imeAction(), @@ -1271,12 +1272,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang public static void latinIME_revertCommit(final String committedWord, final String originallyTypedWord, final boolean isBatchMode) { final ResearchLogger researchLogger = getInstance(); - // Assume that mCurrentLogUnit has been restored to contain the reverted word. - final LogUnit logUnit = researchLogger.mCurrentLogUnit; + // TODO: Verify that mCurrentLogUnit has been restored and contains the reverted word. + final LogUnit logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); if (originallyTypedWord.length() > 0 && hasLetters(originallyTypedWord)) { if (logUnit != null) { - // Probably not necessary, but setting as a precaution in case the word isn't - // committed later. logUnit.setWord(originallyTypedWord); } } @@ -1413,10 +1412,17 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang final String scrubbedTypedWord = scrubDigitsFromString(typedWord); final String scrubbedAutoCorrection = scrubDigitsFromString(autoCorrection); final ResearchLogger researchLogger = getInstance(); - researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_COMMITCURRENTAUTOCORRECTION, - scrubbedTypedWord, scrubbedAutoCorrection, separatorString); researchLogger.commitCurrentLogUnitAsWord(scrubbedAutoCorrection, Long.MAX_VALUE, isBatchMode); + + // Add the autocorrection logStatement at the end of the logUnit for the committed word. + // We have to do this after calling commitCurrentLogUnitAsWord, because it may split the + // current logUnit, and then we have to peek to get the logUnit reference back. + final LogUnit logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + // TODO: Add test to confirm that the commitCurrentAutoCorrection log statement should + // always be added to logUnit (if non-null) and not mCurrentLogUnit. + researchLogger.enqueueEvent(logUnit, LOGSTATEMENT_LATINIME_COMMITCURRENTAUTOCORRECTION, + scrubbedTypedWord, scrubbedAutoCorrection, separatorString); } private boolean isExpectingCommitText = false;