OSDN Git Service

Fix of Settings application sort crash
authorJia Arlan <arlan.jia@sonymobile.com>
Fri, 11 May 2012 08:27:07 +0000 (16:27 +0800)
committerHenrik Baard <henrik.baard@sonymobile.com>
Mon, 21 Jan 2013 13:22:49 +0000 (14:22 +0100)
commitdffcc39ba5cd82bb28e06f0664a3ac8c5f31c33f
treee107c06b71c4b0b951b5e122d282b03f755dc594
parentf141594c0507dccd26e876bf2cd40ba15a34d68b
Fix of Settings application sort crash

The original implementation of compareTo function
will sometimes cause crash when the power usage list
above 32 items.

When comparing double values a proper comparison method
needs to be used. Using just subtraction does not take
into account NaN:S, infinities and +/-0 numbers. In certain
cirtumstances it seems that using subtraction causes
compareTo to return values that is not expected by the
sorting code and causes an illegal argument exception with
"Comparison method violates its general contract!".

This problem only happens if the sort code is called arrays
containing more than 32 (currently) due to how
ComparableTimSort works (call chain is Collections.sort ->
Arrays.sort(Object[]) -> ComparableTimSort.

Change-Id: If732f04797a3c8b2a43568c90bb73a1ec69a4c98
src/com/android/settings/fuelgauge/BatterySipper.java