diff --git a/android-activity/CHANGELOG.md b/android-activity/CHANGELOG.md index f26262b..a4d752b 100644 --- a/android-activity/CHANGELOG.md +++ b/android-activity/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - *Breaking*: `AndroidApp::config()` now returns a clonable `ConfigurationRef` instead of a deep `Configuration` copy ### Removed - The `NativeWindowRef` wrapper struct was removed since `NativeWindow` now implements `Clone` and `Drop` in `ndk 0.7` +- *Breaking*: The `FdEvent` and `Error` enum values were removed from `PollEvents` ## [0.1.1] - 2022-07-04 ### Changed diff --git a/android-activity/src/game_activity/mod.rs b/android-activity/src/game_activity/mod.rs index de9440d..c551dae 100644 --- a/android-activity/src/game_activity/mod.rs +++ b/android-activity/src/game_activity/mod.rs @@ -21,7 +21,6 @@ use ndk_sys::{ALooper, ALooper_pollAll}; use ndk::asset::AssetManager; use ndk::configuration::Configuration; -use ndk::looper::FdEvent; use ndk::native_window::NativeWindow; use crate::{util, AndroidApp, ConfigurationRef, MainEvent, PollEvent, Rect}; @@ -204,14 +203,9 @@ impl AndroidAppInner { callback(PollEvent::Timeout); } ffi::ALOOPER_POLL_ERROR => { - trace!("ALooper_pollAll returned POLL_ERROR"); - callback(PollEvent::Error); - - // Considering that this API is quite likely to be used in `android_main` - // it's rather unergonomic to require the call to unwrap a Result for each - // call to poll_events(). Alternatively we could maybe even just panic!() - // here, while it's hard to imagine practically being able to recover - //return Err(LooperError); + // If we have an IO error with our pipe to the main Java thread that's surely + // not something we can recover from + panic!("ALooper_pollAll returned POLL_ERROR"); } id if id >= 0 => { match id as u32 { @@ -304,17 +298,7 @@ impl AndroidAppInner { } } _ => { - let events = FdEvent::from_bits(events as u32).expect(&format!( - "Spurious ALooper_pollAll event flags {:#04x}", - events as u32 - )); - trace!("Custom ALooper event source: id = {id}, fd = {fd}, events = {events:?}, data = {source:?}"); - callback(PollEvent::FdEvent { - ident: id, - fd: fd as RawFd, - events, - data: source, - }); + error!("Ignoring spurious ALooper event source: id = {id}, fd = {fd}, events = {events:?}, data = {source:?}"); } } } diff --git a/android-activity/src/lib.rs b/android-activity/src/lib.rs index b98e8f1..4317f7a 100644 --- a/android-activity/src/lib.rs +++ b/android-activity/src/lib.rs @@ -1,12 +1,9 @@ use std::hash::Hash; +use std::sync::Arc; use std::sync::RwLock; use std::time::Duration; -use std::{os::unix::prelude::RawFd, sync::Arc}; use ndk::asset::AssetManager; -// TODO: import FdEvent and avoid depending on ndk Looper abstraction in case we want to -// support using epoll directly in the future. -use ndk::looper::FdEvent; use ndk::native_window::NativeWindow; #[cfg(not(target_os = "android"))] @@ -160,16 +157,6 @@ pub enum PollEvent<'a> { Wake, Timeout, Main(MainEvent<'a>), - - #[non_exhaustive] - FdEvent { - ident: i32, - fd: RawFd, - events: FdEvent, - data: *mut std::ffi::c_void, - }, - - Error, } use activity_impl::AndroidAppInner; @@ -210,8 +197,8 @@ impl AndroidApp { self.inner.read().unwrap().native_window() } - /// Calls [`ALooper_pollAll`] on the looper associated with this AndroidApp as well - /// as processing any events (such as lifecycle events) via the given `callback`. + /// Polls for any events associated with this AndroidApp and processes those events + /// (such as lifecycle events) via the given `callback`. /// /// It's important to use this API for polling, and not call [`ALooper_pollAll`] directly since /// some events require pre- and post-processing either side of the callback. For correct @@ -230,9 +217,6 @@ impl AndroidApp { /// Creates a means to wake up the main loop while it is blocked waiting for /// events within [`poll_events()`]. - /// - /// Internally this uses [`ALooper_wake`] on the looper associated with this - /// [AndroidApp]. pub fn create_waker(&self) -> activity_impl::AndroidAppWaker { self.inner.read().unwrap().create_waker() } diff --git a/android-activity/src/native_activity/mod.rs b/android-activity/src/native_activity/mod.rs index e32845b..552dd34 100644 --- a/android-activity/src/native_activity/mod.rs +++ b/android-activity/src/native_activity/mod.rs @@ -19,7 +19,6 @@ use ndk_sys::{ALooper, ALooper_pollAll}; use ndk::asset::AssetManager; use ndk::configuration::Configuration; use ndk::input_queue::InputQueue; -use ndk::looper::FdEvent; use ndk::native_window::NativeWindow; use crate::{util, AndroidApp, ConfigurationRef, MainEvent, PollEvent, Rect}; @@ -208,14 +207,9 @@ impl AndroidAppInner { callback(PollEvent::Timeout); } ffi::ALOOPER_POLL_ERROR => { - trace!("ALooper_pollAll returned POLL_ERROR"); - callback(PollEvent::Error); - - // Considering that this API is quite likely to be used in `android_main` - // it's rather unergonomic to require the call to unwrap a Result for each - // call to poll_events(). Alternatively we could maybe even just panic!() - // here, while it's hard to imagine practically being able to recover - //return Err(LooperError); + // If we have an IO error with our pipe to the main Java thread that's surely + // not something we can recover from + panic!("ALooper_pollAll returned POLL_ERROR"); } id if id >= 0 => { match id as u32 { @@ -313,17 +307,7 @@ impl AndroidAppInner { callback(PollEvent::Main(MainEvent::InputAvailable)) } _ => { - let events = FdEvent::from_bits(events as u32).expect(&format!( - "Spurious ALooper_pollAll event flags {:#04x}", - events as u32 - )); - trace!("Custom ALooper event source: id = {id}, fd = {fd}, events = {events:?}, data = {source:?}"); - callback(PollEvent::FdEvent { - ident: id, - fd: fd as RawFd, - events, - data: source, - }); + error!("Ignoring spurious ALooper event source: id = {id}, fd = {fd}, events = {events:?}, data = {source:?}"); } } }