Merge "Passing SpacingAndPunctuations to CapsModeUtils.getCapsMode"
diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml
index 0d80c03..a7e64bf 100644
--- a/java/AndroidManifest.xml
+++ b/java/AndroidManifest.xml
@@ -34,7 +34,8 @@
     <application android:label="@string/english_ime_name"
             android:icon="@drawable/ic_launcher_keyboard"
             android:killAfterRestore="false"
-            android:supportsRtl="true">
+            android:supportsRtl="true"
+            android:allowBackup="true">
 
         <service android:name="LatinIME"
                 android:label="@string/english_ime_name"
@@ -110,13 +111,14 @@
             </intent-filter>
         </receiver>
 
-        <receiver android:name=".personalization.DictionaryDecayBroadcastReciever">
+        <receiver android:name=".personalization.DictionaryDecayBroadcastReciever"
+            android:exported="false">
             <intent-filter>
                 <action android:name="com.android.inputmethod.latin.personalization.DICT_DECAY" />
             </intent-filter>
         </receiver>
 
-        <receiver android:name=".DictionaryPackInstallBroadcastReceiver">
+        <receiver android:name=".DictionaryPackInstallBroadcastReceiver" android:exported="false">
             <intent-filter>
                 <action android:name="com.android.inputmethod.dictionarypack.aosp.UNKNOWN_CLIENT" />
             </intent-filter>
diff --git a/java/res/layout/research_feedback_fragment_layout.xml b/java/res/layout/research_feedback_fragment_layout.xml
index 505a1e8..fb5c278 100644
--- a/java/res/layout/research_feedback_fragment_layout.xml
+++ b/java/res/layout/research_feedback_fragment_layout.xml
@@ -84,40 +84,32 @@
             android:checked="false"
             android:text="@string/research_feedback_include_recording_label" />
         <LinearLayout
+            style="?android:attr/buttonBarStyle"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:orientation="vertical"
-            android:divider="?android:attr/dividerHorizontal"
-            android:showDividers="beginning"
-            android:dividerPadding="0dip">
-            <LinearLayout
-                style="?android:attr/buttonBarStyle"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal"
-                android:layoutDirection="locale"
-                android:measureWithLargestChild="true">
-                <Button
-                    android:id="@+id/research_feedback_cancel_button"
-                    android:layout_width="wrap_content"
-                    android:layout_gravity="left"
-                    android:layout_weight="1"
-                    android:maxLines="2"
-                    style="?android:attr/buttonBarButtonStyle"
-                    android:textSize="14sp"
-                    android:text="@string/research_feedback_cancel"
-                    android:layout_height="wrap_content" />
-                <Button
-                    android:id="@+id/research_feedback_send_button"
-                    android:layout_width="wrap_content"
-                    android:layout_gravity="right"
-                    android:layout_weight="1"
-                    android:maxLines="2"
-                    style="?android:attr/buttonBarButtonStyle"
-                    android:textSize="14sp"
-                    android:text="@string/research_feedback_send"
-                    android:layout_height="wrap_content" />
-            </LinearLayout>
+            android:orientation="horizontal"
+            android:layoutDirection="locale"
+            android:measureWithLargestChild="true">
+            <Button
+                android:id="@+id/research_feedback_cancel_button"
+                android:layout_width="wrap_content"
+                android:layout_gravity="left"
+                android:layout_weight="1"
+                android:maxLines="2"
+                style="?android:attr/buttonBarButtonStyle"
+                android:textSize="14sp"
+                android:text="@string/research_feedback_cancel"
+                android:layout_height="wrap_content" />
+            <Button
+                android:id="@+id/research_feedback_send_button"
+                android:layout_width="wrap_content"
+                android:layout_gravity="right"
+                android:layout_weight="1"
+                android:maxLines="2"
+                style="?android:attr/buttonBarButtonStyle"
+                android:textSize="14sp"
+                android:text="@string/research_feedback_send"
+                android:layout_height="wrap_content" />
         </LinearLayout>
     </LinearLayout>
 </ScrollView>
diff --git a/java/res/layout/seek_bar_dialog.xml b/java/res/layout/seek_bar_dialog.xml
index a47e9a0..e723ad9 100644
--- a/java/res/layout/seek_bar_dialog.xml
+++ b/java/res/layout/seek_bar_dialog.xml
@@ -33,7 +33,7 @@
         <TextView android:id="@+id/seek_bar_dialog_value"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:textSize="20dp"/>
