record full text after finishing session

uses onWindowHidden() callback as proxy for finishing session.

Bug: 6188932
Change-Id: Ic63b47c946ca91fc35f80d71b2f9e24e2d0339ac
This commit is contained in:
Kurt Partridge 2012-05-01 22:09:53 -07:00
parent b21d167045
commit d67a248de4
2 changed files with 60 additions and 4 deletions

View file

@ -702,6 +702,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void onWindowHidden() { public void onWindowHidden() {
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_onWindowHidden(mLastSelectionStart, mLastSelectionEnd,
getCurrentInputConnection());
}
super.onWindowHidden(); super.onWindowHidden();
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) inputView.closing(); if (inputView != null) inputView.closing();
@ -732,7 +736,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
int composingSpanStart, int composingSpanEnd) { int composingSpanStart, int composingSpanEnd) {
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
composingSpanStart, composingSpanEnd); composingSpanStart, composingSpanEnd);
if (DEBUG) { if (DEBUG) {
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart
+ ", ose=" + oldSelEnd + ", ose=" + oldSelEnd
@ -744,9 +747,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
+ ", ce=" + composingSpanEnd); + ", ce=" + composingSpanEnd);
} }
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
final boolean expectingUpdateSelectionFromLogger =
ResearchLogger.getAndClearLatinIMEExpectingUpdateSelection();
ResearchLogger.latinIME_onUpdateSelection(mLastSelectionStart, mLastSelectionEnd, ResearchLogger.latinIME_onUpdateSelection(mLastSelectionStart, mLastSelectionEnd,
oldSelStart, oldSelEnd, newSelStart, newSelEnd, composingSpanStart, oldSelStart, oldSelEnd, newSelStart, newSelEnd, composingSpanStart,
composingSpanEnd); composingSpanEnd, mExpectingUpdateSelection,
expectingUpdateSelectionFromLogger);
if (expectingUpdateSelectionFromLogger) {
return;
}
} }
// TODO: refactor the following code to be less contrived. // TODO: refactor the following code to be less contrived.

View file

