dexapier / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

Battery monitoring crashes #488

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What device(s) are you experiencing the problem on?
HTC Desire

What firmware version are you running on the device?
2.26.841.2

What steps will reproduce the problem?
1. Run a python script which calls batteryStartMonitoring

What is the expected output? What do you see instead?
An unexpected application stop of SL4A

What version of the product are you using? On what operating system?
version 3 on Android 2.2

Original issue reported on code.google.com by rjmatthews62 on 15 Dec 2010 at 1:23

Attachments:

GoogleCodeExporter commented 9 years ago
For the record, simply running "battery_info.lua", which ships as a sample with 
the Lua interpreter, crashes SL4A every single time too.

o Motorola Droid
o 2.6.32.9-g68eeef5
o version 3 on Android 2.2.1

Original comment by pgy...@gmail.com on 15 Dec 2010 at 3:06

GoogleCodeExporter commented 9 years ago
On further investigation, the error actually occurs when the script stops.
What is more, if 'batterStopMonitoring' is NOT called, the error does not occur.
I would imagine that the problem is being caused here:
BatteryManagerFacade.java:

  @Rpc(description = "Stops tracking battery state.")
  public void batteryStopMonitoring() {
    mService.unregisterReceiver(mReceiver);
    mBatteryData = null;
  }

  @Override
  public void shutdown() {
    batteryStopMonitoring();
  }

unregisterReceiver must throw an IllegalArgumentException it is called twice.

Fix: trap exception in batteryStopMonitoring, and/or reference count calls to 
batteryStartMonitoring

Workaround: don't call batteryStopMonitoring in your script.

Original comment by rjmatthews62 on 15 Dec 2010 at 4:46

GoogleCodeExporter commented 9 years ago
The actual fix is a one line fix in BatteryManagerFacade.java:

  public void batteryStopMonitoring() {
    if (mReceiver != null) {
      mService.unregisterReceiver(mReceiver);
**      mReceiver = null; **
    }
    mBatteryData = null;
  }

I'd fix it myself but I can't get SL4A to compile in my environment.

Original comment by rjmatthews62 on 18 Dec 2010 at 11:23

GoogleCodeExporter commented 9 years ago
... and now the change is checked into clone:
rjmatthews62-android-scripting

Original comment by rjmatthews62 on 19 Dec 2010 at 11:20

GoogleCodeExporter commented 9 years ago
Fixed in latest unofficial release 3x

Original comment by rjmatthews62 on 7 Jan 2011 at 1:45