Merge changes I5058cbe8,Ia0b3f1c9
* changes:
adb-remount-test: Strengthen skip_administrative_mounts
fs_mgr_overlayfs_mount_fstab_entry(): Rename source device name
diff --git a/libutils/Timers.cpp b/libutils/Timers.cpp
index fd3f4a9..4cfac57 100644
--- a/libutils/Timers.cpp
+++ b/libutils/Timers.cpp
@@ -14,9 +14,6 @@
* limitations under the License.
*/
-//
-// Timer functions.
-//
#include <utils/Timers.h>
#include <limits.h>
@@ -24,11 +21,12 @@
#include <time.h>
#include <android-base/macros.h>
+#include <utils/Log.h>
static constexpr size_t clock_id_max = 5;
static void checkClockId(int clock) {
- if (clock < 0 || clock >= clock_id_max) abort();
+ LOG_ALWAYS_FATAL_IF(clock < 0 || clock >= clock_id_max, "invalid clock id");
}
#if defined(__linux__)
@@ -56,18 +54,10 @@
}
#endif
-int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime)
-{
- nsecs_t timeoutDelayMillis;
- if (timeoutTime > referenceTime) {
- uint64_t timeoutDelay = uint64_t(timeoutTime - referenceTime);
- if (timeoutDelay > uint64_t((INT_MAX - 1) * 1000000LL)) {
- timeoutDelayMillis = -1;
- } else {
- timeoutDelayMillis = (timeoutDelay + 999999LL) / 1000000LL;
- }
- } else {
- timeoutDelayMillis = 0;
- }
- return (int)timeoutDelayMillis;
+int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime) {
+ if (timeoutTime <= referenceTime) return 0;
+
+ uint64_t timeoutDelay = uint64_t(timeoutTime - referenceTime);
+ if (timeoutDelay > uint64_t((INT_MAX - 1) * 1000000LL)) return -1;
+ return (timeoutDelay + 999999LL) / 1000000LL;
}
diff --git a/libutils/Timers_test.cpp b/libutils/Timers_test.cpp
index ec0051e..c0a6d49 100644
--- a/libutils/Timers_test.cpp
+++ b/libutils/Timers_test.cpp
@@ -27,3 +27,12 @@
systemTime(SYSTEM_TIME_BOOTTIME);
EXPECT_EXIT(systemTime(SYSTEM_TIME_BOOTTIME + 1), testing::KilledBySignal(SIGABRT), "");
}
+
+TEST(Timers, toMillisecondTimeoutDelay) {
+ EXPECT_EQ(0, toMillisecondTimeoutDelay(100, 100));
+ EXPECT_EQ(0, toMillisecondTimeoutDelay(100, 10));
+
+ EXPECT_EQ(-1, toMillisecondTimeoutDelay(0, INT_MAX * 1000000LL));
+
+ EXPECT_EQ(123, toMillisecondTimeoutDelay(0, 123000000));
+}
diff --git a/libutils/include/utils/KeyedVector.h b/libutils/include/utils/KeyedVector.h
index 7bda99b..5cf7a11 100644
--- a/libutils/include/utils/KeyedVector.h
+++ b/libutils/include/utils/KeyedVector.h
@@ -47,7 +47,7 @@
inline void clear() { mVector.clear(); }
- /*!
+ /*!
* vector stats
*/
@@ -63,14 +63,14 @@
// returns true if the arguments is known to be identical to this vector
inline bool isIdenticalTo(const KeyedVector& rhs) const;
- /*!
+ /*!
* accessors
*/
- const VALUE& valueFor(const KEY& key) const;
- const VALUE& valueAt(size_t index) const;
- const KEY& keyAt(size_t index) const;
- ssize_t indexOfKey(const KEY& key) const;
- const VALUE& operator[] (size_t index) const;
+ const VALUE& valueFor(const KEY& key) const;
+ const VALUE& valueAt(size_t index) const;
+ const KEY& keyAt(size_t index) const;
+ ssize_t indexOfKey(const KEY& key) const;
+ const VALUE& operator[](size_t index) const;
/*!
* modifying the array
@@ -79,10 +79,10 @@
VALUE& editValueFor(const KEY& key);
VALUE& editValueAt(size_t index);
- /*!
+ /*!
* add/insert/replace items
*/
-
+
ssize_t add(const KEY& key, const VALUE& item);
ssize_t replaceValueFor(const KEY& key, const VALUE& item);
ssize_t replaceValueAt(size_t index, const VALUE& item);
@@ -93,7 +93,7 @@
ssize_t removeItem(const KEY& key);
ssize_t removeItemsAt(size_t index, size_t count = 1);
-
+
private:
SortedVector< key_value_pair_t<KEY, VALUE> > mVector;
};
@@ -208,7 +208,7 @@
template<typename KEY, typename VALUE> inline
const VALUE& DefaultKeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
ssize_t i = this->indexOfKey(key);
- return i >= 0 ? KeyedVector<KEY,VALUE>::valueAt(i) : mDefault;
+ return i >= 0 ? KeyedVector<KEY, VALUE>::valueAt(static_cast<size_t>(i)) : mDefault;
}
} // namespace android