Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3472)

Unified Diff: device/usb/usb_service_android.cc

Issue 1565313002: Reland of Implement basic USB device enumeration on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dependency fix added to reland. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/usb/usb_service_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_service_android.cc
diff --git a/device/usb/usb_service_android.cc b/device/usb/usb_service_android.cc
index 45ce49979eccdecd82f239e7b8f3834eadc196c0..3bdf3bc6332650f8b426a8c18cff7586a36ef251 100644
--- a/device/usb/usb_service_android.cc
+++ b/device/usb/usb_service_android.cc
@@ -4,14 +4,30 @@
#include "device/usb/usb_service_android.h"
+#include <string>
+#include <vector>
+
+#include "base/android/context_utils.h"
#include "base/bind.h"
#include "base/location.h"
#include "base/thread_task_runner_handle.h"
-#include "device/usb/usb_device.h"
+#include "device/usb/usb_device_android.h"
+#include "jni/ChromeUsbService_jni.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ScopedJavaLocalRef;
namespace device {
-UsbServiceAndroid::UsbServiceAndroid() {}
+// static
+bool UsbServiceAndroid::RegisterJNI(JNIEnv* env) {
+ return RegisterNativesImpl(env); // Generated in ChromeUsbService_jni.h
+}
+
+UsbServiceAndroid::UsbServiceAndroid() {
+ j_object_.Reset(Java_ChromeUsbService_create(
+ AttachCurrentThread(), base::android::GetApplicationContext()));
+}
UsbServiceAndroid::~UsbServiceAndroid() {}
@@ -20,9 +36,20 @@ scoped_refptr<UsbDevice> UsbServiceAndroid::GetDevice(const std::string& guid) {
}
void UsbServiceAndroid::GetDevices(const GetDevicesCallback& callback) {
- std::vector<scoped_refptr<UsbDevice>> empty;
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobjectArray> devices =
+ Java_ChromeUsbService_getDevices(env, j_object_.obj());
+ jsize length = env->GetArrayLength(devices.obj());
+
+ std::vector<scoped_refptr<UsbDevice>> results;
+ for (jsize i = 0; i < length; ++i) {
+ ScopedJavaLocalRef<jobject> raw_device(
+ env, env->GetObjectArrayElement(devices.obj(), i));
+ results.push_back(UsbDeviceAndroid::Create(env, raw_device));
+ }
+
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
- base::Bind(callback, empty));
+ base::Bind(callback, results));
}
} // namespace device
« no previous file with comments | « device/usb/usb_service_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698