+            android:textSize="20sp"/>
     </LinearLayout>
     <SeekBar
         android:id="@+id/seek_bar_dialog_bar"
diff --git a/java/res/layout/setup_steps_title.xml b/java/res/layout/setup_steps_title.xml
index e3694bf..9ee8693 100644
--- a/java/res/layout/setup_steps_title.xml
+++ b/java/res/layout/setup_steps_title.xml
@@ -21,7 +21,5 @@
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
     <TextView
         android:id="@+id/setup_title"
-        style="@style/setupTitleStyle"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true" />
+        style="@style/setupTitleStyle" />
 </merge>
diff --git a/java/res/layout/setup_welcome_title.xml b/java/res/layout/setup_welcome_title.xml
index af7053a..2c3b489 100644
--- a/java/res/layout/setup_welcome_title.xml
+++ b/java/res/layout/setup_welcome_title.xml
@@ -21,9 +21,7 @@
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
     <TextView
         android:id="@+id/setup_welcome_title"
-        style="@style/setupTitleStyle"
-        android:layout_alignParentLeft="true"
-        android:layout_alignParentTop="true" />
+        style="@style/setupTitleStyle" />
     <TextView
         android:id="@+id/setup_welcome_description"
         android:text="@string/setup_welcome_additional_description"
diff --git a/java/res/layout/suggestions_strip.xml b/java/res/layout/suggestions_strip.xml
index cbf31e6..908e305 100644
--- a/java/res/layout/suggestions_strip.xml
+++ b/java/res/layout/suggestions_strip.xml
@@ -19,9 +19,7 @@
 -->
 
 <merge
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
+    xmlns:android="http://schemas.android.com/apk/res/android">
     <LinearLayout
         android:id="@+id/suggestions_strip"
         android:orientation="horizontal"
diff --git a/java/res/layout/user_dictionary_add_word.xml b/java/res/layout/user_dictionary_add_word.xml
index 607f5c4..615fde5 100644
--- a/java/res/layout/user_dictionary_add_word.xml
+++ b/java/res/layout/user_dictionary_add_word.xml
@@ -58,42 +58,33 @@
     </EditText>
 
     <LinearLayout
+        style="?android:attr/buttonBarStyle"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:divider="?android:attr/dividerHorizontal"
-        android:dividerPadding="0dip"
-        android:orientation="vertical"
-        android:showDividers="beginning" >
+        android:measureWithLargestChild="true"
+        android:orientation="horizontal" >
 
-        <LinearLayout
-            style="?android:attr/buttonBarStyle"
-            android:layout_width="match_parent"
+        <Button
+            style="?android:attr/buttonBarButtonStyle"
+            android:layout_width="0dip"
             android:layout_height="wrap_content"
-            android:measureWithLargestChild="true"
-            android:orientation="horizontal" >
+            android:layout_gravity="start"
+            android:layout_weight="1"
+            android:maxLines="2"
+            android:onClick="onClickCancel"
+            android:text="@string/cancel"
+            android:textSize="14sp" />
 
-            <Button
-                style="?android:attr/buttonBarButtonStyle"
-                android:layout_width="0dip"
-                android:layout_height="wrap_content"
-                android:layout_gravity="start"
-                android:layout_weight="1"
-                android:maxLines="2"
-                android:onClick="onClickCancel"
-                android:text="@string/cancel"
-                android:textSize="14sp" />
-
-            <Button
-                style="?android:attr/buttonBarButtonStyle"
-                android:layout_width="0dip"
-                android:layout_height="wrap_content"
-                android:layout_gravity="end"
-                android:layout_weight="1"
-                android:maxLines="2"
-                android:onClick="onClickConfirm"
-                android:text="@string/user_dict_settings_add_dialog_confirm"
-                android:textSize="14sp" />
-        </LinearLayout>
+        <Button
+            style="?android:attr/buttonBarButtonStyle"
+            android:layout_width="0dip"
+            android:layout_height="wrap_content"
+            android:layout_gravity="end"
+            android:layout_weight="1"
+            android:maxLines="2"
+            android:onClick="onClickConfirm"
+            android:text="@string/user_dict_settings_add_dialog_confirm"
+            android:textSize="14sp" />
     </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/java/res/layout/user_dictionary_item.xml b/java/res/layout/user_dictionary_item.xml
