mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
Use timeout to break out of possible infinite loop waiting for sensor to start.
This commit is contained in:
parent
03f6267c82
commit
c050e00b8f
@ -105,13 +105,18 @@ public class AccelListener implements SensorEventListener, Plugin{
|
|||||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
||||||
}
|
}
|
||||||
// Wait until running
|
// Wait until running
|
||||||
while (this.status == STARTING) {
|
long timeout = 2000;
|
||||||
|
while ((this.status == STARTING) && (timeout > 0)) {
|
||||||
|
timeout = timeout - 100;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (timeout == 0) {
|
||||||
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
JSONObject r = new JSONObject();
|
JSONObject r = new JSONObject();
|
||||||
r.put("x", this.x);
|
r.put("x", this.x);
|
||||||
|
@ -98,13 +98,18 @@ public class CompassListener implements SensorEventListener, Plugin{
|
|||||||
return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
|
||||||
}
|
}
|
||||||
// Wait until running
|
// Wait until running
|
||||||
while (this.status == STARTING) {
|
long timeout = 2000;
|
||||||
|
while ((this.status == STARTING) && (timeout > 0)) {
|
||||||
|
timeout = timeout - 100;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (timeout == 0) {
|
||||||
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
float f = this.getHeading();
|
float f = this.getHeading();
|
||||||
return new PluginResult(status, f);
|
return new PluginResult(status, f);
|
||||||
|
Loading…
Reference in New Issue
Block a user