| Index: device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java
|
| diff --git a/device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java b/device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java
|
| index 90f59f8bd5c2b02ad7056a4e5716a693d08f8a0a..1b3ef895e12823e86ff8fe25dd059245fbeb4093 100644
|
| --- a/device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java
|
| +++ b/device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java
|
| @@ -28,8 +28,7 @@ import java.util.Set;
|
| */
|
| @JNINamespace("device")
|
| class DeviceSensors implements SensorEventListener {
|
| -
|
| - private static final String TAG = "cr.DeviceSensors";
|
| + private static final String TAG = "DeviceSensors";
|
|
|
| // Matches kEnableExperimentalWebPlatformFeatures.
|
| private static final String EXPERIMENTAL_WEB_PLAFTORM_FEATURES =
|
| @@ -71,22 +70,18 @@ class DeviceSensors implements SensorEventListener {
|
| private static DeviceSensors sSingleton;
|
| private static Object sSingletonLock = new Object();
|
|
|
| - static final Set<Integer> DEVICE_ORIENTATION_SENSORS_A = CollectionUtil.newHashSet(
|
| - Sensor.TYPE_GAME_ROTATION_VECTOR);
|
| - static final Set<Integer> DEVICE_ORIENTATION_SENSORS_B = CollectionUtil.newHashSet(
|
| - Sensor.TYPE_ROTATION_VECTOR);
|
| + static final Set<Integer> DEVICE_ORIENTATION_SENSORS_A =
|
| + CollectionUtil.newHashSet(Sensor.TYPE_GAME_ROTATION_VECTOR);
|
| + static final Set<Integer> DEVICE_ORIENTATION_SENSORS_B =
|
| + CollectionUtil.newHashSet(Sensor.TYPE_ROTATION_VECTOR);
|
| // Option C backup sensors are used when options A and B are not available.
|
| - static final Set<Integer> DEVICE_ORIENTATION_SENSORS_C = CollectionUtil.newHashSet(
|
| - Sensor.TYPE_ACCELEROMETER,
|
| - Sensor.TYPE_MAGNETIC_FIELD);
|
| - static final Set<Integer> DEVICE_ORIENTATION_ABSOLUTE_SENSORS = CollectionUtil.newHashSet(
|
| - Sensor.TYPE_ROTATION_VECTOR);
|
| + static final Set<Integer> DEVICE_ORIENTATION_SENSORS_C =
|
| + CollectionUtil.newHashSet(Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_MAGNETIC_FIELD);
|
| + static final Set<Integer> DEVICE_ORIENTATION_ABSOLUTE_SENSORS =
|
| + CollectionUtil.newHashSet(Sensor.TYPE_ROTATION_VECTOR);
|
| static final Set<Integer> DEVICE_MOTION_SENSORS = CollectionUtil.newHashSet(
|
| - Sensor.TYPE_ACCELEROMETER,
|
| - Sensor.TYPE_LINEAR_ACCELERATION,
|
| - Sensor.TYPE_GYROSCOPE);
|
| - static final Set<Integer> DEVICE_LIGHT_SENSORS = CollectionUtil.newHashSet(
|
| - Sensor.TYPE_LIGHT);
|
| + Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_GYROSCOPE);
|
| + static final Set<Integer> DEVICE_LIGHT_SENSORS = CollectionUtil.newHashSet(Sensor.TYPE_LIGHT);
|
|
|
| @VisibleForTesting
|
| final Set<Integer> mActiveSensors = new HashSet<Integer>();
|
| @@ -103,8 +98,7 @@ class DeviceSensors implements SensorEventListener {
|
| mAppContext = context.getApplicationContext();
|
|
|
| mOrientationSensorSets = CollectionUtil.newArrayList(DEVICE_ORIENTATION_SENSORS_A,
|
| - DEVICE_ORIENTATION_SENSORS_B,
|
| - DEVICE_ORIENTATION_SENSORS_C);
|
| + DEVICE_ORIENTATION_SENSORS_B, DEVICE_ORIENTATION_SENSORS_C);
|
| }
|
|
|
| // For orientation we use a 3-way fallback approach where up to 3 different sets of sensors
|
| @@ -160,8 +154,8 @@ class DeviceSensors implements SensorEventListener {
|
| break;
|
| case ConsumerType.ORIENTATION_ABSOLUTE:
|
| ensureRotationStructuresAllocated();
|
| - success = registerSensors(DEVICE_ORIENTATION_ABSOLUTE_SENSORS,
|
| - rateInMicroseconds, true);
|
| + success = registerSensors(
|
| + DEVICE_ORIENTATION_ABSOLUTE_SENSORS, rateInMicroseconds, true);
|
| break;
|
| case ConsumerType.MOTION:
|
| // note: device motion spec does not require all sensors to be available
|
| @@ -204,7 +198,7 @@ class DeviceSensors implements SensorEventListener {
|
| return OrientationSensorType.ACCELEROMETER_MAGNETIC;
|
| }
|
|
|
| - assert false; // should never happen
|
| + assert false; // should never happen
|
| return OrientationSensorType.NOT_AVAILABLE;
|
| }
|
|
|
| @@ -283,8 +277,8 @@ class DeviceSensors implements SensorEventListener {
|
| case Sensor.TYPE_ROTATION_VECTOR:
|
| if (mDeviceOrientationAbsoluteIsActive) {
|
| convertRotationVectorToAngles(values, mRotationAngles);
|
| - gotOrientationAbsolute(mRotationAngles[0], mRotationAngles[1],
|
| - mRotationAngles[2]);
|
| + gotOrientationAbsolute(
|
| + mRotationAngles[0], mRotationAngles[1], mRotationAngles[2]);
|
| }
|
| if (mDeviceOrientationIsActive
|
| && mDeviceOrientationSensors == DEVICE_ORIENTATION_SENSORS_B) {
|
| @@ -306,8 +300,8 @@ class DeviceSensors implements SensorEventListener {
|
| if (mMagneticFieldVector == null) {
|
| mMagneticFieldVector = new float[3];
|
| }
|
| - System.arraycopy(values, 0, mMagneticFieldVector, 0,
|
| - mMagneticFieldVector.length);
|
| + System.arraycopy(
|
| + values, 0, mMagneticFieldVector, 0, mMagneticFieldVector.length);
|
| }
|
| break;
|
| case Sensor.TYPE_LIGHT:
|
| @@ -416,8 +410,8 @@ class DeviceSensors implements SensorEventListener {
|
| // For the purposes of this class the first 4 values of the
|
| // rotation vector are sufficient (see crbug.com/335298 for details).
|
| System.arraycopy(rotationVector, 0, mTruncatedRotationVector, 0, 4);
|
| - SensorManager.getRotationMatrixFromVector(mDeviceRotationMatrix,
|
| - mTruncatedRotationVector);
|
| + SensorManager.getRotationMatrixFromVector(
|
| + mDeviceRotationMatrix, mTruncatedRotationVector);
|
| } else {
|
| SensorManager.getRotationMatrixFromVector(mDeviceRotationMatrix, rotationVector);
|
| }
|
| @@ -436,9 +430,8 @@ class DeviceSensors implements SensorEventListener {
|
| }
|
| computeDeviceOrientationFromRotationMatrix(mDeviceRotationMatrix, mRotationAngles);
|
|
|
| - gotOrientation(Math.toDegrees(mRotationAngles[0]),
|
| - Math.toDegrees(mRotationAngles[1]),
|
| - Math.toDegrees(mRotationAngles[2]));
|
| + gotOrientation(Math.toDegrees(mRotationAngles[0]), Math.toDegrees(mRotationAngles[1]),
|
| + Math.toDegrees(mRotationAngles[2]));
|
| }
|
|
|
| private SensorManagerProxy getSensorManagerProxy() {
|
| @@ -465,8 +458,8 @@ class DeviceSensors implements SensorEventListener {
|
| switch (eventType) {
|
| case ConsumerType.ORIENTATION:
|
| mDeviceOrientationIsActive = active;
|
| - mDeviceOrientationIsActiveWithBackupSensors = active
|
| - && (mDeviceOrientationSensors == DEVICE_ORIENTATION_SENSORS_C);
|
| + mDeviceOrientationIsActiveWithBackupSensors =
|
| + active && (mDeviceOrientationSensors == DEVICE_ORIENTATION_SENSORS_C);
|
| return;
|
| case ConsumerType.ORIENTATION_ABSOLUTE:
|
| mDeviceOrientationAbsoluteIsActive = active;
|
| @@ -499,8 +492,8 @@ class DeviceSensors implements SensorEventListener {
|
| * activated. When false the method return true if at least one
|
| * sensor in sensorTypes could be activated.
|
| */
|
| - private boolean registerSensors(Set<Integer> sensorTypes, int rateInMicroseconds,
|
| - boolean failOnMissingSensor) {
|
| + private boolean registerSensors(
|
| + Set<Integer> sensorTypes, int rateInMicroseconds, boolean failOnMissingSensor) {
|
| Set<Integer> sensorsToActivate = new HashSet<Integer>(sensorTypes);
|
| sensorsToActivate.removeAll(mActiveSensors);
|
| if (sensorsToActivate.isEmpty()) return true;
|
| @@ -594,7 +587,7 @@ class DeviceSensors implements SensorEventListener {
|
| if (mHandler == null) {
|
| HandlerThread thread = new HandlerThread("DeviceMotionAndOrientation");
|
| thread.start();
|
| - mHandler = new Handler(thread.getLooper()); // blocks on thread start
|
| + mHandler = new Handler(thread.getLooper()); // blocks on thread start
|
| }
|
| return mHandler;
|
| }
|
| @@ -619,50 +612,43 @@ class DeviceSensors implements SensorEventListener {
|
| * Orientation of the device with respect to its reference frame.
|
| */
|
| private native void nativeGotOrientation(
|
| - long nativeSensorManagerAndroid,
|
| - double alpha, double beta, double gamma);
|
| + long nativeSensorManagerAndroid, double alpha, double beta, double gamma);
|
|
|
| /**
|
| * Absolute orientation of the device with respect to its reference frame.
|
| */
|
| private native void nativeGotOrientationAbsolute(
|
| - long nativeSensorManagerAndroid,
|
| - double alpha, double beta, double gamma);
|
| + long nativeSensorManagerAndroid, double alpha, double beta, double gamma);
|
|
|
| /**
|
| * Linear acceleration without gravity of the device with respect to its body frame.
|
| */
|
| private native void nativeGotAcceleration(
|
| - long nativeSensorManagerAndroid,
|
| - double x, double y, double z);
|
| + long nativeSensorManagerAndroid, double x, double y, double z);
|
|
|
| /**
|
| * Acceleration including gravity of the device with respect to its body frame.
|
| */
|
| private native void nativeGotAccelerationIncludingGravity(
|
| - long nativeSensorManagerAndroid,
|
| - double x, double y, double z);
|
| + long nativeSensorManagerAndroid, double x, double y, double z);
|
|
|
| /**
|
| * Rotation rate of the device with respect to its body frame.
|
| */
|
| private native void nativeGotRotationRate(
|
| - long nativeSensorManagerAndroid,
|
| - double alpha, double beta, double gamma);
|
| + long nativeSensorManagerAndroid, double alpha, double beta, double gamma);
|
|
|
| /**
|
| * Device Light value from Ambient Light sensors.
|
| */
|
| - private native void nativeGotLight(
|
| - long nativeSensorManagerAndroid,
|
| - double value);
|
| + private native void nativeGotLight(long nativeSensorManagerAndroid, double value);
|
|
|
| /**
|
| * Need the an interface for SensorManager for testing.
|
| */
|
| interface SensorManagerProxy {
|
| - public boolean registerListener(SensorEventListener listener, int sensorType, int rate,
|
| - Handler handler);
|
| + public boolean registerListener(
|
| + SensorEventListener listener, int sensorType, int rate, Handler handler);
|
| public void unregisterListener(SensorEventListener listener, int sensorType);
|
| }
|
|
|
| @@ -674,8 +660,8 @@ class DeviceSensors implements SensorEventListener {
|
| }
|
|
|
| @Override
|
| - public boolean registerListener(SensorEventListener listener, int sensorType, int rate,
|
| - Handler handler) {
|
| + public boolean registerListener(
|
| + SensorEventListener listener, int sensorType, int rate, Handler handler) {
|
| List<Sensor> sensors = mSensorManager.getSensorList(sensorType);
|
| if (sensors.isEmpty()) {
|
| return false;
|
| @@ -699,5 +685,4 @@ class DeviceSensors implements SensorEventListener {
|
| }
|
| }
|
| }
|
| -
|
| }
|
|
|