API Reference
Generated from the source, so the contracts here are the ones the code runs. PHONE_NATIVE is left out: nothing in it is public.
SIMPLE_EIF_PHONE
The app's one handle on the phone. Eiffel owns the loop: `wait_for_event' / `poll_event' deliver `last_event', and before they return, `lifecycle' and `touches' have already applied it. There are no callbacks into Eiffel: the C glue queues, Eiffel pulls. One handle per process; when the app's root returns, the glue finishes the activity and ends the process (research D-012).
Constants
Back_system: INTEGER = 0
Android also handles Back (finishes the app); the key is still delivered.
Back_app: INTEGER = 1
Back is consumed; only the app reacts.
Events
wait_for_event
Block until an event arrives; it becomes `last_event'.
Requires
Ensures
poll_event (a_timeout_ms: INTEGER)
Wait at most `a_timeout_ms'; `last_event' is none on timeout.
Requires
Ensures
delivery_count: INTEGER
Events delivered so far (the C side's count of taken events).
Ensures
is_metric_kind (a_k: INTEGER): BOOLEAN
Does an event of kind `a_k' make `metrics' re-read Android?
last_event: PHONE_EVENT
Most recent delivery (none before the first, or after a timeout).
dropped_event_count: INTEGER
Touch moves dropped on queue overflow so far (never lifecycle or key events).
Ensures
State
lifecycle: PHONE_LIFECYCLE
Where the app is in Android's life, including `last_event'.
touches: PHONE_TOUCHES
Fingers down, including `last_event'.
handle_exists: BOOLEAN
Has this process claimed its platform handle?
Services
screen: PHONE_SCREEN
metrics: PHONE_METRICS
storage: PHONE_STORAGE
assets: PHONE_ASSETS
log: PHONE_LOG
Behavior
back_policy: INTEGER
`Back_system' or `Back_app' (read from the C side, Phase 2 RB-16).
set_back_policy (a_policy: INTEGER)
Decide who handles the Back key from now on.
Requires
Ensures
keep_screen_on: BOOLEAN
Is the screen kept from dimming?
set_keep_screen_on (a_on: BOOLEAN)
Keep the screen awake while the app is shown (or stop).
Ensures
is_finishing: BOOLEAN
Has `finish' been asked for?
finish
Ask Android to end the app; `destroyed' follows.
Requires
Ensures
Invariant
PHONE_SCREEN
The window's pixel buffer, one frame at a time. `present_argb' copies a cairo-format ARGB32 image (native-endian 0xAARRGGBB words) to the screen at (0,0), clipped. It is the one seam a GPU path would replace (research D-005). `has_window' is the live truth from Android; see SIMPLE_EIF_PHONE's invariant for why it matches the lifecycle model at every delivery.
Status
has_window: BOOLEAN
Does Android currently give us a window?
in_frame: BOOLEAN
Is the buffer locked for drawing?
width: INTEGER
Window width in pixels (0 without a window).
Ensures
height: INTEGER
Window height in pixels (0 without a window).
Ensures
Frame
begin_frame
Lock the buffer. Android may refuse: check `in_frame' after.
Requires
Ensures
fill_rect (a_x, a_y, a_w, a_h, a_rgb: INTEGER)
Fill a rectangle with color `a_rgb' (0xRRGGBB), clipped to the window.
Requires
Ensures
present_argb (a_pixels: POINTER; a_width, a_height, a_stride: INTEGER)
Copy an ARGB32 image (`a_stride' bytes per row) to (0,0), clipped.
Requires
Ensures
end_frame
Unlock and show the frame.
Requires
Ensures
Testing
peek (a_x, a_y: INTEGER): NATURAL_32
Window buffer word at (`a_x', `a_y'); for byte-order tests only.
Requires
Invariant
PHONE_METRICS
Window size, density and the content rectangle: the area not covered by the status and navigation bars (or the on-screen keyboard). Insets are derived from it. Values are read from Android at `refresh'; SIMPLE_EIF_PHONE refreshes on window, configuration and content-rect events. Font scale is not here: the NDK has no getter for it (spec 03 A-6).
Access
width, height: INTEGER
Window size in pixels.
density_dpi: INTEGER
Screen density in dots per inch.
content_rect: PHONE_RECT
Area where content is seen by the user.
layout_is_rtl: BOOLEAN
Is the phone's layout direction right-to-left?
inset_left: INTEGER
Pixels covered on the left.
Ensures
inset_top: INTEGER
Pixels covered at the top (status bar).
Ensures
inset_right: INTEGER
Pixels covered on the right.
Ensures
inset_bottom: INTEGER
Pixels covered at the bottom (navigation bar, keyboard).
Ensures
dp (a_dp: INTEGER): INTEGER
`a_dp' density-independent pixels in real pixels (160 dpi baseline).
Requires
Ensures
Update
refresh
Re-read every value from Android. The content rectangle is clamped to the window; an empty one from Android (none reported yet) means the whole window (Phase 2 RB-4).
Ensures
Invariant
PHONE_STORAGE
App-private folders on the phone. `internal_path' always exists and needs no permission; `external_path' may be absent.
Access
internal_path: STRING_8
The app's private files folder (UTF-8 path).
Ensures
external_path: detachable STRING_8
The app's folder on shared storage, if Android offers one.
Ensures
PHONE_ASSETS
Read-only files packed in the APK's assets/ folder, by relative name (e.g. "fonts/noto.ttf"). Missing files are a normal outcome, not an error: `last_asset' is Void.
Status
has_asset (a_name: READABLE_STRING_8): BOOLEAN
Is `a_name' packed in the APK?
Requires
is_valid_name (a_name: READABLE_STRING_8): BOOLEAN
Non-empty and relative.
Access
last_asset: detachable MANAGED_POINTER
Bytes from the last `read_asset', or Void if it was missing.
last_asset_size: INTEGER
Byte count of `last_asset' (0 if missing).
Basic operations
read_asset (a_name: READABLE_STRING_8)
Read `a_name' into `last_asset'.
Requires
Ensures
Invariant
PHONE_LOG
Write lines to the Android log (logcat) under `tag'.
Access
tag: STRING_8
Log tag (what `adb logcat -s <tag>' filters on).
Settings
set_tag (a_tag: READABLE_STRING_8)
Use `a_tag' from now on.
Requires
Ensures
Output
debug_line (a_text: READABLE_STRING_8)
Debug-level line.
info (a_text: READABLE_STRING_8)
Info-level line.
warn (a_text: READABLE_STRING_8)
Warning-level line.
error (a_text: READABLE_STRING_8)
Error-level line.
Invariant
PHONE_EVENT
One thing that happened on the phone: a lifecycle change, a touch or a key. Immutable. Exactly one family per event (or none, for a timed poll that ran out). Touch coordinates are window pixels, rounded; they may lie outside the window while a finger drags off the edge.
Access
kind: INTEGER
Event code (see PHONE_EVENT_KIND).
time_ms: INTEGER
Android uptime in milliseconds, masked to 31 bits by the glue: never negative; wraps to 0 after 2^31 ms (~24.8 days). Compare two times by their difference, not by `<'.
pointer_id: INTEGER
Finger id for touch events; -1 otherwise.
x, y: INTEGER
Window pixel position for touch events; 0 otherwise.
key_code: INTEGER
Android key code for key events; 0 otherwise.
Status
is_none: BOOLEAN
Is this "no event"?
is_lifecycle: BOOLEAN
Is this a lifecycle event?
is_touch: BOOLEAN
Is this a touch event?
is_key: BOOLEAN
Is this a key event?
Output
out_line: STRING_8
One-line description, e.g. "touch_down id=0 x=12 y=40 t=1234".
Ensures
Invariant
PHONE_EVENT_KIND
Event codes for SIMPLE_EIF_PHONE, grouped in three families: lifecycle (1-14), touch (20-23) and key (30-31). Code 0 means no event (a timed poll that ran out). The numbers are shared with the C glue (runtime/c/sephone.h); change both together.
Codes: none
Kind_none: INTEGER = 0
No event (timed poll ran out).
Codes: lifecycle
Kind_started: INTEGER = 1
Kind_resumed: INTEGER = 2
Kind_paused: INTEGER = 3
Kind_stopped: INTEGER = 4
Kind_destroyed: INTEGER = 5
Kind_window_ready: INTEGER = 6
Kind_window_lost: INTEGER = 7
Kind_window_resized: INTEGER = 8
Kind_redraw_needed: INTEGER = 9
Kind_focus_gained: INTEGER = 10
Kind_focus_lost: INTEGER = 11
Kind_configuration_changed: INTEGER = 12
Kind_low_memory: INTEGER = 13
Kind_content_rect_changed: INTEGER = 14
Codes: touch
Kind_touch_down: INTEGER = 20
Kind_touch_move: INTEGER = 21
Kind_touch_up: INTEGER = 22
Kind_touch_cancel: INTEGER = 23
Codes: key
Kind_key_down: INTEGER = 30
Kind_key_up: INTEGER = 31
Families
is_lifecycle_kind (a_k: INTEGER): BOOLEAN
Is `a_k' a lifecycle code?
is_touch_kind (a_k: INTEGER): BOOLEAN
Is `a_k' a touch code?
is_key_kind (a_k: INTEGER): BOOLEAN
Is `a_k' a key code?
is_valid_kind (a_k: INTEGER): BOOLEAN
Is `a_k' none or a member of exactly one family?
Ensures
Names
kind_name (a_k: INTEGER): STRING_8
Lower-case name of `a_k', for logs and tests (e.g. "touch_down").
Requires
Ensures
PHONE_KEY_CODES
Android key codes the layer names (values from android/keycodes.h). Inherit it to compare `last_event.key_code' by name.
Codes
Key_home: INTEGER = 3
Key_back: INTEGER = 4
Key_dpad_up: INTEGER = 19
Key_dpad_down: INTEGER = 20
Key_dpad_left: INTEGER = 21
Key_dpad_right: INTEGER = 22
Key_volume_up: INTEGER = 24
Key_volume_down: INTEGER = 25
Key_enter: INTEGER = 66
Key_del: INTEGER = 67
Key_menu: INTEGER = 82
PHONE_LIFECYCLE
Where the app is in Android's life, built from delivered events. Pure Eiffel: no platform calls, so it is tested on the PC. Lenient by design (Phase 2 RB-17): it accepts any order of events Android may send and only refuses use after `destroyed'. Each event changes exactly the state its kind names (per-kind frame clauses). `resumed' also sets `is_started' (Android always starts before it resumes), so the model stays consistent even if an event is lost.
Status
is_started: BOOLEAN
Between `started' and `stopped'?
is_resumed: BOOLEAN
Between `resumed' and `paused' (in the foreground)?
has_window: BOOLEAN
Between `window_ready' and `window_lost'?
has_focus: BOOLEAN
Between `focus_gained' and `focus_lost'?
is_destroyed: BOOLEAN
Has `destroyed' been applied? (final)
window_generation: INTEGER
Number of `window_ready' events so far; lets apps drop caches tied to an older window.
last_applied: detachable PHONE_EVENT
Most recent event passed to `apply' (any family).
affects_state (a_k: INTEGER): BOOLEAN
Does lifecycle code `a_k' change this model?
Element change
apply (a_e: PHONE_EVENT)
Update the model for `a_e'. Touch, key and the non-state lifecycle events (resized, redraw, configuration, low memory, content rect) change nothing but `last_applied'.
Requires
Ensures
Invariant
PHONE_TOUCHES
The fingers currently on the glass, by pointer id, with their last positions. Built from delivered touch events. Pure Eiffel, PC-tested. A move for an unknown id (its down was lost) is ignored; any `touch_cancel' clears every finger.
Model
active_ids: MML_SET [INTEGER]
Ids of the fingers currently down.
xs_model: MML_MAP [INTEGER, INTEGER]
Last x of each finger down, by id (Phase 2 RB-12).
ys_model: MML_MAP [INTEGER, INTEGER]
Last y of each finger down, by id (Phase 2 RB-12).
Access
count: INTEGER
Number of fingers down.
is_active (a_id: INTEGER): BOOLEAN
Is finger `a_id' down?
Ensures
x_of (a_id: INTEGER): INTEGER
Last x of finger `a_id'.
Requires
Ensures
y_of (a_id: INTEGER): INTEGER
Last y of finger `a_id'.
Requires
Ensures
last_applied: detachable PHONE_EVENT
Most recent event passed to `apply' (any family).
Element change
apply (a_e: PHONE_EVENT)
Update the fingers for `a_e'. Losing the window or focus, or being destroyed, lifts every finger (Phase 2 RB-11: Android is not known to send a cancel then). Other non-touch events change nothing but `last_applied'.
Ensures
clears_touches (a_k: INTEGER): BOOLEAN
Does a non-touch event of kind `a_k' lift every finger?
Invariant
PHONE_RECT
A pixel rectangle: left/top inclusive, right/bottom exclusive. Immutable.
Access
left, top, right, bottom: INTEGER
width: INTEGER
`right' - `left'.
Ensures
height: INTEGER
`bottom' - `top'.
Ensures