Merge "Fix a few known issue in sensor framework" into nyc-dev

This commit is contained in:
Peng Xu
2016-04-01 01:54:37 +00:00
committed by Android (Google) Code Review
8 changed files with 150 additions and 73 deletions

View File

@@ -13503,6 +13503,7 @@ package android.hardware {
public final class Sensor { public final class Sensor {
method public int getFifoMaxEventCount(); method public int getFifoMaxEventCount();
method public int getFifoReservedEventCount(); method public int getFifoReservedEventCount();
method public int getId();
method public int getMaxDelay(); method public int getMaxDelay();
method public float getMaximumRange(); method public float getMaximumRange();
method public int getMinDelay(); method public int getMinDelay();
@@ -13512,9 +13513,10 @@ package android.hardware {
method public float getResolution(); method public float getResolution();
method public java.lang.String getStringType(); method public java.lang.String getStringType();
method public int getType(); method public int getType();
method public java.util.UUID getUuid();
method public java.lang.String getVendor(); method public java.lang.String getVendor();
method public int getVersion(); method public int getVersion();
method public boolean isAdditionalInfoSupported();
method public boolean isDynamicSensor();
method public boolean isWakeUpSensor(); method public boolean isWakeUpSensor();
field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0 field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2 field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
@@ -13633,8 +13635,9 @@ package android.hardware {
method public static void getRotationMatrixFromVector(float[], float[]); method public static void getRotationMatrixFromVector(float[], float[]);
method public java.util.List<android.hardware.Sensor> getSensorList(int); method public java.util.List<android.hardware.Sensor> getSensorList(int);
method public deprecated int getSensors(); method public deprecated int getSensors();
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback); method public boolean isDynamicSensorDiscoverySupported();
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback, android.os.Handler); method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback, android.os.Handler);
method public deprecated boolean registerListener(android.hardware.SensorListener, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int); method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
@@ -13643,7 +13646,7 @@ package android.hardware {
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler); method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler);
method public static boolean remapCoordinateSystem(float[], int, int, float[]); method public static boolean remapCoordinateSystem(float[], int, int, float[]);
method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor); method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback); method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public deprecated void unregisterListener(android.hardware.SensorListener); method public deprecated void unregisterListener(android.hardware.SensorListener);
method public deprecated void unregisterListener(android.hardware.SensorListener, int); method public deprecated void unregisterListener(android.hardware.SensorListener, int);
method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor); method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -13708,8 +13711,8 @@ package android.hardware {
field public static final float STANDARD_GRAVITY = 9.80665f; field public static final float STANDARD_GRAVITY = 9.80665f;
} }
public static abstract class SensorManager.DynamicSensorConnectionCallback { public static abstract class SensorManager.DynamicSensorCallback {
ctor public SensorManager.DynamicSensorConnectionCallback(); ctor public SensorManager.DynamicSensorCallback();
method public void onDynamicSensorConnected(android.hardware.Sensor); method public void onDynamicSensorConnected(android.hardware.Sensor);
method public void onDynamicSensorDisconnected(android.hardware.Sensor); method public void onDynamicSensorDisconnected(android.hardware.Sensor);
} }

View File

