Native Activity

#include <hardware_buffer.h>
#include <native_activity.h>
#include <native_window.h>
#include <native_window_jni.h>
#include <rect.h>
#include <window.h>

Summary

Enumerations

Anonymous Enum 15{
  AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM = 1,
  AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM = 2,
  AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM = 3,
  AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM = 4,
  AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT = 0x16,
  AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM = 0x2b,
  AHARDWAREBUFFER_FORMAT_BLOB = 0x21,
  AHARDWAREBUFFER_FORMAT_D16_UNORM = 0x30,
  AHARDWAREBUFFER_FORMAT_D24_UNORM = 0x31,
  AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT = 0x32,
  AHARDWAREBUFFER_FORMAT_D32_FLOAT = 0x33,
  AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT = 0x34,
  AHARDWAREBUFFER_FORMAT_S8_UINT = 0x35
}
enum
Buffer pixel formats.
Anonymous Enum 16{
  AHARDWAREBUFFER_USAGE_CPU_READ_NEVER = 0UL,
  AHARDWAREBUFFER_USAGE_CPU_READ_RARELY = 2UL,
  AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN = 3UL,
  AHARDWAREBUFFER_USAGE_CPU_READ_MASK = 0xFUL,
  AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER = 0UL << 4,
  AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY = 2UL << 4,
  AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN = 3UL << 4,
  AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK = 0xFUL << 4,
  AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE = 1UL << 8,
  AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT = 1UL << 9,
  AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT = 1UL << 14,
  AHARDWAREBUFFER_USAGE_VIDEO_ENCODE = 1UL << 16,
  AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA = 1UL << 23,
  AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER = 1UL << 24,
  AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP = 1UL << 25,
  AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE = 1UL << 26,
  AHARDWAREBUFFER_USAGE_VENDOR_0 = 1ULL << 28,
  AHARDWAREBUFFER_USAGE_VENDOR_1 = 1ULL << 29,
  AHARDWAREBUFFER_USAGE_VENDOR_2 = 1ULL << 30,
  AHARDWAREBUFFER_USAGE_VENDOR_3 = 1ULL << 31,
  AHARDWAREBUFFER_USAGE_VENDOR_4 = 1ULL << 48,
  AHARDWAREBUFFER_USAGE_VENDOR_5 = 1ULL << 49,
  AHARDWAREBUFFER_USAGE_VENDOR_6 = 1ULL << 50,
  AHARDWAREBUFFER_USAGE_VENDOR_7 = 1ULL << 51,
  AHARDWAREBUFFER_USAGE_VENDOR_8 = 1ULL << 52,
  AHARDWAREBUFFER_USAGE_VENDOR_9 = 1ULL << 53,
  AHARDWAREBUFFER_USAGE_VENDOR_10 = 1ULL << 54,
  AHARDWAREBUFFER_USAGE_VENDOR_11 = 1ULL << 55,
  AHARDWAREBUFFER_USAGE_VENDOR_12 = 1ULL << 56,
  AHARDWAREBUFFER_USAGE_VENDOR_13 = 1ULL << 57,
  AHARDWAREBUFFER_USAGE_VENDOR_14 = 1ULL << 58,
  AHARDWAREBUFFER_USAGE_VENDOR_15 = 1ULL << 59,
  AHARDWAREBUFFER_USAGE_VENDOR_16 = 1ULL << 60,
  AHARDWAREBUFFER_USAGE_VENDOR_17 = 1ULL << 61,
  AHARDWAREBUFFER_USAGE_VENDOR_18 = 1ULL << 62,
  AHARDWAREBUFFER_USAGE_VENDOR_19 = 1ULL << 63
}
enum
Buffer usage flags, specifying how the buffer will be accessed.
Anonymous Enum 36{
  ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT = 0x0001,
  ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED = 0x0002
}
enum
Flags for ANativeActivity_showSoftInput; see the Java InputMethodManager API for documentation.
Anonymous Enum 37{
  ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY = 0x0001,
  ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS = 0x0002
}
enum
Flags for ANativeActivity_hideSoftInput; see the Java InputMethodManager API for documentation.
Anonymous Enum 38{
  WINDOW_FORMAT_RGBA_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,
  WINDOW_FORMAT_RGBX_8888 = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM,
  WINDOW_FORMAT_RGB_565 = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM
}
enum
Legacy window pixel format names, kept for backwards compatibility.
Anonymous Enum 68{
  AWINDOW_FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001,
  AWINDOW_FLAG_DIM_BEHIND = 0x00000002,
  AWINDOW_FLAG_BLUR_BEHIND = 0x00000004,
  AWINDOW_FLAG_NOT_FOCUSABLE = 0x00000008,
  AWINDOW_FLAG_NOT_TOUCHABLE = 0x00000010,
  AWINDOW_FLAG_NOT_TOUCH_MODAL = 0x00000020,
  AWINDOW_FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040,
  AWINDOW_FLAG_KEEP_SCREEN_ON = 0x00000080,
  AWINDOW_FLAG_LAYOUT_IN_SCREEN = 0x00000100,
  AWINDOW_FLAG_LAYOUT_NO_LIMITS = 0x00000200,
  AWINDOW_FLAG_FULLSCREEN = 0x00000400,
  AWINDOW_FLAG_FORCE_NOT_FULLSCREEN = 0x00000800,
  AWINDOW_FLAG_DITHER = 0x00001000,
  AWINDOW_FLAG_SECURE = 0x00002000,
  AWINDOW_FLAG_SCALED = 0x00004000,
  AWINDOW_FLAG_IGNORE_CHEEK_PRESSES = 0x00008000,
  AWINDOW_FLAG_LAYOUT_INSET_DECOR = 0x00010000,
  AWINDOW_FLAG_ALT_FOCUSABLE_IM = 0x00020000,
  AWINDOW_FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000,
  AWINDOW_FLAG_SHOW_WHEN_LOCKED = 0x00080000,
  AWINDOW_FLAG_SHOW_WALLPAPER = 0x00100000,
  AWINDOW_FLAG_TURN_SCREEN_ON = 0x00200000,
  AWINDOW_FLAG_DISMISS_KEYGUARD = 0x00400000
}
enum
Window flags, as per the Java API at android.view.WindowManager.LayoutParams.
ANativeWindowTransform{
  ANATIVEWINDOW_TRANSFORM_IDENTITY = 0x00,
  ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL = 0x01,
  ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL = 0x02,
  ANATIVEWINDOW_TRANSFORM_ROTATE_90 = 0x04,
  ANATIVEWINDOW_TRANSFORM_ROTATE_180 = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL | ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL,
  ANATIVEWINDOW_TRANSFORM_ROTATE_270 = ANATIVEWINDOW_TRANSFORM_ROTATE_180 | ANATIVEWINDOW_TRANSFORM_ROTATE_90
}
enum
Transforms that can be applied to buffers as they are displayed to a window.

