2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-03 15:45:10 +00:00

We don't need the chanel id to chanel map.

This commit is contained in:
Albert Vaca
2016-03-02 10:40:17 -08:00
parent 910af86c31
commit baee1771f5

View File

@@ -84,9 +84,8 @@ public class LanLinkProvider extends BaseLinkProvider {
private final Context context; private final Context context;
private final HashMap<String, LanLink> visibleComputers = new HashMap<String, LanLink>(); private final HashMap<String, LanLink> visibleComputers = new HashMap<String, LanLink>(); //Links by device id
private final LongSparseArray<LanLink> nioLinks = new LongSparseArray<LanLink>(); private final LongSparseArray<LanLink> nioLinks = new LongSparseArray<LanLink>(); //Links by channel id
private final LongSparseArray<Channel> nioChannels = new LongSparseArray<Channel>();
private EventLoopGroup bossGroup, workerGroup, udpGroup, clientGroup; private EventLoopGroup bossGroup, workerGroup, udpGroup, clientGroup;
private TcpHandler tcpHandler = new TcpHandler(); private TcpHandler tcpHandler = new TcpHandler();
@@ -110,14 +109,10 @@ public class LanLinkProvider extends BaseLinkProvider {
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// Called after a long time if remote device closes session unexpectedly, like wifi off // Called after a long time if remote device closes session unexpectedly, like wifi off
try { try {
long id = ctx.channel().hashCode(); Channel channel = ctx.channel();
final LanLink brokenLink = nioLinks.get(id); final LanLink brokenLink = nioLinks.get(channel.hashCode());
Channel channel = nioChannels.get(id);
if (channel != null) {
nioChannels.remove(id);
}
if (brokenLink != null) { if (brokenLink != null) {
nioLinks.remove(id); nioLinks.remove(channel.hashCode());
//Log.i("KDE/LanLinkProvider", "nioLinks.size(): " + nioLinks.size() + " (-)"); //Log.i("KDE/LanLinkProvider", "nioLinks.size(): " + nioLinks.size() + " (-)");
try { try {
brokenLink.closeSocket(); brokenLink.closeSocket();
@@ -174,7 +169,6 @@ public class LanLinkProvider extends BaseLinkProvider {
final LanLink link = new LanLink(context, ctx.channel(), np.getString("deviceId"), LanLinkProvider.this, BaseLink.ConnectionStarted.Locally); final LanLink link = new LanLink(context, ctx.channel(), np.getString("deviceId"), LanLinkProvider.this, BaseLink.ConnectionStarted.Locally);
nioLinks.put(ctx.channel().hashCode(), link); nioLinks.put(ctx.channel().hashCode(), link);
nioChannels.put(ctx.channel().hashCode(), ctx.channel());
//Log.i("KDE/LanLinkProvider","nioLinks.size(): " + nioLinks.size()); //Log.i("KDE/LanLinkProvider","nioLinks.size(): " + nioLinks.size());
// Add ssl handler if device uses new protocol // Add ssl handler if device uses new protocol
@@ -298,7 +292,6 @@ public class LanLinkProvider extends BaseLinkProvider {
@Override @Override
protected void onSuccess() { protected void onSuccess() {
nioLinks.put(channel.hashCode(), link); nioLinks.put(channel.hashCode(), link);
nioChannels.put(channel.hashCode(), channel);
Log.i("KDE/LanLinkProvider", "nioLinks.size(): " + nioLinks.size()); Log.i("KDE/LanLinkProvider", "nioLinks.size(): " + nioLinks.size());
// If ssl handler is in channel, add link after handshake is completed // If ssl handler is in channel, add link after handshake is completed