aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/AndroidManifest.xml8
-rw-r--r--java/res/xml/prefs.xml1
-rw-r--r--java/res/xml/prefs_screen_debug.xml (renamed from java/res/xml/prefs_for_debug.xml)0
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettings.java2
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettingsActivity.java48
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsFragment.java7
-rw-r--r--native/jni/Android.mk2
-rw-r--r--native/jni/NativeFileList.mk1
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp59
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h4
-rw-r--r--native/jni/tests/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer_test.cpp94
-rw-r--r--tools/dicttool/NativeLib.mk1
12 files changed, 139 insertions, 88 deletions
diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml
index 702b7aea2..f37f6cc4b 100644
--- a/java/AndroidManifest.xml
+++ b/java/AndroidManifest.xml
@@ -102,14 +102,6 @@
</intent-filter>
</activity>
- <activity android:name=".settings.DebugSettingsActivity"
- android:theme="@style/platformSettingsTheme"
- android:label="@string/english_ime_debug_settings">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- </intent-filter>
- </activity>
-
<receiver android:name="SuggestionSpanPickedNotificationReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.text.style.SUGGESTION_PICKED" />
diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml
index 550e71ada..6febb3126 100644
--- a/java/res/xml/prefs.xml
+++ b/java/res/xml/prefs.xml
@@ -199,6 +199,7 @@
android:defaultValue="true"
android:persistent="true" />
<PreferenceScreen
+ android:fragment="com.android.inputmethod.latin.settings.DebugSettings"
android:key="screen_debug"
android:title="Debug settings"
android:defaultValue="false"
diff --git a/java/res/xml/prefs_for_debug.xml b/java/res/xml/prefs_screen_debug.xml
index ae29a8a82..ae29a8a82 100644
--- a/java/res/xml/prefs_for_debug.xml
+++ b/java/res/xml/prefs_screen_debug.xml
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index c6a70244c..e4271adac 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -61,7 +61,7 @@ public final class DebugSettings extends PreferenceFragment
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- addPreferencesFromResource(R.xml.prefs_for_debug);
+ addPreferencesFromResource(R.xml.prefs_screen_debug);
TwoStatePreferenceHelper.replaceCheckBoxPreferencesBySwitchPreferences(
getPreferenceScreen());
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettingsActivity.java b/java/src/com/android/inputmethod/latin/settings/DebugSettingsActivity.java
deleted file mode 100644
index a23e37795..000000000
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettingsActivity.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2012 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.settings;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-
-import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.utils.FragmentUtils;
-
-public final class DebugSettingsActivity extends PreferenceActivity {
- private static final String DEFAULT_FRAGMENT = DebugSettings.class.getName();
-
- @Override
- public Intent getIntent() {
- final Intent intent = super.getIntent();
- intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT);
- intent.putExtra(EXTRA_NO_HEADERS, true);
- return intent;
- }
-
- @Override
- protected void onCreate(final Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setTitle(R.string.english_ime_debug_settings);
- }
-
- // TODO: Uncomment the override annotation once we start using SDK version 19.
- // @Override
- public boolean isValidFragment(String fragmentName) {
- return FragmentUtils.isValidFragment(fragmentName);
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
index a9d95fc82..ac5d71c0b 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
@@ -136,12 +136,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final PreferenceScreen debugScreen =
(PreferenceScreen) findPreference(Settings.SCREEN_DEBUG);
- if (Settings.isInternal(prefs)) {
- final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN);
- debugSettingsIntent.setClassName(
- context.getPackageName(), DebugSettingsActivity.class.getName());
- debugScreen.setIntent(debugSettingsIntent);
- } else {
+ if (!Settings.isInternal(prefs)) {
advancedScreen.removePreference(debugScreen);
}
diff --git a/native/jni/Android.mk b/native/jni/Android.mk
index 8be4d78b6..3a2073f03 100644
--- a/native/jni/Android.mk
+++ b/native/jni/Android.mk
@@ -90,7 +90,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_CLANG := true
LOCAL_SDK_VERSION := 14
LOCAL_NDK_STL_VARIANT := c++_static
-LOCAL_LDFLAGS += -ldl -fuse-ld=mcld
+LOCAL_LDFLAGS += -ldl
include $(BUILD_SHARED_LIBRARY)
#################### Clean up the tmp vars
diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk
index fe2106140..1cb61c45f 100644
--- a/native/jni/NativeFileList.mk
+++ b/native/jni/NativeFileList.mk
@@ -124,4 +124,5 @@ LATIN_IME_CORE_TEST_FILES := \
defines_test.cpp \
suggest/core/layout/normal_distribution_2d_test.cpp \
suggest/core/dictionary/bloom_filter_test.cpp \
+ suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer_test.cpp \
utils/autocorrection_threshold_utils_test.cpp
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
index 259dae4c6..825b72c6a 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp
@@ -49,6 +49,10 @@ void BufferWithExtendableBuffer::readCodePointsAndAdvancePosition(const int maxC
}
}
+bool BufferWithExtendableBuffer::extend(const int size) {
+ return checkAndPrepareWriting(getTailPosition(), size);
+}
+
bool BufferWithExtendableBuffer::writeUint(const uint32_t data, const int size, const int pos) {
int writingPos = pos;
return writeUintAndAdvancePosition(data, size, &writingPos);
@@ -96,38 +100,49 @@ bool BufferWithExtendableBuffer::writeCodePointsAndAdvancePosition(const int *co
return true;
}
-bool BufferWithExtendableBuffer::extendBuffer() {
+bool BufferWithExtendableBuffer::extendBuffer(const size_t size) {
+ const size_t extendSize = std::max(EXTEND_ADDITIONAL_BUFFER_SIZE_STEP, size);
const size_t sizeAfterExtending =
- mAdditionalBuffer.size() + EXTEND_ADDITIONAL_BUFFER_SIZE_STEP;
- if (sizeAfterExtending > mMaxAdditionalBufferSize) {
+ std::min(mAdditionalBuffer.size() + extendSize, mMaxAdditionalBufferSize);
+ if (sizeAfterExtending < mAdditionalBuffer.size() + size) {
return false;
}
- mAdditionalBuffer.resize(mAdditionalBuffer.size() + EXTEND_ADDITIONAL_BUFFER_SIZE_STEP);
+ mAdditionalBuffer.resize(sizeAfterExtending);
return true;
}
bool BufferWithExtendableBuffer::checkAndPrepareWriting(const int pos, const int size) {
- if (isInAdditionalBuffer(pos)) {
- const int tailPosition = getTailPosition();
- if (pos == tailPosition) {
- // Append data to the tail.
- if (pos + size > static_cast<int>(mAdditionalBuffer.size()) + mOriginalBufferSize) {
- // Need to extend buffer.
- if (!extendBuffer()) {
- return false;
- }
- }
- mUsedAdditionalBufferSize += size;
- } else if (pos + size > tailPosition) {
- // The access will beyond the tail of used region.
- return false;
- }
- } else {
- if (pos < 0 || mOriginalBufferSize < pos + size) {
- // Invalid position or violate the boundary.
+ if (pos < 0 || size < 0) {
+ // Invalid position or size.
+ return false;
+ }
+ const size_t totalRequiredSize = static_cast<size_t>(pos + size);
+ if (!isInAdditionalBuffer(pos)) {
+ // Here don't need to care about the additional buffer.
+ if (static_cast<size_t>(mOriginalBufferSize) < totalRequiredSize) {
+ // Violate the boundary.
return false;
}
+ // The buffer has sufficient capacity.
+ return true;
+ }
+ // Hereafter, pos is in the additional buffer.
+ const size_t tailPosition = static_cast<size_t>(getTailPosition());
+ if (totalRequiredSize <= tailPosition) {
+ // The buffer has sufficient capacity.
+ return true;
+ }
+ if (static_cast<size_t>(pos) != tailPosition) {
+ // The additional buffer must be extended from the tail position.
+ return false;
+ }
+ const size_t extendSize = totalRequiredSize -
+ std::min(mAdditionalBuffer.size() + mOriginalBufferSize, totalRequiredSize);
+ if (extendSize > 0 && !extendBuffer(extendSize)) {
+ // Failed to extend the buffer.
+ return false;
}
+ mUsedAdditionalBufferSize += size;
return true;
}
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h b/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h
index a2e88a46c..5e1362eee 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h
@@ -87,6 +87,8 @@ class BufferWithExtendableBuffer {
* NEAR_BUFFER_LIMIT_THRESHOLD_PERCENTILE) / 100);
}
+ bool extend(const int size);
+
/**
* For writing.
*
@@ -115,7 +117,7 @@ class BufferWithExtendableBuffer {
const size_t mMaxAdditionalBufferSize;
// Return if the buffer is successfully extended or not.
- bool extendBuffer();
+ bool extendBuffer(const size_t size);
// Returns if it is possible to write size-bytes from pos. When pos is at the tail position of
// the additional buffer, try extending the buffer.
diff --git a/native/jni/tests/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer_test.cpp b/native/jni/tests/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer_test.cpp
new file mode 100644
index 000000000..fa6c6d71e
--- /dev/null
+++ b/native/jni/tests/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer_test.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#include "suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.h"
+
+#include <gtest/gtest.h>
+
+namespace latinime {
+namespace {
+
+const int DEFAULT_MAX_BUFFER_SIZE = 1024;
+
+TEST(BufferWithExtendablebufferTest, TestWriteAndRead) {
+ BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
+ int pos = 0;
+ // 1 byte
+ const uint32_t data_1 = 0xFF;
+ EXPECT_TRUE(buffer.writeUint(data_1, 1 /* size */, pos));
+ EXPECT_EQ(data_1, buffer.readUint(1, pos));
+ pos += 1;
+ // 2 byte
+ const uint32_t data_2 = 0xFFFF;
+ EXPECT_TRUE(buffer.writeUint(data_2, 2 /* size */, pos));
+ EXPECT_EQ(data_2, buffer.readUint(2, pos));
+ pos += 2;
+ // 3 byte
+ const uint32_t data_3 = 0xFFFFFF;
+ EXPECT_TRUE(buffer.writeUint(data_3, 3 /* size */, pos));
+ EXPECT_EQ(data_3, buffer.readUint(3, pos));
+ pos += 3;
+ // 4 byte
+ const uint32_t data_4 = 0xFFFFFFFF;
+ EXPECT_TRUE(buffer.writeUint(data_4, 4 /* size */, pos));
+ EXPECT_EQ(data_4, buffer.readUint(4, pos));
+}
+
+TEST(BufferWithExtendablebufferTest, TestExtend) {
+ BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
+ EXPECT_EQ(0, buffer.getTailPosition());
+ EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */));
+ EXPECT_EQ(4, buffer.getTailPosition());
+ EXPECT_TRUE(buffer.extend(8 /* size */));
+ EXPECT_EQ(12, buffer.getTailPosition());
+ EXPECT_TRUE(buffer.writeUint(0xFFFF /* data */, 4 /* size */, 8 /* pos */));
+ EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */));
+}
+
+TEST(BufferWithExtendablebufferTest, TestCopy) {
+ BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
+ EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */));
+ EXPECT_TRUE(buffer.writeUint(0xFFFF /* data */, 4 /* size */, 4 /* pos */));
+ BufferWithExtendableBuffer targetBuffer(DEFAULT_MAX_BUFFER_SIZE);
+ EXPECT_TRUE(targetBuffer.copy(&buffer));
+ EXPECT_EQ(0xFFu, targetBuffer.readUint(4 /* size */, 0 /* pos */));
+ EXPECT_EQ(0xFFFFu, targetBuffer.readUint(4 /* size */, 4 /* pos */));
+}
+
+TEST(BufferWithExtendablebufferTest, TestSizeLimit) {
+ BufferWithExtendableBuffer emptyBuffer(0 /* maxAdditionalBufferSize */);
+ EXPECT_FALSE(emptyBuffer.writeUint(0 /* data */, 1 /* size */, 0 /* pos */));
+ EXPECT_FALSE(emptyBuffer.extend(1 /* size */));
+
+ BufferWithExtendableBuffer smallBuffer(4 /* maxAdditionalBufferSize */);
+ EXPECT_TRUE(smallBuffer.writeUint(0 /* data */, 4 /* size */, 0 /* pos */));
+ EXPECT_FALSE(smallBuffer.writeUint(0 /* data */, 1 /* size */, 4 /* pos */));
+
+ EXPECT_TRUE(smallBuffer.copy(&emptyBuffer));
+ EXPECT_FALSE(emptyBuffer.copy(&smallBuffer));
+
+ BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
+ EXPECT_FALSE(buffer.isNearSizeLimit());
+ int pos = 0;
+ while (!buffer.isNearSizeLimit()) {
+ EXPECT_TRUE(buffer.writeUintAndAdvancePosition(0 /* data */, 4 /* size */, &pos));
+ }
+ EXPECT_GT(pos, 0);
+ EXPECT_LE(pos, DEFAULT_MAX_BUFFER_SIZE);
+}
+
+} // namespace
+} // namespace latinime
diff --git a/tools/dicttool/NativeLib.mk b/tools/dicttool/NativeLib.mk
index 028025d91..ffb32edbe 100644
--- a/tools/dicttool/NativeLib.mk
+++ b/tools/dicttool/NativeLib.mk
@@ -34,7 +34,6 @@ ifneq ($(strip $(HOST_JDK_IS_64BIT_VERSION)),)
LOCAL_MULTILIB := 64
endif #HOST_JDK_IS_64BIT_VERSION
-LOCAL_CLANG := true
# For C++11
LOCAL_CFLAGS += -std=c++11