Android: Don't share the JNI environment across threads, but obtain it the
[maemo-rb.git] / firmware / target / hosted / android / powermgmt-android.c
blob222212f9c8d3657d586b51bada26061b3cc75532
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 by Thomas Martitz
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include <jni.h>
24 #include <stdbool.h>
25 #include "config.h"
26 #include "system.h"
28 extern jclass RockboxService_class;
29 extern jobject RockboxService_instance;
31 static jfieldID _battery_level;
33 void powermgmt_init_target(void)
35 JNIEnv *env_ptr = getJavaEnvironment();
37 jmethodID initBatteryMonitor = (*env_ptr)->GetMethodID(env_ptr,
38 RockboxService_class,
39 "initBatteryMonitor",
40 "()V");
41 /* start the monitor */
42 (*env_ptr)->CallVoidMethod(env_ptr,
43 RockboxService_instance,
44 initBatteryMonitor);
46 /* cache the battery level field id */
47 _battery_level = (*env_ptr)->GetFieldID(env_ptr,
48 RockboxService_class,
49 "battery_level",
50 "I");
53 int battery_level(void)
55 JNIEnv *env_ptr = getJavaEnvironment();
57 return (*env_ptr)->GetIntField(env_ptr, RockboxService_instance, _battery_level);
60 int battery_time(void)
61 { /* cannot calculate yet */
62 return 0;
65 /* should always be safe on android targets, the host shuts us down before */
66 bool battery_level_safe(void)
68 return true;
71 /* TODO */
72 unsigned battery_voltage(void)
74 return 0;