Typedefs

AHardwareBuffer typedef
struct AHardwareBuffer
AHardwareBuffer_Desc typedef
Buffer description.
ANativeActivity typedef
This structure defines the native side of an android.app.NativeActivity.
ANativeActivityCallbacks typedef
These are the callbacks the framework makes into a native application.
ANativeActivity_createFunc(ANativeActivity *activity, void *savedState, size_t savedStateSize) typedef
void
This is the function that must be in the native code to instantiate the application's native activity.
ANativeWindow typedef
struct ANativeWindow
Opaque type that provides access to a native window.
ANativeWindow_Buffer typedef
Struct that represents a windows buffer.
ARect typedef
struct ARect
Rectangular window area.

Variables

ANativeActivity_onCreate
The name of the function that NativeInstance looks for when launching its native code.

Functions

AHardwareBuffer_acquire(AHardwareBuffer *buffer)
void
Acquire a reference on the given AHardwareBuffer object.
AHardwareBuffer_allocate(const AHardwareBuffer_Desc *desc, AHardwareBuffer **outBuffer)
int
Allocates a buffer that backs an AHardwareBuffer using the passed AHardwareBuffer_Desc.
AHardwareBuffer_describe(const AHardwareBuffer *buffer, AHardwareBuffer_Desc *outDesc)
void
Return a description of the AHardwareBuffer in the passed AHardwareBuffer_Desc struct.
AHardwareBuffer_lock(AHardwareBuffer *buffer, uint64_t usage, int32_t fence, const ARect *rect, void **outVirtualAddress)
int
Lock the AHardwareBuffer for reading or writing, depending on the usage flags passed.
AHardwareBuffer_recvHandleFromUnixSocket(int socketFd, AHardwareBuffer **outBuffer)
int
Receive the AHardwareBuffer from an AF_UNIX socket.
AHardwareBuffer_release(AHardwareBuffer *buffer)
void
Remove a reference that was previously acquired with AHardwareBuffer_acquire().
AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer *buffer, int socketFd)
int
Send the AHardwareBuffer to an AF_UNIX socket.
AHardwareBuffer_unlock(AHardwareBuffer *buffer, int32_t *fence)
int
Unlock the AHardwareBuffer; must be called after all changes to the buffer are completed by the caller.
ANativeActivity_finish(ANativeActivity *activity)
void
Finish the given activity.
ANativeActivity_hideSoftInput(ANativeActivity *activity, uint32_t flags)
void
Hide the IME while in the given activity.
ANativeActivity_setWindowFlags(ANativeActivity *activity, uint32_t addFlags, uint32_t removeFlags)
void
Change the window flags of the given activity.
ANativeActivity_setWindowFormat(ANativeActivity *activity, int32_t format)
void
Change the window format of the given activity.
ANativeActivity_showSoftInput(ANativeActivity *activity, uint32_t flags)
void
Show the IME while in the given activity.
ANativeWindow_acquire(ANativeWindow *window)
void
Acquire a reference on the given ANativeWindow object.
ANativeWindow_fromSurface(JNIEnv *env, jobject surface)
Return the ANativeWindow associated with a Java Surface object, for interacting with it through native code.
ANativeWindow_getBuffersDataSpace(ANativeWindow *window)
int32_t
Get the dataspace of the buffers in window.
ANativeWindow_getFormat(ANativeWindow *window)
int32_t
Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface.
ANativeWindow_getHeight(ANativeWindow *window)
int32_t
Return the current height in pixels of the window surface.
ANativeWindow_getWidth(ANativeWindow *window)
int32_t
Return the current width in pixels of the window surface.
ANativeWindow_lock(ANativeWindow *window, ANativeWindow_Buffer *outBuffer, ARect *inOutDirtyBounds)
int32_t
Lock the window's next drawing surface for writing.
ANativeWindow_release(ANativeWindow *window)
void
Remove a reference that was previously acquired with ANativeWindow_acquire().
ANativeWindow_setBuffersDataSpace(ANativeWindow *window, int32_t dataSpace)
int32_t
All buffers queued after this call will be associated with the dataSpace parameter specified.
ANativeWindow_setBuffersGeometry(ANativeWindow *window, int32_t width, int32_t height, int32_t format)
int32_t
Change the format and size of the window buffers.
ANativeWindow_setBuffersTransform(ANativeWindow *window, int32_t transform)
int32_t
Set a transform that will be applied to future buffers posted to the window.
ANativeWindow_toSurface(JNIEnv *env, ANativeWindow *window)
jobject
Return a Java Surface object derived from the ANativeWindow, for interacting with it through Java code.
ANativeWindow_unlockAndPost(ANativeWindow *window)
int32_t
Unlock the window's drawing surface after previously locking it, posting the new buffer to the display.

