From 458517e4a4d9d078841e7648dea27d46e4f5d057 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Fri, 20 Jun 2014 23:34:16 +0400 Subject: [PATCH] Improved files download speed --- TMessagesProj/build.gradle | 2 +- .../telegram/messenger/BuffersStorage.java | 19 + .../messenger/ConnectionsManager.java | 395 +++++------------- .../org/telegram/messenger/Datacenter.java | 81 +++- .../telegram/messenger/FileLoadOperation.java | 265 ++++++++---- .../telegram/messenger/HandshakeAction.java | 12 +- .../org/telegram/messenger/RPCRequest.java | 1 + .../java/org/telegram/messenger/TLObject.java | 2 + .../java/org/telegram/messenger/TLRPC.java | 12 + .../org/telegram/ui/ApplicationLoader.java | 11 +- .../java/org/telegram/ui/PhotoViewer.java | 2 +- 11 files changed, 398 insertions(+), 404 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index d7917a7f..91f5f5b6 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -81,7 +81,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 262 + versionCode 264 versionName "1.5.7" } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java index d495ab8c..d0980378 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuffersStorage.java @@ -17,6 +17,7 @@ public class BuffersStorage { private final ArrayList freeBuffers4096; private final ArrayList freeBuffers16384; private final ArrayList freeBuffers32768; + private final ArrayList freeBuffersBig; private static volatile BuffersStorage Instance = null; public static BuffersStorage getInstance() { @@ -38,6 +39,7 @@ public class BuffersStorage { freeBuffers4096 = new ArrayList(); freeBuffers16384 = new ArrayList(); freeBuffers32768 = new ArrayList(); + freeBuffersBig = new ArrayList(); for (int a = 0; a < 5; a++) { freeBuffers128.add(new ByteBufferDesc(128)); @@ -113,6 +115,17 @@ public class BuffersStorage { buffer = new ByteBufferDesc(40000); FileLog.e("tmessages", "create new 40000 buffer"); } + } else if (size <= 280000) { + synchronized (freeBuffersBig) { + if (freeBuffersBig.size() > 0) { + buffer = freeBuffersBig.get(0); + freeBuffersBig.remove(0); + } + } + if (buffer == null) { + buffer = new ByteBufferDesc(280000); + FileLog.e("tmessages", "create new big buffer"); + } } else { buffer = new ByteBufferDesc(size); } @@ -154,6 +167,12 @@ public class BuffersStorage { freeBuffers32768.add(buffer); } } + } else if (buffer.buffer.capacity() == 280000) { + synchronized (freeBuffersBig) { + if (freeBuffersBig.size() < 4) { + freeBuffersBig.add(buffer); + } + } } } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java index 788b7985..00674640 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java @@ -44,6 +44,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. private ArrayList runningRequests = new ArrayList(); private ArrayList actionQueue = new ArrayList(); + private ArrayList unknownDatacenterIds = new ArrayList(); + private ArrayList neededDatacenterIds = new ArrayList(); + private ArrayList unauthorizedDatacenterIds = new ArrayList(); + final HashMap> genericMessagesToDatacenters = new HashMap>(); + private TLRPC.TL_auth_exportedAuthorization movingAuthorization; public static final int DEFAULT_DATACENTER_ID = Integer.MAX_VALUE; public static final int DC_UPDATE_TIME = 60 * 60; @@ -126,15 +131,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. if (!paused) { FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout); for (Datacenter datacenter : datacenters.values()) { - if (datacenter.connection != null) { - datacenter.connection.suspendConnection(true); - } - if (datacenter.uploadConnection != null) { - datacenter.uploadConnection.suspendConnection(true); - } - if (datacenter.downloadConnection != null) { - datacenter.downloadConnection.suspendConnection(true); - } + datacenter.suspendConnections(); } } try { @@ -472,15 +469,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. editor.putLong("pushSessionId", pushSessionId); ArrayList sessions = new ArrayList(); - if (currentDatacenter.connection != null) { - sessions.add(currentDatacenter.connection.getSissionId()); - } - if (currentDatacenter.downloadConnection != null) { - sessions.add(currentDatacenter.downloadConnection.getSissionId()); - } - if (currentDatacenter.uploadConnection != null) { - sessions.add(currentDatacenter.uploadConnection.getSissionId()); - } + currentDatacenter.getSessions(sessions); if (!sessions.isEmpty()) { SerializedData data = new SerializedData(sessions.size() * 8 + 4); @@ -539,15 +528,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. @Override public void run() { Datacenter datacenter = datacenterWithId(currentDatacenterId); - if (datacenter.connection != null) { - datacenter.connection.recreateSession(); - } - if (datacenter.downloadConnection != null) { - datacenter.downloadConnection.recreateSession(); - } - if (datacenter.uploadConnection != null) { - datacenter.uploadConnection.recreateSession(); - } + datacenter.recreateSessions(); clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter); clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, datacenter); @@ -632,15 +613,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. addresses.add(ip_address); ports.put(ip_address, port); exist.replaceAddressesAndPorts(addresses, ports); - if (exist.connection != null) { - exist.connection.suspendConnection(true); - } - if (exist.uploadConnection != null) { - exist.uploadConnection.suspendConnection(true); - } - if (exist.downloadConnection != null) { - exist.downloadConnection.suspendConnection(true); - } + exist.suspendConnections(); updateDcSettings(dc); } } @@ -681,15 +654,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. for (HashMap.Entry entry : datacenters.entrySet()) { Datacenter datacenter = entry.getValue(); datacenter.overridePort = 8888; - if (datacenter.connection != null) { - datacenter.connection.suspendConnection(true); - } - if (datacenter.uploadConnection != null) { - datacenter.uploadConnection.suspendConnection(true); - } - if (datacenter.downloadConnection != null) { - datacenter.downloadConnection.suspendConnection(true); - } + datacenter.suspendConnections(); } } else { for (HashMap.Entry entry : datacenters.entrySet()) { @@ -852,6 +817,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } public void cancelRpc(final long token, final boolean notifyServer) { + cancelRpc(token, notifyServer, false); + } + + public void cancelRpc(final long token, final boolean notifyServer, final boolean ifNotSent) { if (token == 0) { return; } @@ -871,30 +840,32 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } } - for (int i = 0; i < runningRequests.size(); i++) { - RPCRequest request = runningRequests.get(i); - if (request.token == token) { - found = true; + if (!ifNotSent) { + for (int i = 0; i < runningRequests.size(); i++) { + RPCRequest request = runningRequests.get(i); + if (request.token == token) { + found = true; - FileLog.d("tmessages", "===== Cancelled running rpc request " + request.rawRequest); + FileLog.d("tmessages", "===== Cancelled running rpc request " + request.rawRequest); - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - if (notifyServer) { - TLRPC.TL_rpc_drop_answer dropAnswer = new TLRPC.TL_rpc_drop_answer(); - dropAnswer.req_msg_id = request.runningMessageId; - performRpc(dropAnswer, null, null, false, request.flags); + if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { + if (notifyServer) { + TLRPC.TL_rpc_drop_answer dropAnswer = new TLRPC.TL_rpc_drop_answer(); + dropAnswer.req_msg_id = request.runningMessageId; + performRpc(dropAnswer, null, null, false, request.flags); + } } - } - request.cancelled = true; - request.rawRequest.freeResources(); - request.rpcRequest.freeResources(); - runningRequests.remove(i); - break; + request.cancelled = true; + request.rawRequest.freeResources(); + request.rpcRequest.freeResources(); + runningRequests.remove(i); + break; + } + } + if (!found) { + FileLog.d("tmessages", "***** Warning: cancelling unknown request"); } - } - if (!found) { - FileLog.d("tmessages", "***** Warning: cancelling unknown request"); } } }); @@ -944,117 +915,18 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } private void processRequestQueue(int requestClass, int _datacenterId) { - final HashMap activeTransportTokens = new HashMap(); - final ArrayList transportsToResume = new ArrayList(); + boolean haveNetwork = true;//isNetworkOnline(); - final HashMap activeDownloadTransportTokens = new HashMap(); - final ArrayList downloadTransportsToResume = new ArrayList(); + genericMessagesToDatacenters.clear(); + unknownDatacenterIds.clear(); + neededDatacenterIds.clear(); + unauthorizedDatacenterIds.clear(); - final HashMap activeUploadTransportTokens = new HashMap(); - final ArrayList uploadTransportsToResume = new ArrayList(); - - for (Datacenter datacenter : datacenters.values()) { - if (datacenter.connection != null) { - int channelToken = datacenter.connection.channelToken; - if (channelToken != 0) { - activeTransportTokens.put(datacenter.datacenterId, channelToken); - } - } - if (datacenter.downloadConnection != null) { - int channelToken = datacenter.downloadConnection.channelToken; - if (channelToken != 0) { - activeDownloadTransportTokens.put(datacenter.datacenterId, channelToken); - } - } - if (datacenter.uploadConnection != null) { - int channelToken = datacenter.uploadConnection.channelToken; - if (channelToken != 0) { - activeUploadTransportTokens.put(datacenter.datacenterId, channelToken); - } - } + TcpConnection genericConnection = null; + Datacenter defaultDatacenter = datacenterWithId(currentDatacenterId); + if (defaultDatacenter != null) { + genericConnection = defaultDatacenter.getGenericConnection(this); } - for (RPCRequest request : runningRequests) { - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId); - if (requestDatacenter != null && !activeTransportTokens.containsKey(requestDatacenter.datacenterId) && !transportsToResume.contains(requestDatacenter.datacenterId)) { - transportsToResume.add(requestDatacenter.datacenterId); - } - } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId); - if (requestDatacenter != null && !activeDownloadTransportTokens.containsKey(requestDatacenter.datacenterId) && !downloadTransportsToResume.contains(requestDatacenter.datacenterId)) { - downloadTransportsToResume.add(requestDatacenter.datacenterId); - } - } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId); - if (requestDatacenter != null && !activeUploadTransportTokens.containsKey(requestDatacenter.datacenterId) && !uploadTransportsToResume.contains(requestDatacenter.datacenterId)) { - uploadTransportsToResume.add(requestDatacenter.datacenterId); - } - } - } - for (RPCRequest request : requestQueue) { - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId); - if (requestDatacenter != null && !activeTransportTokens.containsKey(requestDatacenter.datacenterId) && !transportsToResume.contains(requestDatacenter.datacenterId)) { - transportsToResume.add(requestDatacenter.datacenterId); - } - } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId); - if (requestDatacenter != null && !activeDownloadTransportTokens.containsKey(requestDatacenter.datacenterId) && !downloadTransportsToResume.contains(requestDatacenter.datacenterId)) { - downloadTransportsToResume.add(requestDatacenter.datacenterId); - } - } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - Datacenter requestDatacenter = datacenterWithId(request.runningDatacenterId); - if (requestDatacenter != null && !activeUploadTransportTokens.containsKey(requestDatacenter.datacenterId) && !uploadTransportsToResume.contains(requestDatacenter.datacenterId)) { - uploadTransportsToResume.add(requestDatacenter.datacenterId); - } - } - } - - boolean haveNetwork = true;//activeTransportTokens.size() != 0 || isNetworkOnline(); - - if (!activeTransportTokens.containsKey(currentDatacenterId) && !transportsToResume.contains(currentDatacenterId)) { - transportsToResume.add(currentDatacenterId); - } - - for (int it : transportsToResume) { - Datacenter datacenter = datacenterWithId(it); - if (datacenter.authKey != null) { - if (datacenter.connection == null) { - datacenter.connection = new TcpConnection(datacenter.datacenterId); - datacenter.connection.delegate = this; - datacenter.connection.transportRequestClass = RPCRequest.RPCRequestClassGeneric; - } - datacenter.connection.connect(); - } - } - for (int it : downloadTransportsToResume) { - Datacenter datacenter = datacenterWithId(it); - if (datacenter.authKey != null) { - if (datacenter.downloadConnection == null) { - datacenter.downloadConnection = new TcpConnection(datacenter.datacenterId); - datacenter.downloadConnection.delegate = this; - datacenter.downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia; - } - datacenter.downloadConnection.connect(); - } - } - for (int it : uploadTransportsToResume) { - Datacenter datacenter = datacenterWithId(it); - if (datacenter.authKey != null) { - if (datacenter.uploadConnection == null) { - datacenter.uploadConnection = new TcpConnection(datacenter.datacenterId); - datacenter.uploadConnection.delegate = this; - datacenter.uploadConnection.transportRequestClass = RPCRequest.RPCRequestClassUploadMedia; - } - datacenter.uploadConnection.connect(); - } - } - - final HashMap> genericMessagesToDatacenters = new HashMap>(); - - final ArrayList unknownDatacenterIds = new ArrayList(); - final ArrayList neededDatacenterIds = new ArrayList(); - final ArrayList unauthorizedDatacenterIds = new ArrayList(); int currentTime = (int)(System.currentTimeMillis() / 1000); for (int i = 0; i < runningRequests.size(); i++) { @@ -1107,48 +979,27 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. continue; } - Integer tokenIt = activeTransportTokens.get(requestDatacenter.datacenterId); - int datacenterTransportToken = tokenIt != null ? tokenIt : 0; - - Integer uploadTokenIt = activeUploadTransportTokens.get(requestDatacenter.datacenterId); - int datacenterUploadTransportToken = uploadTokenIt != null ? uploadTokenIt : 0; - - Integer downloadTokenIt = activeDownloadTransportTokens.get(requestDatacenter.datacenterId); - int datacenterDownloadTransportToken = downloadTokenIt != null ? downloadTokenIt : 0; - - double maxTimeout = 8.0; - - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - if (datacenterTransportToken == 0) { - continue; - } - } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - if (!haveNetwork) { - FileLog.d("tmessages", "Don't have any network connection, skipping download request"); - continue; - } - if (datacenterDownloadTransportToken == 0) { - continue; - } - maxTimeout = 40.0; - } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - if (!haveNetwork) { - FileLog.d("tmessages", "Don't have any network connection, skipping upload request"); - continue; - } - if (datacenterUploadTransportToken == 0) { - continue; - } - maxTimeout = 30.0; - } + float maxTimeout = 8.0f; TcpConnection connection = null; if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - connection = requestDatacenter.connection; + connection = requestDatacenter.getGenericConnection(this); } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - connection = requestDatacenter.downloadConnection; + int num = (request.flags & RPCRequest.RPCRequestClassDownloadMedia2) != 0 ? 1 : 0; + connection = requestDatacenter.getDownloadConnection(num, this); } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0 ) { - connection = requestDatacenter.uploadConnection; + connection = requestDatacenter.getUploadConnection(this); + } + + if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { + if (connection.channelToken == 0) { + continue; + } + } else { + if (!haveNetwork || connection.channelToken == 0) { + continue; + } + maxTimeout = 30.0f; } boolean forceThisRequest = (request.flags & requestClass) != 0 && (_datacenterId == Integer.MIN_VALUE || requestDatacenter.datacenterId == _datacenterId); @@ -1165,19 +1016,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. if (((Math.abs(currentTime - request.runningStartTime) > maxTimeout) && (currentTime > request.runningMinStartTime || Math.abs(currentTime - request.runningMinStartTime) > 60.0)) || forceThisRequest) { if (!forceThisRequest && request.transportChannelToken > 0) { - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && datacenterTransportToken == request.transportChannelToken) { + if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && request.transportChannelToken == connection.channelToken) { FileLog.d("tmessages", "Request token is valid, not retrying " + request.rawRequest); continue; - } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - if (datacenterDownloadTransportToken != 0 && request.transportChannelToken == datacenterDownloadTransportToken) { + } else { + if (connection.channelToken != 0 && request.transportChannelToken == connection.channelToken) { FileLog.d("tmessages", "Request download token is valid, not retrying " + request.rawRequest); continue; } - } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - if (datacenterUploadTransportToken != 0 && request.transportChannelToken == datacenterUploadTransportToken) { - FileLog.d("tmessages", "Request upload token is valid, not retrying " + request.rawRequest); - continue; - } } } @@ -1199,15 +1045,15 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. request.runningStartTime = currentTime; if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - request.transportChannelToken = datacenterTransportToken; - addMessageToDatacenter(genericMessagesToDatacenters, requestDatacenter.datacenterId, networkMessage); + request.transportChannelToken = connection.channelToken; + addMessageToDatacenter(requestDatacenter.datacenterId, networkMessage); } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - request.transportChannelToken = datacenterDownloadTransportToken; + request.transportChannelToken = connection.channelToken; ArrayList arr = new ArrayList(); arr.add(networkMessage); proceedToSendingMessages(arr, connection, false); } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - request.transportChannelToken = datacenterUploadTransportToken; + request.transportChannelToken = connection.channelToken; ArrayList arr = new ArrayList(); arr.add(networkMessage); proceedToSendingMessages(arr, connection, false); @@ -1217,7 +1063,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. boolean updatingState = MessagesController.getInstance().updatingState; - if (activeTransportTokens.get(currentDatacenterId) != null) { + if (genericConnection != null && genericConnection.channelToken != 0) { if (!updatingState) { Datacenter currentDatacenter = datacenterWithId(currentDatacenterId); @@ -1234,7 +1080,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. NetworkMessage networkMessage = new NetworkMessage(); networkMessage.protoMessage = wrapMessage(destroySession, currentDatacenter.connection, false); if (networkMessage.protoMessage != null) { - addMessageToDatacenter(genericMessagesToDatacenters, currentDatacenter.datacenterId, networkMessage); + addMessageToDatacenter(currentDatacenter.datacenterId, networkMessage); } } } @@ -1303,7 +1149,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. continue; } - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && activeTransportTokens.get(requestDatacenter.datacenterId) == null) { + TcpConnection connection = null; + if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { + connection = requestDatacenter.getGenericConnection(this); + } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { + int num = (request.flags & RPCRequest.RPCRequestClassDownloadMedia2) != 0 ? 1 : 0; + connection = requestDatacenter.getDownloadConnection(num, this); + } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { + connection = requestDatacenter.getUploadConnection(this); + } + + if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0 && connection.channelToken == 0) { continue; } @@ -1313,40 +1169,19 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. if (request.requiresCompletion) { if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - if (genericRunningRequestCount >= 60) + if (genericRunningRequestCount >= 60) { continue; - + } genericRunningRequestCount++; - - Integer tokenIt = activeTransportTokens.get(requestDatacenter.datacenterId); - request.transportChannelToken = tokenIt != null ? tokenIt : 0; } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - if (!haveNetwork) { - FileLog.d("tmessages", "Don't have any network connection, skipping upload request"); + if (!haveNetwork || uploadRunningRequestCount >= 5) { continue; } - - if (uploadRunningRequestCount >= 5) { - continue; - } - - Integer uploadTokenIt = activeUploadTransportTokens.get(requestDatacenter.datacenterId); - request.transportChannelToken = uploadTokenIt != null ? uploadTokenIt : 0; - uploadRunningRequestCount++; } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - if (!haveNetwork) { - FileLog.d("tmessages", "Don't have any network connection, skipping download request"); + if (!haveNetwork || downloadRunningRequestCount >= 5) { continue; } - - if (downloadRunningRequestCount >= 5) { - continue; - } - - Integer downloadTokenIt = activeDownloadTransportTokens.get(requestDatacenter.datacenterId); - request.transportChannelToken = downloadTokenIt != null ? downloadTokenIt : 0; - downloadRunningRequestCount++; } } @@ -1360,15 +1195,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. int requestLength = os.length(); if (requestLength != 0) { - TcpConnection connection = null; - if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - connection = requestDatacenter.connection; - } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - connection = requestDatacenter.downloadConnection; - } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - connection = requestDatacenter.uploadConnection; - } - if (canCompress) { try { byte[] data = Utilities.compress(os.toByteArray()); @@ -1398,22 +1224,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. request.runningMessageSeqNo = networkMessage.protoMessage.seqno; request.serializedLength = requestLength; request.runningStartTime = (int)(System.currentTimeMillis() / 1000); + request.transportChannelToken = connection.channelToken; if (request.requiresCompletion) { runningRequests.add(request); } if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) { - addMessageToDatacenter(genericMessagesToDatacenters, requestDatacenter.datacenterId, networkMessage); - } else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) { - ArrayList arr = new ArrayList(); - arr.add(networkMessage); - proceedToSendingMessages(arr, requestDatacenter.downloadConnection, false); - } else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) { - ArrayList arr = new ArrayList(); - arr.add(networkMessage); - proceedToSendingMessages(arr, requestDatacenter.uploadConnection, false); + addMessageToDatacenter(requestDatacenter.datacenterId, networkMessage); } else { - FileLog.e("tmessages", "***** Error: request " + request.rawRequest + " has undefined session"); + ArrayList arr = new ArrayList(); + arr.add(networkMessage); + proceedToSendingMessages(arr, connection, false); } } else { FileLog.e("tmessages", "***** Couldn't serialize " + request.rawRequest); @@ -1567,11 +1388,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } } - void addMessageToDatacenter(HashMap> pMap, int datacenterId, NetworkMessage message) { - ArrayList arr = pMap.get(datacenterId); + void addMessageToDatacenter(int datacenterId, NetworkMessage message) { + ArrayList arr = genericMessagesToDatacenters.get(datacenterId); if (arr == null) { arr = new ArrayList(); - pMap.put(datacenterId, arr); + genericMessagesToDatacenters.put(datacenterId, arr); } arr.add(message); } @@ -2278,16 +2099,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. timeDifference = (int)((time - currentTime) / 1000 - currentPingTime / 2.0); } - if (datacenter.connection != null) { - datacenter.connection.recreateSession(); - } - if (datacenter.downloadConnection != null) { - datacenter.downloadConnection.recreateSession(); - } - if (datacenter.uploadConnection != null) { - datacenter.uploadConnection.recreateSession(); - } - + datacenter.recreateSessions(); saveSession(); lastOutgoingMessageId = 0; @@ -2831,15 +2643,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. return; } - if (datacenter.connection != null) { - datacenter.connection.recreateSession(); - } - if (datacenter.downloadConnection != null) { - datacenter.downloadConnection.recreateSession(); - } - if (datacenter.uploadConnection != null) { - datacenter.uploadConnection.recreateSession(); - } + datacenter.recreateSessions(); clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter); clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, datacenter); @@ -2904,16 +2708,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. if (eactor.datacenter.datacenterId == currentDatacenterId || eactor.datacenter.datacenterId == movingToDatacenterId) { timeDifference = (Integer)params.get("timeDifference"); - - if (eactor.datacenter.connection != null) { - eactor.datacenter.connection.recreateSession(); - } - if (eactor.datacenter.downloadConnection != null) { - eactor.datacenter.downloadConnection.recreateSession(); - } - if (eactor.datacenter.uploadConnection != null) { - eactor.datacenter.uploadConnection.recreateSession(); - } + eactor.datacenter.recreateSessions(); clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, eactor.datacenter); clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, eactor.datacenter); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java b/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java index f13560ba..43fa8428 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Datacenter.java @@ -35,8 +35,8 @@ public class Datacenter { private volatile int currentAddressNum = 0; public TcpConnection connection; - public TcpConnection downloadConnection; - public TcpConnection uploadConnection; + private ArrayList downloadConnections = new ArrayList(); + private TcpConnection uploadConnection; public TcpConnection pushConnection; private ArrayList authServerSaltSet = new ArrayList(); @@ -319,4 +319,81 @@ public class Datacenter { } return false; } + + public void suspendConnections() { + if (connection != null) { + connection.suspendConnection(true); + } + if (uploadConnection != null) { + uploadConnection.suspendConnection(true); + } + for (TcpConnection downloadConnection : downloadConnections) { + downloadConnection.suspendConnection(true); + } + } + + public void getSessions(ArrayList sessions) { + if (connection != null) { + sessions.add(connection.getSissionId()); + } + if (uploadConnection != null) { + sessions.add(uploadConnection.getSissionId()); + } + for (TcpConnection downloadConnection : downloadConnections) { + sessions.add(downloadConnection.getSissionId()); + } + } + + public void recreateSessions() { + if (connection != null) { + connection.recreateSession(); + } + if (uploadConnection != null) { + uploadConnection.recreateSession(); + } + for (TcpConnection downloadConnection : downloadConnections) { + downloadConnection.recreateSession(); + } + } + + public TcpConnection getDownloadConnection(int num, TcpConnection.TcpConnectionDelegate delegate) { + if (num >= 0 && authKey != null) { + TcpConnection downloadConnection = null; + if (num < downloadConnections.size()) { + downloadConnection = downloadConnections.get(num); + } else { + downloadConnection = new TcpConnection(datacenterId); + downloadConnection.delegate = delegate; + downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia; + downloadConnections.add(downloadConnection); + } + downloadConnection.connect(); + return downloadConnection; + } + return null; + } + + public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) { + if (authKey != null) { + if (uploadConnection == null) { + uploadConnection = new TcpConnection(datacenterId); + uploadConnection.delegate = delegate; + uploadConnection.transportRequestClass = RPCRequest.RPCRequestClassUploadMedia; + } + uploadConnection.connect(); + } + return uploadConnection; + } + + public TcpConnection getGenericConnection(TcpConnection.TcpConnectionDelegate delegate) { + if (authKey != null) { + if (connection == null) { + connection = new TcpConnection(datacenterId); + connection.delegate = delegate; + connection.transportRequestClass = RPCRequest.RPCRequestClassGeneric; + } + connection.connect(); + } + return connection; + } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java index 894925ad..9f53d4c0 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java @@ -25,7 +25,7 @@ import java.nio.channels.FileChannel; import java.util.Scanner; public class FileLoadOperation { - private int downloadChunkSize = 1024 * 32; + private int downloadChunkSize = 1024 * 256; public int datacenter_id; public TLRPC.InputFileLocation location; @@ -38,6 +38,13 @@ public class FileLoadOperation { private byte[] key; private byte[] iv; private long requestToken = 0; + private long requestToken2 = 0; + private int requestProgress = 0; + private int requestProgress2 = 0; + private int nextDownloadOffset = 0; + private TLRPC.TL_upload_file delayedRes = null; + private int delayedResOffset = 0; + private int delayedResTokenNum = 0; private File cacheFileTemp; private File cacheFileFinal; @@ -335,7 +342,7 @@ public class FileLoadOperation { cacheFileTemp = new File(Utilities.getCacheDir(), fileNameTemp); if (cacheFileTemp.exists()) { downloadedBytes = (int)cacheFileTemp.length(); - downloadedBytes = downloadedBytes / 1024 * 1024; + nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024; } if (fileNameIv != null) { cacheIvTemp = new File(Utilities.getCacheDir(), fileNameIv); @@ -387,8 +394,9 @@ public class FileLoadOperation { } state = 2; cleanup(); - if (httpUrl == null && requestToken != 0) { + if (httpUrl == null) { ConnectionsManager.getInstance().cancelRpc(requestToken, true); + ConnectionsManager.getInstance().cancelRpc(requestToken2, true); } delegate.didFailedLoadingFile(FileLoadOperation.this); } @@ -422,6 +430,12 @@ public class FileLoadOperation { } catch (Exception e) { FileLog.e("tmessages", e); } + + if (delayedRes != null) { + delayedRes.disableFree = false; + delayedRes.freeResources(); + delayedRes = null; + } } } @@ -593,104 +607,171 @@ public class FileLoadOperation { } } + private void processRequestResult(TLRPC.TL_upload_file res, TLRPC.TL_error error, int dowloadOffset, int tokenNum) { + if (error == null) { + try { + if (downloadedBytes != dowloadOffset) { + if (delayedRes != null) { + FileLog.e("tmessages", "something went wrong!"); + } + delayedRes = res; + delayedRes.disableFree = true; + delayedResOffset = dowloadOffset; + delayedResTokenNum = tokenNum; + return; + } else { + if (tokenNum == 0) { + requestToken = 0; + } else if (tokenNum == 1) { + requestToken2 = 0; + } + } + + if (res.bytes.limit() == 0) { + onFinishLoadingFile(); + return; + } + if (key != null) { + Utilities.aesIgeEncryption2(res.bytes.buffer, key, iv, false, true, res.bytes.limit()); + } + if (fileOutputStream != null) { + FileChannel channel = fileOutputStream.getChannel(); + channel.write(res.bytes.buffer); + } + if (fiv != null) { + fiv.seek(0); + fiv.write(iv); + } + downloadedBytes += res.bytes.limit(); + if (totalBytesCount > 0 && state == 1) { + delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)downloadedBytes / (float)totalBytesCount)); + } + + if(delayedRes != null && res != delayedRes) { + TLRPC.TL_upload_file temp = delayedRes; + processRequestResult(temp, null, delayedResOffset, delayedResTokenNum); + if (delayedRes != null) { + delayedRes.disableFree = false; + delayedRes.freeResources(); + delayedRes = null; + } + } + + if (downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount != downloadedBytes) { + startDownloadRequest(); + } else { + onFinishLoadingFile(); + } + } catch (Exception e) { + cleanup(); + delegate.didFailedLoadingFile(FileLoadOperation.this); + FileLog.e("tmessages", e); + } + } else { + if (error.text.contains("FILE_MIGRATE_")) { + String errorMsg = error.text.replace("FILE_MIGRATE_", ""); + Scanner scanner = new Scanner(errorMsg); + scanner.useDelimiter(""); + Integer val; + try { + val = scanner.nextInt(); + } catch (Exception e) { + val = null; + } + if (val == null) { + cleanup(); + delegate.didFailedLoadingFile(FileLoadOperation.this); + } else { + datacenter_id = val; + nextDownloadOffset = 0; + startDownloadRequest(); + } + } else if (error.text.contains("OFFSET_INVALID")) { + if (downloadedBytes % downloadChunkSize == 0) { + try { + onFinishLoadingFile(); + } catch (Exception e) { + FileLog.e("tmessages", e); + cleanup(); + delegate.didFailedLoadingFile(FileLoadOperation.this); + } + } else { + cleanup(); + delegate.didFailedLoadingFile(FileLoadOperation.this); + } + } else { + if (location != null) { + FileLog.e("tmessages", "" + location + " id = " + location.id + " access_hash = " + location.access_hash + " volume_id = " + location.local_id + " secret = " + location.secret); + } + cleanup(); + delegate.didFailedLoadingFile(FileLoadOperation.this); + } + } + } + + private void processRequestProgress() { + delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float) (downloadedBytes + requestProgress + requestProgress2) / (float) totalBytesCount)); + } + private void startDownloadRequest() { if (state != 1) { return; } - TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile(); - req.location = location; - //if (totalBytesCount == -1) { - // req.offset = 0; - // req.limit = 0; - //} else { - req.offset = downloadedBytes; + if (requestToken == 0) { + requestProgress = 0; + if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) { + return; + } + final TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile(); + req.location = location; + req.offset = nextDownloadOffset; req.limit = downloadChunkSize; - //} - requestToken = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - requestToken = 0; - if (error == null) { - TLRPC.TL_upload_file res = (TLRPC.TL_upload_file)response; - try { - if (res.bytes.limit() == 0) { - onFinishLoadingFile(); - return; + nextDownloadOffset += downloadChunkSize; + final long time = System.currentTimeMillis(); + requestToken = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { + @Override + public void run(TLObject response, TLRPC.TL_error error) { + processRequestResult((TLRPC.TL_upload_file) response, error, req.offset, 0); + } + }, new RPCRequest.RPCProgressDelegate() { + @Override + public void progress(int length, int progress) { + if (state == 1) { + requestProgress = progress; + if (totalBytesCount == -1) { + delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float) (progress) / (float) length)); + } else if (totalBytesCount > 0) { + processRequestProgress(); } - if (key != null) { - Utilities.aesIgeEncryption2(res.bytes.buffer, key, iv, false, true, res.bytes.limit()); - } - if (fileOutputStream != null) { - FileChannel channel = fileOutputStream.getChannel(); - channel.write(res.bytes.buffer); - } - if (fiv != null) { - fiv.seek(0); - fiv.write(iv); - } - downloadedBytes += res.bytes.limit(); - if (totalBytesCount > 0) { - delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)downloadedBytes / (float)totalBytesCount)); - } - if (downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount != downloadedBytes) { - startDownloadRequest(); - } else { - onFinishLoadingFile(); - } - } catch (Exception e) { - cleanup(); - delegate.didFailedLoadingFile(FileLoadOperation.this); - FileLog.e("tmessages", e); - } - } else { - if (error.text.contains("FILE_MIGRATE_")) { - String errorMsg = error.text.replace("FILE_MIGRATE_", ""); - Scanner scanner = new Scanner(errorMsg); - scanner.useDelimiter(""); - Integer val; - try { - val = scanner.nextInt(); - } catch (Exception e) { - val = null; - } - if (val == null) { - cleanup(); - delegate.didFailedLoadingFile(FileLoadOperation.this); - } else { - datacenter_id = val; - startDownloadRequest(); - } - } else if (error.text.contains("OFFSET_INVALID")) { - if (downloadedBytes % downloadChunkSize == 0) { - try { - onFinishLoadingFile(); - } catch (Exception e) { - FileLog.e("tmessages", e); - cleanup(); - delegate.didFailedLoadingFile(FileLoadOperation.this); - } - } else { - cleanup(); - delegate.didFailedLoadingFile(FileLoadOperation.this); - } - } else { - if (location != null) { - FileLog.e("tmessages", "" + location + " id = " + location.id + " access_hash = " + location.access_hash + " volume_id = " + location.local_id + " secret = " + location.secret); - } - cleanup(); - delegate.didFailedLoadingFile(FileLoadOperation.this); } } + }, null, true, RPCRequest.RPCRequestClassDownloadMedia, datacenter_id); + } + if (totalBytesCount > 0 && requestToken2 == 0) { + requestProgress2 = 0; + if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) { + return; } - }, new RPCRequest.RPCProgressDelegate() { - @Override - public void progress(int length, int progress) { - if (totalBytesCount > 0) { - delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)(downloadedBytes + progress) / (float)totalBytesCount)); - } else if (totalBytesCount == -1) { - delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)(progress) / (float)length)); + final long time = System.currentTimeMillis(); + final TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile(); + req.location = location; + req.offset = nextDownloadOffset; + req.limit = downloadChunkSize; + nextDownloadOffset += downloadChunkSize; + requestToken2 = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { + @Override + public void run(TLObject response, TLRPC.TL_error error) { + processRequestResult((TLRPC.TL_upload_file) response, error, req.offset, 1); } - } - }, null, true, RPCRequest.RPCRequestClassDownloadMedia, datacenter_id); + }, new RPCRequest.RPCProgressDelegate() { + @Override + public void progress(int length, int progress) { + if (state == 1) { + requestProgress2 = progress; + processRequestProgress(); + } + } + }, null, true, RPCRequest.RPCRequestClassDownloadMedia | RPCRequest.RPCRequestClassDownloadMedia2, datacenter_id); + } } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java b/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java index d86bdbd5..e28cbbbc 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/HandshakeAction.java @@ -52,9 +52,9 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti void beginHandshake(boolean dropConnection) { if (datacenter.connection == null) { datacenter.connection = new TcpConnection(datacenter.datacenterId); - datacenter.connection.delegate = this; datacenter.connection.transportRequestClass = RPCRequest.RPCRequestClassGeneric; } + datacenter.connection.delegate = this; processedMessageIds = new ArrayList(); authNonce = null; @@ -566,8 +566,14 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti } @Override - public void tcpConnectionClosed(TcpConnection connection) { + public void tcpConnectionClosed(final TcpConnection connection) { wasDisconnect = true; + Utilities.stageQueue.postRunnable(new Runnable() { + @Override + public void run() { + connection.connect(); + } + }, 1000); } @Override @@ -591,9 +597,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti @Override public void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length) { - long keyId = data.readInt64(); - if (keyId == 0) { long messageId = data.readInt64(); if (processedMessageIds.contains(messageId)) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java b/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java index 831b91f9..ab6162ae 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/RPCRequest.java @@ -29,6 +29,7 @@ public class RPCRequest { public static int RPCRequestClassCanCompress = 32; public static int RPCRequestClassPush = 64; public static int RPCRequestClassWithoutLogin = 128; + public static int RPCRequestClassDownloadMedia2 = 256; static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java index 1aceb828..9c40cb6e 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/TLObject.java @@ -9,6 +9,8 @@ package org.telegram.messenger; public class TLObject { + public boolean disableFree = false; + public TLObject () { } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java index f4181295..0cbc8368 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/TLRPC.java @@ -8136,6 +8136,9 @@ public class TLRPC { @Override public void freeResources() { + if (disableFree) { + return; + } if (bytes != null) { BuffersStorage.getInstance().reuseFreeBuffer(bytes); bytes = null; @@ -8287,6 +8290,9 @@ public class TLRPC { @Override public void freeResources() { + if (disableFree) { + return; + } if (result != null) { result.freeResources(); } @@ -9171,6 +9177,9 @@ public class TLRPC { @Override public void freeResources() { + if (disableFree) { + return; + } if (bytes != null) { BuffersStorage.getInstance().reuseFreeBuffer(bytes); bytes = null; @@ -9198,6 +9207,9 @@ public class TLRPC { @Override public void freeResources() { + if (disableFree) { + return; + } if (bytes != null) { BuffersStorage.getInstance().reuseFreeBuffer(bytes); bytes = null; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java index 7d5ba1aa..52a7660e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java @@ -40,7 +40,6 @@ import org.telegram.messenger.ScreenReceiver; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; -import java.util.Calendar; import java.util.concurrent.atomic.AtomicInteger; public class ApplicationLoader extends Application { @@ -151,10 +150,14 @@ public class ApplicationLoader extends Application { applicationContext.startService(new Intent(applicationContext, NotificationsService.class)); if (android.os.Build.VERSION.SDK_INT >= 19) { - Calendar cal = Calendar.getInstance(); +// Calendar cal = Calendar.getInstance(); +// PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0); +// AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE); +// alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent); + PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0); - AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE); - alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent); + AlarmManager alarm = (AlarmManager)applicationContext.getSystemService(Context.ALARM_SERVICE); + alarm.cancel(pintent); } } else { stopPushService(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index d5fddb11..871537b8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -1624,7 +1624,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat currentPathObject = null; currentThumb = null; centerImage.setImageBitmap((Bitmap)null); - leftImage.setImageBitmap((Bitmap) null); + leftImage.setImageBitmap((Bitmap)null); rightImage.setImageBitmap((Bitmap)null); if (android.os.Build.VERSION.SDK_INT >= 11 && object != null) { object.imageReceiver.setVisible(true, true);