2 * Copyright (C) 2013 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 "ConsumerIrService"
21 #include "android_runtime/AndroidRuntime.h"
24 #include <utils/misc.h>
25 #include <utils/Log.h>
26 #include <hardware/hardware.h>
27 #include <hardware/consumerir.h>
28 #include <ScopedPrimitiveArray.h>
32 static jint halOpen(JNIEnv *env, jobject obj) {
33 hw_module_t const* module;
34 consumerir_device_t *dev;
37 err = hw_get_module(CONSUMERIR_HARDWARE_MODULE_ID, &module);
39 ALOGE("Can't open consumer IR HW Module, error: %d", err);
43 err = module->methods->open(module, CONSUMERIR_TRANSMITTER,
44 (hw_device_t **) &dev);
46 ALOGE("Can't open consumer IR transmitter, error: %d", err);
50 return reinterpret_cast<jint>(dev);
53 static jint halTransmit(JNIEnv *env, jobject obj, jint halObject,
54 jint carrierFrequency, jintArray pattern) {
57 consumerir_device_t *dev = reinterpret_cast<consumerir_device_t*>(halObject);
58 ScopedIntArrayRO cPattern(env, pattern);
59 if (cPattern.get() == NULL) {
62 jsize patternLength = cPattern.size();
64 ret = dev->transmit(dev, carrierFrequency, cPattern.get(), patternLength);
66 return reinterpret_cast<jint>(ret);
69 static jintArray halGetCarrierFrequencies(JNIEnv *env, jobject obj,
71 consumerir_device_t *dev = (consumerir_device_t *) halObject;
72 consumerir_freq_range_t *ranges;
75 len = dev->get_num_carrier_freqs(dev);
79 ranges = new consumerir_freq_range_t[len];
81 len = dev->get_carrier_freqs(dev, len, ranges);
88 ScopedIntArrayRW freqsOut(env, env->NewIntArray(len*2));
89 jint *arr = freqsOut.get();
94 for (i = 0; i < len; i++) {
95 arr[i*2] = ranges[i].min;
96 arr[i*2+1] = ranges[i].max;
100 return freqsOut.getJavaArray();
103 static JNINativeMethod method_table[] = {
104 { "halOpen", "()I", (void *)halOpen },
105 { "halTransmit", "(II[I)I", (void *)halTransmit },
106 { "halGetCarrierFrequencies", "(I)[I", (void *)halGetCarrierFrequencies},
109 int register_android_server_ConsumerIrService(JNIEnv *env) {
110 return jniRegisterNativeMethods(env, "com/android/server/ConsumerIrService",
111 method_table, NELEM(method_table));