diff options
Diffstat (limited to 'src/main/java/org/traccar/BaseProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/BaseProtocolDecoder.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index 382daf92f..495a866c0 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -29,9 +29,8 @@ import org.traccar.model.Position; import org.traccar.session.ConnectionManager; import org.traccar.session.DeviceSession; import org.traccar.session.cache.CacheManager; -import org.traccar.storage.StorageException; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Collection; @@ -52,6 +51,8 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { private MediaManager mediaManager; private CommandsManager commandsManager; + private String modelOverride; + public BaseProtocolDecoder(Protocol protocol) { this.protocol = protocol; } @@ -125,22 +126,31 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } protected TimeZone getTimeZone(long deviceId, String defaultTimeZone) { - TimeZone result = TimeZone.getTimeZone(defaultTimeZone); String timeZoneName = AttributeUtil.lookup(cacheManager, Keys.DECODER_TIMEZONE, deviceId); if (timeZoneName != null) { - result = TimeZone.getTimeZone(timeZoneName); + return TimeZone.getTimeZone(timeZoneName); + } else if (defaultTimeZone != null) { + return TimeZone.getTimeZone(defaultTimeZone); } - return result; + return null; } public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) { try { return connectionManager.getDeviceSession(protocol, channel, remoteAddress, uniqueIds); - } catch (StorageException e) { + } catch (Exception e) { throw new RuntimeException(e); } } + public void setModelOverride(String modelOverride) { + this.modelOverride = modelOverride; + } + + public String getDeviceModel(DeviceSession deviceSession) { + return modelOverride != null ? modelOverride : deviceSession.getModel(); + } + public void getLastLocation(Position position, Date deviceTime) { if (position.getDeviceId() != 0) { position.setOutdated(true); |