1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17#define LOG_TAG "UsbDeviceJNI" 18 19#include "utils/Log.h" 20 21#include "jni.h" 22#include "JNIHelp.h" 23#include "android_runtime/AndroidRuntime.h" 24 25#include <usbhost/usbhost.h> 26 27using namespace android; 28 29static jint 30android_hardware_UsbDevice_get_device_id(JNIEnv *env, jobject clazz, jstring name) 31{ 32 const char *nameStr = env->GetStringUTFChars(name, NULL); 33 int id = usb_device_get_unique_id_from_name(nameStr); 34 env->ReleaseStringUTFChars(name, nameStr); 35 return id; 36} 37 38static jstring 39android_hardware_UsbDevice_get_device_name(JNIEnv *env, jobject clazz, jint id) 40{ 41 char* name = usb_device_get_name_from_unique_id(id); 42 jstring result = env->NewStringUTF(name); 43 free(name); 44 return result; 45} 46 47static JNINativeMethod method_table[] = { 48 // static methods 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 }, 53}; 54 55int register_android_hardware_UsbDevice(JNIEnv *env) 56{ 57 return AndroidRuntime::registerNativeMethods(env, "android/hardware/usb/UsbDevice", 58 method_table, NELEM(method_table)); 59} 60