Optimization: Start making use of ProductionFlag.IS_EXPERIMENTAL for ResearchLogger

Move GodMode specific tests to relevant directories as well.

This goes along with I9dc4d469

Change-Id: I4a21c53846b26eede346cb1da13e6abbdf9ec27f
main
Ken Wakasa 2012-03-26 22:10:21 +09:00
parent 82e43549e4
commit c166697e3f
6 changed files with 32 additions and 182 deletions

View File

@ -52,6 +52,7 @@ import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeUtils; import com.android.inputmethod.latin.SubtypeUtils;
import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
import com.android.inputmethod.latin.define.ProductionFlag;
import java.util.Locale; import java.util.Locale;
import java.util.WeakHashMap; import java.util.WeakHashMap;
@ -694,15 +695,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
+ size + "," + pressure); + size + "," + pressure);
} }
} }
if (ResearchLogger.sIsLogging) { if (ProductionFlag.IS_EXPERIMENTAL) {
// TODO: remove redundant calculations of size and pressure by if (ResearchLogger.sIsLogging) {
// removing UsabilityStudyLog code once the ResearchLogger is mature enough // TODO: remove redundant calculations of size and pressure by
final float size = me.getSize(index); // removing UsabilityStudyLog code once the ResearchLogger is mature enough
final float pressure = me.getPressure(index); final float size = me.getSize(index);
if (action != MotionEvent.ACTION_MOVE) { final float pressure = me.getPressure(index);
// Skip ACTION_MOVE events as they are logged below if (action != MotionEvent.ACTION_MOVE) {
ResearchLogger.getInstance().logMotionEvent(action, eventTime, id, x, // Skip ACTION_MOVE events as they are logged below
y, size, pressure); ResearchLogger.getInstance().logMotionEvent(action, eventTime, id, x, y,
size, pressure);
}
} }
} }
@ -770,12 +773,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
+ pointerId + "," + px + "," + py + "," + pointerId + "," + px + "," + py + ","
+ pointerSize + "," + pointerPressure); + pointerSize + "," + pointerPressure);
} }
if (ResearchLogger.sIsLogging) { if (ProductionFlag.IS_EXPERIMENTAL) {
// TODO: earlier comment about redundant calculations applies here too if (ResearchLogger.sIsLogging) {
final float pointerSize = me.getSize(i); // TODO: earlier comment about redundant calculations applies here too
final float pointerPressure = me.getPressure(i); final float pointerSize = me.getSize(i);
ResearchLogger.getInstance().logMotionEvent(action, eventTime, pointerId, final float pointerPressure = me.getPressure(i);
px, py, pointerSize, pointerPressure); ResearchLogger.getInstance().logMotionEvent(action, eventTime, pointerId,
px, py, pointerSize, pointerPressure);
}
} }
} }
} else { } else {

View File

@ -69,6 +69,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.suggestions.SuggestionsView; import com.android.inputmethod.latin.suggestions.SuggestionsView;
import java.io.FileDescriptor; import java.io.FileDescriptor;
@ -439,7 +440,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mPrefs = prefs; mPrefs = prefs;
LatinImeLogger.init(this, prefs); LatinImeLogger.init(this, prefs);
ResearchLogger.init(this, prefs); if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.init(this, prefs);
}
LanguageSwitcherProxy.init(this, prefs); LanguageSwitcherProxy.init(this, prefs);
InputMethodManagerCompatWrapper.init(this); InputMethodManagerCompatWrapper.init(this);
SubtypeSwitcher.init(this); SubtypeSwitcher.init(this);
@ -1264,8 +1267,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
mLastKeyTime = when; mLastKeyTime = when;
if (ResearchLogger.sIsLogging) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().logKeyEvent(primaryCode, x, y); if (ResearchLogger.sIsLogging) {
ResearchLogger.getInstance().logKeyEvent(primaryCode, x, y);
}
} }
final KeyboardSwitcher switcher = mKeyboardSwitcher; final KeyboardSwitcher switcher = mKeyboardSwitcher;

View File

@ -80,8 +80,4 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
public static void onPrintAllUsabilityStudyLogs() { public static void onPrintAllUsabilityStudyLogs() {
} }
public static boolean isResearcherPackage(Context context) {
return false;
}
} }

View File

