blob: 89d33e2ace1c1aeaedb9b3d54827b8bf43f5b3b6 [file] [log] [blame]
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001/*
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"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080023#include "core_jni_helpers.h"
Mike Lockwoode7d511e2010-12-30 13:39:37 -050024
25#include <usbhost/usbhost.h>
26
Mike Lockwoode7d511e2010-12-30 13:39:37 -050027using namespace android;
28
Mike Lockwoode7d511e2010-12-30 13:39:37 -050029static 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
Daniel Micay76f6a862015-09-19 17:31:01 -040047static const JNINativeMethod method_table[] = {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050048 // 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{
Andreas Gampeed6b9df2014-11-20 22:02:20 -080057 return RegisterMethodsOrDie(env, "android/hardware/usb/UsbDevice",
Mike Lockwoode7d511e2010-12-30 13:39:37 -050058 method_table, NELEM(method_table));
59}