SystemSensorManagerpublic class SystemSensorManager extends SensorManager Sensor manager implementation that communicates with the built-in
system sensors. |
Fields Summary |
---|
private static boolean | sSensorModuleInitialized | private static final Object | sSensorModuleLock | private static final ArrayList | sFullSensorsList | private static final android.util.SparseArray | sHandleToSensor | private final HashMap | mSensorListeners | private final HashMap | mTriggerListeners | private final android.os.Looper | mMainLooper | private final int | mTargetSdkLevel |
Constructors Summary |
---|
public SystemSensorManager(android.content.Context context, android.os.Looper mainLooper){@hide}
mMainLooper = mainLooper;
mTargetSdkLevel = context.getApplicationInfo().targetSdkVersion;
synchronized(sSensorModuleLock) {
if (!sSensorModuleInitialized) {
sSensorModuleInitialized = true;
nativeClassInit();
// initialize the sensor list
final ArrayList<Sensor> fullList = sFullSensorsList;
int i = 0;
do {
Sensor sensor = new Sensor();
i = nativeGetNextSensor(sensor, i);
if (i>=0) {
//Log.d(TAG, "found sensor: " + sensor.getName() +
// ", handle=" + sensor.getHandle());
fullList.add(sensor);
sHandleToSensor.append(sensor.getHandle(), sensor);
}
} while (i>0);
}
}
|
Methods Summary |
---|
protected boolean | cancelTriggerSensorImpl(TriggerEventListener listener, Sensor sensor, boolean disable)
if (sensor != null && sensor.getReportingMode() != Sensor.REPORTING_MODE_ONE_SHOT) {
return false;
}
synchronized (mTriggerListeners) {
TriggerEventQueue queue = mTriggerListeners.get(listener);
if (queue != null) {
boolean result;
if (sensor == null) {
result = queue.removeAllSensors();
} else {
result = queue.removeSensor(sensor, disable);
}
if (result && !queue.hasSensors()) {
mTriggerListeners.remove(listener);
queue.dispose();
}
return result;
}
return false;
}
| protected boolean | flushImpl(SensorEventListener listener)
if (listener == null) throw new IllegalArgumentException("listener cannot be null");
synchronized (mSensorListeners) {
SensorEventQueue queue = mSensorListeners.get(listener);
if (queue == null) {
return false;
} else {
return (queue.flush() == 0);
}
}
| protected java.util.List | getFullSensorList()
return sFullSensorsList;
| private static native void | nativeClassInit()
| private static native int | nativeGetNextSensor(Sensor sensor, int next)
| protected boolean | registerListenerImpl(SensorEventListener listener, Sensor sensor, int delayUs, android.os.Handler handler, int maxBatchReportLatencyUs, int reservedFlags)
if (listener == null || sensor == null) {
Log.e(TAG, "sensor or listener is null");
return false;
}
// Trigger Sensors should use the requestTriggerSensor call.
if (sensor.getReportingMode() == Sensor.REPORTING_MODE_ONE_SHOT) {
Log.e(TAG, "Trigger Sensors should use the requestTriggerSensor.");
return false;
}
if (maxBatchReportLatencyUs < 0 || delayUs < 0) {
Log.e(TAG, "maxBatchReportLatencyUs and delayUs should be non-negative");
return false;
}
// Invariants to preserve:
// - one Looper per SensorEventListener
// - one Looper per SensorEventQueue
// We map SensorEventListener to a SensorEventQueue, which holds the looper
synchronized (mSensorListeners) {
SensorEventQueue queue = mSensorListeners.get(listener);
if (queue == null) {
Looper looper = (handler != null) ? handler.getLooper() : mMainLooper;
queue = new SensorEventQueue(listener, looper, this);
if (!queue.addSensor(sensor, delayUs, maxBatchReportLatencyUs, reservedFlags)) {
queue.dispose();
return false;
}
mSensorListeners.put(listener, queue);
return true;
} else {
return queue.addSensor(sensor, delayUs, maxBatchReportLatencyUs, reservedFlags);
}
}
| protected boolean | requestTriggerSensorImpl(TriggerEventListener listener, Sensor sensor)
if (sensor == null) throw new IllegalArgumentException("sensor cannot be null");
if (sensor.getReportingMode() != Sensor.REPORTING_MODE_ONE_SHOT) return false;
synchronized (mTriggerListeners) {
TriggerEventQueue queue = mTriggerListeners.get(listener);
if (queue == null) {
queue = new TriggerEventQueue(listener, mMainLooper, this);
if (!queue.addSensor(sensor, 0, 0, 0)) {
queue.dispose();
return false;
}
mTriggerListeners.put(listener, queue);
return true;
} else {
return queue.addSensor(sensor, 0, 0, 0);
}
}
| protected void | unregisterListenerImpl(SensorEventListener listener, Sensor sensor)
// Trigger Sensors should use the cancelTriggerSensor call.
if (sensor != null && sensor.getReportingMode() == Sensor.REPORTING_MODE_ONE_SHOT) {
return;
}
synchronized (mSensorListeners) {
SensorEventQueue queue = mSensorListeners.get(listener);
if (queue != null) {
boolean result;
if (sensor == null) {
result = queue.removeAllSensors();
} else {
result = queue.removeSensor(sensor, true);
}
if (result && !queue.hasSensors()) {
mSensorListeners.remove(listener);
queue.dispose();
}
}
}
|
|