summaryrefslogtreecommitdiffstats
blob: c5c6b80c65dc7ea239dfc9d26a7b25169e65ad8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2011 The Android Open Source Project
 * Copyright (C) 2010-2012 Texas Instruments, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "Board_ID"

#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"

#include <utils/misc.h>
#include <utils/Log.h>
#include "../../include/omap4_board_identity.h"

#include <stdio.h>

namespace android
{
    static jstring getBoardID_sysfs(JNIEnv *env __attribute__ ((unused)),
                              jobject clazz __attribute__ ((unused)),
                              jint id_to_get)
    {
        int data_size = 0;
        char* data_ret;

        ALOGI("Getting the ID %i\n", id_to_get);
	data_ret = get_device_identity(id_to_get);
        jstring jdata_ret = env->NewStringUTF(data_ret);
	return jdata_ret;
    }
    static jstring getBoardID_prop(JNIEnv *env __attribute__ ((unused)),
                              jobject clazz __attribute__ ((unused)),
                              jint id_to_get)
    {
        int data_size = 0;
        char* data_ret;

        ALOGI("Getting the ID %i\n", id_to_get);
	data_ret = get_device_property(id_to_get);
        jstring jdata_ret = env->NewStringUTF(data_ret);
	return jdata_ret;
    }

    static jint setGov(JNIEnv *env __attribute__ ((unused)),
                              jobject clazz __attribute__ ((unused)),
                              jint gov_to_set)
    {
        int data_ret;

        ALOGI("Getting the ID %i\n", gov_to_set);
	data_ret = set_governor(gov_to_set);
	return data_ret;
    }

    static JNINativeMethod method_table[] = {
        { "getBoardIDsysfsNative", "(I)Ljava/lang/String;", (void*)getBoardID_sysfs },
        { "getBoardIDpropNative", "(I)Ljava/lang/String;", (void*)getBoardID_prop },
        { "setGovernorNative", "(I)I", (void*)setGov },
    };

    int register_Board_ID_Service(JNIEnv *env)
    {
         return jniRegisterNativeMethods(env, "board_id/com/ti/BoardIDService",
            method_table, NELEM(method_table));
    }

};

using namespace android;
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
    JNIEnv* env = NULL;
    jint result = -1;

    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        ALOGE("GetEnv failed!");
        return result;
    }
    ALOG_ASSERT(env, "Could not retrieve the env!");

    register_Board_ID_Service(env);

    return JNI_VERSION_1_4;
}