index 56bad77..b8d48b5 100644
--- a/java/res/layout/user_dictionary_item.xml
+++ b/java/res/layout/user_dictionary_item.xml
@@ -19,10 +19,11 @@
     android:background="?android:attr/selectableItemBackground"
     android:gravity="center_vertical"
     android:minHeight="?android:attr/listPreferredItemHeight"
-    android:paddingEnd="?android:attr/scrollbarSize" >
+    android:paddingEnd="?android:attr/scrollbarSize"
+    android:baselineAligned="false" >
 
     <RelativeLayout
-        android:layout_width="wrap_content"
+        android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:padding="6dip"
         android:layout_weight="1" >
diff --git a/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java b/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
index 7c27e6d..3d0e29e 100644
--- a/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
+++ b/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
@@ -23,7 +23,7 @@
     private static final String COMMON_PREFERENCES_NAME = "LatinImeDictPrefs";
 
     public static SharedPreferences getCommonPreferences(final Context context) {
-        return context.getSharedPreferences(COMMON_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
+        return context.getSharedPreferences(COMMON_PREFERENCES_NAME, 0);
     }
 
     public static void enable(final SharedPreferences pref, final String id) {
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
index 88b5032..384ee3e 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
@@ -100,6 +100,7 @@
 
     @Override
     protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
         mIsCurrentlyAttachedToWindow = false;
         updateReporterThreadRunningStatusAccordingToVisibility();
     }
diff --git a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
index ff0d538..8dea908 100644
--- a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
@@ -71,8 +71,8 @@
  * Because of the above reasons, this class doesn't extend {@link KeyboardView}.
  */
 public final class EmojiPalettesView extends LinearLayout implements OnTabChangeListener,
-        ViewPager.OnPageChangeListener, View.OnClickListener,
-        EmojiPageKeyboardView.OnKeyClickListener {
+        ViewPager.OnPageChangeListener, View.OnTouchListener,
+        EmojiPageKeyboardView.OnKeyEventListener {
     static final String TAG = EmojiPalettesView.class.getSimpleName();
     private static final boolean DEBUG_PAGER = false;
     private final int mKeyBackgroundId;
@@ -486,16 +486,16 @@
         final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet);
         alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
         alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
-        alphabetKey.setOnClickListener(this);
+        alphabetKey.setOnTouchListener(this);
         final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space);
         spaceKey.setBackgroundResource(mKeyBackgroundId);
         spaceKey.setTag(Constants.CODE_SPACE);
-        spaceKey.setOnClickListener(this);
+        spaceKey.setOnTouchListener(this);
         mEmojiLayoutParams.setKeyProperties(spaceKey);
         final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2);
         alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
         alphabetKey2.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
-        alphabetKey2.setOnClickListener(this);
+        alphabetKey2.setOnTouchListener(this);
     }
 
     @Override
@@ -543,31 +543,51 @@
         }
     }
 
+    // Called from {@link EmojiPageKeyboardView} through {@link View.OnTouchListener} interface to
+    // handle touch events from View-based elements such as the space bar.
     @Override
-    public void onClick(final View v) {
-        if (v.getTag() instanceof Integer) {
-            final int code = (Integer)v.getTag();
-            registerCode(code);
-            return;
+    public boolean onTouch(final View v, final MotionEvent event) {
+        final Object tag = v.getTag();
+        if (!(tag instanceof Integer)) {
+            return false;
         }
+        final int code = (Integer) tag;
+        switch (event.getAction()) {
+            case MotionEvent.ACTION_DOWN:
+                mKeyboardActionListener.onPressKey(
+                        code, 0 /* repeatCount */, true /* isSinglePointer */);
+                break;
+            case MotionEvent.ACTION_UP:
+                mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE);
+                mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
+                break;
+        }
+        return false;
     }
 
-    private void registerCode(final int code) {
-        mKeyboardActionListener.onPressKey(code, 0 /* repeatCount */, true /* isSinglePointer */);
-        mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE);
-        mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
-    }
-
+    // Called from {@link EmojiPageKeyboardView} through
+    // {@link EmojiPageKeyboardView.OnKeyEventListener} interface to handle touch events from
+    // non-View-based elements like typical Emoji characters.
     @Override
