diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
18 files changed, 215 insertions, 132 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index ab2a12fd0..18e712212 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -31,8 +31,6 @@ import java.util.Locale; */ public final class BinaryDictionary extends Dictionary { private static final String TAG = BinaryDictionary.class.getSimpleName(); - public static final String DICTIONARY_PACK_AUTHORITY = - "com.android.inputmethod.latin.dictionarypack"; // Must be equal to MAX_WORD_LENGTH in native/jni/src/defines.h private static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH; @@ -91,7 +89,7 @@ public final class BinaryDictionary extends Dictionary { private static native long openNative(String sourceDir, long dictOffset, long dictSize); private static native void closeNative(long dict); - private static native int getFrequencyNative(long dict, int[] word); + private static native int getProbabilityNative(long dict, int[] word); private static native boolean isValidBigramNative(long dict, int[] word1, int[] word2); private static native int getSuggestionsNative(long dict, long proximityInfo, long traverseSession, int[] xCoordinates, int[] yCoordinates, int[] times, @@ -186,7 +184,7 @@ public final class BinaryDictionary extends Dictionary { public int getFrequency(final String word) { if (word == null) return -1; int[] codePoints = StringUtils.toCodePointArray(word); - return getFrequencyNative(mNativeDict, codePoints); + return getProbabilityNative(mNativeDict, codePoints); } // TODO: Add a batch process version (isValidBigramMultiple?) to avoid excessive numbers of jni diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java index 0d0ce5756..4bec99c04 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryFileDumper.java @@ -27,6 +27,7 @@ import android.os.RemoteException; import android.text.TextUtils; import android.util.Log; +import com.android.inputmethod.dictionarypack.DictionaryPackConstants; import com.android.inputmethod.latin.DictionaryInfoUtils.DictionaryInfo; import java.io.BufferedInputStream; @@ -93,8 +94,7 @@ public final class BinaryDictionaryFileDumper { */ private static Uri.Builder getProviderUriBuilder(final String path) { return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) - .authority(BinaryDictionary.DICTIONARY_PACK_AUTHORITY).appendPath( - path); + .authority(DictionaryPackConstants.AUTHORITY).appendPath(path); } /** diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index e913f2852..294312843 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -22,6 +22,7 @@ import com.android.inputmethod.latin.makedict.FormatSpec; import android.content.Context; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetFileDescriptor; import android.util.Log; @@ -95,18 +96,8 @@ final class BinaryDictionaryGetter { private static final class DictPackSettings { final SharedPreferences mDictPreferences; public DictPackSettings(final Context context) { - Context dictPackContext = null; - try { - final String dictPackName = - context.getString(R.string.dictionary_pack_package_name); - dictPackContext = context.createPackageContext(dictPackName, 0); - } catch (NameNotFoundException e) { - // The dictionary pack is not installed... - // TODO: fallback on the built-in dict, see the TODO above - Log.e(TAG, "Could not find a dictionary pack"); - } - mDictPreferences = null == dictPackContext ? null - : dictPackContext.getSharedPreferences(COMMON_PREFERENCES_NAME, + mDictPreferences = null == context ? null + : context.getSharedPreferences(COMMON_PREFERENCES_NAME, Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS); } public boolean isWordListActive(final String dictId) { @@ -288,10 +279,16 @@ final class BinaryDictionaryGetter { // cacheWordListsFromContentProvider returns the list of files it copied to local // storage, but we don't really care about what was copied NOW: what we want is the // list of everything we ever cached, so we ignore the return value. - // TODO: The experimental version is not supported by the Dictionary Pack Service yet - if (!ProductionFlag.IS_EXPERIMENTAL) { - BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context, - hasDefaultWordList); + // TODO: The development-only-diagnostic version is not supported by the Dictionary Pack + // Service yet + if (!ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { + // We need internet access to do the following. Only do this if the package actually + // has the permission. + if (context.checkCallingOrSelfPermission(android.Manifest.permission.INTERNET) + == PackageManager.PERMISSION_GRANTED) { + BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context, + hasDefaultWordList); + } } final File[] cachedWordLists = getCachedWordLists(locale.toString(), context); final String mainDictId = DictionaryInfoUtils.getMainDictId(locale); diff --git a/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java b/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java index 2a501a665..e1b5a802e 100644 --- a/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java +++ b/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java @@ -21,15 +21,18 @@ import android.os.Bundle; import android.preference.PreferenceActivity; public final class DebugSettingsActivity extends PreferenceActivity { + private static final String DEFAULT_FRAGMENT = DebugSettings.class.getName(); + @Override public Intent getIntent() { - final Intent modIntent = new Intent(super.getIntent()); - modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DebugSettings.class.getName()); - return modIntent; + final Intent intent = super.getIntent(); + intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT); + intent.putExtra(EXTRA_NO_HEADERS, true); + return intent; } @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.english_ime_debug_settings); } diff --git a/java/src/com/android/inputmethod/latin/DictionaryPackInstallBroadcastReceiver.java b/java/src/com/android/inputmethod/latin/DictionaryPackInstallBroadcastReceiver.java index a8513ff45..35f3119ea 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryPackInstallBroadcastReceiver.java +++ b/java/src/com/android/inputmethod/latin/DictionaryPackInstallBroadcastReceiver.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.dictionarypack.DictionaryPackConstants; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -30,11 +32,6 @@ import android.net.Uri; public final class DictionaryPackInstallBroadcastReceiver extends BroadcastReceiver { final LatinIME mService; - /** - * The action of the intent for publishing that new dictionary data is available. - */ - /* package */ static final String NEW_DICTIONARY_INTENT_ACTION = - "com.android.inputmethod.latin.dictionarypack.newdict"; public DictionaryPackInstallBroadcastReceiver(final LatinIME service) { mService = service; @@ -64,7 +61,7 @@ public final class DictionaryPackInstallBroadcastReceiver extends BroadcastRecei // Search for some dictionary pack in the just-installed package. If found, reread. for (ProviderInfo info : providers) { - if (BinaryDictionary.DICTIONARY_PACK_AUTHORITY.equals(info.authority)) { + if (DictionaryPackConstants.AUTHORITY.equals(info.authority)) { mService.resetSuggestMainDict(); return; } @@ -84,7 +81,7 @@ public final class DictionaryPackInstallBroadcastReceiver extends BroadcastRecei // TODO: Only reload dictionary on REMOVED when the removed package is the one we // read dictionary from? mService.resetSuggestMainDict(); - } else if (action.equals(NEW_DICTIONARY_INTENT_ACTION)) { + } else if (action.equals(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)) { mService.resetSuggestMainDict(); } } diff --git a/java/src/com/android/inputmethod/latin/FeedbackUtils.java b/java/src/com/android/inputmethod/latin/FeedbackUtils.java new file mode 100644 index 000000000..1e5260e34 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/FeedbackUtils.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013 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.content.Context; + +public class FeedbackUtils { + public static boolean isFeedbackFormSupported() { + return false; + } + + public static void showFeedbackForm(Context context) { + } +} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 252fb02c8..e3650d9cc 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -64,6 +64,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.compat.SuggestionSpanUtils; +import com.android.inputmethod.dictionarypack.DictionaryPackConstants; import com.android.inputmethod.event.EventInterpreter; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; @@ -173,9 +174,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private int mDisplayOrientation; // Object for reacting to adding/removing a dictionary pack. - // TODO: The experimental version is not supported by the Dictionary Pack Service yet. + // TODO: The development-only-diagnostic version is not supported by the Dictionary Pack + // Service yet. private BroadcastReceiver mDictionaryPackInstallReceiver = - ProductionFlag.IS_EXPERIMENTAL + ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS ? null : new DictionaryPackInstallBroadcastReceiver(this); // Keeps track of most recently inserted text (multi-character key) for reverting @@ -427,7 +429,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction loadSettings(); initSuggest(); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().init(this, mKeyboardSwitcher, mSuggest); } mDisplayOrientation = getResources().getConfiguration().orientation; @@ -439,8 +441,9 @@ public final class LatinIME extends InputMethodService implements KeyboardAction filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); registerReceiver(mReceiver, filter); - // TODO: The experimental version is not supported by the Dictionary Pack Service yet. - if (!ProductionFlag.IS_EXPERIMENTAL) { + // TODO: The development-only-diagnostic version is not supported by the Dictionary Pack + // Service yet. + if (!ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { final IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); @@ -448,8 +451,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction registerReceiver(mDictionaryPackInstallReceiver, packageFilter); final IntentFilter newDictFilter = new IntentFilter(); - newDictFilter.addAction( - DictionaryPackInstallBroadcastReceiver.NEW_DICTIONARY_INTENT_ACTION); + newDictFilter.addAction(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION); registerReceiver(mDictionaryPackInstallReceiver, newDictFilter); } } @@ -492,7 +494,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().initSuggest(mSuggest); } @@ -563,11 +565,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } mSettings.onDestroy(); unregisterReceiver(mReceiver); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().onDestroy(); } - // TODO: The experimental version is not supported by the Dictionary Pack Service yet. - if (!ProductionFlag.IS_EXPERIMENTAL) { + // TODO: The development-only-diagnostic version is not supported by the Dictionary Pack + // Service yet. + if (!ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { unregisterReceiver(mDictionaryPackInstallReceiver); } LatinImeLogger.commit(); @@ -675,7 +678,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction + ", word caps = " + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS) != 0)); } - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, prefs); } @@ -800,7 +803,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public void onWindowHidden() { - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onWindowHidden(mLastSelectionStart, mLastSelectionEnd, getCurrentInputConnection()); } @@ -831,7 +834,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Remove pending messages related to update suggestions mHandler.cancelUpdateSuggestionStrip(); resetComposingState(true /* alsoResetLastComposedWord */); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().latinIME_onFinishInputViewInternal(); } } @@ -852,7 +855,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction + ", cs=" + composingSpanStart + ", ce=" + composingSpanEnd); } - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { final boolean expectingUpdateSelectionFromLogger = ResearchLogger.getAndClearLatinIMEExpectingUpdateSelection(); ResearchLogger.latinIME_onUpdateSelection(mLastSelectionStart, mLastSelectionEnd, @@ -984,7 +987,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mApplicationSpecifiedCompletions = applicationSpecifiedCompletions; if (applicationSpecifiedCompletions == null) { clearSuggestionStrip(); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onDisplayCompletions(null); } return; @@ -1005,7 +1008,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction setSuggestedWords(suggestedWords, isAutoCorrection); setAutoCorrectionIndicator(isAutoCorrection); setSuggestionStripShown(true); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions); } } @@ -1144,7 +1147,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (typedWord.length() > 0) { commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, separatorString); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().onWordFinished(typedWord, mWordComposer.isBatchMode()); } } @@ -1184,7 +1187,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mConnection.deleteSurroundingText(2, 0); final String text = lastTwo.charAt(1) + " "; mConnection.commitText(text, 1); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_swapSwapperAndSpace(lastTwo, text); } mKeyboardSwitcher.updateShiftState(); @@ -1204,7 +1207,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mConnection.deleteSurroundingText(2, 0); final String textToInsert = ". "; mConnection.commitText(textToInsert, 1); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert, false /* isBatchMode */); } @@ -1319,7 +1322,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } private void sendKeyCodePoint(final int code) { - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_sendKeyCodePoint(code); } // TODO: Remove this special handling of digit letters. @@ -1345,7 +1348,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Implementation of {@link KeyboardActionListener}. @Override public void onCodeInput(final int primaryCode, final int x, final int y) { - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onCodeInput(primaryCode, x, y); } final long when = SystemClock.uptimeMillis(); @@ -1397,7 +1400,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction handleLanguageSwitchKey(); break; case Constants.CODE_RESEARCH: - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().onResearchKeySelected(this); } break; @@ -1451,7 +1454,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } else { didAutoCorrect = false; if (SPACE_STATE_PHANTOM == spaceState) { - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { if (mWordComposer.isComposingWord() && mWordComposer.isBatchMode()) { Stats.onAutoCorrection( "", mWordComposer.getTypedWord(), " ", mWordComposer); @@ -1489,7 +1492,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction promotePhantomSpace(); } mConnection.commitText(text, 1); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */); } mConnection.endBatchEdit(); @@ -1506,7 +1509,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mHandler.cancelUpdateSuggestionStrip(); mConnection.beginBatchEdit(); if (mWordComposer.isComposingWord()) { - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { if (mWordComposer.isBatchMode()) { Stats.onAutoCorrection("", mWordComposer.getTypedWord(), " ", mWordComposer); } @@ -1670,7 +1673,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mConnection.setComposingText(batchInputText, 1); mExpectingUpdateSelection = true; mConnection.endBatchEdit(); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_onEndBatchInput(batchInputText, 0, suggestedWords); } // Space state must be updated before calling updateShiftState @@ -1719,7 +1722,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final int length = mWordComposer.size(); if (length > 0) { if (mWordComposer.isBatchMode()) { - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { final String word = mWordComposer.getTypedWord(); ResearchLogger.latinIME_handleBackspace_batch(word, 1); ResearchLogger.getInstance().uncommitCurrentLogUnit( @@ -1736,7 +1739,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } } else { if (mLastComposedWord.canRevertCommit()) { - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { Stats.onAutoCorrectionCancellation(); } revertCommit(); @@ -1780,7 +1783,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // later (typically, in a subsequent press on backspace). mLastSelectionEnd = mLastSelectionStart; mConnection.deleteSurroundingText(numCharsDeleted, 0); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_handleBackspace(numCharsDeleted); } } else { @@ -1799,12 +1802,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction } else { mConnection.deleteSurroundingText(1, 0); } - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_handleBackspace(1); } if (mDeleteCount > DELETE_ACCELERATE_AT) { mConnection.deleteSurroundingText(1, 0); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_handleBackspace(1); } } @@ -1895,7 +1898,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (null != mSuggestionStripView) mSuggestionStripView.dismissAddToDictionaryHint(); } mHandler.postUpdateSuggestionStrip(); - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { Utils.Stats.onNonSeparator((char)primaryCode, x, y); } } @@ -1903,7 +1906,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // Returns true if we did an autocorrection, false otherwise. private boolean handleSeparator(final int primaryCode, final int x, final int y, final int spaceState) { - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.recordTimeForLogUnitSplit(); ResearchLogger.latinIME_handleSeparator(primaryCode, mWordComposer.isComposingWord()); } @@ -1962,7 +1965,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // already displayed or not, so it's okay. setPunctuationSuggestions(); } - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { Utils.Stats.onSeparator((char)primaryCode, x, y); } @@ -2145,10 +2148,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction throw new RuntimeException("We have an auto-correction but the typed word " + "is empty? Impossible! I must commit suicide."); } - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer); } - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { final SuggestedWords suggestedWords = mSuggestedWords; ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer.isBatchMode(), suggestedWords); @@ -2184,7 +2187,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final int primaryCode = suggestion.charAt(0); onCodeInput(primaryCode, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_punctuationSuggestion(index, suggestion, false /* isBatchMode */, suggestedWords.mIsPrediction); } @@ -2225,7 +2228,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion, mWordComposer.isBatchMode()); } @@ -2244,7 +2247,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // If the suggestion is not in the dictionary, the hint should be shown. && !AutoCorrection.isValidWord(mSuggest.getUnigramDictionaries(), suggestion, true); - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { Stats.onSeparator((char)Constants.CODE_SPACE, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); } @@ -2326,7 +2329,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction restartSuggestionsOnWordBeforeCursor(word); // TODO: Handle the case where the user manually moves the cursor and then backs up over // a separator. In that case, the current log unit should not be uncommitted. - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.getInstance().uncommitCurrentLogUnit(word.toString(), true /* dumpCurrentLogUnit */); } @@ -2368,11 +2371,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mUserHistoryDictionary.cancelAddingUserHistory(previousWord, committedWord); } mConnection.commitText(originallyTypedWord + mLastComposedWord.mSeparatorString, 1); - if (ProductionFlag.IS_INTERNAL) { + if (mSettings.isInternal()) { Stats.onSeparator(mLastComposedWord.mSeparatorString, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); } - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord, mWordComposer.isBatchMode(), mLastComposedWord.mSeparatorString); ResearchLogger.getInstance().uncommitCurrentLogUnit(committedWord, @@ -2389,7 +2392,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction public void promotePhantomSpace() { if (mSettings.getCurrent().shouldInsertSpacesAutomatically()) { sendKeyCodePoint(Constants.CODE_SPACE); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.latinIME_promotePhantomSpace(); } } @@ -2502,12 +2505,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction launchSubActivity(SettingsActivity.class); } - // Called from debug code only - public void launchDebugSettings() { - handleClose(); - launchSubActivity(DebugSettingsActivity.class); - } - public void launchKeyboardedDialogActivity(final Class<? extends Activity> activityClass) { // Put the text in the attached EditText into a safe, saved state before switching to a // new activity that will also use the soft keyboard. diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index 7300dbd23..8a7ade49e 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -142,7 +142,7 @@ public final class RichInputConnection { if (null != textBeforeCursor) mCommittedTextBeforeComposingText.append(textBeforeCursor); if (null != mIC) { mIC.finishComposingText(); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_finishComposingText(); } } @@ -164,7 +164,7 @@ public final class RichInputConnection { mComposingText.setLength(0); if (null != mIC) { mIC.finishComposingText(); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_finishComposingText(); } } @@ -263,7 +263,7 @@ public final class RichInputConnection { } if (null != mIC) { mIC.deleteSurroundingText(i, j); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_deleteSurroundingText(i, j); } } @@ -274,7 +274,7 @@ public final class RichInputConnection { mIC = mParent.getCurrentInputConnection(); if (null != mIC) { mIC.performEditorAction(actionId); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_performEditorAction(actionId); } } @@ -322,7 +322,7 @@ public final class RichInputConnection { } if (null != mIC) { mIC.sendKeyEvent(keyEvent); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_sendKeyEvent(keyEvent); } } @@ -355,7 +355,7 @@ public final class RichInputConnection { // TODO: support values of i != 1. At this time, this is never called with i != 1. if (null != mIC) { mIC.setComposingText(text, i); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_setComposingText(text, i); } } @@ -367,7 +367,7 @@ public final class RichInputConnection { if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug(); if (null != mIC) { mIC.setSelection(from, to); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_setSelection(from, to); } } @@ -396,7 +396,7 @@ public final class RichInputConnection { mComposingText.setLength(0); if (null != mIC) { mIC.commitCompletion(completionInfo); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_commitCompletion(completionInfo); } } @@ -657,7 +657,7 @@ public final class RichInputConnection { deleteSurroundingText(2, 0); final String doubleSpace = " "; commitText(doubleSpace, 1); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_revertDoubleSpacePeriod(); } return true; @@ -682,7 +682,7 @@ public final class RichInputConnection { deleteSurroundingText(2, 0); final String text = " " + textBeforeCursor.subSequence(0, 1); commitText(text, 1); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.richInputConnection_revertSwapPunctuation(); } return true; diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 435074bdb..ce659bf45 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -70,12 +70,15 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_INPUT_LANGUAGE = "input_language"; public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; public static final String PREF_DEBUG_SETTINGS = "debug_settings"; + public static final String PREF_KEY_IS_INTERNAL = "pref_key_is_internal"; // This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead. // This is being used only for the backward compatibility. private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = "pref_suppress_language_switch_key"; + public static final String PREF_SEND_FEEDBACK = "send_feedback"; + private Resources mRes; private SharedPreferences mPrefs; private Locale mCurrentLocale; @@ -127,6 +130,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return mSettingsValues; } + public boolean isInternal() { + return mSettingsValues.mIsInternal; + } + // Accessed from the settings interface, hence public public static boolean readKeypressSoundEnabled(final SharedPreferences prefs, final Resources res) { @@ -274,4 +281,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang } return prefs.getBoolean(Settings.PREF_SHOW_SETUP_WIZARD_ICON, false); } + + public static boolean isInternal(final SharedPreferences prefs) { + return prefs.getBoolean(Settings.PREF_KEY_IS_INTERNAL, false); + } } diff --git a/java/src/com/android/inputmethod/latin/SettingsActivity.java b/java/src/com/android/inputmethod/latin/SettingsActivity.java index ed8cf6d8f..99b572e06 100644 --- a/java/src/com/android/inputmethod/latin/SettingsActivity.java +++ b/java/src/com/android/inputmethod/latin/SettingsActivity.java @@ -25,9 +25,7 @@ public final class SettingsActivity extends PreferenceActivity { @Override public Intent getIntent() { final Intent intent = super.getIntent(); - if (!intent.hasExtra(EXTRA_SHOW_FRAGMENT)) { - intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT); - } + intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT); intent.putExtra(EXTRA_NO_HEADERS, true); return intent; } diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java index 4c90e485a..4fdd83911 100644 --- a/java/src/com/android/inputmethod/latin/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin; +import android.app.Activity; import android.app.backup.BackupManager; import android.content.Context; import android.content.Intent; @@ -26,10 +27,12 @@ import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; +import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.view.inputmethod.InputMethodSubtype; +import com.android.inputmethod.dictionarypack.DictionarySettingsActivity; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager; import com.android.inputmethodcommon.InputMethodSettingsFragment; @@ -92,7 +95,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment final Preference debugSettings = findPreference(Settings.PREF_DEBUG_SETTINGS); if (debugSettings != null) { - if (ProductionFlag.IS_INTERNAL) { + if (Settings.isInternal(prefs)) { final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN); debugSettingsIntent.setClassName( context.getPackageName(), DebugSettingsActivity.class.getName()); @@ -102,6 +105,25 @@ public final class SettingsFragment extends InputMethodSettingsFragment } } + final Preference feedbackSettings = findPreference(Settings.PREF_SEND_FEEDBACK); + if (feedbackSettings != null) { + if (FeedbackUtils.isFeedbackFormSupported()) { + feedbackSettings.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference arg0) { + final Activity activity = getActivity(); + FeedbackUtils.showFeedbackForm(activity); + if (!activity.isFinishing()) { + activity.finish(); + } + return true; + } + }); + } else { + miscSettings.removePreference(feedbackSettings); + } + } + final boolean showVoiceKeyOption = res.getBoolean( R.bool.config_enable_show_voice_key_option); if (!showVoiceKeyOption) { @@ -146,9 +168,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment final PreferenceScreen dictionaryLink = (PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); final Intent intent = dictionaryLink.getIntent(); + intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName()); final int number = context.getPackageManager().queryIntentActivities(intent, 0).size(); - // TODO: The experimental version is not supported by the Dictionary Pack Service yet - if (ProductionFlag.IS_EXPERIMENTAL || 0 >= number) { + // TODO: The development-only-diagnostic version is not supported by the Dictionary Pack + // Service yet + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS || 0 >= number) { textCorrectionGroup.removePreference(dictionaryLink); } @@ -156,10 +180,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen()); } - final CheckBoxPreference showSetupWizardIcon = - (CheckBoxPreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON); - showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, context)); - setupKeyLongpressTimeoutSettings(prefs, res); setupKeypressVibrationDurationSettings(prefs, res); setupKeypressSoundVolumeSettings(prefs, res); @@ -175,6 +195,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment } else { getPreferenceScreen().removePreference(mVoicePreference); } + final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); + final CheckBoxPreference showSetupWizardIcon = + (CheckBoxPreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON); + showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, getActivity())); updateShowCorrectionSuggestionsSummary(); updateKeyPreviewPopupDelaySummary(); updateCustomInputStylesSummary(); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d05868029..f77a92885 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -76,6 +76,9 @@ public final class SettingsValues { private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyOnMain; + // Debug settings + public final boolean mIsInternal; + public SettingsValues(final SharedPreferences prefs, final Resources res, final InputAttributes inputAttributes) { // Get the resources @@ -141,6 +144,7 @@ public final class SettingsValues { Settings.PREF_SHOW_SUGGESTIONS_SETTING, res.getString(R.string.prefs_suggestion_visibility_default_value)); mSuggestionVisibility = createSuggestionVisibility(res, showSuggestionsSetting); + mIsInternal = Settings.isInternal(prefs); } public boolean isApplicationSpecifiedCompletionsOn() { diff --git a/java/src/com/android/inputmethod/latin/StaticInnerHandlerWrapper.java b/java/src/com/android/inputmethod/latin/StaticInnerHandlerWrapper.java index 89d9ea844..e50af4d2d 100644 --- a/java/src/com/android/inputmethod/latin/StaticInnerHandlerWrapper.java +++ b/java/src/com/android/inputmethod/latin/StaticInnerHandlerWrapper.java @@ -22,17 +22,17 @@ import android.os.Looper; import java.lang.ref.WeakReference; public class StaticInnerHandlerWrapper<T> extends Handler { - final private WeakReference<T> mOuterInstanceRef; + private final WeakReference<T> mOuterInstanceRef; - public StaticInnerHandlerWrapper(T outerInstance) { - super(); - if (outerInstance == null) throw new NullPointerException("outerInstance is null"); - mOuterInstanceRef = new WeakReference<T>(outerInstance); + public StaticInnerHandlerWrapper(final T outerInstance) { + this(outerInstance, Looper.myLooper()); } - public StaticInnerHandlerWrapper(T outerInstance, Looper looper) { + public StaticInnerHandlerWrapper(final T outerInstance, final Looper looper) { super(looper); - if (outerInstance == null) throw new NullPointerException("outerInstance is null"); + if (outerInstance == null) { + throw new NullPointerException("outerInstance is null"); + } mOuterInstanceRef = new WeakReference<T>(outerInstance); } diff --git a/java/src/com/android/inputmethod/latin/define/ProductionFlag.java b/java/src/com/android/inputmethod/latin/define/ProductionFlag.java index fe9be16c6..699e47b6a 100644 --- a/java/src/com/android/inputmethod/latin/define/ProductionFlag.java +++ b/java/src/com/android/inputmethod/latin/define/ProductionFlag.java @@ -21,13 +21,12 @@ public final class ProductionFlag { // This class is not publicly instantiable. } - public static final boolean IS_EXPERIMENTAL = false; - public static final boolean IS_INTERNAL = false; + public static final boolean USES_DEVELOPMENT_ONLY_DIAGNOSTICS = false; - // When false, IS_EXPERIMENTAL_DEBUG suggests that all guarded class-private DEBUG flags should - // be false, and any privacy controls should be enforced. IS_EXPERIMENTAL_DEBUG should be false - // for any released build. - public static final boolean IS_EXPERIMENTAL_DEBUG = false; + // When false, USES_DEVELOPMENT_ONLY_DIAGNOSTICS_DEBUG suggests that all guarded + // class-private DEBUG flags should be false, and any privacy controls should be enforced. + // USES_DEVELOPMENT_ONLY_DIAGNOSTICS must be false for any production build. + public static final boolean USES_DEVELOPMENT_ONLY_DIAGNOSTICS_DEBUG = false; public static final boolean IS_HARDWARE_KEYBOARD_SUPPORTED = true; } diff --git a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java index e009fbc39..7f66c6d3e 100644 --- a/java/src/com/android/inputmethod/latin/setup/SetupActivity.java +++ b/java/src/com/android/inputmethod/latin/setup/SetupActivity.java @@ -62,6 +62,9 @@ public final class SetupActivity extends Activity { @Override public void handleMessage(final Message msg) { final SetupActivity setupActivity = getOuterInstance(); + if (setupActivity == null) { + return; + } switch (msg.what) { case MSG_POLLING_IME_SETTINGS: if (SetupActivity.isThisImeEnabled(setupActivity)) { diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java index 63f46b79e..9a1114f7f 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin.spellcheck; +import android.os.Binder; import android.text.TextUtils; import android.util.Log; import android.view.textservice.SentenceSuggestionsInfo; @@ -133,22 +134,27 @@ public final class AndroidSpellCheckerSession extends AndroidWordLevelSpellCheck @Override public SuggestionsInfo[] onGetSuggestionsMultiple(TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) { - final int length = textInfos.length; - final SuggestionsInfo[] retval = new SuggestionsInfo[length]; - for (int i = 0; i < length; ++i) { - final String prevWord; - if (sequentialWords && i > 0) { + long ident = Binder.clearCallingIdentity(); + try { + final int length = textInfos.length; + final SuggestionsInfo[] retval = new SuggestionsInfo[length]; + for (int i = 0; i < length; ++i) { + final String prevWord; + if (sequentialWords && i > 0) { final String prevWordCandidate = textInfos[i - 1].getText(); // Note that an empty string would be used to indicate the initial word // in the future. prevWord = TextUtils.isEmpty(prevWordCandidate) ? null : prevWordCandidate; - } else { - prevWord = null; + } else { + prevWord = null; + } + retval[i] = onGetSuggestionsInternal(textInfos[i], prevWord, suggestionsLimit); + retval[i].setCookieAndSequence(textInfos[i].getCookie(), + textInfos[i].getSequence()); } - retval[i] = onGetSuggestions(textInfos[i], prevWord, suggestionsLimit); - retval[i].setCookieAndSequence(textInfos[i].getCookie(), - textInfos[i].getSequence()); + return retval; + } finally { + Binder.restoreCallingIdentity(ident); } - return retval; } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java index cd3f9e442..4f86a3175 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin.spellcheck; import android.content.ContentResolver; import android.database.ContentObserver; +import android.os.Binder; import android.provider.UserDictionary.Words; import android.service.textservice.SpellCheckerService.Session; import android.text.TextUtils; @@ -234,13 +235,12 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { * corrections for the text passed as an argument. It may split or group words, and * even perform grammatical analysis. */ - @Override - public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, + private SuggestionsInfo onGetSuggestionsInternal(final TextInfo textInfo, final int suggestionsLimit) { - return onGetSuggestions(textInfo, null, suggestionsLimit); + return onGetSuggestionsInternal(textInfo, null, suggestionsLimit); } - protected SuggestionsInfo onGetSuggestions( + protected SuggestionsInfo onGetSuggestionsInternal( final TextInfo textInfo, final String prevWord, final int suggestionsLimit) { try { final String inText = textInfo.getText(); @@ -357,4 +357,22 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { } } } + + /* + * The spell checker acts on its own behalf. That is needed, in particular, to be able to + * access the dictionary files, which the provider restricts to the identity of Latin IME. + * Since it's called externally by the application, the spell checker is using the identity + * of the application by default unless we clearCallingIdentity. + * That's what the following method does. + */ + @Override + public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, + final int suggestionsLimit) { + long ident = Binder.clearCallingIdentity(); + try { + return onGetSuggestionsInternal(textInfo, suggestionsLimit); + } finally { + Binder.restoreCallingIdentity(ident); + } + } } diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 5a29eee4e..8c3d3b08c 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -617,7 +617,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick clear(); mSuggestedWords = suggestedWords; mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth()); - if (ProductionFlag.IS_EXPERIMENTAL) { + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords); } } |