diff options
Diffstat (limited to 'java/src/com/android/inputmethod/research/ResearchLogger.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/ResearchLogger.java | 136 |
1 files changed, 107 insertions, 29 deletions
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index 4d0808271..79a11fbaf 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -324,11 +324,22 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang sIsLogging = enableLogging; } + private static int sLogFileCounter = 0; + private File createLogFile(File filesDir) { final StringBuilder sb = new StringBuilder(); sb.append(FILENAME_PREFIX).append('-'); sb.append(mUUIDString).append('-'); - sb.append(TIMESTAMP_DATEFORMAT.format(new Date())); + sb.append(TIMESTAMP_DATEFORMAT.format(new Date())).append('-'); + // Sometimes logFiles are created within milliseconds of each other. Append a counter to + // separate these. + if (sLogFileCounter < Integer.MAX_VALUE) { + sLogFileCounter++; + } else { + // Wrap the counter, in the unlikely event of overflow. + sLogFileCounter = 0; + } + sb.append(sLogFileCounter); sb.append(FILENAME_SUFFIX); return new File(filesDir, sb.toString()); } @@ -374,12 +385,12 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang return; } if (mMainLogBuffer == null) { - mMainResearchLog = new ResearchLog(createLogFile(mFilesDir)); + mMainResearchLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME); mMainLogBuffer = new MainLogBuffer(mMainResearchLog); mMainLogBuffer.setSuggest(mSuggest); } if (mFeedbackLogBuffer == null) { - mFeedbackLog = new ResearchLog(createLogFile(mFilesDir)); + mFeedbackLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME); // LogBuffer is one more than FEEDBACK_WORD_BUFFER_SIZE, because it must also hold // the feedback LogUnit itself. mFeedbackLogBuffer = new FixedLogBuffer(FEEDBACK_WORD_BUFFER_SIZE + 1); @@ -599,7 +610,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang uploadNow(); } }); - mFeedbackLog = new ResearchLog(createLogFile(mFilesDir)); + mFeedbackLog = new ResearchLog(createLogFile(mFilesDir), mLatinIME); } public void uploadNow() { @@ -730,6 +741,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } } + private static final LogStatement LOGSTATEMENT_UNCOMMIT_CURRENT_LOGUNIT = + new LogStatement("UncommitCurrentLogUnit", false, false); public void uncommitCurrentLogUnit(final String expectedWord, final boolean dumpCurrentLogUnit) { // The user has deleted this word and returned to the previous. Check that the word in the @@ -768,6 +781,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang if (mFeedbackLogBuffer != null) { mFeedbackLogBuffer.unshiftIn(); } + enqueueEvent(LOGSTATEMENT_UNCOMMIT_CURRENT_LOGUNIT); if (DEBUG) { Log.d(TAG, "uncommitCurrentLogUnit (dump=" + dumpCurrentLogUnit + ") back to " + (mCurrentLogUnit.hasWord() ? ": '" + mCurrentLogUnit.getWord() + "'" : "")); @@ -1162,7 +1176,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang suggestion == null ? null : scrubbedWord, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE); researchLogger.commitCurrentLogUnitAsWord(scrubbedWord, Long.MAX_VALUE, isBatchMode); - researchLogger.mStatistics.recordManualSuggestion(); + researchLogger.mStatistics.recordManualSuggestion(SystemClock.uptimeMillis()); } /** @@ -1172,21 +1186,21 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang */ private static final LogStatement LOGSTATEMENT_LATINIME_PUNCTUATIONSUGGESTION = new LogStatement("LatinIMEPunctuationSuggestion", false, false, "index", "suggestion", - "x", "y"); + "x", "y", "isPrediction"); public static void latinIME_punctuationSuggestion(final int index, final String suggestion, - final boolean isBatchMode) { + final boolean isBatchMode, final boolean isPrediction) { final ResearchLogger researchLogger = getInstance(); researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_PUNCTUATIONSUGGESTION, index, suggestion, - Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE); + Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, + isPrediction); researchLogger.commitCurrentLogUnitAsWord(suggestion, Long.MAX_VALUE, isBatchMode); } /** * Log a call to LatinIME.sendKeyCodePoint(). * - * SystemResponse: The IME is simulating a hardware keypress. This happens for numbers; other - * input typically goes through RichInputConnection.setComposingText() and - * RichInputConnection.commitText(). + * SystemResponse: The IME is inserting text into the TextView for numbers, fixed strings, or + * some other unusual mechanism. */ private static final LogStatement LOGSTATEMENT_LATINIME_SENDKEYCODEPOINT = new LogStatement("LatinIMESendKeyCodePoint", true, false, "code"); @@ -1200,6 +1214,24 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } /** + * Log a call to LatinIME.promotePhantomSpace(). + * + * SystemResponse: The IME is inserting a real space in place of a phantom space. + */ + private static final LogStatement LOGSTATEMENT_LATINIME_PROMOTEPHANTOMSPACE = + new LogStatement("LatinIMEPromotPhantomSpace", false, false); + public static void latinIME_promotePhantomSpace() { + final ResearchLogger researchLogger = getInstance(); + final LogUnit logUnit; + if (researchLogger.mMainLogBuffer == null) { + logUnit = researchLogger.mCurrentLogUnit; + } else { + logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + } + researchLogger.enqueueEvent(logUnit, LOGSTATEMENT_LATINIME_PROMOTEPHANTOMSPACE); + } + + /** * Log a call to LatinIME.swapSwapperAndSpace(). * * SystemResponse: A symbol has been swapped with a space character. E.g. punctuation may swap @@ -1211,7 +1243,12 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang public static void latinIME_swapSwapperAndSpace(final CharSequence originalCharacters, final String charactersAfterSwap) { final ResearchLogger researchLogger = getInstance(); - final LogUnit logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + final LogUnit logUnit; + if (researchLogger.mMainLogBuffer == null) { + logUnit = null; + } else { + logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + } if (logUnit != null) { researchLogger.enqueueEvent(logUnit, LOGSTATEMENT_LATINIME_SWAPSWAPPERANDSPACE, originalCharacters, charactersAfterSwap); @@ -1277,20 +1314,27 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang */ private static final LogStatement LOGSTATEMENT_LATINIME_REVERTCOMMIT = new LogStatement("LatinIMERevertCommit", true, false, "committedWord", - "originallyTypedWord"); + "originallyTypedWord", "separatorString"); public static void latinIME_revertCommit(final String committedWord, - final String originallyTypedWord, final boolean isBatchMode) { + final String originallyTypedWord, final boolean isBatchMode, + final String separatorString) { final ResearchLogger researchLogger = getInstance(); // TODO: Verify that mCurrentLogUnit has been restored and contains the reverted word. - final LogUnit logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + final LogUnit logUnit; + if (researchLogger.mMainLogBuffer == null) { + logUnit = null; + } else { + logUnit = researchLogger.mMainLogBuffer.peekLastLogUnit(); + } if (originallyTypedWord.length() > 0 && hasLetters(originallyTypedWord)) { if (logUnit != null) { logUnit.setWord(originallyTypedWord); } } researchLogger.enqueueEvent(logUnit != null ? logUnit : researchLogger.mCurrentLogUnit, - LOGSTATEMENT_LATINIME_REVERTCOMMIT, committedWord, originallyTypedWord); - researchLogger.mStatistics.recordRevertCommit(); + LOGSTATEMENT_LATINIME_REVERTCOMMIT, committedWord, originallyTypedWord, + separatorString); + researchLogger.mStatistics.recordRevertCommit(SystemClock.uptimeMillis()); researchLogger.commitCurrentLogUnitAsWord(originallyTypedWord, Long.MAX_VALUE, isBatchMode); } @@ -1620,28 +1664,62 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang final ResearchLogger researchLogger = getInstance(); researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_ONENDBATCHINPUT, enteredText, enteredWordPos); - researchLogger.mStatistics.recordGestureInput(enteredText.length()); + researchLogger.mStatistics.recordGestureInput(enteredText.length(), + SystemClock.uptimeMillis()); } /** - * Log a call to LatinIME.handleBackspace(). + * Log a call to LatinIME.handleBackspace() that is not a batch delete. + * + * UserInput: The user is deleting one or more characters by hitting the backspace key once. + * The covers single character deletes as well as deleting selections. + */ + private static final LogStatement LOGSTATEMENT_LATINIME_HANDLEBACKSPACE = + new LogStatement("LatinIMEHandleBackspace", true, false, "numCharacters"); + public static void latinIME_handleBackspace(final int numCharacters) { + final ResearchLogger researchLogger = getInstance(); + researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_HANDLEBACKSPACE, numCharacters); + } + + /** + * Log a call to LatinIME.handleBackspace() that is a batch delete. * * UserInput: The user is deleting a gestured word by hitting the backspace key once. */ private static final LogStatement LOGSTATEMENT_LATINIME_HANDLEBACKSPACE_BATCH = - new LogStatement("LatinIMEHandleBackspaceBatch", true, false, "deletedText"); - public static void latinIME_handleBackspace_batch(final CharSequence deletedText) { + new LogStatement("LatinIMEHandleBackspaceBatch", true, false, "deletedText", + "numCharacters"); + public static void latinIME_handleBackspace_batch(final CharSequence deletedText, + final int numCharacters) { + final ResearchLogger researchLogger = getInstance(); + researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_HANDLEBACKSPACE_BATCH, deletedText, + numCharacters); + researchLogger.mStatistics.recordGestureDelete(deletedText.length(), + SystemClock.uptimeMillis()); + } + + /** + * Log a long interval between user operation. + * + * UserInput: The user has not done anything for a while. + */ + private static final LogStatement LOGSTATEMENT_ONUSERPAUSE = new LogStatement("OnUserPause", + false, false, "intervalInMs"); + public static void onUserPause(final long interval) { final ResearchLogger researchLogger = getInstance(); - researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_HANDLEBACKSPACE_BATCH, deletedText); - researchLogger.mStatistics.recordGestureDelete(); + researchLogger.enqueueEvent(LOGSTATEMENT_ONUSERPAUSE, interval); } - public static void latinIME_handleSeparator() { - // Reset the saved down event time. For tapping, motion events, etc. before the separator - // are assigned to the previous LogUnit, and events after the separator are assigned to the - // next LogUnit. In the case of multitap, this might capture down events corresponding to - // the next word, however it should not be more than a character or two. - getInstance().setSavedDownEventTime(SystemClock.uptimeMillis()); + /** + * Record the current time in case the LogUnit is later split. + * + * If the current logUnitis split, then tapping, motion events, etc. before this time should + * be assigned to one LogUnit, and events after this time should go into the following LogUnit. + */ + public static void recordTimeForLogUnitSplit() { + final ResearchLogger researchLogger = getInstance(); + researchLogger.setSavedDownEventTime(SystemClock.uptimeMillis()); + researchLogger.mSavedDownEventTime = Long.MAX_VALUE; } /** |