Fix an occurrence of nested batch edits.

This is harmless, but against policy.
Also, rework the checking code to be more readable, give more
information, and be called for all relevant methods - and not
for informative methods, which are not required to be in a
batch edit.

Change-Id: I03fa8b2e7d68a6a133f86be8a214671750c29256
This commit is contained in:
Jean Chalard 2012-06-08 23:02:37 +09:00
parent c7564a787e
commit 9d71748ba4
3 changed files with 30 additions and 22 deletions

View file

@ -1804,14 +1804,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void pickSuggestionManually(final int index, final CharSequence suggestion, public void pickSuggestionManually(final int index, final CharSequence suggestion,
int x, int y) { final int x, final int y) {
mConnection.beginBatchEdit(getCurrentInputConnection());
pickSuggestionManuallyWhileInBatchEdit(index, suggestion, x, y);
mConnection.endBatchEdit();
}
public void pickSuggestionManuallyWhileInBatchEdit(final int index,
final CharSequence suggestion, final int x, final int y) {
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput // If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
if (suggestion.length() == 1 && isShowingPunctuationList()) { if (suggestion.length() == 1 && isShowingPunctuationList()) {
@ -1846,7 +1839,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
resetComposingState(true /* alsoResetLastComposedWord */); resetComposingState(true /* alsoResetLastComposedWord */);
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index]; final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
mConnection.beginBatchEdit(getCurrentInputConnection());
mConnection.commitCompletion(completionInfo); mConnection.commitCompletion(completionInfo);
mConnection.endBatchEdit();
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_pickApplicationSpecifiedCompletion(index, ResearchLogger.latinIME_pickApplicationSpecifiedCompletion(index,
completionInfo.getText(), x, y); completionInfo.getText(), x, y);

View file

@ -65,66 +65,70 @@ public class RichInputConnection {
if (--mNestLevel == 0 && null != mIC) mIC.endBatchEdit(); if (--mNestLevel == 0 && null != mIC) mIC.endBatchEdit();
} }
private void checkBatchEdit() {
if (mNestLevel != 1) {
// TODO: exception instead
Log.e(TAG, "Batch edit level incorrect : " + mNestLevel);
Log.e(TAG, Utils.getStackTrace(4));
}
}
public void finishComposingText() { public void finishComposingText() {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.finishComposingText(); if (null != mIC) mIC.finishComposingText();
} }
public void commitText(final CharSequence text, final int i) { public void commitText(final CharSequence text, final int i) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.commitText(text, i); if (null != mIC) mIC.commitText(text, i);
} }
public int getCursorCapsMode(final int inputType) { public int getCursorCapsMode(final int inputType) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF; if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF;
return mIC.getCursorCapsMode(inputType); return mIC.getCursorCapsMode(inputType);
} }
public CharSequence getTextBeforeCursor(final int i, final int j) { public CharSequence getTextBeforeCursor(final int i, final int j) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null != mIC) return mIC.getTextBeforeCursor(i, j); if (null != mIC) return mIC.getTextBeforeCursor(i, j);
return null; return null;
} }
public CharSequence getTextAfterCursor(final int i, final int j) { public CharSequence getTextAfterCursor(final int i, final int j) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null != mIC) return mIC.getTextAfterCursor(i, j); if (null != mIC) return mIC.getTextAfterCursor(i, j);
return null; return null;
} }
public void deleteSurroundingText(final int i, final int j) { public void deleteSurroundingText(final int i, final int j) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.deleteSurroundingText(i, j); if (null != mIC) mIC.deleteSurroundingText(i, j);
} }
public void performEditorAction(final int actionId) { public void performEditorAction(final int actionId) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead
if (null != mIC) mIC.performEditorAction(actionId); if (null != mIC) mIC.performEditorAction(actionId);
} }
public void sendKeyEvent(final KeyEvent keyEvent) { public void sendKeyEvent(final KeyEvent keyEvent) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.sendKeyEvent(keyEvent); if (null != mIC) mIC.sendKeyEvent(keyEvent);
} }
public void setComposingText(final CharSequence text, final int i) { public void setComposingText(final CharSequence text, final int i) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.setComposingText(text, i); if (null != mIC) mIC.setComposingText(text, i);
} }
public void setSelection(final int from, final int to) { public void setSelection(final int from, final int to) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.setSelection(from, to); if (null != mIC) mIC.setSelection(from, to);
} }
public void commitCorrection(final CorrectionInfo correctionInfo) { public void commitCorrection(final CorrectionInfo correctionInfo) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.commitCorrection(correctionInfo); if (null != mIC) mIC.commitCorrection(correctionInfo);
} }
public void commitCompletion(final CompletionInfo completionInfo) { public void commitCompletion(final CompletionInfo completionInfo) {
if (mNestLevel <= 0) Log.e(TAG, "Batch edit not in progress!"); // TODO: exception instead checkBatchEdit();
if (null != mIC) mIC.commitCompletion(completionInfo); if (null != mIC) mIC.commitCompletion(completionInfo);
} }
@ -316,6 +320,7 @@ public class RichInputConnection {
} }
public void removeTrailingSpace() { public void removeTrailingSpace() {
checkBatchEdit();
final CharSequence lastOne = getTextBeforeCursor(1, 0); final CharSequence lastOne = getTextBeforeCursor(1, 0);
if (lastOne != null && lastOne.length() == 1 if (lastOne != null && lastOne.length() == 1
&& lastOne.charAt(0) == Keyboard.CODE_SPACE) { && lastOne.charAt(0) == Keyboard.CODE_SPACE) {
@ -372,6 +377,7 @@ public class RichInputConnection {
} }
public boolean revertDoubleSpace() { public boolean revertDoubleSpace() {
checkBatchEdit();
// Here we test whether we indeed have a period and a space before us. This should not // Here we test whether we indeed have a period and a space before us. This should not
// be needed, but it's there just in case something went wrong. // be needed, but it's there just in case something went wrong.
final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0); final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0);
@ -395,6 +401,7 @@ public class RichInputConnection {
} }
public boolean revertSwapPunctuation() { public boolean revertSwapPunctuation() {
checkBatchEdit();
// Here we test whether we indeed have a space and something else before us. This should not // Here we test whether we indeed have a space and something else before us. This should not
// be needed, but it's there just in case something went wrong. // be needed, but it's there just in case something went wrong.
final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0); final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0);

View file

@ -204,18 +204,24 @@ public class Utils {
} }
// Get the current stack trace // Get the current stack trace
public static String getStackTrace() { public static String getStackTrace(final int limit) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
throw new RuntimeException(); throw new RuntimeException();
} catch (RuntimeException e) { } catch (RuntimeException e) {
StackTraceElement[] frames = e.getStackTrace(); StackTraceElement[] frames = e.getStackTrace();
// Start at 1 because the first frame is here and we don't care about it // Start at 1 because the first frame is here and we don't care about it
for (int j = 1; j < frames.length; ++j) sb.append(frames[j].toString() + "\n"); for (int j = 1; j < frames.length && j < limit + 1; ++j) {
sb.append(frames[j].toString() + "\n");
}
} }
return sb.toString(); return sb.toString();
} }
public static String getStackTrace() {
return getStackTrace(Integer.MAX_VALUE);
}
public static class UsabilityStudyLogUtils { public static class UsabilityStudyLogUtils {
// TODO: remove code duplication with ResearchLog class // TODO: remove code duplication with ResearchLog class
private static final String USABILITY_TAG = UsabilityStudyLogUtils.class.getSimpleName(); private static final String USABILITY_TAG = UsabilityStudyLogUtils.class.getSimpleName();