diff options
Diffstat (limited to 'src/main/java/org/traccar/BaseProtocol.java')
-rw-r--r-- | src/main/java/org/traccar/BaseProtocol.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/BaseProtocol.java b/src/main/java/org/traccar/BaseProtocol.java index ec1933dc8..d19fc307e 100644 --- a/src/main/java/org/traccar/BaseProtocol.java +++ b/src/main/java/org/traccar/BaseProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ import io.netty.channel.Channel; import io.netty.handler.codec.string.StringEncoder; import org.traccar.helper.DataConverter; import org.traccar.model.Command; +import org.traccar.sms.SmsManager; +import javax.annotation.Nullable; +import javax.inject.Inject; import java.net.SocketAddress; import java.util.Arrays; import java.util.Collection; @@ -37,6 +40,8 @@ public abstract class BaseProtocol implements Protocol { private final Set<String> supportedTextCommands = new HashSet<>(); private final List<TrackerConnector> connectorList = new LinkedList<>(); + private SmsManager smsManager; + private StringProtocolEncoder textCommandEncoder = null; public static String nameFromClass(Class<?> clazz) { @@ -48,6 +53,11 @@ public abstract class BaseProtocol implements Protocol { name = nameFromClass(getClass()); } + @Inject + public void setSmsManager(@Nullable SmsManager smsManager) { + this.smsManager = smsManager; + } + @Override public String getName() { return name; @@ -111,13 +121,13 @@ public abstract class BaseProtocol implements Protocol { @Override public void sendTextCommand(String destAddress, Command command) throws Exception { - if (Context.getSmsManager() != null) { + if (smsManager != null) { if (command.getType().equals(Command.TYPE_CUSTOM)) { - Context.getSmsManager().sendMessage(destAddress, command.getString(Command.KEY_DATA), true); + smsManager.sendMessage(destAddress, command.getString(Command.KEY_DATA), true); } else if (supportedTextCommands.contains(command.getType()) && textCommandEncoder != null) { String encodedCommand = (String) textCommandEncoder.encodeCommand(command); if (encodedCommand != null) { - Context.getSmsManager().sendMessage(destAddress, encodedCommand, true); + smsManager.sendMessage(destAddress, encodedCommand, true); } else { throw new RuntimeException("Failed to encode command"); } |