@@ -13902,6 +13902,7 @@ package android.hardware {
public final class Sensor { public final class Sensor {
method public int getFifoMaxEventCount(); method public int getFifoMaxEventCount();
method public int getFifoReservedEventCount(); method public int getFifoReservedEventCount();
method public int getId();
method public int getMaxDelay(); method public int getMaxDelay();
method public float getMaximumRange(); method public float getMaximumRange();
method public int getMinDelay(); method public int getMinDelay();
@@ -13914,7 +13915,9 @@ package android.hardware {
method public java.util.UUID getUuid(); method public java.util.UUID getUuid();
method public java.lang.String getVendor(); method public java.lang.String getVendor();
method public int getVersion(); method public int getVersion();
method public boolean isAdditionalInfoSupported();
method public boolean isDataInjectionSupported(); method public boolean isDataInjectionSupported();
method public boolean isDynamicSensor();
method public boolean isWakeUpSensor(); method public boolean isWakeUpSensor();
field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0 field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2 field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
@@ -14039,8 +14042,9 @@ package android.hardware {
method public deprecated int getSensors(); method public deprecated int getSensors();
method public boolean initDataInjection(boolean); method public boolean initDataInjection(boolean);
method public boolean injectSensorData(android.hardware.Sensor, float[], int, long); method public boolean injectSensorData(android.hardware.Sensor, float[], int, long);
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback); method public boolean isDynamicSensorDiscoverySupported();
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback, android.os.Handler); method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback, android.os.Handler);
method public deprecated boolean registerListener(android.hardware.SensorListener, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int); method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
@@ -14049,7 +14053,7 @@ package android.hardware {
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler); method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler);
method public static boolean remapCoordinateSystem(float[], int, int, float[]); method public static boolean remapCoordinateSystem(float[], int, int, float[]);
method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor); method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback); method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public deprecated void unregisterListener(android.hardware.SensorListener); method public deprecated void unregisterListener(android.hardware.SensorListener);
method public deprecated void unregisterListener(android.hardware.SensorListener, int); method public deprecated void unregisterListener(android.hardware.SensorListener, int);
method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor); method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -14114,8 +14118,8 @@ package android.hardware {
field public static final float STANDARD_GRAVITY = 9.80665f; field public static final float STANDARD_GRAVITY = 9.80665f;
} }
public static abstract class SensorManager.DynamicSensorConnectionCallback { public static abstract class SensorManager.DynamicSensorCallback {
ctor public SensorManager.DynamicSensorConnectionCallback(); ctor public SensorManager.DynamicSensorCallback();
method public void onDynamicSensorConnected(android.hardware.Sensor); method public void onDynamicSensorConnected(android.hardware.Sensor);
method public void onDynamicSensorDisconnected(android.hardware.Sensor); method public void onDynamicSensorDisconnected(android.hardware.Sensor);
} }

View File

@@ -13513,6 +13513,7 @@ package android.hardware {
public final class Sensor { public final class Sensor {
method public int getFifoMaxEventCount(); method public int getFifoMaxEventCount();
method public int getFifoReservedEventCount(); method public int getFifoReservedEventCount();
method public int getId();
method public int getMaxDelay(); method public int getMaxDelay();
method public float getMaximumRange(); method public float getMaximumRange();
method public int getMinDelay(); method public int getMinDelay();
@@ -13522,9 +13523,10 @@ package android.hardware {
method public float getResolution(); method public float getResolution();
method public java.lang.String getStringType(); method public java.lang.String getStringType();
method public int getType(); method public int getType();
method public java.util.UUID getUuid();
method public java.lang.String getVendor(); method public java.lang.String getVendor();
method public int getVersion(); method public int getVersion();
method public boolean isAdditionalInfoSupported();
method public boolean isDynamicSensor();
method public boolean isWakeUpSensor(); method public boolean isWakeUpSensor();
field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0 field public static final int REPORTING_MODE_CONTINUOUS = 0; // 0x0
field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2 field public static final int REPORTING_MODE_ONE_SHOT = 2; // 0x2
@@ -13643,8 +13645,9 @@ package android.hardware {
method public static void getRotationMatrixFromVector(float[], float[]); method public static void getRotationMatrixFromVector(float[], float[]);
method public java.util.List<android.hardware.Sensor> getSensorList(int); method public java.util.List<android.hardware.Sensor> getSensorList(int);
method public deprecated int getSensors(); method public deprecated int getSensors();
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback); method public boolean isDynamicSensorDiscoverySupported();
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback, android.os.Handler); method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public void registerDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback, android.os.Handler);
method public deprecated boolean registerListener(android.hardware.SensorListener, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int);
method public deprecated boolean registerListener(android.hardware.SensorListener, int, int); method public deprecated boolean registerListener(android.hardware.SensorListener, int, int);
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int); method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int);
@@ -13653,7 +13656,7 @@ package android.hardware {
method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler); method public boolean registerListener(android.hardware.SensorEventListener, android.hardware.Sensor, int, int, android.os.Handler);
method public static boolean remapCoordinateSystem(float[], int, int, float[]); method public static boolean remapCoordinateSystem(float[], int, int, float[]);
method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor); method public boolean requestTriggerSensor(android.hardware.TriggerEventListener, android.hardware.Sensor);
method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorConnectionCallback); method public void unregisterDynamicSensorCallback(android.hardware.SensorManager.DynamicSensorCallback);
method public deprecated void unregisterListener(android.hardware.SensorListener); method public deprecated void unregisterListener(android.hardware.SensorListener);
method public deprecated void unregisterListener(android.hardware.SensorListener, int); method public deprecated void unregisterListener(android.hardware.SensorListener, int);
method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor); method public void unregisterListener(android.hardware.SensorEventListener, android.hardware.Sensor);
@@ -13718,8 +13721,8 @@ package android.hardware {
field public static final float STANDARD_GRAVITY = 9.80665f; field public static final float STANDARD_GRAVITY = 9.80665f;
} }
public static abstract class SensorManager.DynamicSensorConnectionCallback { public static abstract class SensorManager.DynamicSensorCallback {
ctor public SensorManager.DynamicSensorConnectionCallback(); ctor public SensorManager.DynamicSensorCallback();
method public void onDynamicSensorConnected(android.hardware.Sensor); method public void onDynamicSensorConnected(android.hardware.Sensor);
method public void onDynamicSensorDisconnected(android.hardware.Sensor); method public void onDynamicSensorDisconnected(android.hardware.Sensor);
} }

