OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/generic_sensor/platform_sensor_provider_android.h" | 5 #include "device/generic_sensor/platform_sensor_provider_android.h" |
6 | 6 |
7 #include "base/android/scoped_java_ref.h" | 7 #include "base/android/scoped_java_ref.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "device/generic_sensor/platform_sensor_android.h" | 9 #include "device/generic_sensor/platform_sensor_android.h" |
10 #include "jni/PlatformSensorProvider_jni.h" | 10 #include "jni/PlatformSensorProvider_jni.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 base::LeakySingletonTraits<PlatformSensorProviderAndroid>>::get(); | 21 base::LeakySingletonTraits<PlatformSensorProviderAndroid>>::get(); |
22 } | 22 } |
23 | 23 |
24 PlatformSensorProviderAndroid::PlatformSensorProviderAndroid() { | 24 PlatformSensorProviderAndroid::PlatformSensorProviderAndroid() { |
25 JNIEnv* env = AttachCurrentThread(); | 25 JNIEnv* env = AttachCurrentThread(); |
26 j_object_.Reset(Java_PlatformSensorProvider_create(env)); | 26 j_object_.Reset(Java_PlatformSensorProvider_create(env)); |
27 } | 27 } |
28 | 28 |
29 PlatformSensorProviderAndroid::~PlatformSensorProviderAndroid() = default; | 29 PlatformSensorProviderAndroid::~PlatformSensorProviderAndroid() = default; |
30 | 30 |
| 31 void PlatformSensorProviderAndroid::SetSensorManagerToNullForTesting() { |
| 32 JNIEnv* env = AttachCurrentThread(); |
| 33 Java_PlatformSensorProvider_setSensorManagerToNullForTest(env, |
| 34 j_object_.obj()); |
| 35 } |
| 36 |
31 void PlatformSensorProviderAndroid::CreateSensorInternal( | 37 void PlatformSensorProviderAndroid::CreateSensorInternal( |
32 mojom::SensorType type, | 38 mojom::SensorType type, |
33 mojo::ScopedSharedBufferMapping mapping, | 39 mojo::ScopedSharedBufferMapping mapping, |
34 const CreateSensorCallback& callback) { | 40 const CreateSensorCallback& callback) { |
35 JNIEnv* env = AttachCurrentThread(); | 41 JNIEnv* env = AttachCurrentThread(); |
36 ScopedJavaLocalRef<jobject> sensor = Java_PlatformSensorProvider_createSensor( | 42 ScopedJavaLocalRef<jobject> sensor = Java_PlatformSensorProvider_createSensor( |
37 env, j_object_.obj(), static_cast<jint>(type)); | 43 env, j_object_.obj(), static_cast<jint>(type)); |
38 | 44 |
39 if (!sensor.obj()) | 45 if (!sensor.obj()) { |
40 callback.Run(nullptr); | 46 callback.Run(nullptr); |
| 47 return; |
| 48 } |
41 | 49 |
42 scoped_refptr<PlatformSensorAndroid> concrete_sensor = | 50 scoped_refptr<PlatformSensorAndroid> concrete_sensor = |
43 new PlatformSensorAndroid(type, std::move(mapping), this, sensor); | 51 new PlatformSensorAndroid(type, std::move(mapping), this, sensor); |
44 callback.Run(concrete_sensor); | 52 callback.Run(concrete_sensor); |
45 } | 53 } |
46 | 54 |
47 } // namespace device | 55 } // namespace device |
OLD | NEW |