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/android/context_utils.h" |
| 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "device/generic_sensor/platform_sensor_configuration_android.h" |
| 11 #include "jni/PlatformSensor_jni.h" |
| 12 |
| 13 using base::android::AttachCurrentThread; |
| 14 using base::android::JavaRef; |
| 15 |
| 16 namespace device { |
| 17 |
| 18 // static |
| 19 bool PlatformSensorAndroid::RegisterJNI(JNIEnv* env) { |
| 20 return RegisterNativesImpl(env); |
| 21 } |
| 22 |
| 23 PlatformSensorAndroid::PlatformSensorAndroid( |
| 24 mojom::SensorType type, |
| 25 mojo::ScopedSharedBufferMapping mapping, |
| 26 uint64_t buffer_size, |
| 27 PlatformSensorProvider* provider, |
| 28 const JavaRef<jobject>& java_sensor) |
| 29 : PlatformSensor(type, std::move(mapping), provider), |
| 30 task_runner_(base::MessageLoop::current()->task_runner()) { |
| 31 JNIEnv* env = AttachCurrentThread(); |
| 32 j_object_.Reset(java_sensor); |
| 33 |
| 34 jobject byte_buffer = |
| 35 env->NewDirectByteBuffer(shared_buffer_mapping_.get(), buffer_size); |
| 36 Java_PlatformSensor_initPlatformSensorAndroid( |
| 37 env, j_object_.obj(), reinterpret_cast<jlong>(this), byte_buffer); |
| 38 } |
| 39 |
| 40 PlatformSensorAndroid::~PlatformSensorAndroid() = default; |
| 41 |
| 42 mojom::ReportingMode PlatformSensorAndroid::GetReportingMode() { |
| 43 JNIEnv* env = AttachCurrentThread(); |
| 44 return static_cast<mojom::ReportingMode>( |
| 45 Java_PlatformSensor_getReportingMode(env, j_object_.obj())); |
| 46 } |
| 47 |
| 48 bool PlatformSensorAndroid::StartSensor( |
| 49 const PlatformSensorConfiguration& configuration) { |
| 50 JNIEnv* env = AttachCurrentThread(); |
| 51 return Java_PlatformSensor_startSensor( |
| 52 env, j_object_.obj(), |
| 53 PlatformSensorConfigurationAndroid::Create(env, configuration).obj()); |
| 54 } |
| 55 |
| 56 void PlatformSensorAndroid::StopSensor() { |
| 57 JNIEnv* env = AttachCurrentThread(); |
| 58 Java_PlatformSensor_stopSensor(env, j_object_.obj()); |
| 59 } |
| 60 |
| 61 bool PlatformSensorAndroid::CheckSensorConfiguration( |
| 62 const PlatformSensorConfiguration& configuration) { |
| 63 JNIEnv* env = AttachCurrentThread(); |
| 64 return Java_PlatformSensor_checkSensorConfiguration( |
| 65 env, j_object_.obj(), |
| 66 PlatformSensorConfigurationAndroid::Create(env, configuration).obj()); |
| 67 } |
| 68 |
| 69 void PlatformSensorAndroid::NotifyPlatformSensorReadingChanged( |
| 70 JNIEnv*, |
| 71 const JavaRef<jobject>& caller) { |
| 72 task_runner_->PostTask( |
| 73 FROM_HERE, |
| 74 base::Bind(&PlatformSensorAndroid::NotifySensorReadingChanged, this)); |
| 75 } |
| 76 |
| 77 void PlatformSensorAndroid::NotifyPlatformSensorError( |
| 78 JNIEnv*, |
| 79 const JavaRef<jobject>& caller) { |
| 80 task_runner_->PostTask( |
| 81 FROM_HERE, base::Bind(&PlatformSensorAndroid::NotifySensorError, this)); |
| 82 } |
| 83 |
| 84 } // namespace device |
OLD | NEW |