Merge "Cleanup logging code"
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index c438474..e60a8a9 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -373,7 +373,7 @@
         final boolean needsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
                 ResourceUtils.getDeviceOverrideValue(res,
                         R.array.phantom_sudden_move_event_device_list, "false"));
-        PointerTracker.init(mHasDistinctMultitouch, needsPhantomSuddenMoveEventHack);
+        PointerTracker.init(needsPhantomSuddenMoveEventHack);
 
         final TypedArray a = context.obtainStyledAttributes(
                 attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 77e7812..c868052 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -157,7 +157,7 @@
     private static final boolean sNeedsProximateBogusDownMoveUpEventHack = true;
 
     private static final ArrayList<PointerTracker> sTrackers = CollectionUtils.newArrayList();
-    private static PointerTrackerQueue sPointerTrackerQueue;
+    private static final PointerTrackerQueue sPointerTrackerQueue = new PointerTrackerQueue();
 
     public final int mPointerId;
 
@@ -326,13 +326,7 @@
 
     private final GestureStrokeWithPreviewPoints mGestureStrokeWithPreviewPoints;
 
-    public static void init(boolean hasDistinctMultitouch,
-            boolean needsPhantomSuddenMoveEventHack) {
-        if (hasDistinctMultitouch) {
-            sPointerTrackerQueue = new PointerTrackerQueue();
-        } else {
-            sPointerTrackerQueue = null;
-        }
+    public static void init(final boolean needsPhantomSuddenMoveEventHack) {
         sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack;
         sParams = PointerTrackerParams.DEFAULT;
         sGestureStrokeParams = GestureStrokeParams.DEFAULT;
@@ -376,7 +370,7 @@
     }
 
     public static boolean isAnyInSlidingKeyInput() {
-        return sPointerTrackerQueue != null ? sPointerTrackerQueue.isAnyInSlidingKeyInput() : false;
+        return sPointerTrackerQueue.isAnyInSlidingKeyInput();
     }
 
     public static void setKeyboardActionListener(final KeyboardActionListener listener) {
@@ -683,12 +677,11 @@
     }
 
     private static int getActivePointerTrackerCount() {
-        return (sPointerTrackerQueue == null) ? 1 : sPointerTrackerQueue.size();
+        return sPointerTrackerQueue.size();
     }
 
     private static boolean isOldestTrackerInQueue(final PointerTracker tracker) {
-        return sPointerTrackerQueue == null
-                || sPointerTrackerQueue.getOldestElement() == tracker;
+        return sPointerTrackerQueue.getOldestElement() == tracker;
     }
 
     private void mayStartBatchInput(final Key key) {
@@ -798,15 +791,12 @@
 
         final Key key = getKeyOn(x, y);
         mBogusMoveEventDetector.onActualDownEvent(x, y);
-        final PointerTrackerQueue queue = sPointerTrackerQueue;
-        if (queue != null) {
-            if (key != null && key.isModifier()) {
-                // Before processing a down event of modifier key, all pointers already being
-                // tracked should be released.
-                queue.releaseAllPointers(eventTime);
-            }
-            queue.add(this);
+        if (key != null && key.isModifier()) {
+            // Before processing a down event of modifier key, all pointers already being
+            // tracked should be released.
+            sPointerTrackerQueue.releaseAllPointers(eventTime);
         }
+        sPointerTrackerQueue.add(this);
         onDownEventInternal(x, y, eventTime);
         if (!sShouldHandleGesture) {
             return;
@@ -982,7 +972,7 @@
         // slides off the key. This defends against noise from some touch panels when there are
         // close multiple touches.
         // Caveat: When in chording input mode with a modifier key, we don't use this hack.
-        else if (getActivePointerTrackerCount() > 1 && sPointerTrackerQueue != null
+        else if (getActivePointerTrackerCount() > 1
                 && !sPointerTrackerQueue.hasModifierKeyOlderThan(this)) {
             if (DEBUG_MODE) {
                 Log.w(TAG, String.format("[%d] onMoveEvent:"
@@ -1048,22 +1038,17 @@
             printTouchEvent("onUpEvent  :", x, y, eventTime);
         }
 
-        final PointerTrackerQueue queue = sPointerTrackerQueue;
-        if (queue != null) {
-            if (!sInGesture) {
-                if (mCurrentKey != null && mCurrentKey.isModifier()) {
-                    // Before processing an up event of modifier key, all pointers already being
-                    // tracked should be released.
-                    queue.releaseAllPointersExcept(this, eventTime);
-                } else {
-                    queue.releaseAllPointersOlderThan(this, eventTime);
-                }
+        if (!sInGesture) {
+            if (mCurrentKey != null && mCurrentKey.isModifier()) {
+                // Before processing an up event of modifier key, all pointers already being
+                // tracked should be released.
+                sPointerTrackerQueue.releaseAllPointersExcept(this, eventTime);
+            } else {
+                sPointerTrackerQueue.releaseAllPointersOlderThan(this, eventTime);
             }
         }
         onUpEventInternal(eventTime);
-        if (queue != null) {
-            queue.remove(this);
-        }
+        sPointerTrackerQueue.remove(this);
     }
 
     // Let this pointer tracker know that one of newer-than-this pointer trackers got an up event.
@@ -1116,10 +1101,7 @@
     public void onLongPressed() {
         mKeyAlreadyProcessed = true;
         setReleasedKeyGraphics(mCurrentKey);
-        final PointerTrackerQueue queue = sPointerTrackerQueue;
-        if (queue != null) {
-            queue.remove(this);
-        }
+        sPointerTrackerQueue.remove(this);
     }
 
     public void onCancelEvent(final int x, final int y, final long eventTime) {
@@ -1127,11 +1109,8 @@
             printTouchEvent("onCancelEvt:", x, y, eventTime);
         }
 
-        final PointerTrackerQueue queue = sPointerTrackerQueue;
-        if (queue != null) {
-            queue.releaseAllPointersExcept(this, eventTime);
-            queue.remove(this);
-        }
+        sPointerTrackerQueue.releaseAllPointersExcept(this, eventTime);
+        sPointerTrackerQueue.remove(this);
         onCancelEventInternal();
     }
 
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index 5b8d111..004665a 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -70,7 +70,7 @@
     adjust = static_cast<int>(dictOffset) % pagesize;
     int adjDictOffset = static_cast<int>(dictOffset) - adjust;
     int adjDictSize = static_cast<int>(dictSize) + adjust;
-    dictBuf = mmap(0, sizeof(char) * adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset);
+    dictBuf = mmap(0, adjDictSize, PROT_READ, MAP_PRIVATE, fd, adjDictOffset);
     if (dictBuf == MAP_FAILED) {
         AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
         return 0;
@@ -84,7 +84,7 @@
         AKLOGE("DICT: Can't fopen sourceDir. sourceDirChars=%s errno=%d", sourceDirChars, errno);
         return 0;
     }
-    dictBuf = malloc(sizeof(char) * dictSize);
+    dictBuf = malloc(dictSize);
     if (!dictBuf) {
         AKLOGE("DICT: Can't allocate memory region for dictionary. errno=%d", errno);
         return 0;
@@ -94,7 +94,7 @@
         AKLOGE("DICT: Failure in fseek. ret=%d errno=%d", ret, errno);
         return 0;
     }
-    ret = fread(dictBuf, sizeof(char) * dictSize, 1, file);
+    ret = fread(dictBuf, dictSize, 1, file);
     if (ret != 1) {
         AKLOGE("DICT: Failure in fread. ret=%d errno=%d", ret, errno);
         return 0;
diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp
index e2aa156..aadaae4 100644
--- a/native/jni/src/proximity_info.cpp
+++ b/native/jni/src/proximity_info.cpp
@@ -36,7 +36,7 @@
     if (jArray && buffer) {
         env->GetIntArrayRegion(jArray, 0, len, buffer);
     } else if (buffer) {
-        memset(buffer, 0, len * sizeof(jint));
+        memset(buffer, 0, len * sizeof(buffer[0]));
     }
 }
 
@@ -45,7 +45,7 @@
     if (jArray && buffer) {
         env->GetFloatArrayRegion(jArray, 0, len, buffer);
     } else if (buffer) {
-        memset(buffer, 0, len * sizeof(jfloat));
+        memset(buffer, 0, len * sizeof(buffer[0]));
     }
 }
 
diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp
index dadc9c8..6cde06b 100644
--- a/native/jni/src/unigram_dictionary.cpp
+++ b/native/jni/src/unigram_dictionary.cpp
@@ -45,8 +45,7 @@
         int maxWordLength, int maxWords, const unsigned int flags)
         : DICT_ROOT(streamStart), MAX_WORD_LENGTH(maxWordLength), MAX_WORDS(maxWords),
           FULL_WORD_MULTIPLIER(fullWordMultiplier), // TODO : remove this variable.
-          ROOT_POS(0), BYTES_IN_ONE_CHAR(sizeof(int)),
-          MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
+          ROOT_POS(0), MAX_DIGRAPH_SEARCH_DEPTH(DEFAULT_MAX_DIGRAPH_SEARCH_DEPTH), FLAGS(flags) {
     if (DEBUG_DICT) {
         AKLOGI("UnigramDictionary - constructor");
     }
@@ -103,6 +102,9 @@
         const int codesRemain, const int currentDepth, int *codesDest, Correction *correction,
         WordsPriorityQueuePool *queuePool,
         const digraph_t *const digraphs, const unsigned int digraphsSize) const {
+    assert(sizeof(codesDest[0]) == sizeof(codesSrc[0]));
+    assert(sizeof(xCoordinatesBuffer[0]) == sizeof(xcoordinates[0]));
+    assert(sizeof(yCoordinatesBuffer[0]) == sizeof(ycoordinates[0]));
 
     const int startIndex = static_cast<int>(codesDest - codesBuffer);
     if (currentDepth < MAX_DIGRAPH_SEARCH_DEPTH) {
@@ -123,9 +125,8 @@
                 // Make i the index of the second char of the digraph for simplicity. Forgetting
                 // to do that results in an infinite recursion so take care!
                 ++i;
-                memcpy(codesDest, codesSrc, i * BYTES_IN_ONE_CHAR);
-                codesDest[(i - 1) * (BYTES_IN_ONE_CHAR / sizeof(codesDest[0]))] =
-                        replacementCodePoint;
+                memcpy(codesDest, codesSrc, i * sizeof(codesDest[0]));
+                codesDest[i - 1] = replacementCodePoint;
                 getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
                         codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize,
                         bigramMap, bigramFilter, useFullEditDistance, codesSrc + i + 1,
@@ -135,7 +136,7 @@
                 // Copy the second char of the digraph in place, then continue processing on
                 // the remaining part of the word.
                 // In our example, after "pru" in the buffer copy the "e", and continue on "fen"
-                memcpy(codesDest + i, codesSrc + i, BYTES_IN_ONE_CHAR);
+                memcpy(codesDest + i, codesSrc + i, sizeof(codesDest[0]));
                 getWordWithDigraphSuggestionsRec(proximityInfo, xcoordinates, ycoordinates,
                         codesBuffer, xCoordinatesBuffer, yCoordinatesBuffer, codesBufferSize,
                         bigramMap, bigramFilter, useFullEditDistance, codesSrc + i, codesRemain - i,
@@ -151,13 +152,13 @@
     // If the word contains several digraphs, we'll come it for the product of them.
     // eg. if the word is "ueberpruefen" we'll test, in order, against
     // "uberprufen", "uberpruefen", "ueberprufen", "ueberpruefen".
-    const unsigned int remainingBytes = BYTES_IN_ONE_CHAR * codesRemain;
+    const unsigned int remainingBytes = sizeof(codesDest[0]) * codesRemain;
     if (0 != remainingBytes) {
         memcpy(codesDest, codesSrc, remainingBytes);
         memcpy(&xCoordinatesBuffer[startIndex], &xcoordinates[codesBufferSize - codesRemain],
-                sizeof(int) * codesRemain);
+                sizeof(xCoordinatesBuffer[0]) * codesRemain);
         memcpy(&yCoordinatesBuffer[startIndex], &ycoordinates[codesBufferSize - codesRemain],
-                sizeof(int) * codesRemain);
+                sizeof(yCoordinatesBuffer[0]) * codesRemain);
     }
 
     getWordSuggestions(proximityInfo, xCoordinatesBuffer, yCoordinatesBuffer, codesBuffer,
diff --git a/native/jni/src/unigram_dictionary.h b/native/jni/src/unigram_dictionary.h
index 7649007..248b09d 100644
--- a/native/jni/src/unigram_dictionary.h
+++ b/native/jni/src/unigram_dictionary.h
@@ -116,7 +116,6 @@
     const int MAX_WORDS;
     const int FULL_WORD_MULTIPLIER;
     const int ROOT_POS;
-    const unsigned int BYTES_IN_ONE_CHAR;
     const int MAX_DIGRAPH_SEARCH_DEPTH;
     const int FLAGS;
 
diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h
index ac384dd..c4ee07f 100644
--- a/native/jni/src/words_priority_queue.h
+++ b/native/jni/src/words_priority_queue.h
@@ -38,7 +38,7 @@
         void setParams(int score, int *word, int wordLength, int type) {
             mScore = score;
             mWordLength = wordLength;
-            memcpy(mWord, word, sizeof(int) * wordLength);
+            memcpy(mWord, word, sizeof(mWord[0]) * wordLength);
             mUsed = true;
             mType = type;
         }
@@ -127,7 +127,7 @@
                 }
             }
             if (maxIndex > 0 && nsMaxSw) {
-                memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(SuggestedWord *));
+                memmove(&swBuffer[1], &swBuffer[0], maxIndex * sizeof(swBuffer[0]));
                 swBuffer[0] = nsMaxSw;
             }
         }
@@ -141,7 +141,7 @@
             int *targetAddress = outputCodePoints + i * MAX_WORD_LENGTH;
             frequencies[i] = sw->mScore;
             outputTypes[i] = sw->mType;
-            memcpy(targetAddress, sw->mWord, wordLength * sizeof(int));
+            memcpy(targetAddress, sw->mWord, wordLength * sizeof(targetAddress[0]));
             if (wordLength < MAX_WORD_LENGTH) {
                 targetAddress[wordLength] = 0;
             }