Skip to content

Commit e7d4b4d

Browse files
committedJul 5, 2022
ndk/input_queue: Remove Result wrapping from has_events()
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 [#292]: #292
1 parent dc38fcb commit e7d4b4d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed
 

‎ndk-examples/examples/looper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn main() {
116116
ndk_glue::NDK_GLUE_LOOPER_INPUT_QUEUE_IDENT => {
117117
let input_queue = ndk_glue::input_queue();
118118
let input_queue = input_queue.as_ref().expect("Input queue not attached");
119-
assert!(input_queue.has_events().unwrap());
119+
assert!(input_queue.has_events());
120120
// Consume as many events as possible
121121
while let Some(event) = input_queue.get_event().unwrap() {
122122
// Pass the event by a possible IME (Input Method Editor, ie. an open keyboard) first

‎ndk/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
- native_activity: Add `set_window_flags()` to change window behavior. (#278)
1414
- Add `SurfaceTexture` bindings. (#267)
1515
- Improve library and structure documentation, linking back to the NDK docs more rigorously. (#290)
16-
- **Breaking:** input_queue: `InputQueue::{get_event,has_events}()` now return a `Result` with `std::io::Error`; `InputQueueError` has been removed. (#292)
16+
- **Breaking:** input_queue: `get_event()` now returns a `Result` with `std::io::Error`; `InputQueueError` has been removed. (#292)
17+
- **Breaking:** input_queue: `has_events()` now returns a `bool` directly without being wrapped in `Result`. (#294)
1718
- **Breaking:** Update `jni` crate (used in public API) from `0.18` to `0.19`. (#300)
1819

1920
# 0.6.0 (2022-01-05)

‎ndk/src/input_queue.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ impl InputQueue {
5959
}
6060

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

0 commit comments

Comments
 (0)