Merge "Optimization: Start making use of ProductionFlag.IS_EXPERIMENTAL for ResearchLogger"
This commit is contained in:
commit
b79064cbeb
6 changed files with 32 additions and 182 deletions
|
@ -52,6 +52,7 @@ import com.android.inputmethod.latin.StringUtils;
|
|||
import com.android.inputmethod.latin.SubtypeUtils;
|
||||
import com.android.inputmethod.latin.Utils;
|
||||
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.WeakHashMap;
|
||||
|
@ -694,15 +695,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
|||
+ size + "," + pressure);
|
||||
}
|
||||
}
|
||||
if (ResearchLogger.sIsLogging) {
|
||||
// TODO: remove redundant calculations of size and pressure by
|
||||
// removing UsabilityStudyLog code once the ResearchLogger is mature enough
|
||||
final float size = me.getSize(index);
|
||||
final float pressure = me.getPressure(index);
|
||||
if (action != MotionEvent.ACTION_MOVE) {
|
||||
// Skip ACTION_MOVE events as they are logged below
|
||||
ResearchLogger.getInstance().logMotionEvent(action, eventTime, id, x,
|
||||
y, size, pressure);
|
||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||
if (ResearchLogger.sIsLogging) {
|
||||
// TODO: remove redundant calculations of size and pressure by
|
||||
// removing UsabilityStudyLog code once the ResearchLogger is mature enough
|
||||
final float size = me.getSize(index);
|
||||
final float pressure = me.getPressure(index);
|
||||
if (action != MotionEvent.ACTION_MOVE) {
|
||||
// Skip ACTION_MOVE events as they are logged below
|
||||
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 + ","
|
||||
+ pointerSize + "," + pointerPressure);
|
||||
}
|
||||
if (ResearchLogger.sIsLogging) {
|
||||
// TODO: earlier comment about redundant calculations applies here too
|
||||
final float pointerSize = me.getSize(i);
|
||||
final float pointerPressure = me.getPressure(i);
|
||||
ResearchLogger.getInstance().logMotionEvent(action, eventTime, pointerId,
|
||||
px, py, pointerSize, pointerPressure);
|
||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||
if (ResearchLogger.sIsLogging) {
|
||||
// TODO: earlier comment about redundant calculations applies here too
|
||||
final float pointerSize = me.getSize(i);
|
||||
final float pointerPressure = me.getPressure(i);
|
||||
ResearchLogger.getInstance().logMotionEvent(action, eventTime, pointerId,
|
||||
px, py, pointerSize, pointerPressure);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -69,6 +69,7 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
|||
import com.android.inputmethod.keyboard.KeyboardView;
|
||||
import com.android.inputmethod.keyboard.LatinKeyboardView;
|
||||
import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils;
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
import com.android.inputmethod.latin.suggestions.SuggestionsView;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
|
@ -439,7 +440,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mPrefs = prefs;
|
||||
LatinImeLogger.init(this, prefs);
|
||||
ResearchLogger.init(this, prefs);
|
||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||
ResearchLogger.init(this, prefs);
|
||||
}
|
||||
LanguageSwitcherProxy.init(this, prefs);
|
||||
InputMethodManagerCompatWrapper.init(this);
|
||||
SubtypeSwitcher.init(this);
|
||||
|
@ -1264,8 +1267,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
}
|
||||
mLastKeyTime = when;
|
||||
|
||||
if (ResearchLogger.sIsLogging) {
|
||||
ResearchLogger.getInstance().logKeyEvent(primaryCode, x, y);
|
||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||
if (ResearchLogger.sIsLogging) {
|
||||
ResearchLogger.getInstance().logKeyEvent(primaryCode, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
final KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||
|
|
|
@ -80,8 +80,4 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
|
|||
|
||||
public static void onPrintAllUsabilityStudyLogs() {
|
||||
}
|
||||
|
||||
public static boolean isResearcherPackage(Context context) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ import java.util.Date;
|
|||
* 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.
|
||||
*
|
||||
* This functionality is off by default.
|
||||
* This functionality is off by default. See {@link ProductionFlag.IS_EXPERIMENTAL}.
|
||||
*/
|
||||
public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String TAG = ResearchLogger.class.getSimpleName();
|
||||
|
|
|
@ -46,6 +46,7 @@ import com.android.inputmethod.compat.CompatUtils;
|
|||
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
|
||||
import com.android.inputmethod.compat.VibratorCompatWrapper;
|
||||
import com.android.inputmethod.deprecated.VoiceProxy;
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
import com.android.inputmethodcommon.InputMethodSettingsActivity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -238,17 +239,16 @@ public class Settings extends InputMethodSettingsActivity
|
|||
textCorrectionGroup.removePreference(dictionaryLink);
|
||||
}
|
||||
|
||||
final boolean isResearcherPackage = LatinImeLogger.isResearcherPackage(this);
|
||||
final boolean showUsabilityStudyModeOption =
|
||||
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);
|
||||
if (!showUsabilityStudyModeOption) {
|
||||
if (usabilityStudyPref != null) {
|
||||
miscSettings.removePreference(usabilityStudyPref);
|
||||
}
|
||||
}
|
||||
if (isResearcherPackage) {
|
||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||
if (usabilityStudyPref instanceof CheckBoxPreference) {
|
||||
CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref;
|
||||
checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE, true));
|
||||
|
|
|
@ -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.
|
||||
}
|
Loading…
Reference in a new issue