2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #define LOG_TAG "UsbDeviceJNI"
19 #include "utils/Log.h"
23 #include "core_jni_helpers.h"
25 #include <usbhost/usbhost.h>
27 using namespace android;
30 android_hardware_UsbDevice_get_device_id(JNIEnv *env, jobject clazz, jstring name)
32 const char *nameStr = env->GetStringUTFChars(name, NULL);
33 int id = usb_device_get_unique_id_from_name(nameStr);
34 env->ReleaseStringUTFChars(name, nameStr);
39 android_hardware_UsbDevice_get_device_name(JNIEnv *env, jobject clazz, jint id)
41 char* name = usb_device_get_name_from_unique_id(id);
42 jstring result = env->NewStringUTF(name);
47 static const JNINativeMethod method_table[] = {
49 { "native_get_device_id", "(Ljava/lang/String;)I",
50 (void*)android_hardware_UsbDevice_get_device_id },
51 { "native_get_device_name", "(I)Ljava/lang/String;",
52 (void*)android_hardware_UsbDevice_get_device_name },
55 int register_android_hardware_UsbDevice(JNIEnv *env)
57 return RegisterMethodsOrDie(env, "android/hardware/usb/UsbDevice",
58 method_table, NELEM(method_table));