Merge "Removing some more FloatMath references"
diff --git a/core/java/android/text/format/Time.java b/core/java/android/text/format/Time.java
index aa6ad20..3c90ab6 100644
--- a/core/java/android/text/format/Time.java
+++ b/core/java/android/text/format/Time.java
@@ -212,13 +212,15 @@
      * <p>
      * If "ignoreDst" is true, then this method sets the "isDst" field to -1
      * (the "unknown" value) before normalizing.  It then computes the
-     * correct value for "isDst".
+     * time in milliseconds and sets the correct value for "isDst" if the
+     * fields resolve to a valid date / time.
      *
      * <p>
      * See {@link #toMillis(boolean)} for more information about when to
-     * use <tt>true</tt> or <tt>false</tt> for "ignoreDst".
+     * use <tt>true</tt> or <tt>false</tt> for "ignoreDst" and when {@code -1}
+     * might be returned.
      *
-     * @return the UTC milliseconds since the epoch
+     * @return the UTC milliseconds since the epoch, or {@code -1}
      */
     public long normalize(boolean ignoreDst) {
         calculator.copyFieldsFromTime(this);
@@ -314,6 +316,11 @@
      * a} is less than {@code b}, a positive number if {@code a} is greater than
      * {@code b}, or 0 if they are equal.
      *
+     * <p>
+     * This method can return an incorrect answer when the date / time fields of
+     * either {@code Time} have been set to a local time that contradicts the
+     * available timezone information.
+     *
      * @param a first {@code Time} instance to compare
      * @param b second {@code Time} instance to compare
      * @throws NullPointerException if either argument is {@code null}
@@ -727,6 +734,14 @@
      * <p>
      * You should also use <tt>toMillis(false)</tt> if you want
      * to read back the same milliseconds that you set with {@link #set(long)}
+     *
+     * <p>
+     * This method can return {@code -1} when the date / time fields have been
+     * set to a local time that conflicts with available timezone information.
+     * For example, when daylight savings transitions cause an hour to be
+     * skipped: times within that hour will return {@code -1} if isDst =
+     * {@code -1}.
+     *
      * or {@link #set(Time)} or after parsing a date string.
      */
     public long toMillis(boolean ignoreDst) {
@@ -822,6 +837,10 @@
      * Returns true if the time represented by this Time object occurs before
      * the given time.
      *
+     * <p>
+     * Equivalent to {@code Time.compare(this, that) &lt; 0}. See
+     * {@link #compare(Time, Time)} for details.
+     *
      * @param that a given Time object to compare against
      * @return true if this time is less than the given time
      */
@@ -834,6 +853,10 @@
      * Returns true if the time represented by this Time object occurs after
      * the given time.
      *
+     * <p>
+     * Equivalent to {@code Time.compare(this, that) &gt; 0}. See
+     * {@link #compare(Time, Time)} for details.
+     *
      * @param that a given Time object to compare against
      * @return true if this time is greater than the given time
      */
@@ -914,6 +937,10 @@
      * Returns true if the day of the given time is the epoch on the Julian Calendar
      * (January 1, 1970 on the Gregorian calendar).
      *
+     * <p>
+     * This method can return an incorrect answer when the date / time fields have
+     * been set to a local time that contradicts the available timezone information.
+     *
      * @param time the time to test
      * @return true if epoch.
      */
diff --git a/core/java/android/util/FloatMath.java b/core/java/android/util/FloatMath.java
index 0ffd5bd..d33ca0d 100644
--- a/core/java/android/util/FloatMath.java
+++ b/core/java/android/util/FloatMath.java
@@ -17,10 +17,13 @@
 package android.util;
 
 /**
- * Math routines similar to those found in {@link java.lang.Math}. On
- * versions of Android with a JIT, these are significantly slower than
- * the equivalent {@code Math} functions, which should be used in preference
- * to these.
+ * Math routines similar to those found in {@link java.lang.Math}.
+ *
+ * <p>Historically these methods were faster than the equivalent double-based
+ * {@link java.lang.Math} methods. On versions of Android with a JIT they
+ * became slower and have since been re-implemented to wrap calls to
+ * {@link java.lang.Math}. {@link java.lang.Math} should be used in
+ * preference.
  */
 public class FloatMath {
 
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 5d10f3c..9b3b091 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -80,7 +80,6 @@
 	android_util_Binder.cpp \
 	android_util_EventLog.cpp \
 	android_util_Log.cpp \
-	android_util_FloatMath.cpp \
 	android_util_Process.cpp \
 	android_util_StringBlock.cpp \
 	android_util_XmlBlock.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 0d2cdb9..796a0c3 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -90,8 +90,6 @@
 extern int register_android_media_JetPlayer(JNIEnv *env);
 extern int register_android_media_ToneGenerator(JNIEnv *env);
 
-extern int register_android_util_FloatMath(JNIEnv* env);
-
 namespace android {
 
 /*
@@ -1229,7 +1227,6 @@
     REG_JNI(register_android_os_SystemClock),
     REG_JNI(register_android_util_EventLog),
     REG_JNI(register_android_util_Log),
-    REG_JNI(register_android_util_FloatMath),
     REG_JNI(register_android_content_AssetManager),
     REG_JNI(register_android_content_StringBlock),
     REG_JNI(register_android_content_XmlBlock),
diff --git a/core/jni/android_util_FloatMath.cpp b/core/jni/android_util_FloatMath.cpp
deleted file mode 100644
index 73b7a6f..0000000
--- a/core/jni/android_util_FloatMath.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "jni.h"
-#include <android_runtime/AndroidRuntime.h>
-#include <math.h>
-#include <float.h>
-#include "SkTypes.h"
-
-class MathUtilsGlue {
-public:
-    static float FloorF(JNIEnv* env, jobject clazz, float x) {
-        return floorf(x);
-    }
-    
-    static float CeilF(JNIEnv* env, jobject clazz, float x) {
-        return ceilf(x);
-    }
-    
-    static float SinF(JNIEnv* env, jobject clazz, float x) {
-        return sinf(x);
-    }
-    
-    static float CosF(JNIEnv* env, jobject clazz, float x) {
-        return cosf(x);
-    }
-    
-    static float SqrtF(JNIEnv* env, jobject clazz, float x) {
-        return sqrtf(x);
-    }
-
-    static float ExpF(JNIEnv* env, jobject clazz, float x) {
-        return expf(x);
-    }
-
-    static float PowF(JNIEnv* env, jobject clazz, float x, float y) {
-        return powf(x, y);
-    }
-
-    static float HypotF(JNIEnv* env, jobject clazz, float x, float y) {
-        return hypotf(x, y);
-    }
-};
-
-static JNINativeMethod gMathUtilsMethods[] = {
-    {"floor", "(F)F", (void*) MathUtilsGlue::FloorF},
-    {"ceil", "(F)F", (void*) MathUtilsGlue::CeilF},
-    {"sin", "(F)F", (void*) MathUtilsGlue::SinF},
-    {"cos", "(F)F", (void*) MathUtilsGlue::CosF},
-    {"sqrt", "(F)F", (void*) MathUtilsGlue::SqrtF},
-    {"exp", "(F)F", (void*) MathUtilsGlue::ExpF},
-    {"pow", "(FF)F", (void*) MathUtilsGlue::PowF},
-    {"hypot", "(FF)F", (void*) MathUtilsGlue::HypotF},
-};
-
-int register_android_util_FloatMath(JNIEnv* env)
-{
-    int result = android::AndroidRuntime::registerNativeMethods(env,
-                                            "android/util/FloatMath",
-                                            gMathUtilsMethods,
-                                            SK_ARRAY_COUNT(gMathUtilsMethods));
-    return result;
-}
-
diff --git a/core/tests/benchmarks/src/android/util/FloatMathBenchmark.java b/core/tests/benchmarks/src/android/util/FloatMathBenchmark.java
new file mode 100644
index 0000000..4f36492
--- /dev/null
+++ b/core/tests/benchmarks/src/android/util/FloatMathBenchmark.java
@@ -0,0 +1,103 @@
+package android.util;
+
+import com.google.caliper.Param;
+import com.google.caliper.Runner;
+import com.google.caliper.SimpleBenchmark;
+
+import android.util.FloatMath;
+
+import dalvik.system.VMDebug;
+
+public class FloatMathBenchmark extends SimpleBenchmark {
+
+    public float timeFloatMathCeil(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.ceil(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathCeil_math(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += (float) Math.ceil(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathCos(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.cos(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathExp(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.exp(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathFloor(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.floor(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathHypot(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.hypot(100.123f, 100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathPow(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.pow(10.123f, 10.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathSin(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.sin(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathSqrt(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += FloatMath.sqrt(100.123f);
+        }
+        return f;
+    }
+
+    public float timeFloatMathSqrt_math(int reps) {
+        // Keep an answer so we don't optimize the method call away.
+        float f = 0.0f;
+        for (int i = 0; i < reps; i++) {
+            f += (float) Math.sqrt(100.123f);
+        }
+        return f;
+    }
+
+}
diff --git a/services/input/tests/InputDispatcher_test.cpp b/services/input/tests/InputDispatcher_test.cpp
index 26b4fab..d132a80 100644
--- a/services/input/tests/InputDispatcher_test.cpp
+++ b/services/input/tests/InputDispatcher_test.cpp
@@ -46,16 +46,16 @@
     }
 
 private:
-    virtual void notifyConfigurationChanged(nsecs_t when) {
+    virtual void notifyConfigurationChanged(nsecs_t) {
     }
 
-    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
-            const sp<InputWindowHandle>& inputWindowHandle,
-            const String8& reason) {
+    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>&,
+            const sp<InputWindowHandle>&,
+            const String8&) {
         return 0;
     }
 
-    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
+    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>&) {
     }
 
     virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
@@ -66,35 +66,33 @@
         return true;
     }
 
-    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
+    virtual bool filterInputEvent(const InputEvent*, uint32_t) {
         return true;
     }
 
-    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) {
+    virtual void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) {
     }
 
-    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
+    virtual void interceptMotionBeforeQueueing(nsecs_t, uint32_t&) {
     }
 
-    virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags) {
+    virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>&,
+            const KeyEvent*, uint32_t) {
         return 0;
     }
 
-    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
+    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>&,
+            const KeyEvent*, uint32_t, KeyEvent*) {
         return false;
     }
 
-    virtual void notifySwitch(nsecs_t when,
-            uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
+    virtual void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) {
     }
 
-    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
+    virtual void pokeUserActivity(nsecs_t, int32_t) {
     }
 
-    virtual bool checkInjectEventsPermissionNonReentrant(
-            int32_t injectorPid, int32_t injectorUid) {
+    virtual bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) {
         return false;
     }
 };
diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp
index f068732..9aa7cc40 100644
--- a/services/input/tests/InputReader_test.cpp
+++ b/services/input/tests/InputReader_test.cpp
@@ -104,17 +104,16 @@
         if (mY > mMaxY) mY = mMaxY;
     }
 
-    virtual void fade(Transition transition) {
+    virtual void fade(Transition) {
     }
 
-    virtual void unfade(Transition transition) {
+    virtual void unfade(Transition) {
     }
 
-    virtual void setPresentation(Presentation presentation) {
+    virtual void setPresentation(Presentation) {
     }
 
-    virtual void setSpots(const PointerCoords* spotCoords,
-            const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
+    virtual void setSpots(const PointerCoords*, const uint32_t*, BitSet32) {
     }
 
     virtual void clearSpots() {
@@ -186,11 +185,11 @@
         mInputDevices = inputDevices;
     }
 
-    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) {
+    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8&) {
         return NULL;
     }
 
-    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) {
+    virtual String8 getDeviceAlias(const InputDeviceIdentifier&) {
         return String8::empty();
     }
 };
@@ -472,7 +471,7 @@
         return device ? device->identifier : InputDeviceIdentifier();
     }
 
-    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const {
+    virtual int32_t getDeviceControllerNumber(int32_t) const {
         return 0;
     }
 
@@ -505,7 +504,7 @@
         return false;
     }
 
-    virtual bool hasInputProperty(int32_t deviceId, int property) const {
+    virtual bool hasInputProperty(int32_t, int) const {
         return false;
     }
 
@@ -543,8 +542,7 @@
         return NULL;
     }
 
-    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
-            AxisInfo* outAxisInfo) const {
+    virtual status_t mapAxis(int32_t, int32_t, AxisInfo*) const {
         return NAME_NOT_FOUND;
     }
 
@@ -552,7 +550,7 @@
         mExcludedDevices = devices;
     }
 
-    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
+    virtual size_t getEvents(int, RawEvent* buffer, size_t) {
         if (mEvents.empty()) {
             return 0;
         }
@@ -670,25 +668,25 @@
         }
     }
 
-    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const {
+    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t) const {
         return NULL;
     }
 
-    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) {
+    virtual bool setKeyboardLayoutOverlay(int32_t, const sp<KeyCharacterMap>&) {
         return false;
     }
 
-    virtual void vibrate(int32_t deviceId, nsecs_t duration) {
+    virtual void vibrate(int32_t, nsecs_t) {
     }
 
-    virtual void cancelVibrate(int32_t deviceId) {
+    virtual void cancelVibrate(int32_t) {
     }
 
-    virtual bool isExternal(int32_t deviceId) const {
+    virtual bool isExternal(int32_t) const {
         return false;
     }
 
-    virtual void dump(String8& dump) {
+    virtual void dump(String8&) {
     }
 
     virtual void monitor() {
@@ -753,18 +751,17 @@
         return mListener.get();
     }
 
-    virtual void disableVirtualKeysUntil(nsecs_t time) {
+    virtual void disableVirtualKeysUntil(nsecs_t) {
     }
 
-    virtual bool shouldDropVirtualKey(nsecs_t now,
-            InputDevice* device, int32_t keyCode, int32_t scanCode) {
+    virtual bool shouldDropVirtualKey(nsecs_t, InputDevice*, int32_t, int32_t) {
         return false;
     }
 
     virtual void fadePointer() {
     }
 
-    virtual void requestTimeoutAtTime(nsecs_t when) {
+    virtual void requestTimeoutAtTime(nsecs_t) {
     }
 
     virtual int32_t bumpGeneration() {
@@ -857,12 +854,11 @@
         }
     }
 
-    virtual void configure(nsecs_t when,
-            const InputReaderConfiguration* config, uint32_t changes) {
+    virtual void configure(nsecs_t, const InputReaderConfiguration*, uint32_t) {
         mConfigureWasCalled = true;
     }
 
-    virtual void reset(nsecs_t when) {
+    virtual void reset(nsecs_t) {
         mResetWasCalled = true;
     }
 
@@ -871,22 +867,22 @@
         mProcessWasCalled = true;
     }
 
-    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
+    virtual int32_t getKeyCodeState(uint32_t, int32_t keyCode) {
         ssize_t index = mKeyCodeStates.indexOfKey(keyCode);
         return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
     }
 
-    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+    virtual int32_t getScanCodeState(uint32_t, int32_t scanCode) {
         ssize_t index = mScanCodeStates.indexOfKey(scanCode);
         return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
     }
 
-    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode) {
+    virtual int32_t getSwitchState(uint32_t, int32_t switchCode) {
         ssize_t index = mSwitchStates.indexOfKey(switchCode);
         return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN;
     }
 
-    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+    virtual bool markSupportedKeyCodes(uint32_t, size_t numCodes,
             const int32_t* keyCodes, uint8_t* outFlags) {
         bool result = false;
         for (size_t i = 0; i < numCodes; i++) {
@@ -1526,7 +1522,7 @@
 };
 
 void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper,
-        int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode) {
+        int32_t originalScanCode, int32_t, int32_t rotatedKeyCode) {
     NotifyKeyArgs args;
 
     process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 1);
diff --git a/services/jni/com_android_server_AlarmManagerService.cpp b/services/jni/com_android_server_AlarmManagerService.cpp
index a58b00bce..3d981ab 100644
--- a/services/jni/com_android_server_AlarmManagerService.cpp
+++ b/services/jni/com_android_server_AlarmManagerService.cpp
@@ -290,7 +290,7 @@
 
     epollfd = epoll_create(N_ANDROID_TIMERFDS);
     if (epollfd < 0) {
-        ALOGV("epoll_create(%u) failed: %s", N_ANDROID_TIMERFDS,
+        ALOGV("epoll_create(%zu) failed: %s", N_ANDROID_TIMERFDS,
                 strerror(errno));
         return 0;
     }
diff --git a/services/jni/com_android_server_input_InputManagerService.cpp b/services/jni/com_android_server_input_InputManagerService.cpp
index facd8df..3b4b4d8 100644
--- a/services/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/jni/com_android_server_input_InputManagerService.cpp
@@ -1244,7 +1244,7 @@
 
     size_t patternSize = env->GetArrayLength(patternObj);
     if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
-        ALOGI("Skipped requested vibration because the pattern size is %d "
+        ALOGI("Skipped requested vibration because the pattern size is %zd "
                 "which is more than the maximum supported size of %d.",
                 patternSize, MAX_VIBRATE_PATTERN_SIZE);
         return; // limit to reasonable size