Loading core/java/android/hardware/LegacySensorManager.java +35 −31 Original line number Diff line number Diff line Loading @@ -204,7 +204,7 @@ final class LegacySensorManager { } private static final class LegacyListener implements SensorEventListener { private float mValues[] = new float[6]; private float[] mValues = new float[6]; private SensorListener mTarget; private int mSensors; private final LmsFilter mYawfilter = new LmsFilter(); Loading Loading @@ -256,7 +256,7 @@ final class LegacySensorManager { } public void onSensorChanged(SensorEvent event) { final float v[] = mValues; final float[] v = mValues; v[0] = event.values[0]; v[1] = event.values[1]; v[2] = event.values[2]; Loading Loading @@ -370,9 +370,10 @@ final class LegacySensorManager { private static final int SENSORS_RATE_MS = 20; private static final int COUNT = 12; private static final float PREDICTION_RATIO = 1.0f / 3.0f; private static final float PREDICTION_TIME = (SENSORS_RATE_MS*COUNT/1000.0f)*PREDICTION_RATIO; private float mV[] = new float[COUNT*2]; private long mT[] = new long[COUNT*2]; private static final float PREDICTION_TIME = (SENSORS_RATE_MS * COUNT / 1000.0f) * PREDICTION_RATIO; private float[] mV = new float[COUNT * 2]; private long[] mT = new long[COUNT * 2]; private int mIndex; public LmsFilter() { Loading @@ -393,8 +394,9 @@ final class LegacySensorManager { * when it's full */ mIndex++; if (mIndex >= COUNT*2) if (mIndex >= COUNT * 2) { mIndex = COUNT; } mV[mIndex] = v; mT[mIndex] = time; mV[mIndex - COUNT] = v; Loading Loading @@ -423,10 +425,12 @@ final class LegacySensorManager { // Normalize f *= (1.0f / 360.0f); if (((f>=0)?f:-f) >= 0.5f) if (((f >= 0) ? f : -f) >= 0.5f) { f = f - (float) Math.ceil(f + 0.5f) + 1.0f; if (f < 0) } if (f < 0) { f += 1.0f; } f *= 360.0f; return f; } Loading core/java/android/hardware/Sensor.java +8 −8 Original line number Diff line number Diff line Loading @@ -857,8 +857,8 @@ public final class Sensor { static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) { // RotationVector length has changed to 3 to 5 for API level 18 // Set it to 3 for backward compatibility. if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR && sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR && sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) { return 3; } int offset = sensor.mType; Loading Loading @@ -1033,9 +1033,9 @@ public final class Sensor { * Returns true if the sensor is a wake-up sensor. * <p> * <b>Application Processor Power modes</b> <p> * Application Processor(AP), is the processor on which applications run. When no wake lock is held * and the user is not interacting with the device, this processor can enter a “Suspend” mode, * reducing the power consumption by 10 times or more. * Application Processor(AP), is the processor on which applications run. When no wake lock is * held and the user is not interacting with the device, this processor can enter a “Suspend” * mode, reducing the power consumption by 10 times or more. * </p> * <p> * <b>Non-wake-up sensors</b> <p> Loading core/java/android/hardware/SensorAdditionalInfo.java +4 −4 Original line number Diff line number Diff line Loading @@ -224,8 +224,8 @@ public class SensorAdditionalInfo { /** @hide */ public static SensorAdditionalInfo createCustomInfo(Sensor aSensor, int type, float[] data) { if (type < TYPE_CUSTOM_INFO || type >= TYPE_DEBUG_INFO || aSensor == null) { throw new IllegalArgumentException("invalid parameter(s): type: " + type + "; sensor: " + aSensor); throw new IllegalArgumentException( "invalid parameter(s): type: " + type + "; sensor: " + aSensor); } return new SensorAdditionalInfo(aSensor, type, 0, null, data); Loading core/java/android/hardware/SensorEvent.java +14 −13 Original line number Diff line number Diff line Loading @@ -207,8 +207,8 @@ public class SensorEvent { * timestamp = event.timestamp; * float[] deltaRotationMatrix = new float[9]; * SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector); * // User code should concatenate the delta rotation we computed with the current rotation * // in order to get the updated rotation. * // User code should concatenate the delta rotation we computed with the current * // rotation in order to get the updated rotation. * // rotationCurrent = rotationCurrent * deltaRotationMatrix; * } * </pre> Loading Loading @@ -244,21 +244,22 @@ public class SensorEvent { * <h4>{@link android.hardware.Sensor#TYPE_GRAVITY Sensor.TYPE_GRAVITY}:</h4> * <p>A three dimensional vector indicating the direction and magnitude of gravity. Units * are m/s^2. The coordinate system is the same as is used by the acceleration sensor.</p> * <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be identical * to that of the accelerometer.</p> * * <h4>{@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}:</h4> * A three dimensional vector indicating acceleration along each device axis, not including * gravity. All values have units of m/s^2. The coordinate system is the same as is used by the * acceleration sensor. * <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be * identical to that of the accelerometer.</p> * * <h4> * {@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}: * </h4> A three dimensional vector indicating acceleration along each device axis, not * including gravity. All values have units of m/s^2. The coordinate system is the same as is * used by the acceleration sensor. * <p>The output of the accelerometer, gravity and linear-acceleration sensors must obey the * following relation:</p> * <p><ul>acceleration = gravity + linear-acceleration</ul></p> * * <h4>{@link android.hardware.Sensor#TYPE_ROTATION_VECTOR Sensor.TYPE_ROTATION_VECTOR}:</h4> * <p>The rotation vector represents the orientation of the device as a combination of an <i>angle</i> * and an <i>axis</i>, in which the device has rotated through an angle θ around an axis * <x, y, z>.</p> * <p>The rotation vector represents the orientation of the device as a combination of an * <i>angle</i> and an <i>axis</i>, in which the device has rotated through an angle θ * around an axis <x, y, z>.</p> * <p>The three elements of the rotation vector are * <x*sin(θ/2), y*sin(θ/2), z*sin(θ/2)>, such that the magnitude of the rotation * vector is equal to sin(θ/2), and the direction of the rotation vector is equal to the Loading core/java/android/hardware/SensorManager.java +98 −91 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ public abstract class SensorManager { /** @hide */ protected static final String TAG = "SensorManager"; private static final float[] mTempMatrix = new float[16]; private static final float[] sTempMatrix = new float[16]; // Cached lists of sensors by type. Guarded by mSensorListByType. private final SparseArray<List<Sensor>> mSensorListByType = Loading Loading @@ -425,10 +425,11 @@ public abstract class SensorManager { } else { list = new ArrayList<Sensor>(); for (Sensor i : fullList) { if (i.getType() == type) if (i.getType() == type) { list.add(i); } } } list = Collections.unmodifiableList(list); mSensorListByType.append(type, list); } Loading Loading @@ -461,9 +462,10 @@ public abstract class SensorManager { } else { List<Sensor> list = new ArrayList(); for (Sensor i : fullList) { if (i.getType() == type) if (i.getType() == type) { list.add(i); } } return Collections.unmodifiableList(list); } } Loading @@ -490,10 +492,11 @@ public abstract class SensorManager { // For the following sensor types, return a wake-up sensor. These types are by default // defined as wake-up sensors. For the rest of the SDK defined sensor types return a // non_wake-up version. if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION || type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE || type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE || type == Sensor.TYPE_WRIST_TILT_GESTURE || type == Sensor.TYPE_DYNAMIC_SENSOR_META) { if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION || type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE || type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE || type == Sensor.TYPE_WRIST_TILT_GESTURE || type == Sensor.TYPE_DYNAMIC_SENSOR_META) { wakeUpSensor = true; } Loading @@ -509,12 +512,12 @@ public abstract class SensorManager { * <p> * For example, * <ul> * <li>getDefaultSensor({@link Sensor#TYPE_ACCELEROMETER}, true) returns a wake-up accelerometer * sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, false) returns a non wake-up proximity * sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, true) returns a wake-up proximity sensor * which is the same as the Sensor returned by {@link #getDefaultSensor(int)}. </li> * <li>getDefaultSensor({@link Sensor#TYPE_ACCELEROMETER}, true) returns a wake-up * accelerometer sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, false) returns a non wake-up * proximity sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, true) returns a wake-up proximity * sensor which is the same as the Sensor returned by {@link #getDefaultSensor(int)}. </li> * </ul> * </p> * <p class="note"> Loading @@ -532,9 +535,10 @@ public abstract class SensorManager { public Sensor getDefaultSensor(int type, boolean wakeUp) { List<Sensor> l = getSensorList(type); for (Sensor sensor : l) { if (sensor.isWakeUpSensor() == wakeUp) if (sensor.isWakeUpSensor() == wakeUp) { return sensor; } } return null; } Loading Loading @@ -842,8 +846,8 @@ public abstract class SensorManager { * @return <code>true</code> if the sensor is supported and successfully enabled. * @see #registerListener(SensorEventListener, Sensor, int, int) */ public boolean registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs, Handler handler) { public boolean registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs, Handler handler) { int delayUs = getDelay(samplingPeriodUs); return registerListenerImpl(listener, sensor, delayUs, handler, maxReportLatencyUs, 0); } Loading Loading @@ -953,7 +957,7 @@ public abstract class SensorManager { * Used for receiving notifications from the SensorManager when dynamic sensors are connected or * disconnected. */ public static abstract class DynamicSensorCallback { public abstract static class DynamicSensorCallback { /** * Called when there is a dynamic sensor being connected to the system. * Loading Loading @@ -1343,17 +1347,16 @@ public abstract class SensorManager { * @see #getRotationMatrix(float[], float[], float[], float[]) */ public static boolean remapCoordinateSystem(float[] inR, int X, int Y, float[] outR) { public static boolean remapCoordinateSystem(float[] inR, int X, int Y, float[] outR) { if (inR == outR) { final float[] temp = mTempMatrix; final float[] temp = sTempMatrix; synchronized (temp) { // we don't expect to have a lot of contention if (remapCoordinateSystemImpl(inR, X, Y, temp)) { final int size = outR.length; for (int i=0 ; i<size ; i++) for (int i = 0; i < size; i++) { outR[i] = temp[i]; } return true; } } Loading @@ -1361,9 +1364,7 @@ public abstract class SensorManager { return remapCoordinateSystemImpl(inR, X, Y, outR); } private static boolean remapCoordinateSystemImpl(float[] inR, int X, int Y, float[] outR) { private static boolean remapCoordinateSystemImpl(float[] inR, int X, int Y, float[] outR) { /* * X and Y define a rotation matrix 'r': * Loading @@ -1376,14 +1377,18 @@ public abstract class SensorManager { */ final int length = outR.length; if (inR.length != length) if (inR.length != length) { return false; // invalid parameter if ((X & 0x7C)!=0 || (Y & 0x7C)!=0) } if ((X & 0x7C) != 0 || (Y & 0x7C) != 0) { return false; // invalid parameter if (((X & 0x3)==0) || ((Y & 0x3)==0)) } if (((X & 0x3) == 0) || ((Y & 0x3) == 0)) { return false; // no axis specified if ((X & 0x3) == (Y & 0x3)) } if ((X & 0x3) == (Y & 0x3)) { return false; // same axis specified } // Z is "the other" axis, its sign is either +/- sign(X)*sign(Y) // this can be calculated by exclusive-or'ing X and Y; except for Loading @@ -1398,8 +1403,9 @@ public abstract class SensorManager { // compute the sign of Z (whether it needs to be inverted) final int axis_y = (z + 1) % 3; final int axis_z = (z + 2) % 3; if (((x^axis_y)|(y^axis_z)) != 0) if (((x ^ axis_y) | (y ^ axis_z)) != 0) { Z ^= 0x80; } final boolean sx = (X >= 0x80); final boolean sy = (Y >= 0x80); Loading Loading @@ -1466,7 +1472,7 @@ public abstract class SensorManager { * @see #getRotationMatrix(float[], float[], float[], float[]) * @see GeomagneticField */ public static float[] getOrientation(float[] R, float values[]) { public static float[] getOrientation(float[] R, float[] values) { /* * 4x4 (length=16) case: * / R[ 0] R[ 1] R[ 2] 0 \ Loading Loading @@ -1560,7 +1566,8 @@ public abstract class SensorManager { public static void getAngleChange(float[] angleChange, float[] R, float[] prevR) { float rd1 = 0, rd4 = 0, rd6 = 0, rd7 = 0, rd8 = 0; float ri0 = 0, ri1 = 0, ri2 = 0, ri3 = 0, ri4 = 0, ri5 = 0, ri6 = 0, ri7 = 0, ri8 = 0; float pri0=0, pri1=0, pri2=0, pri3=0, pri4=0, pri5=0, pri6=0, pri7=0, pri8=0; float pri0 = 0, pri1 = 0, pri2 = 0, pri3 = 0, pri4 = 0; float pri5 = 0, pri6 = 0, pri7 = 0, pri8 = 0; if (R.length == 9) { ri0 = R[0]; Loading Loading @@ -1846,9 +1853,9 @@ public abstract class SensorManager { } int expectedNumValues = Sensor.getMaxLengthValuesArray(sensor, Build.VERSION_CODES.M); if (values.length != expectedNumValues) { throw new IllegalArgumentException ("Wrong number of values for sensor " + sensor.getName() + " actual=" + values.length + " expected=" + expectedNumValues); throw new IllegalArgumentException("Wrong number of values for sensor " + sensor.getName() + " actual=" + values.length + " expected=" + expectedNumValues); } if (accuracy < SENSOR_STATUS_NO_CONTACT || accuracy > SENSOR_STATUS_ACCURACY_HIGH) { throw new IllegalArgumentException("Invalid sensor accuracy"); Loading Loading
core/java/android/hardware/LegacySensorManager.java +35 −31 Original line number Diff line number Diff line Loading @@ -204,7 +204,7 @@ final class LegacySensorManager { } private static final class LegacyListener implements SensorEventListener { private float mValues[] = new float[6]; private float[] mValues = new float[6]; private SensorListener mTarget; private int mSensors; private final LmsFilter mYawfilter = new LmsFilter(); Loading Loading @@ -256,7 +256,7 @@ final class LegacySensorManager { } public void onSensorChanged(SensorEvent event) { final float v[] = mValues; final float[] v = mValues; v[0] = event.values[0]; v[1] = event.values[1]; v[2] = event.values[2]; Loading Loading @@ -370,9 +370,10 @@ final class LegacySensorManager { private static final int SENSORS_RATE_MS = 20; private static final int COUNT = 12; private static final float PREDICTION_RATIO = 1.0f / 3.0f; private static final float PREDICTION_TIME = (SENSORS_RATE_MS*COUNT/1000.0f)*PREDICTION_RATIO; private float mV[] = new float[COUNT*2]; private long mT[] = new long[COUNT*2]; private static final float PREDICTION_TIME = (SENSORS_RATE_MS * COUNT / 1000.0f) * PREDICTION_RATIO; private float[] mV = new float[COUNT * 2]; private long[] mT = new long[COUNT * 2]; private int mIndex; public LmsFilter() { Loading @@ -393,8 +394,9 @@ final class LegacySensorManager { * when it's full */ mIndex++; if (mIndex >= COUNT*2) if (mIndex >= COUNT * 2) { mIndex = COUNT; } mV[mIndex] = v; mT[mIndex] = time; mV[mIndex - COUNT] = v; Loading Loading @@ -423,10 +425,12 @@ final class LegacySensorManager { // Normalize f *= (1.0f / 360.0f); if (((f>=0)?f:-f) >= 0.5f) if (((f >= 0) ? f : -f) >= 0.5f) { f = f - (float) Math.ceil(f + 0.5f) + 1.0f; if (f < 0) } if (f < 0) { f += 1.0f; } f *= 360.0f; return f; } Loading
core/java/android/hardware/Sensor.java +8 −8 Original line number Diff line number Diff line Loading @@ -857,8 +857,8 @@ public final class Sensor { static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) { // RotationVector length has changed to 3 to 5 for API level 18 // Set it to 3 for backward compatibility. if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR && sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR && sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) { return 3; } int offset = sensor.mType; Loading Loading @@ -1033,9 +1033,9 @@ public final class Sensor { * Returns true if the sensor is a wake-up sensor. * <p> * <b>Application Processor Power modes</b> <p> * Application Processor(AP), is the processor on which applications run. When no wake lock is held * and the user is not interacting with the device, this processor can enter a “Suspend” mode, * reducing the power consumption by 10 times or more. * Application Processor(AP), is the processor on which applications run. When no wake lock is * held and the user is not interacting with the device, this processor can enter a “Suspend” * mode, reducing the power consumption by 10 times or more. * </p> * <p> * <b>Non-wake-up sensors</b> <p> Loading
core/java/android/hardware/SensorAdditionalInfo.java +4 −4 Original line number Diff line number Diff line Loading @@ -224,8 +224,8 @@ public class SensorAdditionalInfo { /** @hide */ public static SensorAdditionalInfo createCustomInfo(Sensor aSensor, int type, float[] data) { if (type < TYPE_CUSTOM_INFO || type >= TYPE_DEBUG_INFO || aSensor == null) { throw new IllegalArgumentException("invalid parameter(s): type: " + type + "; sensor: " + aSensor); throw new IllegalArgumentException( "invalid parameter(s): type: " + type + "; sensor: " + aSensor); } return new SensorAdditionalInfo(aSensor, type, 0, null, data); Loading
core/java/android/hardware/SensorEvent.java +14 −13 Original line number Diff line number Diff line Loading @@ -207,8 +207,8 @@ public class SensorEvent { * timestamp = event.timestamp; * float[] deltaRotationMatrix = new float[9]; * SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector); * // User code should concatenate the delta rotation we computed with the current rotation * // in order to get the updated rotation. * // User code should concatenate the delta rotation we computed with the current * // rotation in order to get the updated rotation. * // rotationCurrent = rotationCurrent * deltaRotationMatrix; * } * </pre> Loading Loading @@ -244,21 +244,22 @@ public class SensorEvent { * <h4>{@link android.hardware.Sensor#TYPE_GRAVITY Sensor.TYPE_GRAVITY}:</h4> * <p>A three dimensional vector indicating the direction and magnitude of gravity. Units * are m/s^2. The coordinate system is the same as is used by the acceleration sensor.</p> * <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be identical * to that of the accelerometer.</p> * * <h4>{@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}:</h4> * A three dimensional vector indicating acceleration along each device axis, not including * gravity. All values have units of m/s^2. The coordinate system is the same as is used by the * acceleration sensor. * <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be * identical to that of the accelerometer.</p> * * <h4> * {@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}: * </h4> A three dimensional vector indicating acceleration along each device axis, not * including gravity. All values have units of m/s^2. The coordinate system is the same as is * used by the acceleration sensor. * <p>The output of the accelerometer, gravity and linear-acceleration sensors must obey the * following relation:</p> * <p><ul>acceleration = gravity + linear-acceleration</ul></p> * * <h4>{@link android.hardware.Sensor#TYPE_ROTATION_VECTOR Sensor.TYPE_ROTATION_VECTOR}:</h4> * <p>The rotation vector represents the orientation of the device as a combination of an <i>angle</i> * and an <i>axis</i>, in which the device has rotated through an angle θ around an axis * <x, y, z>.</p> * <p>The rotation vector represents the orientation of the device as a combination of an * <i>angle</i> and an <i>axis</i>, in which the device has rotated through an angle θ * around an axis <x, y, z>.</p> * <p>The three elements of the rotation vector are * <x*sin(θ/2), y*sin(θ/2), z*sin(θ/2)>, such that the magnitude of the rotation * vector is equal to sin(θ/2), and the direction of the rotation vector is equal to the Loading
core/java/android/hardware/SensorManager.java +98 −91 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ public abstract class SensorManager { /** @hide */ protected static final String TAG = "SensorManager"; private static final float[] mTempMatrix = new float[16]; private static final float[] sTempMatrix = new float[16]; // Cached lists of sensors by type. Guarded by mSensorListByType. private final SparseArray<List<Sensor>> mSensorListByType = Loading Loading @@ -425,10 +425,11 @@ public abstract class SensorManager { } else { list = new ArrayList<Sensor>(); for (Sensor i : fullList) { if (i.getType() == type) if (i.getType() == type) { list.add(i); } } } list = Collections.unmodifiableList(list); mSensorListByType.append(type, list); } Loading Loading @@ -461,9 +462,10 @@ public abstract class SensorManager { } else { List<Sensor> list = new ArrayList(); for (Sensor i : fullList) { if (i.getType() == type) if (i.getType() == type) { list.add(i); } } return Collections.unmodifiableList(list); } } Loading @@ -490,10 +492,11 @@ public abstract class SensorManager { // For the following sensor types, return a wake-up sensor. These types are by default // defined as wake-up sensors. For the rest of the SDK defined sensor types return a // non_wake-up version. if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION || type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE || type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE || type == Sensor.TYPE_WRIST_TILT_GESTURE || type == Sensor.TYPE_DYNAMIC_SENSOR_META) { if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION || type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE || type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE || type == Sensor.TYPE_WRIST_TILT_GESTURE || type == Sensor.TYPE_DYNAMIC_SENSOR_META) { wakeUpSensor = true; } Loading @@ -509,12 +512,12 @@ public abstract class SensorManager { * <p> * For example, * <ul> * <li>getDefaultSensor({@link Sensor#TYPE_ACCELEROMETER}, true) returns a wake-up accelerometer * sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, false) returns a non wake-up proximity * sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, true) returns a wake-up proximity sensor * which is the same as the Sensor returned by {@link #getDefaultSensor(int)}. </li> * <li>getDefaultSensor({@link Sensor#TYPE_ACCELEROMETER}, true) returns a wake-up * accelerometer sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, false) returns a non wake-up * proximity sensor if it exists. </li> * <li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, true) returns a wake-up proximity * sensor which is the same as the Sensor returned by {@link #getDefaultSensor(int)}. </li> * </ul> * </p> * <p class="note"> Loading @@ -532,9 +535,10 @@ public abstract class SensorManager { public Sensor getDefaultSensor(int type, boolean wakeUp) { List<Sensor> l = getSensorList(type); for (Sensor sensor : l) { if (sensor.isWakeUpSensor() == wakeUp) if (sensor.isWakeUpSensor() == wakeUp) { return sensor; } } return null; } Loading Loading @@ -842,8 +846,8 @@ public abstract class SensorManager { * @return <code>true</code> if the sensor is supported and successfully enabled. * @see #registerListener(SensorEventListener, Sensor, int, int) */ public boolean registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs, Handler handler) { public boolean registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, int maxReportLatencyUs, Handler handler) { int delayUs = getDelay(samplingPeriodUs); return registerListenerImpl(listener, sensor, delayUs, handler, maxReportLatencyUs, 0); } Loading Loading @@ -953,7 +957,7 @@ public abstract class SensorManager { * Used for receiving notifications from the SensorManager when dynamic sensors are connected or * disconnected. */ public static abstract class DynamicSensorCallback { public abstract static class DynamicSensorCallback { /** * Called when there is a dynamic sensor being connected to the system. * Loading Loading @@ -1343,17 +1347,16 @@ public abstract class SensorManager { * @see #getRotationMatrix(float[], float[], float[], float[]) */ public static boolean remapCoordinateSystem(float[] inR, int X, int Y, float[] outR) { public static boolean remapCoordinateSystem(float[] inR, int X, int Y, float[] outR) { if (inR == outR) { final float[] temp = mTempMatrix; final float[] temp = sTempMatrix; synchronized (temp) { // we don't expect to have a lot of contention if (remapCoordinateSystemImpl(inR, X, Y, temp)) { final int size = outR.length; for (int i=0 ; i<size ; i++) for (int i = 0; i < size; i++) { outR[i] = temp[i]; } return true; } } Loading @@ -1361,9 +1364,7 @@ public abstract class SensorManager { return remapCoordinateSystemImpl(inR, X, Y, outR); } private static boolean remapCoordinateSystemImpl(float[] inR, int X, int Y, float[] outR) { private static boolean remapCoordinateSystemImpl(float[] inR, int X, int Y, float[] outR) { /* * X and Y define a rotation matrix 'r': * Loading @@ -1376,14 +1377,18 @@ public abstract class SensorManager { */ final int length = outR.length; if (inR.length != length) if (inR.length != length) { return false; // invalid parameter if ((X & 0x7C)!=0 || (Y & 0x7C)!=0) } if ((X & 0x7C) != 0 || (Y & 0x7C) != 0) { return false; // invalid parameter if (((X & 0x3)==0) || ((Y & 0x3)==0)) } if (((X & 0x3) == 0) || ((Y & 0x3) == 0)) { return false; // no axis specified if ((X & 0x3) == (Y & 0x3)) } if ((X & 0x3) == (Y & 0x3)) { return false; // same axis specified } // Z is "the other" axis, its sign is either +/- sign(X)*sign(Y) // this can be calculated by exclusive-or'ing X and Y; except for Loading @@ -1398,8 +1403,9 @@ public abstract class SensorManager { // compute the sign of Z (whether it needs to be inverted) final int axis_y = (z + 1) % 3; final int axis_z = (z + 2) % 3; if (((x^axis_y)|(y^axis_z)) != 0) if (((x ^ axis_y) | (y ^ axis_z)) != 0) { Z ^= 0x80; } final boolean sx = (X >= 0x80); final boolean sy = (Y >= 0x80); Loading Loading @@ -1466,7 +1472,7 @@ public abstract class SensorManager { * @see #getRotationMatrix(float[], float[], float[], float[]) * @see GeomagneticField */ public static float[] getOrientation(float[] R, float values[]) { public static float[] getOrientation(float[] R, float[] values) { /* * 4x4 (length=16) case: * / R[ 0] R[ 1] R[ 2] 0 \ Loading Loading @@ -1560,7 +1566,8 @@ public abstract class SensorManager { public static void getAngleChange(float[] angleChange, float[] R, float[] prevR) { float rd1 = 0, rd4 = 0, rd6 = 0, rd7 = 0, rd8 = 0; float ri0 = 0, ri1 = 0, ri2 = 0, ri3 = 0, ri4 = 0, ri5 = 0, ri6 = 0, ri7 = 0, ri8 = 0; float pri0=0, pri1=0, pri2=0, pri3=0, pri4=0, pri5=0, pri6=0, pri7=0, pri8=0; float pri0 = 0, pri1 = 0, pri2 = 0, pri3 = 0, pri4 = 0; float pri5 = 0, pri6 = 0, pri7 = 0, pri8 = 0; if (R.length == 9) { ri0 = R[0]; Loading Loading @@ -1846,9 +1853,9 @@ public abstract class SensorManager { } int expectedNumValues = Sensor.getMaxLengthValuesArray(sensor, Build.VERSION_CODES.M); if (values.length != expectedNumValues) { throw new IllegalArgumentException ("Wrong number of values for sensor " + sensor.getName() + " actual=" + values.length + " expected=" + expectedNumValues); throw new IllegalArgumentException("Wrong number of values for sensor " + sensor.getName() + " actual=" + values.length + " expected=" + expectedNumValues); } if (accuracy < SENSOR_STATUS_NO_CONTACT || accuracy > SENSOR_STATUS_ACCURACY_HIGH) { throw new IllegalArgumentException("Invalid sensor accuracy"); Loading