SensorDirectChannel
public final class SensorDirectChannel
extends Object
implements Channel
java.lang.Object | |
↳ | android.hardware.SensorDirectChannel |
Class representing a sensor direct channel. Use SensorManager.createDirectChannel(android.os.MemoryFile)
or SensorManager.createDirectChannel(android.hardware.HardwareBuffer)
to obtain an object. The channel object can be then configured (see configure(android.hardware.Sensor, int)
) to start delivery of sensor events into shared memory buffer.
Summary
Constants | |
---|---|
int | RATE_FAST Sensor operates at nominal rate of 200Hz. |
int | RATE_NORMAL Sensor operates at nominal rate of 50Hz. |
int | RATE_STOP Sensor stopped (no event output). |
int | RATE_VERY_FAST Sensor operates at nominal rate of 800Hz. |
int | TYPE_HARDWARE_BUFFER Shared memory type wrapped by HardwareBuffer object. |
int | TYPE_MEMORY_FILE Shared memory type ashmem, wrapped in MemoryFile object. |
Public methods | |
---|---|
void | close() Close sensor direct channel. |
int | configure(Sensor sensor, int rateLevel) Configure sensor rate or stop sensor report. |
boolean | isOpen() Determine if a channel is still valid. |
Protected methods | |
---|---|
void | finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
Inherited methods | |
---|---|
Constants
RATE_FAST
public static final int RATE_FAST
Sensor operates at nominal rate of 200Hz. The actual rate is expected to be between 55% to 220% of nominal rate, thus between 110Hz to 440Hz.
See also:
Constant Value: 2 (0x00000002)
RATE_NORMAL
public static final int RATE_NORMAL
Sensor operates at nominal rate of 50Hz. The actual rate is expected to be between 55% to 220% of nominal rate, thus between 27.5Hz to 110Hz.
See also:
Constant Value: 1 (0x00000001)
RATE_STOP
public static final int RATE_STOP
Sensor stopped (no event output).
See also:
Constant Value: 0 (0x00000000)
RATE_VERY_FAST
public static final int RATE_VERY_FAST
Sensor operates at nominal rate of 800Hz. The actual rate is expected to be between 55% to 220% of nominal rate, thus between 440Hz to 1760Hz.
See also:
Constant Value: 3 (0x00000003)
TYPE_HARDWARE_BUFFER
public static final int TYPE_HARDWARE_BUFFER
Shared memory type wrapped by HardwareBuffer object.
Constant Value: 2 (0x00000002)
TYPE_MEMORY_FILE
public static final int TYPE_MEMORY_FILE
Shared memory type ashmem, wrapped in MemoryFile object.
Constant Value: 1 (0x00000001)
Public methods
close
public void close ()
Close sensor direct channel. Stop all active sensor in the channel and free sensor system resource related to channel. Shared memory used for creating the direct channel need to be closed or freed separately.
configure
public int configure (Sensor sensor, int rateLevel)
Configure sensor rate or stop sensor report. To start event report of a sensor, or change rate of existing report, call this function with rateLevel other than RATE_STOP
. Sensor events will be added into a queue formed by the shared memory used in creation of direction channel. Each element of the queue has size of 104 bytes and represents a sensor event. Data structure of an element (all fields in little-endian):
offset type name ------------------------------------------------------------------------ 0x0000 int32_t size (always 104) 0x0004 int32_t sensor report token 0x0008 int32_t type (see SensorType) 0x000C uint32_t atomic counter 0x0010 int64_t timestamp (see Event) 0x0018 float[16]/int64_t[8] data (data type depends on sensor type) 0x0058 int32_t[4] reserved (set to zero)
RATE_STOP
. If the sensor parameter is left to be null, this will stop all active sensor report associated with the direct channel specified. Function return 1 on success or 0 on failure. Parameters | |
---|---|
sensor | Sensor : A Sensor object to denote sensor to be operated. |
rateLevel | int : rate level defined in SensorDirectChannel . Value is RATE_STOP , RATE_NORMAL , RATE_FAST , or RATE_VERY_FAST |
Returns | |
---|---|
int | * starting report or changing rate: positive sensor report token on success, 0 on failure; * stopping report: 1 on success, 0 on failure. |
Throws | |
---|---|
NullPointerException | when channel is null. |
isOpen
public boolean isOpen ()
Determine if a channel is still valid. A channel is invalidated after close()
is called.
Returns | |
---|---|
boolean | true if channel is valid. |
Protected methods
finalize
protected void finalize ()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize
method to dispose of system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize
method may take any action, including making this object available again to other threads; the usual purpose of finalize
, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
The finalize
method of class Object
performs no special action; it simply returns normally. Subclasses of Object
may override this definition.
The Java programming language does not guarantee which thread will invoke the finalize
method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java virtual machine for any given object.
Any exception thrown by the finalize
method causes the finalization of this object to be halted, but is otherwise ignored.
Throws | |
---|---|
Throwable |