aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/research
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/research')
-rw-r--r--java/src/com/android/inputmethod/research/LogStatement.java4
-rw-r--r--java/src/com/android/inputmethod/research/LogUnit.java8
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLog.java13
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLogger.java20
4 files changed, 30 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/research/LogStatement.java b/java/src/com/android/inputmethod/research/LogStatement.java
index 059146ae6..09b12fcfa 100644
--- a/java/src/com/android/inputmethod/research/LogStatement.java
+++ b/java/src/com/android/inputmethod/research/LogStatement.java
@@ -35,7 +35,7 @@ import java.io.IOException;
* associated with the {@code String[] keys} are likely to reveal information about the user. The
* actual values are stored separately.
*/
-class LogStatement {
+public class LogStatement {
private static final String TAG = LogStatement.class.getSimpleName();
private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG;
@@ -166,6 +166,8 @@ class LogStatement {
/**
* Write the contents out through jsonWriter.
*
+ * The JsonWriter class must have already had {@code JsonWriter.beginArray} called on it.
+ *
* Note that this method is not thread safe for the same jsonWriter. Callers must ensure
* thread safety.
*/
diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java
index a584a3af6..1a9a720f3 100644
--- a/java/src/com/android/inputmethod/research/LogUnit.java
+++ b/java/src/com/android/inputmethod/research/LogUnit.java
@@ -110,7 +110,13 @@ import java.util.List;
}
/**
- * Publish the contents of this LogUnit to researchLog.
+ * Publish the contents of this LogUnit to {@code researchLog}.
+ *
+ * For each publishable {@code LogStatement}, invoke {@link LogStatement#outputToLocked}.
+ *
+ * @param researchLog where to publish the contents of this {@code LogUnit}
+ * @param canIncludePrivateData whether the private data in this {@code LogUnit} should be
+ * included
*/
public synchronized void publishTo(final ResearchLog researchLog,
final boolean canIncludePrivateData) {
diff --git a/java/src/com/android/inputmethod/research/ResearchLog.java b/java/src/com/android/inputmethod/research/ResearchLog.java
index 24bf7d15f..5114977d8 100644
--- a/java/src/com/android/inputmethod/research/ResearchLog.java
+++ b/java/src/com/android/inputmethod/research/ResearchLog.java
@@ -81,10 +81,7 @@ public class ResearchLog {
}
}
- public ResearchLog(final File outputFile, Context context) {
- if (outputFile == null) {
- throw new IllegalArgumentException();
- }
+ public ResearchLog(final File outputFile, final Context context) {
mExecutor = Executors.newSingleThreadScheduledExecutor();
mFile = outputFile;
mContext = context;
@@ -112,7 +109,7 @@ public class ResearchLog {
Log.d(TAG, "error when closing ResearchLog:");
e.printStackTrace();
} finally {
- if (mFile.exists()) {
+ if (mFile != null && mFile.exists()) {
mFile.setWritable(false, false);
}
if (onClosed != null) {
@@ -139,7 +136,9 @@ public class ResearchLog {
mHasWrittenData = false;
}
} finally {
- mIsAbortSuccessful = mFile.delete();
+ if (mFile != null) {
+ mIsAbortSuccessful = mFile.delete();
+ }
}
return null;
}
@@ -209,7 +208,7 @@ public class ResearchLog {
*/
public JsonWriter getValidJsonWriterLocked() {
try {
- if (mJsonWriter == NULL_JSON_WRITER) {
+ if (mJsonWriter == NULL_JSON_WRITER && mFile != null) {
final FileOutputStream fos =
mContext.openFileOutput(mFile.getName(), Context.MODE_PRIVATE);
mJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(fos)));
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index 364ab2da2..45212913e 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -763,18 +763,26 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
if (isIncludingRecording) {
// Try to read recording from recently written json file
if (mUserRecordingFile != null) {
+ FileChannel channel = null;
try {
- final FileChannel channel =
- new FileInputStream(mUserRecordingFile).getChannel();
+ channel = new FileInputStream(mUserRecordingFile).getChannel();
final MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0,
channel.size());
// Android's openFileOutput() creates the file, so we use Android's default
// Charset (UTF-8) here to read it.
recording = Charset.defaultCharset().decode(buffer).toString();
} catch (FileNotFoundException e) {
- e.printStackTrace();
+ Log.e(TAG, "Could not find recording file", e);
} catch (IOException e) {
- e.printStackTrace();
+ Log.e(TAG, "Error reading recording file", e);
+ } finally {
+ if (channel != null) {
+ try {
+ channel.close();
+ } catch (IOException e) {
+ Log.e(TAG, "Error closing recording file", e);
+ }
+ }
}
}
}
@@ -1395,7 +1403,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
*/
private static final LogStatement LOGSTATEMENT_LATINIME_PICKSUGGESTIONMANUALLY =
new LogStatement("LatinIMEPickSuggestionManually", true, false, "replacedWord", "index",
- "suggestion", "x", "y");
+ "suggestion", "x", "y", "isBatchMode");
public static void latinIME_pickSuggestionManually(final String replacedWord,
final int index, final String suggestion, final boolean isBatchMode) {
final ResearchLogger researchLogger = getInstance();
@@ -1408,7 +1416,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
researchLogger.enqueueEvent(LOGSTATEMENT_LATINIME_PICKSUGGESTIONMANUALLY,
scrubDigitsFromString(replacedWord), index,
suggestion == null ? null : scrubbedWord, Constants.SUGGESTION_STRIP_COORDINATE,
- Constants.SUGGESTION_STRIP_COORDINATE);
+ Constants.SUGGESTION_STRIP_COORDINATE, isBatchMode);
researchLogger.commitCurrentLogUnitAsWord(scrubbedWord, Long.MAX_VALUE, isBatchMode);
researchLogger.mStatistics.recordManualSuggestion(SystemClock.uptimeMillis());
}