View File

@@ -186,7 +186,7 @@ public final class Sensor {
* @see #TYPE_LINEAR_ACCELERATION * @see #TYPE_LINEAR_ACCELERATION
*/ */
public static final String STRING_TYPE_LINEAR_ACCELERATION = public static final String STRING_TYPE_LINEAR_ACCELERATION =
"android.sensor.linear_acceleration"; "android.sensor.linear_acceleration";
/** /**
* A constant describing a rotation vector sensor type. * A constant describing a rotation vector sensor type.
@@ -229,7 +229,7 @@ public final class Sensor {
* @see #TYPE_AMBIENT_TEMPERATURE * @see #TYPE_AMBIENT_TEMPERATURE
*/ */
public static final String STRING_TYPE_AMBIENT_TEMPERATURE = public static final String STRING_TYPE_AMBIENT_TEMPERATURE =
"android.sensor.ambient_temperature"; "android.sensor.ambient_temperature";
/** /**
* A constant describing an uncalibrated magnetic field sensor type. * A constant describing an uncalibrated magnetic field sensor type.
@@ -254,7 +254,7 @@ public final class Sensor {
* @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED
*/ */
public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED = public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED =
"android.sensor.magnetic_field_uncalibrated"; "android.sensor.magnetic_field_uncalibrated";
/** /**
* A constant describing an uncalibrated rotation vector sensor type. * A constant describing an uncalibrated rotation vector sensor type.
@@ -280,7 +280,7 @@ public final class Sensor {
* @see #TYPE_GAME_ROTATION_VECTOR * @see #TYPE_GAME_ROTATION_VECTOR
*/ */
public static final String STRING_TYPE_GAME_ROTATION_VECTOR = public static final String STRING_TYPE_GAME_ROTATION_VECTOR =
"android.sensor.game_rotation_vector"; "android.sensor.game_rotation_vector";
/** /**
* A constant describing an uncalibrated gyroscope sensor type. * A constant describing an uncalibrated gyroscope sensor type.
@@ -302,7 +302,7 @@ public final class Sensor {
* @see #TYPE_GYROSCOPE_UNCALIBRATED * @see #TYPE_GYROSCOPE_UNCALIBRATED
*/ */
public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED = public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED =
"android.sensor.gyroscope_uncalibrated"; "android.sensor.gyroscope_uncalibrated";
/** /**
* A constant describing a significant motion trigger sensor. * A constant describing a significant motion trigger sensor.
@@ -324,7 +324,7 @@ public final class Sensor {
* @see #TYPE_SIGNIFICANT_MOTION * @see #TYPE_SIGNIFICANT_MOTION
*/ */
public static final String STRING_TYPE_SIGNIFICANT_MOTION = public static final String STRING_TYPE_SIGNIFICANT_MOTION =
"android.sensor.significant_motion"; "android.sensor.significant_motion";
/** /**
* A constant describing a step detector sensor. * A constant describing a step detector sensor.
@@ -391,7 +391,7 @@ public final class Sensor {
* @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR
*/ */
public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR = public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR =
"android.sensor.geomagnetic_rotation_vector"; "android.sensor.geomagnetic_rotation_vector";
/** /**
* A constant describing a heart rate monitor. * A constant describing a heart rate monitor.
@@ -431,7 +431,7 @@ public final class Sensor {
* A constant string describing a wake up tilt detector sensor type. * A constant string describing a wake up tilt detector sensor type.
* *
* @hide * @hide
* @see #TYPE_WAKE_UP_TILT_DETECTOR * @see #TYPE_TILT_DETECTOR
*/ */
public static final String SENSOR_STRING_TYPE_TILT_DETECTOR = public static final String SENSOR_STRING_TYPE_TILT_DETECTOR =
"android.sensor.tilt_detector"; "android.sensor.tilt_detector";
@@ -495,7 +495,7 @@ public final class Sensor {
*/ */
public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture"; public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture";
/** /**
* A constant describing a pick up sensor. * A constant describing a pick up sensor.
* *
* A sensor of this type triggers when the device is picked up regardless of wherever it was * A sensor of this type triggers when the device is picked up regardless of wherever it was
@@ -514,7 +514,7 @@ public final class Sensor {
*/ */
public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture"; public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture";
/** /**
* A constant describing a wrist tilt gesture sensor. * A constant describing a wrist tilt gesture sensor.
* *
* A sensor of this type triggers when the device face is tilted towards the user. * A sensor of this type triggers when the device face is tilted towards the user.
@@ -553,7 +553,7 @@ public final class Sensor {
*/ */
public static final String STRING_TYPE_DEVICE_ORIENTATION = "android.sensor.device_orientation"; public static final String STRING_TYPE_DEVICE_ORIENTATION = "android.sensor.device_orientation";
/** /**
* A constant describing a pose sensor with 6 degrees of freedom. * A constant describing a pose sensor with 6 degrees of freedom.
* *
* Similar to {@link #TYPE_ROTATION_VECTOR}, with additional delta * Similar to {@link #TYPE_ROTATION_VECTOR}, with additional delta
@@ -578,7 +578,7 @@ public final class Sensor {
*/ */
public static final String STRING_TYPE_POSE_6DOF = "android.sensor.pose_6dof"; public static final String STRING_TYPE_POSE_6DOF = "android.sensor.pose_6dof";
/** /**
* A constant describing a stationary detect sensor. * A constant describing a stationary detect sensor.
* *
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
@@ -593,7 +593,7 @@ public final class Sensor {
*/ */
public static final String STRING_TYPE_STATIONARY_DETECT = "android.sensor.stationary_detect"; public static final String STRING_TYPE_STATIONARY_DETECT = "android.sensor.stationary_detect";
/** /**
* A constant describing a motion detect sensor. * A constant describing a motion detect sensor.
* *
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
@@ -608,7 +608,7 @@ public final class Sensor {
*/ */
public static final String STRING_TYPE_MOTION_DETECT = "android.sensor.motion_detect"; public static final String STRING_TYPE_MOTION_DETECT = "android.sensor.motion_detect";
/** /**
* A constant describing a motion detect sensor. * A constant describing a motion detect sensor.
* *
* See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
@@ -706,6 +706,14 @@ public final class Sensor {
private static final int DATA_INJECTION_MASK = 0x10; private static final int DATA_INJECTION_MASK = 0x10;
private static final int DATA_INJECTION_SHIFT = 4; private static final int DATA_INJECTION_SHIFT = 4;
// MASK for dynamic sensor (sensor that added during runtime), bit 6.
private static final int DYNAMIC_SENSOR_MASK = 0x20;
private static final int DYNAMIC_SENSOR_SHIFT = 5;
// MASK for indication bit of sensor additional information support (bit 7).
private static final int ADDITIONAL_INFO_MASK = 0x40;
private static final int ADDITIONAL_INFO_SHIFT = 6;
// TODO(): The following arrays are fragile and error-prone. This needs to be refactored. // TODO(): The following arrays are fragile and error-prone. This needs to be refactored.
// Note: This needs to be updated, whenever a new sensor is added. // Note: This needs to be updated, whenever a new sensor is added.
@@ -887,12 +895,36 @@ public final class Sensor {
} }
/** /**
* @return The type of this sensor as a string. * @return The UUID of the sensor. If the sensor does not support UUID, the returned value will
* be an all zero UUID; if the sensor's combination of type and name is guaranteed to be unique
* in system, the return value will be an all "F" UUID.
*
* @hide
*/ */
@SystemApi
public UUID getUuid() { public UUID getUuid() {
return mUuid; return mUuid;
} }
/**
* @return The unique id of sensor. Return value of 0 means this sensor does not support UUID;
* return value of -1 means this sensor can be uniquely identified in system by combination of
* its type and name.
*/
public int getId() {
if (mUuid == ALL_0_UUID) {
return 0;
} else if (mUuid == ALL_F_UUID) {
return -1;
} else {
int id = Math.abs(mUuid.hashCode()) + 1;
if (id <= 0) { // catch corner case when hash is Integer.MIN_VALUE and Integer.MAX_VALUE
id = 1;
}
return id;
}
}
/** /**
* @hide * @hide
* @return The permission required to access this sensor. If empty, no permission is required. * @return The permission required to access this sensor. If empty, no permission is required.
@@ -960,6 +992,26 @@ public final class Sensor {
return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0; return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0;
} }
/**
* Returns true if the sensor is a dynamic sensor.
*
* @return <code>true</code> if the sensor is a dynamic sensor (sensor added at runtime).
* @see SensorManager.DynamicSensorCallback
*/
public boolean isDynamicSensor() {
return (mFlags & DYNAMIC_SENSOR_MASK) != 0;
}
/**
* Returns true if the sensor supports sensor additional information API
*
* @return <code>true</code> if the sensor supports sensor additional information API
* @see SensorAdditionalInfo
*/
public boolean isAdditionalInfoSupported() {
return (mFlags & ADDITIONAL_INFO_MASK) != 0;
}
/** /**
* Returns true if the sensor supports data injection when the * Returns true if the sensor supports data injection when the
* HAL is set to data injection mode. * HAL is set to data injection mode.
@@ -986,6 +1038,10 @@ public final class Sensor {
+ ", power=" + mPower + ", minDelay=" + mMinDelay + "}"; + ", power=" + mPower + ", minDelay=" + mMinDelay + "}";
} }
//special UUID hash constant
private final static UUID ALL_0_UUID = new UUID(0,0);
private final static UUID ALL_F_UUID = new UUID(~0L, ~0L);
/** /**
* Sets the Type associated with the sensor. * Sets the Type associated with the sensor.
* NOTE: to be used only by native bindings in SensorManager. * NOTE: to be used only by native bindings in SensorManager.

View File

@@ -27,7 +27,7 @@ import java.lang.annotation.RetentionPolicy;
* android.hardware.SensorEventCallback#onSensorAdditionalInfo onSensorAdditionalInfo}. * android.hardware.SensorEventCallback#onSensorAdditionalInfo onSensorAdditionalInfo}.
* *
* @see SensorManager * @see SensorManager
* @see SensorEventListener3 * @see SensorEventCallback
* @see Sensor * @see Sensor
* *
*/ */
@@ -106,7 +106,7 @@ public class SensorAdditionalInfo {
* such as accelerometer, gyro, etc. * such as accelerometer, gyro, etc.
* *
* Payload: * Payload:
* floatValues[0..11]: First 3 rows of a homogenous matrix in row major order that captures * floatValues[0..11]: First 3 rows of a homogeneous matrix in row major order that captures
* any linear transformation, including rotation, scaling, shear, shift. * any linear transformation, including rotation, scaling, shear, shift.
*/ */
public static final int TYPE_VEC3_CALIBRATION = 0x10002; public static final int TYPE_VEC3_CALIBRATION = 0x10002;

View File

@@ -18,7 +18,7 @@ package android.hardware;
/** /**
* This class represents a {@link android.hardware.Sensor Sensor} event and * This class represents a {@link android.hardware.Sensor Sensor} event and
* holds informations such as the sensor's type, the time-stamp, accuracy and of * holds information such as the sensor's type, the time-stamp, accuracy and of
* course the sensor's {@link SensorEvent#values data}. * course the sensor's {@link SensorEvent#values data}.
* *
* <p> * <p>
@@ -163,7 +163,7 @@ public class SensorEvent {
* </ul> * </ul>
* <p> * <p>
* Typically the output of the gyroscope is integrated over time to * Typically the output of the gyroscope is integrated over time to
* calculate a rotation describing the change of angles over the timestep, * calculate a rotation describing the change of angles over the time step,
* for example: * for example:
* </p> * </p>
* *
@@ -173,7 +173,7 @@ public class SensorEvent {
* private float timestamp; * private float timestamp;
* *
* public void onSensorChanged(SensorEvent event) { * public void onSensorChanged(SensorEvent event) {
* // This timestep's delta rotation to be multiplied by the current rotation * // This time step's delta rotation to be multiplied by the current rotation
* // after computing it from the gyro sample data. * // after computing it from the gyro sample data.
* if (timestamp != 0) { * if (timestamp != 0) {
* final float dT = (event.timestamp - timestamp) * NS2S; * final float dT = (event.timestamp - timestamp) * NS2S;
@@ -192,8 +192,8 @@ public class SensorEvent {
* axisZ /= omegaMagnitude; * axisZ /= omegaMagnitude;
* } * }
* *
* // Integrate around this axis with the angular speed by the timestep * // Integrate around this axis with the angular speed by the time step
* // in order to get a delta rotation from this sample over the timestep * // in order to get a delta rotation from this sample over the time step
* // We will convert this axis-angle representation of the delta rotation * // We will convert this axis-angle representation of the delta rotation
* // into a quaternion before turning it into the rotation matrix. * // into a quaternion before turning it into the rotation matrix.
* float thetaOverTwo = omegaMagnitude * dT / 2.0f; * float thetaOverTwo = omegaMagnitude * dT / 2.0f;
@@ -433,9 +433,9 @@ public class SensorEvent {
* Each field is a component of the estimated hard iron calibration. * Each field is a component of the estimated hard iron calibration.
* The values are in micro-Tesla (uT). * The values are in micro-Tesla (uT).
* </p> * </p>
* <p> Hard iron - These distortions arise due to the magnetized iron, steel or permanenet * <p> Hard iron - These distortions arise due to the magnetized iron, steel or permanent
* magnets on the device. * magnets on the device.
* Soft iron - These distortions arise due to the interaction with the earth's magentic * Soft iron - These distortions arise due to the interaction with the earth's magnetic
* field. * field.
* </p> * </p>
* <h4> {@link android.hardware.Sensor#TYPE_GAME_ROTATION_VECTOR}:</h4> * <h4> {@link android.hardware.Sensor#TYPE_GAME_ROTATION_VECTOR}:</h4>
@@ -508,14 +508,14 @@ public class SensorEvent {
* *
* *
* <ul> * <ul>
* <li> values[0]: x*sin(&#952/2) </li> * <li> values[0]: x*sin(&#952/2) </li>
* <li> values[1]: y*sin(&#952/2) </li> * <li> values[1]: y*sin(&#952/2) </li>
* <li> values[2]: z*sin(&#952/2) </li> * <li> values[2]: z*sin(&#952/2) </li>
* <li> values[3]: cos(&#952/2) </li> * <li> values[3]: cos(&#952/2) </li>
* *
* *
* <li> values[4]: Translation along x axis from an arbitrary origin. </li> * <li> values[4]: Translation along x axis from an arbitrary origin. </li>
* li> values[5]: Translation along y axis from an arbitrary origin. </li> * <li> values[5]: Translation along y axis from an arbitrary origin. </li>
* <li> values[6]: Translation along z axis from an arbitrary origin. </li> * <li> values[6]: Translation along z axis from an arbitrary origin. </li>
* *
* <li> values[7]: Delta quaternion rotation x*sin(&#952/2) </li> * <li> values[7]: Delta quaternion rotation x*sin(&#952/2) </li>

View File

@@ -884,7 +884,7 @@ public abstract class SensorManager {
* Used for receiving notifications from the SensorManager when dynamic sensors are connected or * Used for receiving notifications from the SensorManager when dynamic sensors are connected or
* disconnected. * disconnected.
*/ */
public static abstract class DynamicSensorConnectionCallback { public static abstract class DynamicSensorCallback {
/** /**
* Called when there is a dynamic sensor being connected to the system. * Called when there is a dynamic sensor being connected to the system.
* *
@@ -902,62 +902,73 @@ public abstract class SensorManager {
/** /**
* Add a {@link android.hardware.SensorManager.DynamicSensorConnectionCallback * Add a {@link android.hardware.SensorManager.DynamicSensorCallback
* DynamicSensorConnectionCallback} to receive dynamic sensor connection callbacks. Repeat * DynamicSensorCallback} to receive dynamic sensor connection callbacks. Repeat
* registration with the already registered callback object will have no additional effect. * registration with the already registered callback object will have no additional effect.
* *
* @param callback An object that implements the * @param callback An object that implements the
* {@link android.hardware.SensorManager.DynamicSensorConnectionCallback * {@link android.hardware.SensorManager.DynamicSensorCallback
* DynamicSensorConnectionCallback} * DynamicSensorCallback}
* interface for receiving callbacks. * interface for receiving callbacks.
* @see #addDynamicSensorCallback(DynamicSensorConnectionCallback, Handler) * @see #addDynamicSensorCallback(DynamicSensorCallback, Handler)
* *
* @throws IllegalArgumentException when callback is null. * @throws IllegalArgumentException when callback is null.
*/ */
public void registerDynamicSensorCallback(DynamicSensorConnectionCallback callback) { public void registerDynamicSensorCallback(DynamicSensorCallback callback) {
registerDynamicSensorCallback(callback, null); registerDynamicSensorCallback(callback, null);
} }
/** /**
* Add a {@link android.hardware.SensorManager.DynamicSensorConnectionCallback * Add a {@link android.hardware.SensorManager.DynamicSensorCallback
* DynamicSensorConnectionCallback} to receive dynamic sensor connection callbacks. Repeat * DynamicSensorCallback} to receive dynamic sensor connection callbacks. Repeat
* registration with the already registered callback object will have no additional effect. * registration with the already registered callback object will have no additional effect.
* *
* @param callback An object that implements the * @param callback An object that implements the
* {@link android.hardware.SensorManager.DynamicSensorConnectionCallback * {@link android.hardware.SensorManager.DynamicSensorCallback
* DynamicSensorConnectionCallback} interface for receiving callbacks. * DynamicSensorCallback} interface for receiving callbacks.
* @param handler The {@link android.os.Handler Handler} the {@link * @param handler The {@link android.os.Handler Handler} the {@link
* android.hardware.SensorManager.DynamicSensorConnectionCallback * android.hardware.SensorManager.DynamicSensorCallback
* sensor connection events} will be delivered to. * sensor connection events} will be delivered to.
* *
* @throws IllegalArgumentException when callback is null. * @throws IllegalArgumentException when callback is null.
*/ */
public void registerDynamicSensorCallback( public void registerDynamicSensorCallback(
DynamicSensorConnectionCallback callback, Handler handler) { DynamicSensorCallback callback, Handler handler) {
registerDynamicSensorCallbackImpl(callback, handler); registerDynamicSensorCallbackImpl(callback, handler);
} }
/** /**
* Remove a {@link android.hardware.SensorManager.DynamicSensorConnectionCallback * Remove a {@link android.hardware.SensorManager.DynamicSensorCallback
* DynamicSensorConnectionCallback} to stop sending dynamic sensor connection events to that * DynamicSensorCallback} to stop sending dynamic sensor connection events to that
* callback. * callback.
* *
* @param callback An object that implements the * @param callback An object that implements the
* {@link android.hardware.SensorManager.DynamicSensorConnectionCallback * {@link android.hardware.SensorManager.DynamicSensorCallback
* DynamicSensorConnectionCallback} * DynamicSensorCallback}
* interface for receiving callbacks. * interface for receiving callbacks.
*/ */
public void unregisterDynamicSensorCallback(DynamicSensorConnectionCallback callback) { public void unregisterDynamicSensorCallback(DynamicSensorCallback callback) {
unregisterDynamicSensorCallbackImpl(callback); unregisterDynamicSensorCallbackImpl(callback);
} }
/**
* Tell if dynamic sensor discovery feature is supported by system.
*
* @return <code>true</code> if dynamic sensor discovery is supported, <code>false</code>
* otherwise.
*/
public boolean isDynamicSensorDiscoverySupported() {
List<Sensor> sensors = getSensorList(Sensor.TYPE_DYNAMIC_SENSOR_META);
return sensors.size() > 0;
}
/** @hide */ /** @hide */
protected abstract void registerDynamicSensorCallbackImpl( protected abstract void registerDynamicSensorCallbackImpl(
DynamicSensorConnectionCallback callback, Handler handler); DynamicSensorCallback callback, Handler handler);
/** @hide */ /** @hide */
protected abstract void unregisterDynamicSensorCallbackImpl( protected abstract void unregisterDynamicSensorCallbackImpl(
DynamicSensorConnectionCallback callback); DynamicSensorCallback callback);
/** /**
* <p> * <p>

View File

@@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2012 The Android Open Source Project * Copyright (C) 2012 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@@ -76,7 +76,7 @@ public class SystemSensorManager extends SensorManager {
new HashMap<TriggerEventListener, TriggerEventQueue>(); new HashMap<TriggerEventListener, TriggerEventQueue>();
// Dynamic Sensor callbacks // Dynamic Sensor callbacks
private HashMap<DynamicSensorConnectionCallback, Handler> private HashMap<DynamicSensorCallback, Handler>
mDynamicSensorCallbacks = new HashMap<>(); mDynamicSensorCallbacks = new HashMap<>();
private BroadcastReceiver mDynamicSensorBroadcastReceiver; private BroadcastReceiver mDynamicSensorBroadcastReceiver;
@@ -120,7 +120,7 @@ public class SystemSensorManager extends SensorManager {
@Override @Override
protected List<Sensor> getFullDynamicSensorList() { protected List<Sensor> getFullDynamicSensorList() {
// only set up broadcast receiver if the application tries to find dynamic sensors or // only set up broadcast receiver if the application tries to find dynamic sensors or
// explicitly register a DynamicSensorConnectionCallback // explicitly register a DynamicSensorCallback
setupDynamicSensorBroadcastReceiver(); setupDynamicSensorBroadcastReceiver();
updateDynamicSensorList(); updateDynamicSensorList();
return mFullDynamicSensorsList; return mFullDynamicSensorsList;
@@ -354,9 +354,9 @@ public class SystemSensorManager extends SensorManager {
Handler mainHandler = new Handler(mContext.getMainLooper()); Handler mainHandler = new Handler(mContext.getMainLooper());
for (Map.Entry<DynamicSensorConnectionCallback, Handler> entry : for (Map.Entry<DynamicSensorCallback, Handler> entry :
mDynamicSensorCallbacks.entrySet()) { mDynamicSensorCallbacks.entrySet()) {
final DynamicSensorConnectionCallback callback = entry.getKey(); final DynamicSensorCallback callback = entry.getKey();
Handler handler = Handler handler =
entry.getValue() == null ? mainHandler : entry.getValue(); entry.getValue() == null ? mainHandler : entry.getValue();
@@ -413,7 +413,7 @@ public class SystemSensorManager extends SensorManager {
/** @hide */ /** @hide */
protected void registerDynamicSensorCallbackImpl( protected void registerDynamicSensorCallbackImpl(
DynamicSensorConnectionCallback callback, Handler handler) { DynamicSensorCallback callback, Handler handler) {
if (DEBUG_DYNAMIC_SENSOR) { if (DEBUG_DYNAMIC_SENSOR) {
Log.i(TAG, "DYNS Register dynamic sensor callback"); Log.i(TAG, "DYNS Register dynamic sensor callback");
} }
@@ -432,7 +432,7 @@ public class SystemSensorManager extends SensorManager {
/** @hide */ /** @hide */
protected void unregisterDynamicSensorCallbackImpl( protected void unregisterDynamicSensorCallbackImpl(
DynamicSensorConnectionCallback callback) { DynamicSensorCallback callback) {
if (DEBUG_DYNAMIC_SENSOR) { if (DEBUG_DYNAMIC_SENSOR) {
Log.i(TAG, "Removing dynamic sensor listerner"); Log.i(TAG, "Removing dynamic sensor listerner");
} }