From 0aafbcf879a31afc8361078bd9574915d95694c0 Mon Sep 17 00:00:00 2001 From: Kurt Partridge Date: Mon, 17 Dec 2012 18:19:58 -0800 Subject: [PATCH] Add ProductionFlag.IS_EXPERIMENTAL_DEBUG The IS_EXPERIMENTAL_DEBUG flag gives a single place to turn off all debugging flags that might be set and to also enforce privacy controls. Currently only used in the research package. multi-project commit with I9275a7c8e40bf56106447a02d3056655329074b3 Change-Id: If769fe3a633f33963ca49e8ddf01ab24a30b6fd2 --- .../android/inputmethod/latin/define/ProductionFlag.java | 5 +++++ .../com/android/inputmethod/research/MainLogBuffer.java | 7 ++++--- .../src/com/android/inputmethod/research/ResearchLog.java | 2 +- .../com/android/inputmethod/research/ResearchLogger.java | 8 +++++--- java/src/com/android/inputmethod/research/Statistics.java | 3 ++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/define/ProductionFlag.java b/java/src/com/android/inputmethod/latin/define/ProductionFlag.java index 52c066a44..a14398f64 100644 --- a/java/src/com/android/inputmethod/latin/define/ProductionFlag.java +++ b/java/src/com/android/inputmethod/latin/define/ProductionFlag.java @@ -23,4 +23,9 @@ public final class ProductionFlag { public static final boolean IS_EXPERIMENTAL = false; public static final boolean IS_INTERNAL = false; + + // When false, IS_EXPERIMENTAL_DEBUG suggests that all guarded class-private DEBUG flags should + // be false, and any privacy controls should be enforced. IS_EXPERIMENTAL_DEBUG should be false + // for any released build. + public static final boolean IS_EXPERIMENTAL_DEBUG = false; } diff --git a/java/src/com/android/inputmethod/research/MainLogBuffer.java b/java/src/com/android/inputmethod/research/MainLogBuffer.java index b027643a1..0185e5fc0 100644 --- a/java/src/com/android/inputmethod/research/MainLogBuffer.java +++ b/java/src/com/android/inputmethod/research/MainLogBuffer.java @@ -20,18 +20,19 @@ import android.util.Log; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Suggest; +import com.android.inputmethod.latin.define.ProductionFlag; import java.util.Random; public class MainLogBuffer extends LogBuffer { private static final String TAG = MainLogBuffer.class.getSimpleName(); - // For privacy reasons, be sure to set to "false" for production code. - private static final boolean DEBUG = false; + private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; // The size of the n-grams logged. E.g. N_GRAM_SIZE = 2 means to sample bigrams. private static final int N_GRAM_SIZE = 2; // The number of words between n-grams to omit from the log. - private static final int DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES = DEBUG ? 2 : 18; + private static final int DEFAULT_NUMBER_OF_WORDS_BETWEEN_SAMPLES = + ProductionFlag.IS_EXPERIMENTAL_DEBUG ? 2 : 18; private final ResearchLog mResearchLog; private Suggest mSuggest; diff --git a/java/src/com/android/inputmethod/research/ResearchLog.java b/java/src/com/android/inputmethod/research/ResearchLog.java index f0a1317b2..3c8731995 100644 --- a/java/src/com/android/inputmethod/research/ResearchLog.java +++ b/java/src/com/android/inputmethod/research/ResearchLog.java @@ -52,7 +52,7 @@ import java.util.concurrent.TimeUnit; */ public class ResearchLog { private static final String TAG = ResearchLog.class.getSimpleName(); - private static final boolean DEBUG = false; + private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; private static final long FLUSH_DELAY_IN_MS = 1000 * 5; private static final int ABORT_TIMEOUT_IN_MS = 1000 * 4; diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java index 89cc8d751..6aafbfcb6 100644 --- a/java/src/com/android/inputmethod/research/ResearchLogger.java +++ b/java/src/com/android/inputmethod/research/ResearchLogger.java @@ -83,7 +83,7 @@ import java.util.UUID; */ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChangeListener { private static final String TAG = ResearchLogger.class.getSimpleName(); - private static final boolean DEBUG = false; + private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; private static final boolean LOG_EVERYTHING = false; // true will disclose private info public static final boolean DEFAULT_USABILITY_STUDY_MODE = false; /* package */ static boolean sIsLogging = false; @@ -796,7 +796,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private static final LogStatement LOGSTATEMENT_LATIN_IME_ON_START_INPUT_VIEW_INTERNAL = new LogStatement("LatinImeOnStartInputViewInternal", false, false, "uuid", "packageName", "inputType", "imeOptions", "fieldId", "display", "model", - "prefs", "versionCode", "versionName", "outputFormatVersion", "logEverything"); + "prefs", "versionCode", "versionName", "outputFormatVersion", "logEverything", + "isExperimentalDebug"); public static void latinIME_onStartInputViewInternal(final EditorInfo editorInfo, final SharedPreferences prefs) { final ResearchLogger researchLogger = getInstance(); @@ -817,7 +818,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang Integer.toHexString(editorInfo.inputType), Integer.toHexString(editorInfo.imeOptions), editorInfo.fieldId, Build.DISPLAY, Build.MODEL, prefs, versionCode, versionName, - OUTPUT_FORMAT_VERSION, LOG_EVERYTHING); + OUTPUT_FORMAT_VERSION, LOG_EVERYTHING, + ProductionFlag.IS_EXPERIMENTAL_DEBUG); } catch (NameNotFoundException e) { e.printStackTrace(); } diff --git a/java/src/com/android/inputmethod/research/Statistics.java b/java/src/com/android/inputmethod/research/Statistics.java index 90d7f38b3..23d1050cb 100644 --- a/java/src/com/android/inputmethod/research/Statistics.java +++ b/java/src/com/android/inputmethod/research/Statistics.java @@ -19,10 +19,11 @@ package com.android.inputmethod.research; import android.util.Log; import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.define.ProductionFlag; public class Statistics { private static final String TAG = Statistics.class.getSimpleName(); - private static final boolean DEBUG = false; + private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; // Number of characters entered during a typing session int mCharCount;