record full text after finishing session

uses onWindowHidden() callback as proxy for finishing session.

Bug: 6188932
Change-Id: Ic63b47c946ca91fc35f80d71b2f9e24e2d0339ac
main
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
public void onWindowHidden() {
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_onWindowHidden(mLastSelectionStart, mLastSelectionEnd,
getCurrentInputConnection());
}
super.onWindowHidden();
KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView != null) inputView.closing();
@ -732,7 +736,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
int composingSpanStart, int composingSpanEnd) {
super.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd,
composingSpanStart, composingSpanEnd);
if (DEBUG) {
Log.i(TAG, "onUpdateSelection: oss=" + oldSelStart
+ ", ose=" + oldSelEnd
@ -744,9 +747,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
+ ", ce=" + composingSpanEnd);
}
if (ProductionFlag.IS_EXPERIMENTAL) {
final boolean expectingUpdateSelectionFromLogger =
ResearchLogger.getAndClearLatinIMEExpectingUpdateSelection();
ResearchLogger.latinIME_onUpdateSelection(mLastSelectionStart, mLastSelectionEnd,
oldSelStart, oldSelEnd, newSelStart, newSelEnd, composingSpanStart,
composingSpanEnd);
composingSpanEnd, mExpectingUpdateSelection,
expectingUpdateSelectionFromLogger);
if (expectingUpdateSelectionFromLogger) {
return;
}
}
// 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.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import com.android.inputmethod.keyboard.Key;
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 ResearchLogger sInstance = new ResearchLogger(new LogFileManager());
private static final int MAX_INPUTVIEW_LENGTH_TO_CAPTURE = 8192; // must be >=1
public static boolean sIsLogging = false;
/* package */ final Handler mLoggingHandler;
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
* 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_DOUBLESPACEAUTOPERIOD_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_ONUPDATESELECTION_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,
final SharedPreferences prefs) {
if (UnsLogGroup.LATINIME_ONSTARTINPUTVIEWINTERNAL_ENABLED) {
@ -551,7 +595,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
public static void latinIME_onUpdateSelection(final int lastSelectionStart,
final int lastSelectionEnd, final int oldSelStart, final int oldSelEnd,
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) {
final String s = "onUpdateSelection: oss=" + oldSelStart
+ ", ose=" + oldSelEnd
@ -560,7 +605,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
+ ", nss=" + newSelStart
+ ", nse=" + newSelEnd
+ ", cs=" + composingSpanStart
+ ", ce=" + composingSpanEnd;
+ ", ce=" + composingSpanEnd
+ ", eus=" + expectingUpdateSelection
+ ", eusfl=" + expectingUpdateSelectionFromLogger;
logUnstructured("LatinIME_onUpdateSelection", s);
}
}