Merge changes from topic 'VelocityTracker - fix debugging flags'
* changes:
Convert String8 to std::string
Fix SIGABRT caused by integer sanitizer.
diff --git a/libs/input/Android.bp b/libs/input/Android.bp
index 9294419..2f39976 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -34,6 +34,7 @@
clang: true,
shared_libs: [
+ "libbase",
"liblog",
"libcutils",
],
diff --git a/libs/input/VelocityTracker.cpp b/libs/input/VelocityTracker.cpp
index 7f6b157..b174fa8 100644
--- a/libs/input/VelocityTracker.cpp
+++ b/libs/input/VelocityTracker.cpp
@@ -23,13 +23,14 @@
// Log debug messages about the progress of the algorithm itself.
#define DEBUG_STRATEGY 0
-#include <math.h>
+#include <inttypes.h>
#include <limits.h>
+#include <math.h>
+#include <android-base/stringprintf.h>
#include <cutils/properties.h>
#include <input/VelocityTracker.h>
#include <utils/BitSet.h>
-#include <utils/String8.h>
#include <utils/Timers.h>
namespace android {
@@ -46,8 +47,7 @@
static float vectorDot(const float* a, const float* b, uint32_t m) {
float r = 0;
- while (m) {
- m--;
+ for (size_t i = 0; i < m; i++) {
r += *(a++) * *(b++);
}
return r;
@@ -55,8 +55,7 @@
static float vectorNorm(const float* a, uint32_t m) {
float r = 0;
- while (m) {
- m--;
+ for (size_t i = 0; i < m; i++) {
float t = *(a++);
r += t * t;
}
@@ -64,36 +63,36 @@
}
#if DEBUG_STRATEGY || DEBUG_VELOCITY
-static String8 vectorToString(const float* a, uint32_t m) {
- String8 str;
- str.append("[");
- while (m--) {
- str.appendFormat(" %f", *(a++));
- if (m) {
- str.append(",");
+static std::string vectorToString(const float* a, uint32_t m) {
+ std::string str;
+ str += "[";
+ for (size_t i = 0; i < m; i++) {
+ if (i) {
+ str += ",";
}
+ str += android::base::StringPrintf(" %f", *(a++));
}
- str.append(" ]");
+ str += " ]";
return str;
}
-static String8 matrixToString(const float* a, uint32_t m, uint32_t n, bool rowMajor) {
- String8 str;
- str.append("[");
+static std::string matrixToString(const float* a, uint32_t m, uint32_t n, bool rowMajor) {
+ std::string str;
+ str = "[";
for (size_t i = 0; i < m; i++) {
if (i) {
- str.append(",");
+ str += ",";
}
- str.append(" [");
+ str += " [";
for (size_t j = 0; j < n; j++) {
if (j) {
- str.append(",");
+ str += ",";
}
- str.appendFormat(" %f", a[rowMajor ? i * n + j : j * m + i]);
+ str += android::base::StringPrintf(" %f", a[rowMajor ? i * n + j : j * m + i]);
}
- str.append(" ]");
+ str += " ]";
}
- str.append(" ]");
+ str += " ]";
return str;
}
#endif
@@ -244,7 +243,7 @@
mStrategy->addMovement(eventTime, idBits, positions);
#if DEBUG_VELOCITY
- ALOGD("VelocityTracker: addMovement eventTime=%lld, idBits=0x%08x, activePointerId=%d",
+ ALOGD("VelocityTracker: addMovement eventTime=%" PRId64 ", idBits=0x%08x, activePointerId=%d",
eventTime, idBits.value, mActivePointerId);
for (BitSet32 iterBits(idBits); !iterBits.isEmpty(); ) {
uint32_t id = iterBits.firstMarkedBit();
@@ -256,8 +255,8 @@
"estimator (degree=%d, xCoeff=%s, yCoeff=%s, confidence=%f)",
id, positions[index].x, positions[index].y,
int(estimator.degree),
- vectorToString(estimator.xCoeff, estimator.degree + 1).string(),
- vectorToString(estimator.yCoeff, estimator.degree + 1).string(),
+ vectorToString(estimator.xCoeff, estimator.degree + 1).c_str(),
+ vectorToString(estimator.yCoeff, estimator.degree + 1).c_str(),
estimator.confidence);
}
#endif
@@ -443,8 +442,8 @@
const float* w, uint32_t m, uint32_t n, float* outB, float* outDet) {
#if DEBUG_STRATEGY
ALOGD("solveLeastSquares: m=%d, n=%d, x=%s, y=%s, w=%s", int(m), int(n),
- vectorToString(x, m).string(), vectorToString(y, m).string(),
- vectorToString(w, m).string());
+ vectorToString(x, m).c_str(), vectorToString(y, m).c_str(),
+ vectorToString(w, m).c_str());
#endif
// Expand the X vector to a matrix A, pre-multiplied by the weights.
@@ -456,7 +455,7 @@
}
}
#if DEBUG_STRATEGY
- ALOGD(" - a=%s", matrixToString(&a[0][0], m, n, false /*rowMajor*/).string());
+ ALOGD(" - a=%s", matrixToString(&a[0][0], m, n, false /*rowMajor*/).c_str());
#endif
// Apply the Gram-Schmidt process to A to obtain its QR decomposition.
@@ -491,8 +490,8 @@
}
}
#if DEBUG_STRATEGY
- ALOGD(" - q=%s", matrixToString(&q[0][0], m, n, false /*rowMajor*/).string());
- ALOGD(" - r=%s", matrixToString(&r[0][0], n, n, true /*rowMajor*/).string());
+ ALOGD(" - q=%s", matrixToString(&q[0][0], m, n, false /*rowMajor*/).c_str());
+ ALOGD(" - r=%s", matrixToString(&r[0][0], n, n, true /*rowMajor*/).c_str());
// calculate QR, if we factored A correctly then QR should equal A
float qr[n][m];
@@ -504,7 +503,7 @@
}
}
}
- ALOGD(" - qr=%s", matrixToString(&qr[0][0], m, n, false /*rowMajor*/).string());
+ ALOGD(" - qr=%s", matrixToString(&qr[0][0], m, n, false /*rowMajor*/).c_str());
#endif
// Solve R B = Qt W Y to find B. This is easy because R is upper triangular.
@@ -522,7 +521,7 @@
outB[i] /= r[i][i];
}
#if DEBUG_STRATEGY
- ALOGD(" - b=%s", vectorToString(outB, n).string());
+ ALOGD(" - b=%s", vectorToString(outB, n).c_str());
#endif
// Calculate the coefficient of determination as 1 - (SSerr / SStot) where
@@ -608,8 +607,8 @@
#if DEBUG_STRATEGY
ALOGD("estimate: degree=%d, xCoeff=%s, yCoeff=%s, confidence=%f",
int(outEstimator->degree),
- vectorToString(outEstimator->xCoeff, n).string(),
- vectorToString(outEstimator->yCoeff, n).string(),
+ vectorToString(outEstimator->xCoeff, n).c_str(),
+ vectorToString(outEstimator->yCoeff, n).c_str(),
outEstimator->confidence);
#endif
return true;