Loading include/android/choreographer.h +1 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ #define __INTRODUCED_IN(__api_level) /* nothing */ #endif #if !defined(__DEPRECATED_IN) #define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__)) #define __DEPRECATED_IN(__api_level, ...) __attribute__((__deprecated__)) #endif __BEGIN_DECLS Loading include/ftl/algorithm.h +12 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,18 @@ namespace android::ftl { // Determines if a container contains a value. This is a simplified version of the C++23 // std::ranges::contains function. // // const ftl::StaticVector vector = {1, 2, 3}; // assert(ftl::contains(vector, 1)); // // TODO: Remove in C++23. template <typename Container, typename Value> auto contains(const Container& container, const Value& value) -> bool { return std::find(container.begin(), container.end(), value) != container.end(); } // Adapter for std::find_if that converts the return value from iterator to optional. // // const ftl::StaticVector vector = {"upside"sv, "down"sv, "cake"sv}; Loading include/ftl/non_null.h +104 −8 Original line number Diff line number Diff line Loading @@ -68,26 +68,28 @@ class NonNull final { constexpr NonNull(const NonNull&) = default; constexpr NonNull& operator=(const NonNull&) = default; constexpr const Pointer& get() const { return pointer_; } constexpr explicit operator const Pointer&() const { return get(); } [[nodiscard]] constexpr const Pointer& get() const { return pointer_; } [[nodiscard]] constexpr explicit operator const Pointer&() const { return get(); } // Move operations. These break the invariant, so care must be taken to avoid subsequent access. constexpr NonNull(NonNull&&) = default; constexpr NonNull& operator=(NonNull&&) = default; constexpr Pointer take() && { return std::move(pointer_); } constexpr explicit operator Pointer() && { return take(); } [[nodiscard]] constexpr Pointer take() && { return std::move(pointer_); } [[nodiscard]] constexpr explicit operator Pointer() && { return take(); } // Dereferencing. constexpr decltype(auto) operator*() const { return *get(); } constexpr decltype(auto) operator->() const { return get(); } [[nodiscard]] constexpr decltype(auto) operator*() const { return *get(); } [[nodiscard]] constexpr decltype(auto) operator->() const { return get(); } [[nodiscard]] constexpr explicit operator bool() const { return !(pointer_ == nullptr); } // Private constructor for ftl::as_non_null. Excluded from candidate constructors for conversions // through the passkey idiom, for clear compilation errors. template <typename P> constexpr NonNull(Passkey, P&& pointer) : pointer_(std::forward<P>(pointer)) { if (!pointer_) std::abort(); if (pointer_ == nullptr) std::abort(); } private: Loading @@ -98,11 +100,13 @@ class NonNull final { }; template <typename P> constexpr auto as_non_null(P&& pointer) -> NonNull<std::decay_t<P>> { [[nodiscard]] constexpr auto as_non_null(P&& pointer) -> NonNull<std::decay_t<P>> { using Passkey = typename NonNull<std::decay_t<P>>::Passkey; return {Passkey{}, std::forward<P>(pointer)}; } // NonNull<P> <=> NonNull<Q> template <typename P, typename Q> constexpr bool operator==(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() == rhs.get(); Loading @@ -113,4 +117,96 @@ constexpr bool operator!=(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return !operator==(lhs, rhs); } template <typename P, typename Q> constexpr bool operator<(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() < rhs.get(); } template <typename P, typename Q> constexpr bool operator<=(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() <= rhs.get(); } template <typename P, typename Q> constexpr bool operator>=(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() >= rhs.get(); } template <typename P, typename Q> constexpr bool operator>(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() > rhs.get(); } // NonNull<P> <=> Q template <typename P, typename Q> constexpr bool operator==(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() == rhs; } template <typename P, typename Q> constexpr bool operator!=(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() != rhs; } template <typename P, typename Q> constexpr bool operator<(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() < rhs; } template <typename P, typename Q> constexpr bool operator<=(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() <= rhs; } template <typename P, typename Q> constexpr bool operator>=(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() >= rhs; } template <typename P, typename Q> constexpr bool operator>(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() > rhs; } // P <=> NonNull<Q> template <typename P, typename Q> constexpr bool operator==(const P& lhs, const NonNull<Q>& rhs) { return lhs == rhs.get(); } template <typename P, typename Q> constexpr bool operator!=(const P& lhs, const NonNull<Q>& rhs) { return lhs != rhs.get(); } template <typename P, typename Q> constexpr bool operator<(const P& lhs, const NonNull<Q>& rhs) { return lhs < rhs.get(); } template <typename P, typename Q> constexpr bool operator<=(const P& lhs, const NonNull<Q>& rhs) { return lhs <= rhs.get(); } template <typename P, typename Q> constexpr bool operator>=(const P& lhs, const NonNull<Q>& rhs) { return lhs >= rhs.get(); } template <typename P, typename Q> constexpr bool operator>(const P& lhs, const NonNull<Q>& rhs) { return lhs > rhs.get(); } } // namespace android::ftl // Specialize std::hash for ftl::NonNull<T> template <typename P> struct std::hash<android::ftl::NonNull<P>> { std::size_t operator()(const android::ftl::NonNull<P>& ptr) const { return std::hash<P>()(ptr.get()); } }; include/input/Input.h +19 −11 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ enum { #ifdef __linux__ /* This event was generated or modified by accessibility service. */ AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, // 0x800, android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, #else AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800, #endif Loading @@ -54,11 +54,11 @@ enum { AKEY_EVENT_FLAG_START_TRACKING = 0x40000000, /* Key event is inconsistent with previously sent key events. */ AKEY_EVENT_FLAG_TAINTED = 0x80000000, AKEY_EVENT_FLAG_TAINTED = android::os::IInputConstants::INPUT_EVENT_FLAG_TAINTED, }; enum { // AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED is defined in include/android/input.h /** * This flag indicates that the window that received this motion event is partly * or wholly obscured by another visible window above it. This flag is set to true Loading @@ -69,13 +69,16 @@ enum { * to drop the suspect touches or to take additional precautions to confirm the user's * actual intent. */ AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = android::os::IInputConstants::MOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED, AMOTION_EVENT_FLAG_HOVER_EXIT_PENDING = android::os::IInputConstants::MOTION_EVENT_FLAG_HOVER_EXIT_PENDING, /** * This flag indicates that the event has been generated by a gesture generator. It * provides a hint to the GestureDetector to not apply any touch slop. */ AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8, AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = android::os::IInputConstants::MOTION_EVENT_FLAG_IS_GENERATED_GESTURE, /** * This flag indicates that the event will not cause a focus change if it is directed to an Loading @@ -83,20 +86,24 @@ enum { * gestures to allow the user to direct gestures to an unfocused window without bringing it * into focus. */ AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = 0x40, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = android::os::IInputConstants::MOTION_EVENT_FLAG_NO_FOCUS_CHANGE, #if defined(__linux__) /** * This event was generated or modified by accessibility service. */ AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, // 0x800, android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, #else AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800, #endif AMOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS = android::os::IInputConstants::MOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS, /* Motion event is inconsistent with previously sent motion events. */ AMOTION_EVENT_FLAG_TAINTED = 0x80000000, AMOTION_EVENT_FLAG_TAINTED = android::os::IInputConstants::INPUT_EVENT_FLAG_TAINTED, }; /** Loading @@ -116,9 +123,10 @@ constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS = AMOTION_EVENT_FLAG_WINDOW_IS_OBS /** * This flag indicates that the point up event has been canceled. * Typically this is used for palm event when the user has accidental touches. * TODO: Adjust flag to public api * TODO(b/338143308): Add this to NDK */ constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20; constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = android::os::IInputConstants::INPUT_EVENT_FLAG_CANCELED; enum { /* Loading include/input/InputDevice.h +2 −1 Original line number Diff line number Diff line Loading @@ -130,8 +130,9 @@ enum class InputDeviceLightType : int32_t { INPUT = 0, PLAYER_ID = 1, KEYBOARD_BACKLIGHT = 2, KEYBOARD_MIC_MUTE = 3, ftl_last = KEYBOARD_BACKLIGHT ftl_last = KEYBOARD_MIC_MUTE }; enum class InputDeviceLightCapability : uint32_t { Loading Loading
include/android/choreographer.h +1 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ #define __INTRODUCED_IN(__api_level) /* nothing */ #endif #if !defined(__DEPRECATED_IN) #define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__)) #define __DEPRECATED_IN(__api_level, ...) __attribute__((__deprecated__)) #endif __BEGIN_DECLS Loading
include/ftl/algorithm.h +12 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,18 @@ namespace android::ftl { // Determines if a container contains a value. This is a simplified version of the C++23 // std::ranges::contains function. // // const ftl::StaticVector vector = {1, 2, 3}; // assert(ftl::contains(vector, 1)); // // TODO: Remove in C++23. template <typename Container, typename Value> auto contains(const Container& container, const Value& value) -> bool { return std::find(container.begin(), container.end(), value) != container.end(); } // Adapter for std::find_if that converts the return value from iterator to optional. // // const ftl::StaticVector vector = {"upside"sv, "down"sv, "cake"sv}; Loading
include/ftl/non_null.h +104 −8 Original line number Diff line number Diff line Loading @@ -68,26 +68,28 @@ class NonNull final { constexpr NonNull(const NonNull&) = default; constexpr NonNull& operator=(const NonNull&) = default; constexpr const Pointer& get() const { return pointer_; } constexpr explicit operator const Pointer&() const { return get(); } [[nodiscard]] constexpr const Pointer& get() const { return pointer_; } [[nodiscard]] constexpr explicit operator const Pointer&() const { return get(); } // Move operations. These break the invariant, so care must be taken to avoid subsequent access. constexpr NonNull(NonNull&&) = default; constexpr NonNull& operator=(NonNull&&) = default; constexpr Pointer take() && { return std::move(pointer_); } constexpr explicit operator Pointer() && { return take(); } [[nodiscard]] constexpr Pointer take() && { return std::move(pointer_); } [[nodiscard]] constexpr explicit operator Pointer() && { return take(); } // Dereferencing. constexpr decltype(auto) operator*() const { return *get(); } constexpr decltype(auto) operator->() const { return get(); } [[nodiscard]] constexpr decltype(auto) operator*() const { return *get(); } [[nodiscard]] constexpr decltype(auto) operator->() const { return get(); } [[nodiscard]] constexpr explicit operator bool() const { return !(pointer_ == nullptr); } // Private constructor for ftl::as_non_null. Excluded from candidate constructors for conversions // through the passkey idiom, for clear compilation errors. template <typename P> constexpr NonNull(Passkey, P&& pointer) : pointer_(std::forward<P>(pointer)) { if (!pointer_) std::abort(); if (pointer_ == nullptr) std::abort(); } private: Loading @@ -98,11 +100,13 @@ class NonNull final { }; template <typename P> constexpr auto as_non_null(P&& pointer) -> NonNull<std::decay_t<P>> { [[nodiscard]] constexpr auto as_non_null(P&& pointer) -> NonNull<std::decay_t<P>> { using Passkey = typename NonNull<std::decay_t<P>>::Passkey; return {Passkey{}, std::forward<P>(pointer)}; } // NonNull<P> <=> NonNull<Q> template <typename P, typename Q> constexpr bool operator==(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() == rhs.get(); Loading @@ -113,4 +117,96 @@ constexpr bool operator!=(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return !operator==(lhs, rhs); } template <typename P, typename Q> constexpr bool operator<(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() < rhs.get(); } template <typename P, typename Q> constexpr bool operator<=(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() <= rhs.get(); } template <typename P, typename Q> constexpr bool operator>=(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() >= rhs.get(); } template <typename P, typename Q> constexpr bool operator>(const NonNull<P>& lhs, const NonNull<Q>& rhs) { return lhs.get() > rhs.get(); } // NonNull<P> <=> Q template <typename P, typename Q> constexpr bool operator==(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() == rhs; } template <typename P, typename Q> constexpr bool operator!=(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() != rhs; } template <typename P, typename Q> constexpr bool operator<(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() < rhs; } template <typename P, typename Q> constexpr bool operator<=(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() <= rhs; } template <typename P, typename Q> constexpr bool operator>=(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() >= rhs; } template <typename P, typename Q> constexpr bool operator>(const NonNull<P>& lhs, const Q& rhs) { return lhs.get() > rhs; } // P <=> NonNull<Q> template <typename P, typename Q> constexpr bool operator==(const P& lhs, const NonNull<Q>& rhs) { return lhs == rhs.get(); } template <typename P, typename Q> constexpr bool operator!=(const P& lhs, const NonNull<Q>& rhs) { return lhs != rhs.get(); } template <typename P, typename Q> constexpr bool operator<(const P& lhs, const NonNull<Q>& rhs) { return lhs < rhs.get(); } template <typename P, typename Q> constexpr bool operator<=(const P& lhs, const NonNull<Q>& rhs) { return lhs <= rhs.get(); } template <typename P, typename Q> constexpr bool operator>=(const P& lhs, const NonNull<Q>& rhs) { return lhs >= rhs.get(); } template <typename P, typename Q> constexpr bool operator>(const P& lhs, const NonNull<Q>& rhs) { return lhs > rhs.get(); } } // namespace android::ftl // Specialize std::hash for ftl::NonNull<T> template <typename P> struct std::hash<android::ftl::NonNull<P>> { std::size_t operator()(const android::ftl::NonNull<P>& ptr) const { return std::hash<P>()(ptr.get()); } };
include/input/Input.h +19 −11 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ enum { #ifdef __linux__ /* This event was generated or modified by accessibility service. */ AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, // 0x800, android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, #else AKEY_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800, #endif Loading @@ -54,11 +54,11 @@ enum { AKEY_EVENT_FLAG_START_TRACKING = 0x40000000, /* Key event is inconsistent with previously sent key events. */ AKEY_EVENT_FLAG_TAINTED = 0x80000000, AKEY_EVENT_FLAG_TAINTED = android::os::IInputConstants::INPUT_EVENT_FLAG_TAINTED, }; enum { // AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED is defined in include/android/input.h /** * This flag indicates that the window that received this motion event is partly * or wholly obscured by another visible window above it. This flag is set to true Loading @@ -69,13 +69,16 @@ enum { * to drop the suspect touches or to take additional precautions to confirm the user's * actual intent. */ AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = android::os::IInputConstants::MOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED, AMOTION_EVENT_FLAG_HOVER_EXIT_PENDING = android::os::IInputConstants::MOTION_EVENT_FLAG_HOVER_EXIT_PENDING, /** * This flag indicates that the event has been generated by a gesture generator. It * provides a hint to the GestureDetector to not apply any touch slop. */ AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8, AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = android::os::IInputConstants::MOTION_EVENT_FLAG_IS_GENERATED_GESTURE, /** * This flag indicates that the event will not cause a focus change if it is directed to an Loading @@ -83,20 +86,24 @@ enum { * gestures to allow the user to direct gestures to an unfocused window without bringing it * into focus. */ AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = 0x40, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = android::os::IInputConstants::MOTION_EVENT_FLAG_NO_FOCUS_CHANGE, #if defined(__linux__) /** * This event was generated or modified by accessibility service. */ AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, // 0x800, android::os::IInputConstants::INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT, #else AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800, #endif AMOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS = android::os::IInputConstants::MOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS, /* Motion event is inconsistent with previously sent motion events. */ AMOTION_EVENT_FLAG_TAINTED = 0x80000000, AMOTION_EVENT_FLAG_TAINTED = android::os::IInputConstants::INPUT_EVENT_FLAG_TAINTED, }; /** Loading @@ -116,9 +123,10 @@ constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS = AMOTION_EVENT_FLAG_WINDOW_IS_OBS /** * This flag indicates that the point up event has been canceled. * Typically this is used for palm event when the user has accidental touches. * TODO: Adjust flag to public api * TODO(b/338143308): Add this to NDK */ constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20; constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = android::os::IInputConstants::INPUT_EVENT_FLAG_CANCELED; enum { /* Loading
include/input/InputDevice.h +2 −1 Original line number Diff line number Diff line Loading @@ -130,8 +130,9 @@ enum class InputDeviceLightType : int32_t { INPUT = 0, PLAYER_ID = 1, KEYBOARD_BACKLIGHT = 2, KEYBOARD_MIC_MUTE = 3, ftl_last = KEYBOARD_BACKLIGHT ftl_last = KEYBOARD_MIC_MUTE }; enum class InputDeviceLightCapability : uint32_t { Loading