@ -29,6 +29,7 @@ import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.KeyDetector;
@ -62,10 +63,15 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final ResearchLogger sInstance = new ResearchLogger(new LogFileManager()); private static final ResearchLogger sInstance = new ResearchLogger(new LogFileManager());
private static final int MAX_INPUTVIEW_LENGTH_TO_CAPTURE = 8192; // must be >=1
public static boolean sIsLogging = false; public static boolean sIsLogging = false;
/* package */ final Handler mLoggingHandler; /* package */ final Handler mLoggingHandler;
private InputMethodService mIms; private InputMethodService mIms;
// set when LatinIME should ignore a onUpdateSelection() callback that
// arises from operations in this class
private static boolean mLatinIMEExpectingUpdateSelection = false;
/** /**
* Isolates management of files. This variable should never be null, but can be changed * Isolates management of files. This variable should never be null, but can be changed
* to support testing. * to support testing.
@ -336,6 +342,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private static final boolean LATINIME_DELETESURROUNDINGTEXT_ENABLED = DEFAULT_ENABLED; private static final boolean LATINIME_DELETESURROUNDINGTEXT_ENABLED = DEFAULT_ENABLED;
private static final boolean LATINIME_DOUBLESPACEAUTOPERIOD_ENABLED = DEFAULT_ENABLED; private static final boolean LATINIME_DOUBLESPACEAUTOPERIOD_ENABLED = DEFAULT_ENABLED;
private static final boolean LATINIME_ONDISPLAYCOMPLETIONS_ENABLED = DEFAULT_ENABLED; private static final boolean LATINIME_ONDISPLAYCOMPLETIONS_ENABLED = DEFAULT_ENABLED;
private static final boolean LATINIME_ONWINDOWHIDDEN_ENABLED = DEFAULT_ENABLED;
private static final boolean LATINIME_ONSTARTINPUTVIEWINTERNAL_ENABLED = DEFAULT_ENABLED; private static final boolean LATINIME_ONSTARTINPUTVIEWINTERNAL_ENABLED = DEFAULT_ENABLED;
private static final boolean LATINIME_ONUPDATESELECTION_ENABLED = DEFAULT_ENABLED; private static final boolean LATINIME_ONUPDATESELECTION_ENABLED = DEFAULT_ENABLED;
private static final boolean LATINIME_PERFORMEDITORACTION_ENABLED = DEFAULT_ENABLED; private static final boolean LATINIME_PERFORMEDITORACTION_ENABLED = DEFAULT_ENABLED;
@ -528,6 +535,43 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
} }
/* package */ static boolean getAndClearLatinIMEExpectingUpdateSelection() {
boolean returnValue = mLatinIMEExpectingUpdateSelection;
mLatinIMEExpectingUpdateSelection = false;
return returnValue;
}
public static void latinIME_onWindowHidden(final int savedSelectionStart,
final int savedSelectionEnd, final InputConnection ic) {
if (UnsLogGroup.LATINIME_ONWINDOWHIDDEN_ENABLED) {
if (ic != null) {
ic.beginBatchEdit();
ic.performContextMenuAction(android.R.id.selectAll);
CharSequence charSequence = ic.getSelectedText(0);
ic.setSelection(savedSelectionStart, savedSelectionEnd);
ic.endBatchEdit();
mLatinIMEExpectingUpdateSelection = true;
if (TextUtils.isEmpty(charSequence)) {
logUnstructured("LatinIME_onWindowHidden", "<no text>");
} else {
if (charSequence.length() > MAX_INPUTVIEW_LENGTH_TO_CAPTURE) {
// do not cut in the middle of a supplementary character
int length = MAX_INPUTVIEW_LENGTH_TO_CAPTURE;
if (!Character.isLetter(charSequence.charAt(length))) {
length--;
}
final CharSequence truncatedCharSequence = charSequence.subSequence(0,
length);
logUnstructured("LatinIME_onWindowHidden", truncatedCharSequence.toString()
+ "<truncated>");
} else {
logUnstructured("LatinIME_onWindowHidden", charSequence.toString());
}
}
}
}
}
public static void latinIME_onStartInputViewInternal(final EditorInfo editorInfo, public static void latinIME_onStartInputViewInternal(final EditorInfo editorInfo,
final SharedPreferences prefs) { final SharedPreferences prefs) {
if (UnsLogGroup.LATINIME_ONSTARTINPUTVIEWINTERNAL_ENABLED) { if (UnsLogGroup.LATINIME_ONSTARTINPUTVIEWINTERNAL_ENABLED) {
@ -551,7 +595,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
public static void latinIME_onUpdateSelection(final int lastSelectionStart, public static void latinIME_onUpdateSelection(final int lastSelectionStart,
final int lastSelectionEnd, final int oldSelStart, final int oldSelEnd, final int lastSelectionEnd, final int oldSelStart, final int oldSelEnd,
final int newSelStart, final int newSelEnd, final int composingSpanStart, final int newSelStart, final int newSelEnd, final int composingSpanStart,
final int composingSpanEnd) { final int composingSpanEnd, final boolean expectingUpdateSelection,
final boolean expectingUpdateSelectionFromLogger) {
if (UnsLogGroup.LATINIME_ONUPDATESELECTION_ENABLED) { if (UnsLogGroup.LATINIME_ONUPDATESELECTION_ENABLED) {
final String s = "onUpdateSelection: oss=" + oldSelStart final String s = "onUpdateSelection: oss=" + oldSelStart
+ ", ose=" + oldSelEnd + ", ose=" + oldSelEnd
@ -560,7 +605,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
+ ", nss=" + newSelStart + ", nss=" + newSelStart
+ ", nse=" + newSelEnd + ", nse=" + newSelEnd
+ ", cs=" + composingSpanStart + ", cs=" + composingSpanStart
+ ", ce=" + composingSpanEnd; + ", ce=" + composingSpanEnd
+ ", eus=" + expectingUpdateSelection
+ ", eusfl=" + expectingUpdateSelectionFromLogger;
logUnstructured("LatinIME_onUpdateSelection", s); logUnstructured("LatinIME_onUpdateSelection", s);
} }
} }