-    public void onKeyClick(final Key key) {
+    public void onPressKey(final Key key) {
+        final int code = key.getCode();
+        mKeyboardActionListener.onPressKey(code, 0 /* repeatCount */, true /* isSinglePointer */);
+    }
+
+    // Called from {@link EmojiPageKeyboardView} through
+    // {@link EmojiPageKeyboardView.OnKeyEventListener} interface to handle touch events from
+    // non-View-based elements like typical Emoji characters.
+    @Override
+    public void onReleaseKey(final Key key) {
         mEmojiPalettesAdapter.addRecentKey(key);
         mEmojiCategory.saveLastTypedCategoryPage();
         final int code = key.getCode();
         if (code == Constants.CODE_OUTPUT_TEXT) {
             mKeyboardActionListener.onTextInput(key.getOutputText());
-            return;
+        } else {
+            mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE);
         }
-        registerCode(code);
+        mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
     }
 
     public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
@@ -630,7 +650,7 @@
     }
 
     private static class EmojiPalettesAdapter extends PagerAdapter {
-        private final EmojiPageKeyboardView.OnKeyClickListener mListener;
+        private final EmojiPageKeyboardView.OnKeyEventListener mListener;
         private final DynamicGridKeyboard mRecentsKeyboard;
         private final SparseArray<EmojiPageKeyboardView> mActiveKeyboardViews =
                 CollectionUtils.newSparseArray();
@@ -638,7 +658,7 @@
         private int mActivePosition = 0;
 
         public EmojiPalettesAdapter(final EmojiCategory emojiCategory,
-                final EmojiPageKeyboardView.OnKeyClickListener listener) {
+                final EmojiPageKeyboardView.OnKeyEventListener listener) {
             mEmojiCategory = emojiCategory;
             mListener = listener;
             mRecentsKeyboard = mEmojiCategory.getKeyboard(CATEGORY_ID_RECENTS, 0);
@@ -702,7 +722,7 @@
             final EmojiPageKeyboardView keyboardView = (EmojiPageKeyboardView)inflater.inflate(
                     R.layout.emoji_keyboard_page, container, false /* attachToRoot */);
             keyboardView.setKeyboard(keyboard);
-            keyboardView.setOnKeyClickListener(mListener);
+            keyboardView.setOnKeyEventListener(mListener);
             container.addView(keyboardView);
             mActiveKeyboardViews.put(position, keyboardView);
             return keyboardView;
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index e1c841d..810bd91 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -424,8 +424,8 @@
      */
     @Override
     public void setKeyboard(final Keyboard keyboard) {
-        // Remove any pending messages.
-        mKeyTimerHandler.cancelAllKeyTimers();
+        // Remove any pending messages, except dismissing preview and key repeat.
+        mKeyTimerHandler.cancelLongPressTimers();
         super.setKeyboard(keyboard);
         mKeyDetector.setKeyboard(
                 keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
diff --git a/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java b/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java
index 2e80f79..5c7c6e3 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java
@@ -35,16 +35,19 @@
 // TODO: Implement key popup preview.
 public final class EmojiPageKeyboardView extends KeyboardView implements
         GestureDetector.OnGestureListener {
-    public interface OnKeyClickListener {
-        public void onKeyClick(Key key);
+    public interface OnKeyEventListener {
+        public void onPressKey(Key key);
+        public void onReleaseKey(Key key);
     }
 
-    private static final OnKeyClickListener EMPTY_LISTENER = new OnKeyClickListener() {
-        @Override
-        public void onKeyClick(final Key key) {}
+    private static final OnKeyEventListener EMPTY_LISTENER = new OnKeyEventListener() {
+      @Override
+      public void onPressKey(final Key key) {}
+      @Override
+      public void onReleaseKey(final Key key) {}
     };
 
-    private OnKeyClickListener mListener = EMPTY_LISTENER;
+    private OnKeyEventListener mListener = EMPTY_LISTENER;
     private final KeyDetector mKeyDetector = new KeyDetector(0.0f /*keyHysteresisDistance */);
     private final GestureDetector mGestureDetector;
 
@@ -59,7 +62,7 @@
         mGestureDetector.setIsLongpressEnabled(false /* isLongpressEnabled */);
     }
 
-    public void setOnKeyClickListener(final OnKeyClickListener listener) {
+    public void setOnKeyEventListener(final OnKeyEventListener listener) {
         mListener = listener;
     }
 
@@ -115,9 +118,9 @@
         if (key == null) {
             return false;
         }
-        // TODO: May call {@link KeyboardActionListener#onPressKey(int,int,boolean)}.
         key.onPressed();
         invalidateKey(key);
+        mListener.onPressKey(key);
         return false;
     }
 
@@ -133,10 +136,9 @@
         if (key == null) {
             return false;
         }
-        // TODO: May call {@link KeyboardActionListener#onReleaseKey(int,boolean)}.
         key.onReleased();
         invalidateKey(key);
-        mListener.onKeyClick(key);
+        mListener.onReleaseKey(key);
         return true;
     }
 
diff --git a/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java b/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java
index 3298a3f..ec7b9b0 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java
@@ -126,7 +126,7 @@
         removeMessages(MSG_LONGPRESS_SHIFT_KEY);
     }
 
-    private void cancelLongPressTimers() {
+    public void cancelLongPressTimers() {
         removeMessages(MSG_LONGPRESS_KEY);
         removeMessages(MSG_LONGPRESS_SHIFT_KEY);
     }
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 95ac3e2..708f75a 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -365,6 +365,7 @@
     }
 
     public static class LanguageModelParam {
+        public final String mTargetWord;
         public final int[] mWord0;
         public final int[] mWord1;
         // TODO: this needs to be a list of shortcuts
@@ -379,6 +380,7 @@
         // Constructor for unigram. TODO: support shortcuts
         public LanguageModelParam(final String word, final int unigramProbability,
                 final int timestamp) {
+            mTargetWord = word;
             mWord0 = null;
             mWord1 = StringUtils.toCodePointArray(word);
             mShortcutTarget = null;
@@ -394,6 +396,7 @@
         public LanguageModelParam(final String word0, final String word1,
                 final int unigramProbability, final int bigramProbability,
                 final int timestamp) {
+            mTargetWord = word1;
             mWord0 = StringUtils.toCodePointArray(word0);
             mWord1 = StringUtils.toCodePointArray(word1);
             mShortcutTarget = null;
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 181ad17..7e97802 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -112,7 +112,7 @@
         public DictPackSettings(final Context context) {
             mDictPreferences = null == context ? null
                     : context.getSharedPreferences(COMMON_PREFERENCES_NAME,
-                            Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
+                            Context.MODE_MULTI_PROCESS);
         }
         public boolean isWordListActive(final String dictId) {
             if (null == mDictPreferences) {
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp
index 4050ad3..d58d259 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.cpp
@@ -42,6 +42,7 @@
 
 const ForgettingCurveUtils::ProbabilityTable ForgettingCurveUtils::sProbabilityTable;
 
+// TODO: Revise the logic to decide the initial probability depending on the given probability.
 /* static */ const HistoricalInfo ForgettingCurveUtils::createUpdatedHistoricalInfo(
         const HistoricalInfo *const originalHistoricalInfo,
         const int newProbability, const int timestamp) {
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h
index 6ac8dc5..b373534 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h
@@ -26,7 +26,6 @@
 
 class DictionaryHeaderStructurePolicy;
 
-// TODO: Quit using bigram probability to indicate the delta.
 class ForgettingCurveUtils {
  public:
     static const int MAX_UNIGRAM_COUNT;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h b/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h
index 21fe355..14fdf53 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/probability_utils.h
@@ -23,6 +23,7 @@
 
 namespace latinime {
 
+// TODO: Quit using bigram probability to indicate the delta.
 class ProbabilityUtils {
  public:
     static AK_FORCE_INLINE int backoff(const int unigramProbability) {
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index 039f581..1a249ce 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -368,8 +368,8 @@
         // Choose the auto-correction, which is always in position 0. For "Barack", the
         // auto-correction should be "Barack".
         pickSuggestionManually(0, WORD_TO_TYPE);
-        runMessages();
         sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+        runMessages();
         // Test the first prediction is displayed
         final SuggestedWords suggestedWords = mLatinIME.getSuggestedWords();
         assertEquals("predictions after manual pick", "Obama",