Structs

AHardwareBuffer_Desc

Buffer description.

ANativeActivity

This structure defines the native side of an android.app.NativeActivity.

ANativeActivityCallbacks

These are the callbacks the framework makes into a native application.

ANativeWindow_Buffer

Struct that represents a windows buffer.

ARect

Rectangular window area.

Enumerations

Anonymous Enum 15

 Anonymous Enum 15

Buffer pixel formats.

Properties
AHARDWAREBUFFER_FORMAT_BLOB

An opaque binary blob format that must have height 1, with width equal to the buffer size in bytes.

AHARDWAREBUFFER_FORMAT_D16_UNORM

Corresponding formats: Vulkan: VK_FORMAT_D16_UNORM OpenGL ES: GL_DEPTH_COMPONENT16.

AHARDWAREBUFFER_FORMAT_D24_UNORM

Corresponding formats: Vulkan: VK_FORMAT_X8_D24_UNORM_PACK32 OpenGL ES: GL_DEPTH_COMPONENT24.

AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT

Corresponding formats: Vulkan: VK_FORMAT_D24_UNORM_S8_UINT OpenGL ES: GL_DEPTH24_STENCIL8.

AHARDWAREBUFFER_FORMAT_D32_FLOAT

Corresponding formats: Vulkan: VK_FORMAT_D32_SFLOAT OpenGL ES: GL_DEPTH_COMPONENT32F.

AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT

Corresponding formats: Vulkan: VK_FORMAT_D32_SFLOAT_S8_UINT OpenGL ES: GL_DEPTH32F_STENCIL8.

AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM

Corresponding formats: Vulkan: VK_FORMAT_A2B10G10R10_UNORM_PACK32 OpenGL ES: GL_RGB10_A2.

AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT

Corresponding formats: Vulkan: VK_FORMAT_R16G16B16A16_SFLOAT OpenGL ES: GL_RGBA16F.

AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM

Corresponding formats: Vulkan: VK_FORMAT_R5G6B5_UNORM_PACK16 OpenGL ES: GL_RGB565.

AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM

Corresponding formats: Vulkan: VK_FORMAT_R8G8B8A8_UNORM OpenGL ES: GL_RGBA8.

AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM

32 bits per pixel, 8 bits per channel format where alpha values are ignored (always opaque).

Corresponding formats: Vulkan: VK_FORMAT_R8G8B8A8_UNORM OpenGL ES: GL_RGB8

AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM

Corresponding formats: Vulkan: VK_FORMAT_R8G8B8_UNORM OpenGL ES: GL_RGB8.

AHARDWAREBUFFER_FORMAT_S8_UINT

Corresponding formats: Vulkan: VK_FORMAT_S8_UINT OpenGL ES: GL_STENCIL_INDEX8.

Anonymous Enum 16

 Anonymous Enum 16

Buffer usage flags, specifying how the buffer will be accessed.

Properties
AHARDWAREBUFFER_USAGE_CPU_READ_MASK

CPU read value mask.

AHARDWAREBUFFER_USAGE_CPU_READ_NEVER

The buffer will never be read by the CPU.

AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN

The buffer will often be read by the CPU.

AHARDWAREBUFFER_USAGE_CPU_READ_RARELY

The buffer will sometimes be read by the CPU.

AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK

CPU write value mask.

AHARDWAREBUFFER_USAGE_CPU_WRITE_NEVER

The buffer will never be written by the CPU.

AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN

The buffer will often be written to by the CPU.

AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY

The buffer will sometimes be written to by the CPU.

AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT

The buffer will be written to by the GPU as a framebuffer attachment.

Note that the name of this flag is somewhat misleading: it does not imply that the buffer contains a color format. A buffer with depth or stencil format that will be used as a framebuffer attachment should also have this flag.

AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP

The buffer will be used as a cube map texture.

AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER

The buffer will be used as a shader storage or uniform buffer object.

AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE

The buffer contains a complete mipmap hierarchy.

AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE

The buffer will be read from by the GPU as a texture.

AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT

The buffer must not be used outside of a protected hardware path.

AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA

The buffer will be used for direct writes from sensors.

AHARDWAREBUFFER_USAGE_VENDOR_0
AHARDWAREBUFFER_USAGE_VENDOR_1
AHARDWAREBUFFER_USAGE_VENDOR_10
AHARDWAREBUFFER_USAGE_VENDOR_11
AHARDWAREBUFFER_USAGE_VENDOR_12
AHARDWAREBUFFER_USAGE_VENDOR_13
AHARDWAREBUFFER_USAGE_VENDOR_14
AHARDWAREBUFFER_USAGE_VENDOR_15
AHARDWAREBUFFER_USAGE_VENDOR_16
AHARDWAREBUFFER_USAGE_VENDOR_17
AHARDWAREBUFFER_USAGE_VENDOR_18
AHARDWAREBUFFER_USAGE_VENDOR_19
AHARDWAREBUFFER_USAGE_VENDOR_2
AHARDWAREBUFFER_USAGE_VENDOR_3
AHARDWAREBUFFER_USAGE_VENDOR_4
AHARDWAREBUFFER_USAGE_VENDOR_5
AHARDWAREBUFFER_USAGE_VENDOR_6
AHARDWAREBUFFER_USAGE_VENDOR_7
AHARDWAREBUFFER_USAGE_VENDOR_8
AHARDWAREBUFFER_USAGE_VENDOR_9
AHARDWAREBUFFER_USAGE_VIDEO_ENCODE

The buffer will be read by a hardware video encoder.

Anonymous Enum 36

 Anonymous Enum 36

Flags for ANativeActivity_showSoftInput; see the Java InputMethodManager API for documentation.

Properties
ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED

The user has forced the input method open (such as by long-pressing menu) so it should not be closed until they explicitly do so.

ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT

Implicit request to show the input window, not as the result of a direct request by the user.

Anonymous Enum 37

 Anonymous Enum 37

Flags for ANativeActivity_hideSoftInput; see the Java InputMethodManager API for documentation.

Properties
ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY

The soft input window should only be hidden if it was not explicitly shown by the user.

ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS

The soft input window should normally be hidden, unless it was originally shown with ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED.

Anonymous Enum 38

 Anonymous Enum 38

Legacy window pixel format names, kept for backwards compatibility.

New code and APIs should use AHARDWAREBUFFER_FORMAT_*.

Properties
WINDOW_FORMAT_RGBA_8888

Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits.

WINDOW_FORMAT_RGBX_8888

Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits.

WINDOW_FORMAT_RGB_565

Red: 5 bits, Green: 6 bits, Blue: 5 bits.

Anonymous Enum 68

 Anonymous Enum 68

Window flags, as per the Java API at android.view.WindowManager.LayoutParams.

