Skip to content

Commit

Permalink
ndk/input_queue: Remove Result wrapping from has_events()
Browse files Browse the repository at this point in the history
After having blindly retained error handling in [#292], it turns out the
underlying [`InputQueue::hasEvents()` implementation] doesn't ever
return an error nor does the documentation state that this is possible.

As such, mimic what we're already doing in `fn pre_dispatch()` and panic
if the value doesn't represent a `bool`.

[`InputQueue::hasEvents()` implementation]: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/jni/android_view_InputQueue.cpp;l=88-91;drc=5497dd365e9135805636a40267cb98e2e2b78ee6
  • Loading branch information
MarijnS95 committed Jun 12, 2022
1 parent 51f5fb0 commit 4bf3edf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ndk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
- native_activity: Add `set_window_flags()` to change window behavior. (#278)
- Add `SurfaceTexture` bindings. (#267)
- Improve library and structure documentation, linking back to the NDK docs more rigorously. (#290)
- **Breaking:** input_queue: `InputQueue::{get_event,has_events}()` now return a `Result` with `std::io::Error`; `InputQueueError` has been removed. (#292)
- **Breaking:** input_queue: `get_event()` now returns a `Result` with `std::io::Error`; `InputQueueError` has been removed. (#292)
- **Breaking:** input_queue: `has_events()` now returns a `bool` directly without being wrapped in `Result`. (#294)

# 0.6.0 (2022-01-05)

Expand Down
7 changes: 3 additions & 4 deletions ndk/src/input_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ impl InputQueue {
}

/// Returns [`true`] if there are one or more events available in the input queue.
pub fn has_events(&self) -> Result<bool> {
pub fn has_events(&self) -> bool {
match unsafe { ffi::AInputQueue_hasEvents(self.ptr.as_ptr()) } {
0 => Ok(false),
1 => Ok(true),
r if r < 0 => Err(Error::from_raw_os_error(-r)),
0 => false,
1 => true,
r => unreachable!("AInputQueue_hasEvents returned non-boolean {}", r),
}
}
Expand Down

0 comments on commit 4bf3edf

Please sign in to comment.