NativeService
ANativeService APIs allow you to implement Services declared as.
Summary
android:nativeService=true
Because most NDK APIs rely on the Android Runtime (ART), the APIs available to native services (which may not have the ART loaded inside their processes) are limited to a specific subset. The current set of supported APIs is:
- AFont_*
- AFontMatcher_*
- AIBinder_*
- except AIBinder_fromJavaBinder and AIBinder_toJavaBinder
- ALooper_*
- ANativeService_*
- AParcel_*
- except AParcel_fromJavaParcel
- APersistableBundle_*
- ASharedMemory_*
- except ASharedMemory_dupFromJava
- AStatus_*
- ASystemFontIterator_*
- ATrace_*
Enumerations |
|
|---|---|
ANativeServiceTrimMemoryLevel{
|
enum The levels for ANativeService_onTrimMemoryCallback indicating the context of the trim, giving a hint of the amount of trimming the application may like to perform. |
Typedefs |
|
|---|---|
ANativeService
|
typedeftypedef__BEGIN_DECLS struct ANativeService
An opaque struct representing a native service instance. |
ANativeServiceTrimMemoryLevel
|
typedef The levels for ANativeService_onTrimMemoryCallback indicating the context of the trim, giving a hint of the amount of trimming the application may like to perform. |
ANativeService_createFunc(ANativeService *_Nonnull service)
|
typedefvoid
The function type signature definition of the entry point function of the service. |
ANativeService_onBindCallback)(ANativeService *_Nonnull service, uint64_t bindToken, char const *_Nullable action, char const *_Nullable data)
|
typedefAIBinder *_Nullable(*
The function type signature definition of the "onBind" callback function called when someone is binding to the service, with the given action and data on the intent. |
ANativeService_onDestroyCallback)(ANativeService *_Nonnull service)
|
typedefvoid(*
The function type signature definition of the "onDestroy" callback function called when the service is being destroyed. |
ANativeService_onRebindCallback)(ANativeService *_Nonnull service, uint64_t bindToken)
|
typedefvoid(*
The function type signature definition of the "onRebind" callback function called when someone is rebinding to the service. |
ANativeService_onTrimMemoryCallback)(ANativeService *_Nonnull service, ANativeServiceTrimMemoryLevel level)
|
typedefvoid(*
The function type signature definition of the "onTrimMemory" callback function called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. |
ANativeService_onUnbindCallback)(ANativeService *_Nonnull service, uint64_t bindToken)
|
typedefbool(*
The function type signature definition of the "onUnbind" callback function called when all clients have disconnected from a particular interface published by the service. |
Variables |
|
|---|---|
ANativeService_onCreate
|
The default name of the entry point function.
|
Functions |
|
|---|---|
ANativeService_setOnBindCallback(ANativeService *_Nonnull service, ANativeService_onBindCallback _Nonnull callback)
|
void
Sets the "onBind" callback function for the service.
|
ANativeService_setOnDestroyCallback(ANativeService *_Nonnull service, ANativeService_onDestroyCallback_Nullable callback)
|
void
Sets the "onDestroy" callback function for the service.
|
ANativeService_setOnRebindCallback(ANativeService *_Nonnull service, ANativeService_onRebindCallback_Nullable callback)
|
void
Sets the "onRebind" callback function for the service.
|
ANativeService_setOnTrimMemoryCallback(ANativeService *_Nonnull service, ANativeService_onTrimMemoryCallback_Nullable callback)
|
void
Sets the "onTrimMemory" callback function for the service.
|
ANativeService_setOnUnbindCallback(ANativeService *_Nonnull service, ANativeService_onUnbindCallback_Nullable callback)
|
void
Sets the "onUnbind" callback function for the service.
|
Enumerations
ANativeServiceTrimMemoryLevel
Declared inandroid/native_service.h
ANativeServiceTrimMemoryLevel
The levels for ANativeService_onTrimMemoryCallback indicating the context of the trim, giving a hint of the amount of trimming the application may like to perform.
Introduced in API 37.
Typedefs
ANativeService
Declared inandroid/native_service.h
typedef__BEGIN_DECLS struct ANativeService ANativeService
An opaque struct representing a native service instance.
The framework creates a unique instance of this struct for each service. A handle to this same instance is passed to every callback function of the service.
Introduced in API 37.
ANativeServiceTrimMemoryLevel
Declared inandroid/native_service.h
enum ANativeServiceTrimMemoryLevel ANativeServiceTrimMemoryLevel
The levels for ANativeService_onTrimMemoryCallback indicating the context of the trim, giving a hint of the amount of trimming the application may like to perform.
Introduced in API 37.
ANativeService_createFunc
Declared inandroid/native_service.h
void ANativeService_createFunc(ANativeService *_Nonnull service)
The function type signature definition of the entry point function of the service.
service must be initialized in this function.
This function will run on the main thread of the process.
Introduced in API 37.
| Details | |||
|---|---|---|---|
| Parameters |
|
ANativeService_onBindCallback
Declared inandroid/native_service.h
AIBinder *_Nullable(* ANativeService_onBindCallback)(ANativeService *_Nonnull service, uint64_t bindToken, char const *_Nullable action, char const *_Nullable data)
The function type signature definition of the "onBind" callback function called when someone is binding to the service, with the given action and data on the intent.
This may return NULL if clients cannot bind to the service, or a pointer to a valid AIBinder. If an AIBinder is returned, its ownership is transferred to the system, which is responsible for decrementing the reference count of the instance.
This callback function will run on the main thread of the process.
Introduced in API 37.
| Details | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Parameters |
|
||||||||
| Returns |
an AIBinder pointer through which clients can call on to the service. Ownership is transferred to the system.
|
ANativeService_onDestroyCallback
Declared inandroid/native_service.h
void(* ANativeService_onDestroyCallback)(ANativeService *_Nonnull service)
The function type signature definition of the "onDestroy" callback function called when the service is being destroyed.
This callback function will run on the main thread of the process.
Introduced in API 37.
| Details | |||
|---|---|---|---|
| Parameters |
|
ANativeService_onRebindCallback
Declared inandroid/native_service.h
void(* ANativeService_onRebindCallback)(ANativeService *_Nonnull service, uint64_t bindToken)
The function type signature definition of the "onRebind" callback function called when someone is rebinding to the service.
This callback is called only when onUnbind() returned true before.
This callback function will run on the main thread of the process.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ANativeService_onTrimMemoryCallback
Declared inandroid/native_service.h
void(* ANativeService_onTrimMemoryCallback)(ANativeService *_Nonnull service, ANativeServiceTrimMemoryLevel level)
The function type signature definition of the "onTrimMemory" callback function called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.
You should never compare to exact values of the level, since new intermediate values may be added you will typically want to compare if the value is greater or equal to a level you are interested in.
This callback function will run on the main thread of the process.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ANativeService_onUnbindCallback
Declared inandroid/native_service.h
bool(* ANativeService_onUnbindCallback)(ANativeService *_Nonnull service, uint64_t bindToken)
The function type signature definition of the "onUnbind" callback function called when all clients have disconnected from a particular interface published by the service.
Return true if you would like to have the service's onRebind() method later called when new clients bind to it.
This callback function will run on the main thread of the process.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
||||
| Returns |
true if you would like to have the service's ANativeService_onRebindCallback callback later called when new clients bind to it, otherwise false.
|
Variables
ANativeService_onCreate
Declared inandroid/native_service.h
ANativeService_createFunc ANativeService_onCreate
The default name of the entry point function.
You can specify a different function name through android.app.PROPERTY_NATIVE_SERVICE_FUNCTION_NAME property in your manifest.
Introduced in API 37.
Functions
ANativeService_setOnBindCallback
Declared inandroid/native_service.h
void ANativeService_setOnBindCallback( ANativeService *_Nonnull service, ANativeService_onBindCallback _Nonnull callback )
Sets the "onBind" callback function for the service.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ANativeService_setOnDestroyCallback
Declared inandroid/native_service.h
void ANativeService_setOnDestroyCallback( ANativeService *_Nonnull service, ANativeService_onDestroyCallback_Nullable callback )
Sets the "onDestroy" callback function for the service.
If NULL is specified as the callback, then the system skips calling the callback when the event happens.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ANativeService_setOnRebindCallback
Declared inandroid/native_service.h
void ANativeService_setOnRebindCallback( ANativeService *_Nonnull service, ANativeService_onRebindCallback_Nullable callback )
Sets the "onRebind" callback function for the service.
If NULL is specified as the callback, then the system skips calling the callback when the event happens.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ANativeService_setOnTrimMemoryCallback
Declared inandroid/native_service.h
void ANativeService_setOnTrimMemoryCallback( ANativeService *_Nonnull service, ANativeService_onTrimMemoryCallback_Nullable callback )
Sets the "onTrimMemory" callback function for the service.
If NULL is specified as the callback, then the system skips calling the callback when the event happens.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ANativeService_setOnUnbindCallback
Declared inandroid/native_service.h
void ANativeService_setOnUnbindCallback( ANativeService *_Nonnull service, ANativeService_onUnbindCallback_Nullable callback )
Sets the "onUnbind" callback function for the service.
If NULL is specified as the callback, then the system runs the default implementation which does nothing and returns false.
Introduced in API 37.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|