am de3e5fbf: Merge "Cleanup in preparation for tests"
# Via Android (Google) Code Review (1) and Kurt Partridge (1) * commit 'de3e5fbf9dfb2e4e34095e0c34e8aec8d8de02f5': Cleanup in preparation for testsmain
commit
d4d515f4bf
|
@ -35,7 +35,7 @@ import java.io.IOException;
|
||||||
* associated with the {@code String[] keys} are likely to reveal information about the user. The
|
* associated with the {@code String[] keys} are likely to reveal information about the user. The
|
||||||
* actual values are stored separately.
|
* actual values are stored separately.
|
||||||
*/
|
*/
|
||||||
class LogStatement {
|
public class LogStatement {
|
||||||
private static final String TAG = LogStatement.class.getSimpleName();
|
private static final String TAG = LogStatement.class.getSimpleName();
|
||||||
private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG;
|
private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG;
|
||||||
|
|
||||||
|
@ -166,6 +166,8 @@ class LogStatement {
|
||||||
/**
|
/**
|
||||||
* Write the contents out through jsonWriter.
|
* 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
|
* Note that this method is not thread safe for the same jsonWriter. Callers must ensure
|
||||||
* thread safety.
|
* thread safety.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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,
|
public synchronized void publishTo(final ResearchLog researchLog,
|
||||||
final boolean canIncludePrivateData) {
|
final boolean canIncludePrivateData) {
|
||||||
|
|
|
@ -81,10 +81,7 @@ public class ResearchLog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResearchLog(final File outputFile, Context context) {
|
public ResearchLog(final File outputFile, final Context context) {
|
||||||
if (outputFile == null) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
mExecutor = Executors.newSingleThreadScheduledExecutor();
|
mExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
mFile = outputFile;
|
mFile = outputFile;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
@ -112,7 +109,7 @@ public class ResearchLog {
|
||||||
Log.d(TAG, "error when closing ResearchLog:");
|
Log.d(TAG, "error when closing ResearchLog:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (mFile.exists()) {
|
if (mFile != null && mFile.exists()) {
|
||||||
mFile.setWritable(false, false);
|
mFile.setWritable(false, false);
|
||||||
}
|
}
|
||||||
if (onClosed != null) {
|
if (onClosed != null) {
|
||||||
|
@ -139,8 +136,10 @@ public class ResearchLog {
|
||||||
mHasWrittenData = false;
|
mHasWrittenData = false;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
if (mFile != null) {
|
||||||
mIsAbortSuccessful = mFile.delete();
|
mIsAbortSuccessful = mFile.delete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -209,7 +208,7 @@ public class ResearchLog {
|
||||||
*/
|
*/
|
||||||
public JsonWriter getValidJsonWriterLocked() {
|
public JsonWriter getValidJsonWriterLocked() {
|
||||||
try {
|
try {
|
||||||
if (mJsonWriter == NULL_JSON_WRITER) {
|
if (mJsonWriter == NULL_JSON_WRITER && mFile != null) {
|
||||||
final FileOutputStream fos =
|
final FileOutputStream fos =
|
||||||
mContext.openFileOutput(mFile.getName(), Context.MODE_PRIVATE);
|
mContext.openFileOutput(mFile.getName(), Context.MODE_PRIVATE);
|
||||||
mJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(fos)));
|
mJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(fos)));
|
||||||
|
|
Loading…
Reference in New Issue