| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "device/generic_sensor/platform_sensor_android.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "jni/PlatformSensor_jni.h" | |
| 9 | |
| 10 using base::android::AttachCurrentThread; | |
| 11 using base::android::JavaRef; | |
| 12 | |
| 13 namespace device { | |
| 14 | |
| 15 // static | |
| 16 bool PlatformSensorAndroid::RegisterJNI(JNIEnv* env) { | |
| 17 return RegisterNativesImpl(env); | |
| 18 } | |
| 19 | |
| 20 PlatformSensorAndroid::PlatformSensorAndroid( | |
| 21 mojom::SensorType type, | |
| 22 mojo::ScopedSharedBufferMapping mapping, | |
| 23 PlatformSensorProvider* provider, | |
| 24 const JavaRef<jobject>& java_sensor) | |
| 25 : PlatformSensor(type, std::move(mapping), provider) { | |
| 26 JNIEnv* env = AttachCurrentThread(); | |
| 27 j_object_.Reset(java_sensor); | |
| 28 | |
| 29 Java_PlatformSensor_initPlatformSensorAndroid(env, j_object_.obj(), | |
| 30 reinterpret_cast<jlong>(this)); | |
| 31 } | |
| 32 | |
| 33 PlatformSensorAndroid::~PlatformSensorAndroid() { | |
| 34 StopSensor(); | |
| 35 } | |
| 36 | |
| 37 mojom::ReportingMode PlatformSensorAndroid::GetReportingMode() { | |
| 38 JNIEnv* env = AttachCurrentThread(); | |
| 39 return static_cast<mojom::ReportingMode>( | |
| 40 Java_PlatformSensor_getReportingMode(env, j_object_.obj())); | |
| 41 } | |
| 42 | |
| 43 PlatformSensorConfiguration PlatformSensorAndroid::GetDefaultConfiguration() { | |
| 44 JNIEnv* env = AttachCurrentThread(); | |
| 45 jdouble frequency = | |
| 46 Java_PlatformSensor_getDefaultConfiguration(env, j_object_.obj()); | |
| 47 return PlatformSensorConfiguration(frequency); | |
| 48 } | |
| 49 | |
| 50 double PlatformSensorAndroid::GetMaximumSupportedFrequency() { | |
| 51 JNIEnv* env = AttachCurrentThread(); | |
| 52 return Java_PlatformSensor_getMaximumSupportedFrequency(env, j_object_.obj()); | |
| 53 } | |
| 54 | |
| 55 bool PlatformSensorAndroid::StartSensor( | |
| 56 const PlatformSensorConfiguration& configuration) { | |
| 57 JNIEnv* env = AttachCurrentThread(); | |
| 58 return Java_PlatformSensor_startSensor(env, j_object_.obj(), | |
| 59 configuration.frequency()); | |
| 60 } | |
| 61 | |
| 62 void PlatformSensorAndroid::StopSensor() { | |
| 63 JNIEnv* env = AttachCurrentThread(); | |
| 64 Java_PlatformSensor_stopSensor(env, j_object_.obj()); | |
| 65 } | |
| 66 | |
| 67 bool PlatformSensorAndroid::CheckSensorConfiguration( | |
| 68 const PlatformSensorConfiguration& configuration) { | |
| 69 JNIEnv* env = AttachCurrentThread(); | |
| 70 return Java_PlatformSensor_checkSensorConfiguration( | |
| 71 env, j_object_.obj(), configuration.frequency()); | |
| 72 } | |
| 73 | |
| 74 void PlatformSensorAndroid::NotifyPlatformSensorError( | |
| 75 JNIEnv*, | |
| 76 const JavaRef<jobject>& caller) { | |
| 77 task_runner_->PostTask( | |
| 78 FROM_HERE, base::Bind(&PlatformSensorAndroid::NotifySensorError, this)); | |
| 79 } | |
| 80 | |
| 81 void PlatformSensorAndroid::UpdatePlatformSensorReading( | |
| 82 JNIEnv*, | |
| 83 const base::android::JavaRef<jobject>& caller, | |
| 84 jdouble timestamp, | |
| 85 jdouble value1, | |
| 86 jdouble value2, | |
| 87 jdouble value3, | |
| 88 jdouble value4) { | |
| 89 SensorReading reading; | |
| 90 reading.timestamp = timestamp; | |
| 91 reading.values[0] = value1; | |
| 92 reading.values[1] = value2; | |
| 93 reading.values[2] = value3; | |
| 94 reading.values[3] = value4; | |
| 95 | |
| 96 bool needNotify = (GetReportingMode() == mojom::ReportingMode::ON_CHANGE); | |
| 97 UpdateSensorReading(reading, needNotify); | |
| 98 } | |
| 99 | |
| 100 } // namespace device | |
| OLD | NEW |