Loading java/src/com/android/inputmethod/research/LogUnit.java +6 −51 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package com.android.inputmethod.research; import com.android.inputmethod.latin.CollectionUtils; import java.util.List; import java.util.ArrayList; /** * A group of log statements related to each other. Loading @@ -35,39 +35,16 @@ import java.util.List; * been published recently, or whether the LogUnit contains numbers, etc. */ /* package */ class LogUnit { private final List<String[]> mKeysList; private final List<Object[]> mValuesList; // Assume that mTimeList is sorted in increasing order. Do not insert null values into // mTimeList. private final List<Long> mTimeList; private final List<Boolean> mIsPotentiallyPrivate; private final ArrayList<String[]> mKeysList = CollectionUtils.newArrayList(); private final ArrayList<Object[]> mValuesList = CollectionUtils.newArrayList(); private final ArrayList<Boolean> mIsPotentiallyPrivate = CollectionUtils.newArrayList(); private String mWord; private boolean mContainsDigit; public LogUnit() { mKeysList = CollectionUtils.newArrayList(); mValuesList = CollectionUtils.newArrayList(); mTimeList = CollectionUtils.newArrayList(); mIsPotentiallyPrivate = CollectionUtils.newArrayList(); } private LogUnit(final List<String[]> keysList, final List<Object[]> valuesList, final List<Long> timeList, final List<Boolean> isPotentiallyPrivate) { mKeysList = keysList; mValuesList = valuesList; mTimeList = timeList; mIsPotentiallyPrivate = isPotentiallyPrivate; } /** * Adds a new log statement. The time parameter in successive calls to this method must be * monotonically increasing, or splitByTime() will not work. */ public void addLogStatement(final String[] keys, final Object[] values, final long time, final boolean isPotentiallyPrivate) { final Boolean isPotentiallyPrivate) { mKeysList.add(keys); mValuesList.add(values); mTimeList.add(time); mIsPotentiallyPrivate.add(isPotentiallyPrivate); } Loading @@ -75,7 +52,7 @@ import java.util.List; final int size = mKeysList.size(); for (int i = 0; i < size; i++) { if (!mIsPotentiallyPrivate.get(i) || isIncludingPrivateData) { researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i), mTimeList.get(i)); researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i)); } } } Loading Loading @@ -103,26 +80,4 @@ import java.util.List; public boolean isEmpty() { return mKeysList.isEmpty(); } /** * Split this logUnit, with all events before maxTime staying in the current logUnit, and all * events after maxTime going into a new LogUnit that is returned. */ public LogUnit splitByTime(final long maxTime) { // Assume that mTimeList is in sorted order. final int length = mTimeList.size(); for (int index = 0; index < length; index++) { if (mTimeList.get(index) >= maxTime) { final LogUnit newLogUnit = new LogUnit( mKeysList.subList(index, length), mValuesList.subList(index, length), mTimeList.subList(index, length), mIsPotentiallyPrivate.subList(index, length)); newLogUnit.mWord = null; newLogUnit.mContainsDigit = mContainsDigit; return newLogUnit; } } return new LogUnit(); } } java/src/com/android/inputmethod/research/ResearchLog.java +2 −2 Original line number Diff line number Diff line Loading @@ -207,7 +207,7 @@ public class ResearchLog { private static final String UPTIME_KEY = "_ut"; private static final String EVENT_TYPE_KEY = "_ty"; void outputEvent(final String[] keys, final Object[] values, final long time) { void outputEvent(final String[] keys, final Object[] values) { // Not thread safe. if (keys.length == 0) { return; Loading @@ -225,7 +225,7 @@ public class ResearchLog { } mJsonWriter.beginObject(); mJsonWriter.name(CURRENT_TIME_KEY).value(System.currentTimeMillis()); mJsonWriter.name(UPTIME_KEY).value(time); mJsonWriter.name(UPTIME_KEY).value(SystemClock.uptimeMillis()); mJsonWriter.name(EVENT_TYPE_KEY).value(keys[0]); final int length = values.length; for (int i = 0; i < length; i++) { Loading java/src/com/android/inputmethod/research/ResearchLogger.java +13 −17 Original line number Diff line number Diff line Loading @@ -380,7 +380,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang Log.d(TAG, "stop called"); } logStatistics(); commitCurrentLogUnit(SystemClock.uptimeMillis()); commitCurrentLogUnit(); if (mMainLogBuffer != null) { publishLogBuffer(mMainLogBuffer, mMainResearchLog, false /* isIncludingPrivateData */); Loading Loading @@ -548,7 +548,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang return; } if (includeHistory) { commitCurrentLogUnit(SystemClock.uptimeMillis()); commitCurrentLogUnit(); } else { mFeedbackLogBuffer.clear(); } Loading @@ -557,7 +557,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang feedbackContents }; feedbackLogUnit.addLogStatement(EVENTKEYS_FEEDBACK, values, SystemClock.uptimeMillis(), false /* isPotentiallyPrivate */); false /* isPotentiallyPrivate */); mFeedbackLogBuffer.shiftIn(feedbackLogUnit); publishLogBuffer(mFeedbackLogBuffer, mFeedbackLog, true /* isIncludingPrivateData */); mFeedbackLog.close(new Runnable() { Loading Loading @@ -658,9 +658,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private synchronized void enqueuePotentiallyPrivateEvent(final String[] keys, final Object[] values) { assert values.length + 1 == keys.length; final long time = SystemClock.uptimeMillis(); if (isAllowedToLog()) { mCurrentLogUnit.addLogStatement(keys, values, time, true /* isPotentiallyPrivate */); mCurrentLogUnit.addLogStatement(keys, values, true /* isPotentiallyPrivate */); } } Loading @@ -682,19 +681,17 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang */ private synchronized void enqueueEvent(final String[] keys, final Object[] values) { assert values.length + 1 == keys.length; final long time = SystemClock.uptimeMillis(); if (isAllowedToLog()) { mCurrentLogUnit.addLogStatement(keys, values, time, false /* isPotentiallyPrivate */); mCurrentLogUnit.addLogStatement(keys, values, false /* isPotentiallyPrivate */); } } /* package for test */ void commitCurrentLogUnit(final long maxTime) { /* package for test */ void commitCurrentLogUnit() { if (DEBUG) { Log.d(TAG, "commitCurrentLogUnit" + (mCurrentLogUnit.hasWord() ? ": " + mCurrentLogUnit.getWord() : "")); } if (!mCurrentLogUnit.isEmpty()) { final LogUnit newLogUnit = mCurrentLogUnit.splitByTime(maxTime); if (mMainLogBuffer != null) { mMainLogBuffer.shiftIn(mCurrentLogUnit); if (mMainLogBuffer.isSafeToLog() && mMainResearchLog != null) { Loading @@ -706,7 +703,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang if (mFeedbackLogBuffer != null) { mFeedbackLogBuffer.shiftIn(mCurrentLogUnit); } mCurrentLogUnit = newLogUnit; mCurrentLogUnit = new LogUnit(); Log.d(TAG, "commitCurrentLogUnit"); } } Loading @@ -724,7 +721,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang isIncludingPrivateData }; openingLogUnit.addLogStatement(EVENTKEYS_LOG_SEGMENT_START, values, SystemClock.uptimeMillis(), false /* isPotentiallyPrivate */); false /* isPotentiallyPrivate */); researchLog.publish(openingLogUnit, true /* isIncludingPrivateData */); LogUnit logUnit; while ((logUnit = logBuffer.shiftOut()) != null) { Loading @@ -732,7 +729,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } final LogUnit closingLogUnit = new LogUnit(); closingLogUnit.addLogStatement(EVENTKEYS_LOG_SEGMENT_END, EVENTKEYS_NULLVALUES, SystemClock.uptimeMillis(), false /* isPotentiallyPrivate */); false /* isPotentiallyPrivate */); researchLog.publish(closingLogUnit, true /* isIncludingPrivateData */); } Loading @@ -747,13 +744,13 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang return false; } private void onWordComplete(final String word, final long maxTime) { private void onWordComplete(final String word) { Log.d(TAG, "onWordComplete: " + word); if (word != null && word.length() > 0 && hasLetters(word)) { mCurrentLogUnit.setWord(word); mStatistics.recordWordEntered(); } commitCurrentLogUnit(maxTime); commitCurrentLogUnit(); } private static int scrubDigitFromCodePoint(int codePoint) { Loading Loading @@ -966,7 +963,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } final ResearchLogger researchLogger = getInstance(); researchLogger.enqueueEvent(EVENTKEYS_LATINIME_ONWINDOWHIDDEN, values); researchLogger.commitCurrentLogUnit(SystemClock.uptimeMillis()); researchLogger.commitCurrentLogUnit(); getInstance().stop(); } } Loading Loading @@ -1212,8 +1209,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang final ResearchLogger researchLogger = getInstance(); researchLogger.enqueuePotentiallyPrivateEvent(EVENTKEYS_RICHINPUTCONNECTION_COMMITTEXT, values); // TODO: Replace Long.MAX_VALUE with timestamp of last data to include researchLogger.onWordComplete(scrubbedWord, Long.MAX_VALUE); researchLogger.onWordComplete(scrubbedWord); } private static final String[] EVENTKEYS_RICHINPUTCONNECTION_DELETESURROUNDINGTEXT = { Loading Loading
java/src/com/android/inputmethod/research/LogUnit.java +6 −51 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package com.android.inputmethod.research; import com.android.inputmethod.latin.CollectionUtils; import java.util.List; import java.util.ArrayList; /** * A group of log statements related to each other. Loading @@ -35,39 +35,16 @@ import java.util.List; * been published recently, or whether the LogUnit contains numbers, etc. */ /* package */ class LogUnit { private final List<String[]> mKeysList; private final List<Object[]> mValuesList; // Assume that mTimeList is sorted in increasing order. Do not insert null values into // mTimeList. private final List<Long> mTimeList; private final List<Boolean> mIsPotentiallyPrivate; private final ArrayList<String[]> mKeysList = CollectionUtils.newArrayList(); private final ArrayList<Object[]> mValuesList = CollectionUtils.newArrayList(); private final ArrayList<Boolean> mIsPotentiallyPrivate = CollectionUtils.newArrayList(); private String mWord; private boolean mContainsDigit; public LogUnit() { mKeysList = CollectionUtils.newArrayList(); mValuesList = CollectionUtils.newArrayList(); mTimeList = CollectionUtils.newArrayList(); mIsPotentiallyPrivate = CollectionUtils.newArrayList(); } private LogUnit(final List<String[]> keysList, final List<Object[]> valuesList, final List<Long> timeList, final List<Boolean> isPotentiallyPrivate) { mKeysList = keysList; mValuesList = valuesList; mTimeList = timeList; mIsPotentiallyPrivate = isPotentiallyPrivate; } /** * Adds a new log statement. The time parameter in successive calls to this method must be * monotonically increasing, or splitByTime() will not work. */ public void addLogStatement(final String[] keys, final Object[] values, final long time, final boolean isPotentiallyPrivate) { final Boolean isPotentiallyPrivate) { mKeysList.add(keys); mValuesList.add(values); mTimeList.add(time); mIsPotentiallyPrivate.add(isPotentiallyPrivate); } Loading @@ -75,7 +52,7 @@ import java.util.List; final int size = mKeysList.size(); for (int i = 0; i < size; i++) { if (!mIsPotentiallyPrivate.get(i) || isIncludingPrivateData) { researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i), mTimeList.get(i)); researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i)); } } } Loading Loading @@ -103,26 +80,4 @@ import java.util.List; public boolean isEmpty() { return mKeysList.isEmpty(); } /** * Split this logUnit, with all events before maxTime staying in the current logUnit, and all * events after maxTime going into a new LogUnit that is returned. */ public LogUnit splitByTime(final long maxTime) { // Assume that mTimeList is in sorted order. final int length = mTimeList.size(); for (int index = 0; index < length; index++) { if (mTimeList.get(index) >= maxTime) { final LogUnit newLogUnit = new LogUnit( mKeysList.subList(index, length), mValuesList.subList(index, length), mTimeList.subList(index, length), mIsPotentiallyPrivate.subList(index, length)); newLogUnit.mWord = null; newLogUnit.mContainsDigit = mContainsDigit; return newLogUnit; } } return new LogUnit(); } }
java/src/com/android/inputmethod/research/ResearchLog.java +2 −2 Original line number Diff line number Diff line Loading @@ -207,7 +207,7 @@ public class ResearchLog { private static final String UPTIME_KEY = "_ut"; private static final String EVENT_TYPE_KEY = "_ty"; void outputEvent(final String[] keys, final Object[] values, final long time) { void outputEvent(final String[] keys, final Object[] values) { // Not thread safe. if (keys.length == 0) { return; Loading @@ -225,7 +225,7 @@ public class ResearchLog { } mJsonWriter.beginObject(); mJsonWriter.name(CURRENT_TIME_KEY).value(System.currentTimeMillis()); mJsonWriter.name(UPTIME_KEY).value(time); mJsonWriter.name(UPTIME_KEY).value(SystemClock.uptimeMillis()); mJsonWriter.name(EVENT_TYPE_KEY).value(keys[0]); final int length = values.length; for (int i = 0; i < length; i++) { Loading
java/src/com/android/inputmethod/research/ResearchLogger.java +13 −17 Original line number Diff line number Diff line Loading @@ -380,7 +380,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang Log.d(TAG, "stop called"); } logStatistics(); commitCurrentLogUnit(SystemClock.uptimeMillis()); commitCurrentLogUnit(); if (mMainLogBuffer != null) { publishLogBuffer(mMainLogBuffer, mMainResearchLog, false /* isIncludingPrivateData */); Loading Loading @@ -548,7 +548,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang return; } if (includeHistory) { commitCurrentLogUnit(SystemClock.uptimeMillis()); commitCurrentLogUnit(); } else { mFeedbackLogBuffer.clear(); } Loading @@ -557,7 +557,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang feedbackContents }; feedbackLogUnit.addLogStatement(EVENTKEYS_FEEDBACK, values, SystemClock.uptimeMillis(), false /* isPotentiallyPrivate */); false /* isPotentiallyPrivate */); mFeedbackLogBuffer.shiftIn(feedbackLogUnit); publishLogBuffer(mFeedbackLogBuffer, mFeedbackLog, true /* isIncludingPrivateData */); mFeedbackLog.close(new Runnable() { Loading Loading @@ -658,9 +658,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private synchronized void enqueuePotentiallyPrivateEvent(final String[] keys, final Object[] values) { assert values.length + 1 == keys.length; final long time = SystemClock.uptimeMillis(); if (isAllowedToLog()) { mCurrentLogUnit.addLogStatement(keys, values, time, true /* isPotentiallyPrivate */); mCurrentLogUnit.addLogStatement(keys, values, true /* isPotentiallyPrivate */); } } Loading @@ -682,19 +681,17 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang */ private synchronized void enqueueEvent(final String[] keys, final Object[] values) { assert values.length + 1 == keys.length; final long time = SystemClock.uptimeMillis(); if (isAllowedToLog()) { mCurrentLogUnit.addLogStatement(keys, values, time, false /* isPotentiallyPrivate */); mCurrentLogUnit.addLogStatement(keys, values, false /* isPotentiallyPrivate */); } } /* package for test */ void commitCurrentLogUnit(final long maxTime) { /* package for test */ void commitCurrentLogUnit() { if (DEBUG) { Log.d(TAG, "commitCurrentLogUnit" + (mCurrentLogUnit.hasWord() ? ": " + mCurrentLogUnit.getWord() : "")); } if (!mCurrentLogUnit.isEmpty()) { final LogUnit newLogUnit = mCurrentLogUnit.splitByTime(maxTime); if (mMainLogBuffer != null) { mMainLogBuffer.shiftIn(mCurrentLogUnit); if (mMainLogBuffer.isSafeToLog() && mMainResearchLog != null) { Loading @@ -706,7 +703,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang if (mFeedbackLogBuffer != null) { mFeedbackLogBuffer.shiftIn(mCurrentLogUnit); } mCurrentLogUnit = newLogUnit; mCurrentLogUnit = new LogUnit(); Log.d(TAG, "commitCurrentLogUnit"); } } Loading @@ -724,7 +721,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang isIncludingPrivateData }; openingLogUnit.addLogStatement(EVENTKEYS_LOG_SEGMENT_START, values, SystemClock.uptimeMillis(), false /* isPotentiallyPrivate */); false /* isPotentiallyPrivate */); researchLog.publish(openingLogUnit, true /* isIncludingPrivateData */); LogUnit logUnit; while ((logUnit = logBuffer.shiftOut()) != null) { Loading @@ -732,7 +729,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } final LogUnit closingLogUnit = new LogUnit(); closingLogUnit.addLogStatement(EVENTKEYS_LOG_SEGMENT_END, EVENTKEYS_NULLVALUES, SystemClock.uptimeMillis(), false /* isPotentiallyPrivate */); false /* isPotentiallyPrivate */); researchLog.publish(closingLogUnit, true /* isIncludingPrivateData */); } Loading @@ -747,13 +744,13 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang return false; } private void onWordComplete(final String word, final long maxTime) { private void onWordComplete(final String word) { Log.d(TAG, "onWordComplete: " + word); if (word != null && word.length() > 0 && hasLetters(word)) { mCurrentLogUnit.setWord(word); mStatistics.recordWordEntered(); } commitCurrentLogUnit(maxTime); commitCurrentLogUnit(); } private static int scrubDigitFromCodePoint(int codePoint) { Loading Loading @@ -966,7 +963,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } final ResearchLogger researchLogger = getInstance(); researchLogger.enqueueEvent(EVENTKEYS_LATINIME_ONWINDOWHIDDEN, values); researchLogger.commitCurrentLogUnit(SystemClock.uptimeMillis()); researchLogger.commitCurrentLogUnit(); getInstance().stop(); } } Loading Loading @@ -1212,8 +1209,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang final ResearchLogger researchLogger = getInstance(); researchLogger.enqueuePotentiallyPrivateEvent(EVENTKEYS_RICHINPUTCONNECTION_COMMITTEXT, values); // TODO: Replace Long.MAX_VALUE with timestamp of last data to include researchLogger.onWordComplete(scrubbedWord, Long.MAX_VALUE); researchLogger.onWordComplete(scrubbedWord); } private static final String[] EVENTKEYS_RICHINPUTCONNECTION_DELETESURROUNDINGTEXT = { Loading