forked from upstream-mirrors/OpenTracks
Improve AntSensorManager.
Reduce checking sensor connection timer period to 20 seconds.
This commit is contained in:
@@ -33,8 +33,8 @@ public abstract class SensorManager {
|
|||||||
|
|
||||||
private static final String TAG = SensorManager.class.getSimpleName();
|
private static final String TAG = SensorManager.class.getSimpleName();
|
||||||
private static final long MAX_SENSOR_DATE_SET_AGE = 5000;
|
private static final long MAX_SENSOR_DATE_SET_AGE = 5000;
|
||||||
private static final long MAX_SENSOR_STATE_AGE = 30000;
|
private static final long MAX_SENSOR_STATE_AGE = 20000;
|
||||||
private static final int RETRY_PERIOD = 30000;
|
private static final int RETRY_PERIOD = 20000;
|
||||||
|
|
||||||
private SensorState sensorState = SensorState.NONE;
|
private SensorState sensorState = SensorState.NONE;
|
||||||
private long sensorStateTimestamp = System.currentTimeMillis();
|
private long sensorStateTimestamp = System.currentTimeMillis();
|
||||||
|
|||||||
+26
-24
@@ -126,28 +126,39 @@ public class AntSensorManager extends SensorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUpChannel() {
|
protected synchronized void setUpChannel() {
|
||||||
|
tearDownChannel();
|
||||||
if (AntInterface.hasAntSupport(context)) {
|
if (AntInterface.hasAntSupport(context)) {
|
||||||
context.registerReceiver(statusReceiver, statusIntentFilter);
|
context.registerReceiver(statusReceiver, statusIntentFilter);
|
||||||
if (!antInterface.initService(context, serviceListener)) {
|
if (!antInterface.initService(context, serviceListener)) {
|
||||||
AntInterface.goToMarket(context);
|
AntInterface.goToMarket(context);
|
||||||
} else {
|
} else {
|
||||||
setSensorState(Sensor.SensorState.CONNECTING);
|
setSensorState(Sensor.SensorState.CONNECTING);
|
||||||
serviceConnected = antInterface.isServiceConnected();
|
handleServiceConnected();
|
||||||
if (serviceConnected) {
|
|
||||||
try {
|
|
||||||
hasClaimedInterface = antInterface.hasClaimedInterface();
|
|
||||||
if (hasClaimedInterface) {
|
|
||||||
enableDataMessage(true);
|
|
||||||
}
|
|
||||||
} catch (AntInterfaceException e) {
|
|
||||||
handleAntError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles service connected. Needs to be synchronized.
|
||||||
|
*/
|
||||||
|
private synchronized void handleServiceConnected() {
|
||||||
|
serviceConnected = antInterface.isServiceConnected();
|
||||||
|
if (serviceConnected) {
|
||||||
|
try {
|
||||||
|
hasClaimedInterface = antInterface.hasClaimedInterface();
|
||||||
|
if (hasClaimedInterface) {
|
||||||
|
enableDataMessage(true);
|
||||||
|
} else {
|
||||||
|
// Need to claim the ant interface if it is available
|
||||||
|
hasClaimedInterface = antInterface.claimInterface();
|
||||||
|
}
|
||||||
|
} catch (AntInterfaceException e) {
|
||||||
|
handleAntError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDownChannel() {
|
protected void tearDownChannel() {
|
||||||
try {
|
try {
|
||||||
@@ -161,6 +172,7 @@ public class AntSensorManager extends SensorManager {
|
|||||||
if (hasClaimedInterface) {
|
if (hasClaimedInterface) {
|
||||||
antInterface.releaseInterface();
|
antInterface.releaseInterface();
|
||||||
}
|
}
|
||||||
|
hasClaimedInterface = false;
|
||||||
antInterface.stopRequestForceClaimInterface();
|
antInterface.stopRequestForceClaimInterface();
|
||||||
} catch (AntServiceNotConnectedException e) {
|
} catch (AntServiceNotConnectedException e) {
|
||||||
// Can safely ignore
|
// Can safely ignore
|
||||||
@@ -168,6 +180,7 @@ public class AntSensorManager extends SensorManager {
|
|||||||
Log.w(TAG, "Exception in tearDonwChannel.", e);
|
Log.w(TAG, "Exception in tearDonwChannel.", e);
|
||||||
}
|
}
|
||||||
antInterface.releaseService();
|
antInterface.releaseService();
|
||||||
|
serviceConnected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,18 +203,7 @@ public class AntSensorManager extends SensorManager {
|
|||||||
private AntInterface.ServiceListener serviceListener = new AntInterface.ServiceListener() {
|
private AntInterface.ServiceListener serviceListener = new AntInterface.ServiceListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected() {
|
public void onServiceConnected() {
|
||||||
serviceConnected = true;
|
handleServiceConnected();
|
||||||
try {
|
|
||||||
hasClaimedInterface = antInterface.hasClaimedInterface();
|
|
||||||
if (hasClaimedInterface) {
|
|
||||||
enableDataMessage(true);
|
|
||||||
} else {
|
|
||||||
// Need to claim the ant interface if it is available
|
|
||||||
hasClaimedInterface = antInterface.claimInterface();
|
|
||||||
}
|
|
||||||
} catch (AntInterfaceException e) {
|
|
||||||
handleAntError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user