OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/usb/usb_configuration_android.h" | 5 #include "device/usb/usb_configuration_android.h" |
6 | 6 |
7 #include "device/usb/usb_interface_android.h" | 7 #include "device/usb/usb_interface_android.h" |
8 #include "jni/ChromeUsbConfiguration_jni.h" | 8 #include "jni/ChromeUsbConfiguration_jni.h" |
9 | 9 |
10 using base::android::ScopedJavaLocalRef; | 10 using base::android::ScopedJavaLocalRef; |
11 | 11 |
12 namespace device { | 12 namespace device { |
13 | 13 |
14 // static | 14 // static |
15 bool UsbConfigurationAndroid::RegisterJNI(JNIEnv* env) { | 15 bool UsbConfigurationAndroid::RegisterJNI(JNIEnv* env) { |
16 return RegisterNativesImpl(env); // Generated in ChromeUsbConfiguration_jni.h | 16 return RegisterNativesImpl(env); // Generated in ChromeUsbConfiguration_jni.h |
17 } | 17 } |
18 | 18 |
19 // static | 19 // static |
20 UsbConfigDescriptor UsbConfigurationAndroid::Convert( | 20 UsbConfigDescriptor UsbConfigurationAndroid::Convert( |
21 JNIEnv* env, | 21 JNIEnv* env, |
22 const base::android::JavaRef<jobject>& usb_configuration) { | 22 const base::android::JavaRef<jobject>& usb_configuration) { |
23 ScopedJavaLocalRef<jobject> wrapper = | 23 ScopedJavaLocalRef<jobject> wrapper = |
24 Java_ChromeUsbConfiguration_create(env, usb_configuration.obj()); | 24 Java_ChromeUsbConfiguration_create(env, usb_configuration.obj()); |
25 | 25 |
26 UsbConfigDescriptor config; | 26 UsbConfigDescriptor config( |
27 config.configuration_value = | 27 Java_ChromeUsbConfiguration_getConfigurationValue(env, wrapper.obj()), |
28 Java_ChromeUsbConfiguration_getConfigurationValue(env, wrapper.obj()); | 28 Java_ChromeUsbConfiguration_isSelfPowered(env, wrapper.obj()), |
29 config.self_powered = | 29 Java_ChromeUsbConfiguration_isRemoteWakeup(env, wrapper.obj()), |
30 Java_ChromeUsbConfiguration_isSelfPowered(env, wrapper.obj()); | 30 Java_ChromeUsbConfiguration_getMaxPower(env, wrapper.obj())); |
31 config.remote_wakeup = | |
32 Java_ChromeUsbConfiguration_isRemoteWakeup(env, wrapper.obj()); | |
33 config.maximum_power = | |
34 Java_ChromeUsbConfiguration_getMaxPower(env, wrapper.obj()); | |
35 | 31 |
36 ScopedJavaLocalRef<jobjectArray> interfaces = | 32 ScopedJavaLocalRef<jobjectArray> interfaces = |
37 Java_ChromeUsbConfiguration_getInterfaces(env, wrapper.obj()); | 33 Java_ChromeUsbConfiguration_getInterfaces(env, wrapper.obj()); |
38 jsize count = env->GetArrayLength(interfaces.obj()); | 34 jsize count = env->GetArrayLength(interfaces.obj()); |
39 config.interfaces.reserve(count); | 35 config.interfaces.reserve(count); |
40 for (jsize i = 0; i < count; ++i) { | 36 for (jsize i = 0; i < count; ++i) { |
41 ScopedJavaLocalRef<jobject> interface( | 37 ScopedJavaLocalRef<jobject> interface( |
42 env, env->GetObjectArrayElement(interfaces.obj(), i)); | 38 env, env->GetObjectArrayElement(interfaces.obj(), i)); |
43 config.interfaces.push_back(UsbInterfaceAndroid::Convert(env, interface)); | 39 config.interfaces.push_back(UsbInterfaceAndroid::Convert(env, interface)); |
44 } | 40 } |
45 | 41 |
46 return config; | 42 return config; |
47 } | 43 } |
48 | 44 |
49 } // namespace device | 45 } // namespace device |
OLD | NEW |