@ -41,7 +41,7 @@ import java.util.Date;
* This class logs operations on the IME keyboard, including what the user has typed. * This class logs operations on the IME keyboard, including what the user has typed.
* Data is stored locally in a file in app-specific storage. * Data is stored locally in a file in app-specific storage.
* *
* This functionality is off by default. * This functionality is off by default. See {@link ProductionFlag.IS_EXPERIMENTAL}.
*/ */
public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChangeListener { public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = ResearchLogger.class.getSimpleName(); private static final String TAG = ResearchLogger.class.getSimpleName();

View File

@ -46,6 +46,7 @@ import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethodcommon.InputMethodSettingsActivity; import com.android.inputmethodcommon.InputMethodSettingsActivity;
import java.util.Locale; import java.util.Locale;
@ -238,17 +239,16 @@ public class Settings extends InputMethodSettingsActivity
textCorrectionGroup.removePreference(dictionaryLink); textCorrectionGroup.removePreference(dictionaryLink);
} }
final boolean isResearcherPackage = LatinImeLogger.isResearcherPackage(this);
final boolean showUsabilityStudyModeOption = final boolean showUsabilityStudyModeOption =
res.getBoolean(R.bool.config_enable_usability_study_mode_option) res.getBoolean(R.bool.config_enable_usability_study_mode_option)
|| isResearcherPackage || ENABLE_EXPERIMENTAL_SETTINGS; || ProductionFlag.IS_EXPERIMENTAL || ENABLE_EXPERIMENTAL_SETTINGS;
final Preference usabilityStudyPref = findPreference(PREF_USABILITY_STUDY_MODE); final Preference usabilityStudyPref = findPreference(PREF_USABILITY_STUDY_MODE);
if (!showUsabilityStudyModeOption) { if (!showUsabilityStudyModeOption) {
if (usabilityStudyPref != null) { if (usabilityStudyPref != null) {
miscSettings.removePreference(usabilityStudyPref); miscSettings.removePreference(usabilityStudyPref);
} }
} }
if (isResearcherPackage) { if (ProductionFlag.IS_EXPERIMENTAL) {
if (usabilityStudyPref instanceof CheckBoxPreference) { if (usabilityStudyPref instanceof CheckBoxPreference) {
CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref; CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref;
checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE, true)); checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE, true));

View File

@ -1,156 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.latin;
import android.inputmethodservice.InputMethodService;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import com.android.inputmethod.latin.ResearchLogger.LogFileManager;
import java.io.FileNotFoundException;
public class ResearchLoggerTests extends InputTestsBase {
private static final String TAG = ResearchLoggerTests.class.getSimpleName();
private static final int TEST_INT = 0x12345678;
private static final long TEST_LONG = 0x1234567812345678L;
private static ResearchLogger sLogger;
private MockLogFileManager mMockLogFileManager;
@Override
protected void setUp() {
super.setUp();
sLogger = ResearchLogger.getInstance();
mMockLogFileManager = new MockLogFileManager();
sLogger.setLogFileManager(mMockLogFileManager);
ResearchLogger.sIsLogging = true;
}
public static class MockLogFileManager extends LogFileManager {
private final StringBuilder mContents = new StringBuilder();
@Override
public void init(InputMethodService ims) {
}
@Override
public synchronized void createLogFile() {
mContents.setLength(0);
}
@Override
public synchronized void createLogFile(String dir, String filename)
throws FileNotFoundException {
mContents.setLength(0);
}
@Override
public synchronized boolean append(String s) {
mContents.append(s);
return true;
}
@Override
public synchronized void reset() {
mContents.setLength(0);
}
@Override
public synchronized void close() {
mContents.setLength(0);
}
private String getAppendedString() {
return mContents.toString();
}
}
private void waitOnResearchLogger() {
// post another Runnable that notify()'s the test that it may proceed.
// assumes that the MessageQueue is processed in-order
Handler handler = sLogger.mLoggingHandler;
handler.post(new Runnable() {
@Override
public void run() {
synchronized (ResearchLoggerTests.this) {
ResearchLoggerTests.this.notify();
}
}
});
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
Log.i(TAG, "interrupted when waiting for handler to finish.", e);
}
}
}
/*********************** Tests *********************/
public void testLogStartsEmpty() {
waitOnResearchLogger();
String result = mMockLogFileManager.getAppendedString();
assertEquals(result, "");
}
public void testMotionEvent() {
// verify that input values appear somewhere in output
sLogger.logMotionEvent(MotionEvent.ACTION_CANCEL,
TEST_LONG, TEST_INT, 1111, 3333, 5555, 7777);
waitOnResearchLogger();
String output = mMockLogFileManager.getAppendedString();
assertTrue(output.matches("(?sui).*\\bcancel\\b.*"));
assertFalse(output.matches("(?sui).*\\bdown\\b.*"));
assertTrue(output.matches("(?s).*\\b" + TEST_LONG + "\\b.*"));
assertTrue(output.matches("(?s).*\\b" + TEST_INT + "\\b.*"));
assertTrue(output.matches("(?s).*\\b1111\\b.*"));
assertTrue(output.matches("(?s).*\\b3333\\b.*"));
assertTrue(output.matches("(?s).*\\b5555\\b.*"));
assertTrue(output.matches("(?s).*\\b7777\\b.*"));
}
public void testKeyEvent() {
type("abc");
waitOnResearchLogger();
String output = mMockLogFileManager.getAppendedString();
assertTrue(output.matches("(?s).*\\ba\\b.*"));
assertTrue(output.matches("(?s).*\\bb\\b.*"));
assertTrue(output.matches("(?s).*\\bc\\b.*"));
}
public void testCorrection() {
sLogger.logCorrection("aaaa", "thos", "this", 1);
waitOnResearchLogger();
String output = mMockLogFileManager.getAppendedString();
assertTrue(output.matches("(?sui).*\\baaaa\\b.*"));
assertTrue(output.matches("(?sui).*\\bthos\\b.*"));
assertTrue(output.matches("(?sui).*\\bthis\\b.*"));
}
public void testStateChange() {
sLogger.logStateChange("aaaa", "bbbb");
waitOnResearchLogger();
String output = mMockLogFileManager.getAppendedString();
assertTrue(output.matches("(?sui).*\\baaaa\\b.*"));
assertTrue(output.matches("(?sui).*\\bbbbb\\b.*"));
}
// TODO: add integration tests that start at point of event generation.
}