Android: don't compile powermgmt-sim.c
Instead implement a bit of battery monitoring. Currently it only fetches the battery level (in %) every 30s, but it could do more like battery status, charger connected, voltage... Theoretically, we could also exit/quit after some time of inactivity too (perhaps not a bad idea since Rockbox puts a slight but still non-zero CPU load even if doing nothing). Ironically, Rockbox is now the only way to get the exact battery level (at least I haven't found anything yet) on my phone :-) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27974 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c00fbc4d06
commit
f05cdc46f2
7 changed files with 56 additions and 2 deletions
|
@ -9,6 +9,8 @@ import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
@ -16,7 +18,10 @@ import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -36,6 +41,9 @@ public class RockboxService extends Service
|
||||||
private Method mStopForeground;
|
private Method mStopForeground;
|
||||||
private Object[] mStartForegroundArgs = new Object[2];
|
private Object[] mStartForegroundArgs = new Object[2];
|
||||||
private Object[] mStopForegroundArgs = new Object[1];
|
private Object[] mStopForegroundArgs = new Object[1];
|
||||||
|
private IntentFilter itf;
|
||||||
|
private BroadcastReceiver batt_monitor;
|
||||||
|
private int battery_level;
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
|
@ -161,6 +169,43 @@ public class RockboxService extends Service
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
/*
|
||||||
|
* Sets up the battery monitor which receives the battery level
|
||||||
|
* about each 30 seconds
|
||||||
|
*/
|
||||||
|
private void initBatteryMonitor()
|
||||||
|
{
|
||||||
|
itf = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||||
|
batt_monitor = new BroadcastReceiver()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent)
|
||||||
|
{
|
||||||
|
/* we get literally spammed with battery statuses
|
||||||
|
* if we don't delay the re-attaching
|
||||||
|
*/
|
||||||
|
TimerTask tk = new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
registerReceiver(batt_monitor, itf);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Timer t = new Timer();
|
||||||
|
context.unregisterReceiver(this);
|
||||||
|
int rawlevel = intent.getIntExtra("level", -1);
|
||||||
|
int scale = intent.getIntExtra("scale", -1);
|
||||||
|
if (rawlevel >= 0 && scale > 0)
|
||||||
|
battery_level = (rawlevel * 100) / scale;
|
||||||
|
else
|
||||||
|
battery_level = -1;
|
||||||
|
/* query every 30s should be sufficient */
|
||||||
|
t.schedule(tk, 30000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
registerReceiver(batt_monitor, itf);
|
||||||
|
}
|
||||||
|
|
||||||
/* all below is heavily based on the examples found on
|
/* all below is heavily based on the examples found on
|
||||||
* http://developer.android.com/reference/android/app/Service.html
|
* http://developer.android.com/reference/android/app/Service.html
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -852,7 +852,10 @@ void settings_apply(bool read_disk)
|
||||||
#endif
|
#endif
|
||||||
set_poweroff_timeout(global_settings.poweroff);
|
set_poweroff_timeout(global_settings.poweroff);
|
||||||
|
|
||||||
|
#if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
|
||||||
set_battery_capacity(global_settings.battery_capacity);
|
set_battery_capacity(global_settings.battery_capacity);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BATTERY_TYPES_COUNT > 1
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
set_battery_type(global_settings.battery_type);
|
set_battery_type(global_settings.battery_type);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -619,7 +619,9 @@ struct user_settings
|
||||||
|
|
||||||
/* power settings */
|
/* power settings */
|
||||||
int poweroff; /* idle power off timer */
|
int poweroff; /* idle power off timer */
|
||||||
|
#if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
|
||||||
int battery_capacity; /* in mAh */
|
int battery_capacity; /* in mAh */
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BATTERY_TYPES_COUNT > 1
|
#if BATTERY_TYPES_COUNT > 1
|
||||||
int battery_type; /* for units which can take multiple types (Ondio). */
|
int battery_type; /* for units which can take multiple types (Ondio). */
|
||||||
|
|
|
@ -763,7 +763,7 @@ const struct settings_list settings[] = {
|
||||||
#endif
|
#endif
|
||||||
"max files in dir", UNIT_INT, 50, 10000, 50,
|
"max files in dir", UNIT_INT, 50, 10000, 50,
|
||||||
NULL, NULL, NULL),
|
NULL, NULL, NULL),
|
||||||
#if BATTERY_CAPACITY_INC > 0
|
#if defined(BATTERY_CAPACITY_INC) && BATTERY_CAPACITY_INC > 0
|
||||||
INT_SETTING(0, battery_capacity, LANG_BATTERY_CAPACITY,
|
INT_SETTING(0, battery_capacity, LANG_BATTERY_CAPACITY,
|
||||||
BATTERY_CAPACITY_DEFAULT, "battery capacity", UNIT_MAH,
|
BATTERY_CAPACITY_DEFAULT, "battery capacity", UNIT_MAH,
|
||||||
BATTERY_CAPACITY_MIN, BATTERY_CAPACITY_MAX,
|
BATTERY_CAPACITY_MIN, BATTERY_CAPACITY_MAX,
|
||||||
|
|
|
@ -1709,6 +1709,7 @@ target/hosted/android/lc-android.c
|
||||||
target/hosted/android/button-android.c
|
target/hosted/android/button-android.c
|
||||||
target/hosted/android/kernel-android.c
|
target/hosted/android/kernel-android.c
|
||||||
target/hosted/android/pcm-android.c
|
target/hosted/android/pcm-android.c
|
||||||
|
target/hosted/android/powermgmt-android.c
|
||||||
target/hosted/android/system-android.c
|
target/hosted/android/system-android.c
|
||||||
#ifdef APPLICATION
|
#ifdef APPLICATION
|
||||||
target/hosted/android/app/button-application.c
|
target/hosted/android/app/button-application.c
|
||||||
|
|
|
@ -55,5 +55,8 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this)
|
||||||
env_ptr = env;
|
env_ptr = env;
|
||||||
RockboxService_instance = this;
|
RockboxService_instance = this;
|
||||||
RockboxService_class = (*env)->GetObjectClass(env, this);
|
RockboxService_class = (*env)->GetObjectClass(env, this);
|
||||||
|
|
||||||
|
|
||||||
|
powermgmt_init_target();
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ backlight-sim.c
|
||||||
#if (CONFIG_PLATFORM & PLATFORM_SDL)
|
#if (CONFIG_PLATFORM & PLATFORM_SDL)
|
||||||
io.c
|
io.c
|
||||||
sim_tasks.c
|
sim_tasks.c
|
||||||
|
powermgmt-sim.c
|
||||||
#endif
|
#endif
|
||||||
/* this is still needed for application since it has some stubs */
|
/* this is still needed for application since it has some stubs */
|
||||||
powermgmt-sim.c
|
|
||||||
stubs.c
|
stubs.c
|
||||||
|
|
Loading…
Reference in a new issue