Properties
AWINDOW_FLAG_ALLOW_LOCK_WHILE_SCREEN_ON

As long as this window is visible to the user, allow the lock screen to activate while the screen is on.

This can be used independently, or in combination with AWINDOW_FLAG_KEEP_SCREEN_ON and/or AWINDOW_FLAG_SHOW_WHEN_LOCKED

AWINDOW_FLAG_ALT_FOCUSABLE_IM

Invert the state of AWINDOW_FLAG_NOT_FOCUSABLE with respect to how this window interacts with the current method.

That is, if FLAG_NOT_FOCUSABLE is set and this flag is set, then the window will behave as if it needs to interact with the input method and thus be placed behind/away from it; if AWINDOW_FLAG_NOT_FOCUSABLE is not set and this flag is set, then the window will behave as if it doesn't need to interact with the input method and can be placed to use more space and cover the input method.

AWINDOW_FLAG_BLUR_BEHIND

Blur everything behind this window.

Deprecated. Blurring is no longer supported.

AWINDOW_FLAG_DIM_BEHIND

Everything behind this window will be dimmed.

AWINDOW_FLAG_DISMISS_KEYGUARD

When set the window will cause the keyguard to be dismissed, only if it is not a secure lock keyguard.

Because such a keyguard is not needed for security, it will never re-appear if the user navigates to another window (in contrast to AWINDOW_FLAG_SHOW_WHEN_LOCKED, which will only temporarily hide both secure and non-secure keyguards but ensure they reappear when the user moves to another UI that doesn't hide them). If the keyguard is currently active and is secure (requires an unlock pattern) than the user will still need to confirm it before seeing this window, unless AWINDOW_FLAG_SHOW_WHEN_LOCKED has also been set.

AWINDOW_FLAG_DITHER

Turn on dithering when compositing this window to the screen.

Deprecated. This flag is no longer used.

AWINDOW_FLAG_FORCE_NOT_FULLSCREEN

Override AWINDOW_FLAG_FULLSCREEN and force the screen decorations (such as the status bar) to be shown.

AWINDOW_FLAG_FULLSCREEN

Hide all screen decorations (such as the status bar) while this window is displayed.

This allows the window to use the entire display space for itself the status bar will be hidden when an app window with this flag set is on the top layer. A fullscreen window will ignore a value of AWINDOW_SOFT_INPUT_ADJUST_RESIZE; the window will stay fullscreen and will not resize.

AWINDOW_FLAG_IGNORE_CHEEK_PRESSES

Intended for windows that will often be used when the user is holding the screen against their face, it will aggressively filter the event stream to prevent unintended presses in this situation that may not be desired for a particular window, when such an event stream is detected, the application will receive a AMOTION_EVENT_ACTION_CANCEL to indicate this so applications can handle this accordingly by taking no action on the event until the finger is released.

AWINDOW_FLAG_KEEP_SCREEN_ON

As long as this window is visible to the user, keep the device's screen turned on and bright.

AWINDOW_FLAG_LAYOUT_INSET_DECOR

A special option only for use in combination with AWINDOW_FLAG_LAYOUT_IN_SCREEN.

When requesting layout in the screen your window may appear on top of or behind screen decorations such as the status bar. By also including this flag, the window manager will report the inset rectangle needed to ensure your content is not covered by screen decorations.

AWINDOW_FLAG_LAYOUT_IN_SCREEN

Place the window within the entire screen, ignoring decorations around the border (such as the status bar).

The window must correctly position its contents to take the screen decoration into account.

AWINDOW_FLAG_LAYOUT_NO_LIMITS

allow window to extend outside of the screen.

AWINDOW_FLAG_NOT_FOCUSABLE

This window won't ever get key input focus, so the user can not send key or other button events to it.

Those will instead go to whatever focusable window is behind it. This flag will also enable AWINDOW_FLAG_NOT_TOUCH_MODAL whether or not that is explicitly set.

Setting this flag also implies that the window will not need to interact with a soft input method, so it will be Z-ordered and positioned independently of any active input method (typically this means it gets Z-ordered on top of the input method, so it can use the full screen for its content and cover the input method if needed. You can use AWINDOW_FLAG_ALT_FOCUSABLE_IM to modify this behavior.

AWINDOW_FLAG_NOT_TOUCHABLE

this window can never receive touch events.

AWINDOW_FLAG_NOT_TOUCH_MODAL

Even when this window is focusable (its AWINDOW_FLAG_NOT_FOCUSABLE is not set), allow any pointer events outside of the window to be sent to the windows behind it.

Otherwise it will consume all pointer events itself, regardless of whether they are inside of the window.

AWINDOW_FLAG_SCALED

A special mode where the layout parameters are used to perform scaling of the surface when it is composited to the screen.

AWINDOW_FLAG_SECURE

Treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.

AWINDOW_FLAG_SHOW_WALLPAPER

Ask that the system wallpaper be shown behind your window.

The window surface must be translucent to be able to actually see the wallpaper behind it; this flag just ensures that the wallpaper surface will be there if this window actually has translucent regions.

AWINDOW_FLAG_SHOW_WHEN_LOCKED

Special flag to let windows be shown when the screen is locked.

This will let application windows take precedence over key guard or any other lock screens. Can be used with AWINDOW_FLAG_KEEP_SCREEN_ON to turn screen on and display windows directly before showing the key guard window. Can be used with AWINDOW_FLAG_DISMISS_KEYGUARD to automatically fully dismisss non-secure keyguards. This flag only applies to the top-most full-screen window.

AWINDOW_FLAG_TOUCHABLE_WHEN_WAKING

When set, if the device is asleep when the touch screen is pressed, you will receive this first touch event.

Usually the first touch event is consumed by the system since the user can not see what they are pressing on.

Deprecated. This flag has no effect.

AWINDOW_FLAG_TURN_SCREEN_ON

When set as a window is being added or made visible, once the window has been shown then the system will poke the power manager's user activity (as if the user had woken up the device) to turn the screen on.

AWINDOW_FLAG_WATCH_OUTSIDE_TOUCH

If you have set AWINDOW_FLAG_NOT_TOUCH_MODAL, you can set this flag to receive a single special MotionEvent with the action AMOTION_EVENT_ACTION_OUTSIDE for touches that occur outside of your window.

Note that you will not receive the full down/move/up gesture, only the location of the first down as an AMOTION_EVENT_ACTION_OUTSIDE.

ANativeWindowTransform

 ANativeWindowTransform

Transforms that can be applied to buffers as they are displayed to a window.

Supported transforms are any combination of horizontal mirror, vertical mirror, and clockwise 90 degree rotation, in that order. Rotations of 180 and 270 degrees are made up of those basic transforms.

Properties
ANATIVEWINDOW_TRANSFORM_IDENTITY
ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL
ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL
ANATIVEWINDOW_TRANSFORM_ROTATE_180
ANATIVEWINDOW_TRANSFORM_ROTATE_270
ANATIVEWINDOW_TRANSFORM_ROTATE_90

Typedefs

AHardwareBuffer

struct AHardwareBuffer AHardwareBuffer

AHardwareBuffer_Desc

struct AHardwareBuffer_Desc AHardwareBuffer_Desc

Buffer description.

Used for allocating new buffers and querying parameters of existing ones.

ANativeActivity

struct ANativeActivity ANativeActivity

This structure defines the native side of an android.app.NativeActivity.

It is created by the framework, and handed to the application's native code as it is being launched.

ANativeActivityCallbacks

struct ANativeActivityCallbacks ANativeActivityCallbacks

These are the callbacks the framework makes into a native application.

All of these callbacks happen on the main thread of the application. By default, all callbacks are NULL; set to a pointer to your own function to have it called.

ANativeActivity_createFunc

void ANativeActivity_createFunc(ANativeActivity *activity, void *savedState, size_t savedStateSize)

This is the function that must be in the native code to instantiate the application's native activity.

It is called with the activity instance (see above); if the code is being instantiated from a previously saved instance, the savedState will be non-NULL and point to the saved data. You must make any copy of this data you need it will be released after you return from this function.

ANativeWindow

struct ANativeWindow ANativeWindow

Opaque type that provides access to a native window.

A pointer can be obtained using ANativeWindow_fromSurface().

ANativeWindow_Buffer

struct ANativeWindow_Buffer ANativeWindow_Buffer

Struct that represents a windows buffer.

A pointer can be obtained using ANativeWindow_lock().

ARect

struct ARect ARect

Rectangular window area.

This is the NDK equivalent of the android.graphics.Rect class in Java. It is used with ANativeActivityCallbacks::onContentRectChanged event callback and the ANativeWindow_lock() function.

In a valid ARect, left <= right and top <= bottom. ARect with left=0, top=10, right=1, bottom=11 contains only one pixel at x=0, y=10.

Variables

ANativeActivity_onCreate

ANativeActivity_createFunc ANativeActivity_onCreate

The name of the function that NativeInstance looks for when launching its native code.

This is the default function that is used, you can specify "android.app.func_name" string meta-data in your manifest to use a different function.

Functions

AHardwareBuffer_acquire

void AHardwareBuffer_acquire(
  AHardwareBuffer *buffer
)

Acquire a reference on the given AHardwareBuffer object.

This prevents the object from being deleted until the last reference is removed.

AHardwareBuffer_allocate

int AHardwareBuffer_allocate(
  const AHardwareBuffer_Desc *desc,
  AHardwareBuffer **outBuffer
)

Allocates a buffer that backs an AHardwareBuffer using the passed AHardwareBuffer_Desc.

Details
Returns
0 on success, or an error number of the allocation fails for any reason. The returned buffer has a reference count of 1.

AHardwareBuffer_describe

void AHardwareBuffer_describe(
  const AHardwareBuffer *buffer,
  AHardwareBuffer_Desc *outDesc
)

Return a description of the AHardwareBuffer in the passed AHardwareBuffer_Desc struct.

AHardwareBuffer_lock

int AHardwareBuffer_lock(
  AHardwareBuffer *buffer,
  uint64_t usage,
  int32_t fence,
  const ARect *rect,
  void **outVirtualAddress
)

Lock the AHardwareBuffer for reading or writing, depending on the usage flags passed.

This call may block if the hardware needs to finish rendering or if CPU caches need to be synchronized, or possibly for other implementation- specific reasons. If fence is not negative, then it specifies a fence file descriptor that will be signaled when the buffer is locked, otherwise the caller will block until the buffer is available.

If rect is not NULL, the caller promises to modify only data in the area specified by rect. If rect is NULL, the caller may modify the contents of the entire buffer.

The content of the buffer outside of the specified rect is NOT modified by this call.

The usage parameter may only specify AHARDWAREBUFFER_USAGE_CPU_*. If set, then outVirtualAddress is filled with the address of the buffer in virtual memory.

THREADING CONSIDERATIONS:

It is legal for several different threads to lock a buffer for read access; none of the threads are blocked.

Locking a buffer simultaneously for write or read/write is undefined, but will neither terminate the process nor block the caller; AHardwareBuffer_lock may return an error or leave the buffer's content into an indeterminate state.

Details
Returns
0 on success, -EINVAL if buffer is NULL or if the usage flags are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or an error number of the lock fails for any reason.

AHardwareBuffer_recvHandleFromUnixSocket

int AHardwareBuffer_recvHandleFromUnixSocket(
  int socketFd,
  AHardwareBuffer **outBuffer
)

Receive the AHardwareBuffer from an AF_UNIX socket.

Details
Returns
0 on success, -EINVAL if outBuffer is NULL, or an error number if the operation fails for any reason.

AHardwareBuffer_release

void AHardwareBuffer_release(
  AHardwareBuffer *buffer
)

Remove a reference that was previously acquired with AHardwareBuffer_acquire().

AHardwareBuffer_sendHandleToUnixSocket

int AHardwareBuffer_sendHandleToUnixSocket(
  const AHardwareBuffer *buffer,
  int socketFd
)

Send the AHardwareBuffer to an AF_UNIX socket.

Details
Returns
0 on success, -EINVAL if buffer is NULL, or an error number if the operation fails for any reason.

AHardwareBuffer_unlock

int AHardwareBuffer_unlock(
  AHardwareBuffer *buffer,
  int32_t *fence
)

Unlock the AHardwareBuffer; must be called after all changes to the buffer are completed by the caller.

If fence is not NULL then it will be set to a file descriptor that is signaled when all pending work on the buffer is completed. The caller is responsible for closing the fence when it is no longer needed.

Details
Returns
0 on success, -EINVAL if buffer is NULL, or an error number if the unlock fails for any reason.

ANativeActivity_finish

void ANativeActivity_finish(
  ANativeActivity *activity
)

Finish the given activity.

Its finish() method will be called, causing it to be stopped and destroyed. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.

ANativeActivity_hideSoftInput

void ANativeActivity_hideSoftInput(
  ANativeActivity *activity,
  uint32_t flags
)

Hide the IME while in the given activity.

Calls InputMethodManager.hideSoftInput() for the given activity. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.

ANativeActivity_setWindowFlags

void ANativeActivity_setWindowFlags(
  ANativeActivity *activity,
  uint32_t addFlags,
  uint32_t removeFlags
)

Change the window flags of the given activity.

Calls getWindow().setFlags() of the given activity. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place. See window.h for flag constants.

ANativeActivity_setWindowFormat

void ANativeActivity_setWindowFormat(
  ANativeActivity *activity,
  int32_t format
)

Change the window format of the given activity.

Calls getWindow().setFormat() of the given activity. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.

ANativeActivity_showSoftInput

void ANativeActivity_showSoftInput(
  ANativeActivity *activity,
  uint32_t flags
)

Show the IME while in the given activity.

Calls InputMethodManager.showSoftInput() for the given activity. Note that this method can be called from any thread; it will send a message to the main thread of the process where the Java finish call will take place.

ANativeWindow_acquire

void ANativeWindow_acquire(
  ANativeWindow *window
)

Acquire a reference on the given ANativeWindow object.

This prevents the object from being deleted until the reference is removed.

ANativeWindow_fromSurface

ANativeWindow * ANativeWindow_fromSurface(
  JNIEnv *env,
  jobject surface
)

Return the ANativeWindow associated with a Java Surface object, for interacting with it through native code.

This acquires a reference on the ANativeWindow that is returned; be sure to use ANativeWindow_release() when done with it so that it doesn't leak.

ANativeWindow_getBuffersDataSpace

int32_t ANativeWindow_getBuffersDataSpace(
  ANativeWindow *window
)

Get the dataspace of the buffers in window.

Details
Returns
the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if dataspace is unknown, or -EINVAL if window is invalid.

ANativeWindow_getFormat

int32_t ANativeWindow_getFormat(
  ANativeWindow *window
)

Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface.

Details
Returns
a negative value on error.

ANativeWindow_getHeight

int32_t ANativeWindow_getHeight(
  ANativeWindow *window
)

Return the current height in pixels of the window surface.

Details
Returns
a negative value on error.

ANativeWindow_getWidth

int32_t ANativeWindow_getWidth(
  ANativeWindow *window
)

Return the current width in pixels of the window surface.

Details
Returns
negative value on error.

ANativeWindow_lock

int32_t ANativeWindow_lock(
  ANativeWindow *window,
  ANativeWindow_Buffer *outBuffer,
  ARect *inOutDirtyBounds
)

Lock the window's next drawing surface for writing.

inOutDirtyBounds is used as an in/out parameter, upon entering the function, it contains the dirty region, that is, the region the caller intends to redraw. When the function returns, inOutDirtyBounds is updated with the actual area the caller needs to redraw this region is often extended by ANativeWindow_lock.

Details
Returns
0 for success, or a negative value on error.

ANativeWindow_release

void ANativeWindow_release(
  ANativeWindow *window
)

Remove a reference that was previously acquired with ANativeWindow_acquire().

ANativeWindow_setBuffersDataSpace

int32_t ANativeWindow_setBuffersDataSpace(
  ANativeWindow *window,
  int32_t dataSpace
)

All buffers queued after this call will be associated with the dataSpace parameter specified.

dataSpace specifies additional information about the buffer. For example, it can be used to convey the color space of the image data in the buffer, or it can be used to indicate that the buffers contain depth measurement data instead of color images. The default dataSpace is 0, ADATASPACE_UNKNOWN, unless it has been overridden by the producer.

Details
Parameters
dataSpace
data space of all buffers queued after this call.
Returns
0 for success, -EINVAL if window is invalid or the dataspace is not supported.

ANativeWindow_setBuffersGeometry

int32_t ANativeWindow_setBuffersGeometry(
  ANativeWindow *window,
  int32_t width,
  int32_t height,
  int32_t format
)

Change the format and size of the window buffers.

The width and height control the number of pixels in the buffers, not the dimensions of the window on screen. If these are different than the window's physical size, then its buffer will be scaled to match that size when compositing it to the screen. The width and height must be either both zero or both non-zero.

For all of these parameters, if 0 is supplied then the window's base value will come back in force.

Details
Parameters
width
width of the buffers in pixels.
height
height of the buffers in pixels.
format
one of AHARDWAREBUFFER_FORMAT_* constants.
Returns
0 for success, or a negative value on error.

ANativeWindow_setBuffersTransform

int32_t ANativeWindow_setBuffersTransform(
  ANativeWindow *window,
  int32_t transform
)

Set a transform that will be applied to future buffers posted to the window.

Details
Parameters
transform
combination of ANativeWindowTransform flags
Returns
0 for success, or -EINVAL if transform is invalid

ANativeWindow_toSurface

jobject ANativeWindow_toSurface(
  JNIEnv *env,
  ANativeWindow *window
)

Return a Java Surface object derived from the ANativeWindow, for interacting with it through Java code.

The returned Java object acquires a reference on the ANativeWindow; maintains it through general Java object's life cycle; and will automatically release the reference when the Java object gets garbage collected.

ANativeWindow_unlockAndPost

int32_t ANativeWindow_unlockAndPost(
  ANativeWindow *window
)

Unlock the window's drawing surface after previously locking it, posting the new buffer to the display.

Details
Returns
0 for success, or a negative value on error.