Chromium Code Reviews| Index: device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java b/device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java |
| similarity index 83% |
| rename from content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java |
| rename to device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java |
| index e2e91f380f6d89a85484700bdceefc666fca27ab..f0c62c89b7f7761bde12c4546e55203c207d98b1 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java |
| +++ b/device/sensors/android/java/src/org/chromium/device/sensors/DeviceSensors.java |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -package org.chromium.content.browser; |
| +package org.chromium.device.sensors; |
| import android.content.Context; |
| import android.hardware.Sensor; |
| @@ -26,10 +26,9 @@ import java.util.Set; |
| /** |
| * Android implementation of the device {motion|orientation|light} APIs. |
| */ |
| -@JNINamespace("content") |
| -class DeviceSensors implements SensorEventListener { |
| - |
| - private static final String TAG = "cr.DeviceSensors"; |
| +@JNINamespace("device") |
| +public class DeviceSensors implements SensorEventListener { |
| + private static final String TAG = "DeviceSensors"; |
| // Matches kEnableExperimentalWebPlatformFeatures. |
| private static final String EXPERIMENTAL_WEB_PLAFTORM_FEATURES = |
| @@ -71,40 +70,36 @@ 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); |
| + public static final Set<Integer> DEVICE_ORIENTATION_SENSORS_A = |
|
timvolodine
2017/01/26 14:01:15
why does this have to be public? also below and th
ke.he
2017/01/26 15:33:22
With this patch, the package name of this class is
timvolodine
2017/01/31 07:13:15
I assume this is a temporary situation? Is it poss
|
| + CollectionUtil.newHashSet(Sensor.TYPE_GAME_ROTATION_VECTOR); |
| + public 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_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); |
| + public static final Set<Integer> DEVICE_ORIENTATION_SENSORS_C = |
| + CollectionUtil.newHashSet(Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_MAGNETIC_FIELD); |
| + public static final Set<Integer> DEVICE_ORIENTATION_ABSOLUTE_SENSORS = |
| + CollectionUtil.newHashSet(Sensor.TYPE_ROTATION_VECTOR); |
| + public static final Set<Integer> DEVICE_MOTION_SENSORS = CollectionUtil.newHashSet( |
| + Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_LINEAR_ACCELERATION, Sensor.TYPE_GYROSCOPE); |
| + public static final Set<Integer> DEVICE_LIGHT_SENSORS = |
| + CollectionUtil.newHashSet(Sensor.TYPE_LIGHT); |
| @VisibleForTesting |
| - final Set<Integer> mActiveSensors = new HashSet<Integer>(); |
| - final List<Set<Integer>> mOrientationSensorSets; |
| - Set<Integer> mDeviceOrientationSensors; |
| - boolean mDeviceLightIsActive; |
| - boolean mDeviceMotionIsActive; |
| - boolean mDeviceOrientationIsActive; |
| - boolean mDeviceOrientationIsActiveWithBackupSensors; |
| - boolean mDeviceOrientationAbsoluteIsActive; |
| - boolean mOrientationNotAvailable; |
| + public final Set<Integer> mActiveSensors = new HashSet<Integer>(); |
| + public final List<Set<Integer>> mOrientationSensorSets; |
| + public Set<Integer> mDeviceOrientationSensors; |
| + public boolean mDeviceLightIsActive; |
| + public boolean mDeviceMotionIsActive; |
| + public boolean mDeviceOrientationIsActive; |
| + public boolean mDeviceOrientationIsActiveWithBackupSensors; |
| + public boolean mDeviceOrientationAbsoluteIsActive; |
| + public boolean mOrientationNotAvailable; |
| protected DeviceSensors(Context context) { |
| 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 +155,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 +199,7 @@ class DeviceSensors implements SensorEventListener { |
| return OrientationSensorType.ACCELEROMETER_MAGNETIC; |
| } |
| - assert false; // should never happen |
| + assert false; // should never happen |
| return OrientationSensorType.NOT_AVAILABLE; |
| } |
| @@ -260,7 +255,7 @@ class DeviceSensors implements SensorEventListener { |
| } |
| @VisibleForTesting |
| - void sensorChanged(int type, float[] values) { |
| + public void sensorChanged(int type, float[] values) { |
| switch (type) { |
| case Sensor.TYPE_ACCELEROMETER: |
| if (mDeviceMotionIsActive) { |
| @@ -283,8 +278,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 +301,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: |
| @@ -370,30 +365,30 @@ class DeviceSensors implements SensorEventListener { |
| */ |
| if (matrixR.length != 9) return values; |
| - if (matrixR[8] > 0) { // cos(beta) > 0 |
| + if (matrixR[8] > 0) { // cos(beta) > 0 |
| values[0] = Math.atan2(-matrixR[1], matrixR[4]); |
| - values[1] = Math.asin(matrixR[7]); // beta (-pi/2, pi/2) |
| - values[2] = Math.atan2(-matrixR[6], matrixR[8]); // gamma (-pi/2, pi/2) |
| - } else if (matrixR[8] < 0) { // cos(beta) < 0 |
| + values[1] = Math.asin(matrixR[7]); // beta (-pi/2, pi/2) |
|
timvolodine
2017/01/26 14:01:15
the alignment here was actually done on purpose fo
ke.he
2017/01/26 15:33:22
The format is changed by "git cl format", I'll kee
|
| + values[2] = Math.atan2(-matrixR[6], matrixR[8]); // gamma (-pi/2, pi/2) |
| + } else if (matrixR[8] < 0) { // cos(beta) < 0 |
| values[0] = Math.atan2(matrixR[1], -matrixR[4]); |
| values[1] = -Math.asin(matrixR[7]); |
| values[1] += (values[1] >= 0) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) |
| - values[2] = Math.atan2(matrixR[6], -matrixR[8]); // gamma (-pi/2, pi/2) |
| + values[2] = Math.atan2(matrixR[6], -matrixR[8]); // gamma (-pi/2, pi/2) |
| } else { // R[8] == 0 |
| - if (matrixR[6] > 0) { // cos(gamma) == 0, cos(beta) > 0 |
| + if (matrixR[6] > 0) { // cos(gamma) == 0, cos(beta) > 0 |
| values[0] = Math.atan2(-matrixR[1], matrixR[4]); |
| - values[1] = Math.asin(matrixR[7]); // beta [-pi/2, pi/2] |
| - values[2] = -Math.PI / 2; // gamma = -pi/2 |
| + values[1] = Math.asin(matrixR[7]); // beta [-pi/2, pi/2] |
| + values[2] = -Math.PI / 2; // gamma = -pi/2 |
| } else if (matrixR[6] < 0) { // cos(gamma) == 0, cos(beta) < 0 |
| values[0] = Math.atan2(matrixR[1], -matrixR[4]); |
| values[1] = -Math.asin(matrixR[7]); |
| values[1] += (values[1] >= 0) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) |
| - values[2] = -Math.PI / 2; // gamma = -pi/2 |
| + values[2] = -Math.PI / 2; // gamma = -pi/2 |
| } else { // R[6] == 0, cos(beta) == 0 |
| // gimbal lock discontinuity |
| values[0] = Math.atan2(matrixR[3], matrixR[0]); |
| - values[1] = (matrixR[7] > 0) ? Math.PI / 2 : -Math.PI / 2; // beta = +-pi/2 |
| - values[2] = 0; // gamma = 0 |
| + values[1] = (matrixR[7] > 0) ? Math.PI / 2 : -Math.PI / 2; // beta = +-pi/2 |
| + values[2] = 0; // gamma = 0 |
| } |
| } |
| @@ -416,8 +411,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 +431,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() { |
| @@ -457,7 +451,7 @@ class DeviceSensors implements SensorEventListener { |
| } |
| @VisibleForTesting |
| - void setSensorManagerProxy(SensorManagerProxy sensorManagerProxy) { |
| + public void setSensorManagerProxy(SensorManagerProxy sensorManagerProxy) { |
| mSensorManagerProxy = sensorManagerProxy; |
| } |
| @@ -465,8 +459,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 +493,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 +588,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; |
| } |
| @@ -612,57 +606,50 @@ class DeviceSensors implements SensorEventListener { |
| /** |
| * Native JNI calls, |
| - * see content/browser/device_sensors/sensor_manager_android.cc |
| + * see device/sensors/sensor_manager_android.cc |
| */ |
| /** |
| * 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 interface SensorManagerProxy { |
| + public boolean registerListener( |
| + SensorEventListener listener, int sensorType, int rate, Handler handler); |
| public void unregisterListener(SensorEventListener listener, int sensorType); |
| } |
| @@ -674,8 +661,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 +686,4 @@ class DeviceSensors implements SensorEventListener { |
| } |
| } |
| } |
| - |
| } |