mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
Improved files download speed
This commit is contained in:
parent
70882c5d28
commit
458517e4a4
11 changed files with 398 additions and 404 deletions
|
@ -81,7 +81,7 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 8
|
||||||
targetSdkVersion 19
|
targetSdkVersion 19
|
||||||
versionCode 262
|
versionCode 264
|
||||||
versionName "1.5.7"
|
versionName "1.5.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ public class BuffersStorage {
|
||||||
private final ArrayList<ByteBufferDesc> freeBuffers4096;
|
private final ArrayList<ByteBufferDesc> freeBuffers4096;
|
||||||
private final ArrayList<ByteBufferDesc> freeBuffers16384;
|
private final ArrayList<ByteBufferDesc> freeBuffers16384;
|
||||||
private final ArrayList<ByteBufferDesc> freeBuffers32768;
|
private final ArrayList<ByteBufferDesc> freeBuffers32768;
|
||||||
|
private final ArrayList<ByteBufferDesc> freeBuffersBig;
|
||||||
|
|
||||||
private static volatile BuffersStorage Instance = null;
|
private static volatile BuffersStorage Instance = null;
|
||||||
public static BuffersStorage getInstance() {
|
public static BuffersStorage getInstance() {
|
||||||
|
@ -38,6 +39,7 @@ public class BuffersStorage {
|
||||||
freeBuffers4096 = new ArrayList<ByteBufferDesc>();
|
freeBuffers4096 = new ArrayList<ByteBufferDesc>();
|
||||||
freeBuffers16384 = new ArrayList<ByteBufferDesc>();
|
freeBuffers16384 = new ArrayList<ByteBufferDesc>();
|
||||||
freeBuffers32768 = new ArrayList<ByteBufferDesc>();
|
freeBuffers32768 = new ArrayList<ByteBufferDesc>();
|
||||||
|
freeBuffersBig = new ArrayList<ByteBufferDesc>();
|
||||||
|
|
||||||
for (int a = 0; a < 5; a++) {
|
for (int a = 0; a < 5; a++) {
|
||||||
freeBuffers128.add(new ByteBufferDesc(128));
|
freeBuffers128.add(new ByteBufferDesc(128));
|
||||||
|
@ -113,6 +115,17 @@ public class BuffersStorage {
|
||||||
buffer = new ByteBufferDesc(40000);
|
buffer = new ByteBufferDesc(40000);
|
||||||
FileLog.e("tmessages", "create new 40000 buffer");
|
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 {
|
} else {
|
||||||
buffer = new ByteBufferDesc(size);
|
buffer = new ByteBufferDesc(size);
|
||||||
}
|
}
|
||||||
|
@ -154,6 +167,12 @@ public class BuffersStorage {
|
||||||
freeBuffers32768.add(buffer);
|
freeBuffers32768.add(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (buffer.buffer.capacity() == 280000) {
|
||||||
|
synchronized (freeBuffersBig) {
|
||||||
|
if (freeBuffersBig.size() < 4) {
|
||||||
|
freeBuffersBig.add(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
private ArrayList<RPCRequest> runningRequests = new ArrayList<RPCRequest>();
|
private ArrayList<RPCRequest> runningRequests = new ArrayList<RPCRequest>();
|
||||||
private ArrayList<Action> actionQueue = new ArrayList<Action>();
|
private ArrayList<Action> actionQueue = new ArrayList<Action>();
|
||||||
|
|
||||||
|
private ArrayList<Integer> unknownDatacenterIds = new ArrayList<Integer>();
|
||||||
|
private ArrayList<Integer> neededDatacenterIds = new ArrayList<Integer>();
|
||||||
|
private ArrayList<Integer> unauthorizedDatacenterIds = new ArrayList<Integer>();
|
||||||
|
final HashMap<Integer, ArrayList<NetworkMessage>> genericMessagesToDatacenters = new HashMap<Integer, ArrayList<NetworkMessage>>();
|
||||||
|
|
||||||
private TLRPC.TL_auth_exportedAuthorization movingAuthorization;
|
private TLRPC.TL_auth_exportedAuthorization movingAuthorization;
|
||||||
public static final int DEFAULT_DATACENTER_ID = Integer.MAX_VALUE;
|
public static final int DEFAULT_DATACENTER_ID = Integer.MAX_VALUE;
|
||||||
public static final int DC_UPDATE_TIME = 60 * 60;
|
public static final int DC_UPDATE_TIME = 60 * 60;
|
||||||
|
@ -126,15 +131,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout);
|
FileLog.e("tmessages", "pausing network and timers by sleep time = " + nextSleepTimeout);
|
||||||
for (Datacenter datacenter : datacenters.values()) {
|
for (Datacenter datacenter : datacenters.values()) {
|
||||||
if (datacenter.connection != null) {
|
datacenter.suspendConnections();
|
||||||
datacenter.connection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
if (datacenter.uploadConnection != null) {
|
|
||||||
datacenter.uploadConnection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
if (datacenter.downloadConnection != null) {
|
|
||||||
datacenter.downloadConnection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -472,15 +469,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
editor.putLong("pushSessionId", pushSessionId);
|
editor.putLong("pushSessionId", pushSessionId);
|
||||||
|
|
||||||
ArrayList<Long> sessions = new ArrayList<Long>();
|
ArrayList<Long> sessions = new ArrayList<Long>();
|
||||||
if (currentDatacenter.connection != null) {
|
currentDatacenter.getSessions(sessions);
|
||||||
sessions.add(currentDatacenter.connection.getSissionId());
|
|
||||||
}
|
|
||||||
if (currentDatacenter.downloadConnection != null) {
|
|
||||||
sessions.add(currentDatacenter.downloadConnection.getSissionId());
|
|
||||||
}
|
|
||||||
if (currentDatacenter.uploadConnection != null) {
|
|
||||||
sessions.add(currentDatacenter.uploadConnection.getSissionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sessions.isEmpty()) {
|
if (!sessions.isEmpty()) {
|
||||||
SerializedData data = new SerializedData(sessions.size() * 8 + 4);
|
SerializedData data = new SerializedData(sessions.size() * 8 + 4);
|
||||||
|
@ -539,15 +528,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Datacenter datacenter = datacenterWithId(currentDatacenterId);
|
Datacenter datacenter = datacenterWithId(currentDatacenterId);
|
||||||
if (datacenter.connection != null) {
|
datacenter.recreateSessions();
|
||||||
datacenter.connection.recreateSession();
|
|
||||||
}
|
|
||||||
if (datacenter.downloadConnection != null) {
|
|
||||||
datacenter.downloadConnection.recreateSession();
|
|
||||||
}
|
|
||||||
if (datacenter.uploadConnection != null) {
|
|
||||||
datacenter.uploadConnection.recreateSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter);
|
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter);
|
||||||
clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, datacenter);
|
clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, datacenter);
|
||||||
|
@ -632,15 +613,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
addresses.add(ip_address);
|
addresses.add(ip_address);
|
||||||
ports.put(ip_address, port);
|
ports.put(ip_address, port);
|
||||||
exist.replaceAddressesAndPorts(addresses, ports);
|
exist.replaceAddressesAndPorts(addresses, ports);
|
||||||
if (exist.connection != null) {
|
exist.suspendConnections();
|
||||||
exist.connection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
if (exist.uploadConnection != null) {
|
|
||||||
exist.uploadConnection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
if (exist.downloadConnection != null) {
|
|
||||||
exist.downloadConnection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
updateDcSettings(dc);
|
updateDcSettings(dc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,15 +654,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
for (HashMap.Entry<Integer, Datacenter> entry : datacenters.entrySet()) {
|
for (HashMap.Entry<Integer, Datacenter> entry : datacenters.entrySet()) {
|
||||||
Datacenter datacenter = entry.getValue();
|
Datacenter datacenter = entry.getValue();
|
||||||
datacenter.overridePort = 8888;
|
datacenter.overridePort = 8888;
|
||||||
if (datacenter.connection != null) {
|
datacenter.suspendConnections();
|
||||||
datacenter.connection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
if (datacenter.uploadConnection != null) {
|
|
||||||
datacenter.uploadConnection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
if (datacenter.downloadConnection != null) {
|
|
||||||
datacenter.downloadConnection.suspendConnection(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (HashMap.Entry<Integer, Datacenter> entry : datacenters.entrySet()) {
|
for (HashMap.Entry<Integer, Datacenter> entry : datacenters.entrySet()) {
|
||||||
|
@ -852,6 +817,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelRpc(final long token, final boolean notifyServer) {
|
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) {
|
if (token == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -871,30 +840,32 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < runningRequests.size(); i++) {
|
if (!ifNotSent) {
|
||||||
RPCRequest request = runningRequests.get(i);
|
for (int i = 0; i < runningRequests.size(); i++) {
|
||||||
if (request.token == token) {
|
RPCRequest request = runningRequests.get(i);
|
||||||
found = true;
|
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 ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||||
if (notifyServer) {
|
if (notifyServer) {
|
||||||
TLRPC.TL_rpc_drop_answer dropAnswer = new TLRPC.TL_rpc_drop_answer();
|
TLRPC.TL_rpc_drop_answer dropAnswer = new TLRPC.TL_rpc_drop_answer();
|
||||||
dropAnswer.req_msg_id = request.runningMessageId;
|
dropAnswer.req_msg_id = request.runningMessageId;
|
||||||
performRpc(dropAnswer, null, null, false, request.flags);
|
performRpc(dropAnswer, null, null, false, request.flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
request.cancelled = true;
|
request.cancelled = true;
|
||||||
request.rawRequest.freeResources();
|
request.rawRequest.freeResources();
|
||||||
request.rpcRequest.freeResources();
|
request.rpcRequest.freeResources();
|
||||||
runningRequests.remove(i);
|
runningRequests.remove(i);
|
||||||
break;
|
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) {
|
private void processRequestQueue(int requestClass, int _datacenterId) {
|
||||||
final HashMap<Integer, Integer> activeTransportTokens = new HashMap<Integer, Integer>();
|
boolean haveNetwork = true;//isNetworkOnline();
|
||||||
final ArrayList<Integer> transportsToResume = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
final HashMap<Integer, Integer> activeDownloadTransportTokens = new HashMap<Integer, Integer>();
|
genericMessagesToDatacenters.clear();
|
||||||
final ArrayList<Integer> downloadTransportsToResume = new ArrayList<Integer>();
|
unknownDatacenterIds.clear();
|
||||||
|
neededDatacenterIds.clear();
|
||||||
|
unauthorizedDatacenterIds.clear();
|
||||||
|
|
||||||
final HashMap<Integer, Integer> activeUploadTransportTokens = new HashMap<Integer, Integer>();
|
TcpConnection genericConnection = null;
|
||||||
final ArrayList<Integer> uploadTransportsToResume = new ArrayList<Integer>();
|
Datacenter defaultDatacenter = datacenterWithId(currentDatacenterId);
|
||||||
|
if (defaultDatacenter != null) {
|
||||||
for (Datacenter datacenter : datacenters.values()) {
|
genericConnection = defaultDatacenter.getGenericConnection(this);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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<Integer, ArrayList<NetworkMessage>> genericMessagesToDatacenters = new HashMap<Integer, ArrayList<NetworkMessage>>();
|
|
||||||
|
|
||||||
final ArrayList<Integer> unknownDatacenterIds = new ArrayList<Integer>();
|
|
||||||
final ArrayList<Integer> neededDatacenterIds = new ArrayList<Integer>();
|
|
||||||
final ArrayList<Integer> unauthorizedDatacenterIds = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
int currentTime = (int)(System.currentTimeMillis() / 1000);
|
int currentTime = (int)(System.currentTimeMillis() / 1000);
|
||||||
for (int i = 0; i < runningRequests.size(); i++) {
|
for (int i = 0; i < runningRequests.size(); i++) {
|
||||||
|
@ -1107,48 +979,27 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer tokenIt = activeTransportTokens.get(requestDatacenter.datacenterId);
|
float maxTimeout = 8.0f;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
TcpConnection connection = null;
|
TcpConnection connection = null;
|
||||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||||
connection = requestDatacenter.connection;
|
connection = requestDatacenter.getGenericConnection(this);
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
} 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 ) {
|
} 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);
|
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 (((Math.abs(currentTime - request.runningStartTime) > maxTimeout) && (currentTime > request.runningMinStartTime || Math.abs(currentTime - request.runningMinStartTime) > 60.0)) || forceThisRequest) {
|
||||||
if (!forceThisRequest && request.transportChannelToken > 0) {
|
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);
|
FileLog.d("tmessages", "Request token is valid, not retrying " + request.rawRequest);
|
||||||
continue;
|
continue;
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
} else {
|
||||||
if (datacenterDownloadTransportToken != 0 && request.transportChannelToken == datacenterDownloadTransportToken) {
|
if (connection.channelToken != 0 && request.transportChannelToken == connection.channelToken) {
|
||||||
FileLog.d("tmessages", "Request download token is valid, not retrying " + request.rawRequest);
|
FileLog.d("tmessages", "Request download token is valid, not retrying " + request.rawRequest);
|
||||||
continue;
|
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;
|
request.runningStartTime = currentTime;
|
||||||
|
|
||||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||||
request.transportChannelToken = datacenterTransportToken;
|
request.transportChannelToken = connection.channelToken;
|
||||||
addMessageToDatacenter(genericMessagesToDatacenters, requestDatacenter.datacenterId, networkMessage);
|
addMessageToDatacenter(requestDatacenter.datacenterId, networkMessage);
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
||||||
request.transportChannelToken = datacenterDownloadTransportToken;
|
request.transportChannelToken = connection.channelToken;
|
||||||
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
||||||
arr.add(networkMessage);
|
arr.add(networkMessage);
|
||||||
proceedToSendingMessages(arr, connection, false);
|
proceedToSendingMessages(arr, connection, false);
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
||||||
request.transportChannelToken = datacenterUploadTransportToken;
|
request.transportChannelToken = connection.channelToken;
|
||||||
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
||||||
arr.add(networkMessage);
|
arr.add(networkMessage);
|
||||||
proceedToSendingMessages(arr, connection, false);
|
proceedToSendingMessages(arr, connection, false);
|
||||||
|
@ -1217,7 +1063,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
|
|
||||||
boolean updatingState = MessagesController.getInstance().updatingState;
|
boolean updatingState = MessagesController.getInstance().updatingState;
|
||||||
|
|
||||||
if (activeTransportTokens.get(currentDatacenterId) != null) {
|
if (genericConnection != null && genericConnection.channelToken != 0) {
|
||||||
if (!updatingState) {
|
if (!updatingState) {
|
||||||
Datacenter currentDatacenter = datacenterWithId(currentDatacenterId);
|
Datacenter currentDatacenter = datacenterWithId(currentDatacenterId);
|
||||||
|
|
||||||
|
@ -1234,7 +1080,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
NetworkMessage networkMessage = new NetworkMessage();
|
NetworkMessage networkMessage = new NetworkMessage();
|
||||||
networkMessage.protoMessage = wrapMessage(destroySession, currentDatacenter.connection, false);
|
networkMessage.protoMessage = wrapMessage(destroySession, currentDatacenter.connection, false);
|
||||||
if (networkMessage.protoMessage != null) {
|
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;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1313,40 +1169,19 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
|
|
||||||
if (request.requiresCompletion) {
|
if (request.requiresCompletion) {
|
||||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||||
if (genericRunningRequestCount >= 60)
|
if (genericRunningRequestCount >= 60) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
genericRunningRequestCount++;
|
genericRunningRequestCount++;
|
||||||
|
|
||||||
Integer tokenIt = activeTransportTokens.get(requestDatacenter.datacenterId);
|
|
||||||
request.transportChannelToken = tokenIt != null ? tokenIt : 0;
|
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
||||||
if (!haveNetwork) {
|
if (!haveNetwork || uploadRunningRequestCount >= 5) {
|
||||||
FileLog.d("tmessages", "Don't have any network connection, skipping upload request");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadRunningRequestCount >= 5) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer uploadTokenIt = activeUploadTransportTokens.get(requestDatacenter.datacenterId);
|
|
||||||
request.transportChannelToken = uploadTokenIt != null ? uploadTokenIt : 0;
|
|
||||||
|
|
||||||
uploadRunningRequestCount++;
|
uploadRunningRequestCount++;
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
||||||
if (!haveNetwork) {
|
if (!haveNetwork || downloadRunningRequestCount >= 5) {
|
||||||
FileLog.d("tmessages", "Don't have any network connection, skipping download request");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadRunningRequestCount >= 5) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer downloadTokenIt = activeDownloadTransportTokens.get(requestDatacenter.datacenterId);
|
|
||||||
request.transportChannelToken = downloadTokenIt != null ? downloadTokenIt : 0;
|
|
||||||
|
|
||||||
downloadRunningRequestCount++;
|
downloadRunningRequestCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1360,15 +1195,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
int requestLength = os.length();
|
int requestLength = os.length();
|
||||||
|
|
||||||
if (requestLength != 0) {
|
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) {
|
if (canCompress) {
|
||||||
try {
|
try {
|
||||||
byte[] data = Utilities.compress(os.toByteArray());
|
byte[] data = Utilities.compress(os.toByteArray());
|
||||||
|
@ -1398,22 +1224,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
request.runningMessageSeqNo = networkMessage.protoMessage.seqno;
|
request.runningMessageSeqNo = networkMessage.protoMessage.seqno;
|
||||||
request.serializedLength = requestLength;
|
request.serializedLength = requestLength;
|
||||||
request.runningStartTime = (int)(System.currentTimeMillis() / 1000);
|
request.runningStartTime = (int)(System.currentTimeMillis() / 1000);
|
||||||
|
request.transportChannelToken = connection.channelToken;
|
||||||
if (request.requiresCompletion) {
|
if (request.requiresCompletion) {
|
||||||
runningRequests.add(request);
|
runningRequests.add(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||||
addMessageToDatacenter(genericMessagesToDatacenters, requestDatacenter.datacenterId, networkMessage);
|
addMessageToDatacenter(requestDatacenter.datacenterId, networkMessage);
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
|
|
||||||
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
|
||||||
arr.add(networkMessage);
|
|
||||||
proceedToSendingMessages(arr, requestDatacenter.downloadConnection, false);
|
|
||||||
} else if ((request.flags & RPCRequest.RPCRequestClassUploadMedia) != 0) {
|
|
||||||
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
|
||||||
arr.add(networkMessage);
|
|
||||||
proceedToSendingMessages(arr, requestDatacenter.uploadConnection, false);
|
|
||||||
} else {
|
} else {
|
||||||
FileLog.e("tmessages", "***** Error: request " + request.rawRequest + " has undefined session");
|
ArrayList<NetworkMessage> arr = new ArrayList<NetworkMessage>();
|
||||||
|
arr.add(networkMessage);
|
||||||
|
proceedToSendingMessages(arr, connection, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FileLog.e("tmessages", "***** Couldn't serialize " + request.rawRequest);
|
FileLog.e("tmessages", "***** Couldn't serialize " + request.rawRequest);
|
||||||
|
@ -1567,11 +1388,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addMessageToDatacenter(HashMap<Integer, ArrayList<NetworkMessage>> pMap, int datacenterId, NetworkMessage message) {
|
void addMessageToDatacenter(int datacenterId, NetworkMessage message) {
|
||||||
ArrayList<NetworkMessage> arr = pMap.get(datacenterId);
|
ArrayList<NetworkMessage> arr = genericMessagesToDatacenters.get(datacenterId);
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
arr = new ArrayList<NetworkMessage>();
|
arr = new ArrayList<NetworkMessage>();
|
||||||
pMap.put(datacenterId, arr);
|
genericMessagesToDatacenters.put(datacenterId, arr);
|
||||||
}
|
}
|
||||||
arr.add(message);
|
arr.add(message);
|
||||||
}
|
}
|
||||||
|
@ -2278,16 +2099,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
timeDifference = (int)((time - currentTime) / 1000 - currentPingTime / 2.0);
|
timeDifference = (int)((time - currentTime) / 1000 - currentPingTime / 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datacenter.connection != null) {
|
datacenter.recreateSessions();
|
||||||
datacenter.connection.recreateSession();
|
|
||||||
}
|
|
||||||
if (datacenter.downloadConnection != null) {
|
|
||||||
datacenter.downloadConnection.recreateSession();
|
|
||||||
}
|
|
||||||
if (datacenter.uploadConnection != null) {
|
|
||||||
datacenter.uploadConnection.recreateSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
saveSession();
|
saveSession();
|
||||||
|
|
||||||
lastOutgoingMessageId = 0;
|
lastOutgoingMessageId = 0;
|
||||||
|
@ -2831,15 +2643,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datacenter.connection != null) {
|
datacenter.recreateSessions();
|
||||||
datacenter.connection.recreateSession();
|
|
||||||
}
|
|
||||||
if (datacenter.downloadConnection != null) {
|
|
||||||
datacenter.downloadConnection.recreateSession();
|
|
||||||
}
|
|
||||||
if (datacenter.uploadConnection != null) {
|
|
||||||
datacenter.uploadConnection.recreateSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter);
|
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, datacenter);
|
||||||
clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, 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) {
|
if (eactor.datacenter.datacenterId == currentDatacenterId || eactor.datacenter.datacenterId == movingToDatacenterId) {
|
||||||
timeDifference = (Integer)params.get("timeDifference");
|
timeDifference = (Integer)params.get("timeDifference");
|
||||||
|
eactor.datacenter.recreateSessions();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, eactor.datacenter);
|
clearRequestsForRequestClass(RPCRequest.RPCRequestClassGeneric, eactor.datacenter);
|
||||||
clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, eactor.datacenter);
|
clearRequestsForRequestClass(RPCRequest.RPCRequestClassDownloadMedia, eactor.datacenter);
|
||||||
|
|
|
@ -35,8 +35,8 @@ public class Datacenter {
|
||||||
private volatile int currentAddressNum = 0;
|
private volatile int currentAddressNum = 0;
|
||||||
|
|
||||||
public TcpConnection connection;
|
public TcpConnection connection;
|
||||||
public TcpConnection downloadConnection;
|
private ArrayList<TcpConnection> downloadConnections = new ArrayList<TcpConnection>();
|
||||||
public TcpConnection uploadConnection;
|
private TcpConnection uploadConnection;
|
||||||
public TcpConnection pushConnection;
|
public TcpConnection pushConnection;
|
||||||
|
|
||||||
private ArrayList<ServerSalt> authServerSaltSet = new ArrayList<ServerSalt>();
|
private ArrayList<ServerSalt> authServerSaltSet = new ArrayList<ServerSalt>();
|
||||||
|
@ -319,4 +319,81 @@ public class Datacenter {
|
||||||
}
|
}
|
||||||
return false;
|
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<Long> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.nio.channels.FileChannel;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class FileLoadOperation {
|
public class FileLoadOperation {
|
||||||
private int downloadChunkSize = 1024 * 32;
|
private int downloadChunkSize = 1024 * 256;
|
||||||
|
|
||||||
public int datacenter_id;
|
public int datacenter_id;
|
||||||
public TLRPC.InputFileLocation location;
|
public TLRPC.InputFileLocation location;
|
||||||
|
@ -38,6 +38,13 @@ public class FileLoadOperation {
|
||||||
private byte[] key;
|
private byte[] key;
|
||||||
private byte[] iv;
|
private byte[] iv;
|
||||||
private long requestToken = 0;
|
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 cacheFileTemp;
|
||||||
private File cacheFileFinal;
|
private File cacheFileFinal;
|
||||||
|
@ -335,7 +342,7 @@ public class FileLoadOperation {
|
||||||
cacheFileTemp = new File(Utilities.getCacheDir(), fileNameTemp);
|
cacheFileTemp = new File(Utilities.getCacheDir(), fileNameTemp);
|
||||||
if (cacheFileTemp.exists()) {
|
if (cacheFileTemp.exists()) {
|
||||||
downloadedBytes = (int)cacheFileTemp.length();
|
downloadedBytes = (int)cacheFileTemp.length();
|
||||||
downloadedBytes = downloadedBytes / 1024 * 1024;
|
nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024;
|
||||||
}
|
}
|
||||||
if (fileNameIv != null) {
|
if (fileNameIv != null) {
|
||||||
cacheIvTemp = new File(Utilities.getCacheDir(), fileNameIv);
|
cacheIvTemp = new File(Utilities.getCacheDir(), fileNameIv);
|
||||||
|
@ -387,8 +394,9 @@ public class FileLoadOperation {
|
||||||
}
|
}
|
||||||
state = 2;
|
state = 2;
|
||||||
cleanup();
|
cleanup();
|
||||||
if (httpUrl == null && requestToken != 0) {
|
if (httpUrl == null) {
|
||||||
ConnectionsManager.getInstance().cancelRpc(requestToken, true);
|
ConnectionsManager.getInstance().cancelRpc(requestToken, true);
|
||||||
|
ConnectionsManager.getInstance().cancelRpc(requestToken2, true);
|
||||||
}
|
}
|
||||||
delegate.didFailedLoadingFile(FileLoadOperation.this);
|
delegate.didFailedLoadingFile(FileLoadOperation.this);
|
||||||
}
|
}
|
||||||
|
@ -422,6 +430,12 @@ public class FileLoadOperation {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", 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() {
|
private void startDownloadRequest() {
|
||||||
if (state != 1) {
|
if (state != 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
|
if (requestToken == 0) {
|
||||||
req.location = location;
|
requestProgress = 0;
|
||||||
//if (totalBytesCount == -1) {
|
if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) {
|
||||||
// req.offset = 0;
|
return;
|
||||||
// req.limit = 0;
|
}
|
||||||
//} else {
|
final TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
|
||||||
req.offset = downloadedBytes;
|
req.location = location;
|
||||||
|
req.offset = nextDownloadOffset;
|
||||||
req.limit = downloadChunkSize;
|
req.limit = downloadChunkSize;
|
||||||
//}
|
nextDownloadOffset += downloadChunkSize;
|
||||||
requestToken = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
final long time = System.currentTimeMillis();
|
||||||
@Override
|
requestToken = ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
|
||||||
public void run(TLObject response, TLRPC.TL_error error) {
|
@Override
|
||||||
requestToken = 0;
|
public void run(TLObject response, TLRPC.TL_error error) {
|
||||||
if (error == null) {
|
processRequestResult((TLRPC.TL_upload_file) response, error, req.offset, 0);
|
||||||
TLRPC.TL_upload_file res = (TLRPC.TL_upload_file)response;
|
}
|
||||||
try {
|
}, new RPCRequest.RPCProgressDelegate() {
|
||||||
if (res.bytes.limit() == 0) {
|
@Override
|
||||||
onFinishLoadingFile();
|
public void progress(int length, int progress) {
|
||||||
return;
|
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() {
|
final long time = System.currentTimeMillis();
|
||||||
@Override
|
final TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
|
||||||
public void progress(int length, int progress) {
|
req.location = location;
|
||||||
if (totalBytesCount > 0) {
|
req.offset = nextDownloadOffset;
|
||||||
delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)(downloadedBytes + progress) / (float)totalBytesCount));
|
req.limit = downloadChunkSize;
|
||||||
} else if (totalBytesCount == -1) {
|
nextDownloadOffset += downloadChunkSize;
|
||||||
delegate.didChangedLoadProgress(FileLoadOperation.this, Math.min(1.0f, (float)(progress) / (float)length));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}, new RPCRequest.RPCProgressDelegate() {
|
||||||
}, null, true, RPCRequest.RPCRequestClassDownloadMedia, datacenter_id);
|
@Override
|
||||||
|
public void progress(int length, int progress) {
|
||||||
|
if (state == 1) {
|
||||||
|
requestProgress2 = progress;
|
||||||
|
processRequestProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, null, true, RPCRequest.RPCRequestClassDownloadMedia | RPCRequest.RPCRequestClassDownloadMedia2, datacenter_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
void beginHandshake(boolean dropConnection) {
|
void beginHandshake(boolean dropConnection) {
|
||||||
if (datacenter.connection == null) {
|
if (datacenter.connection == null) {
|
||||||
datacenter.connection = new TcpConnection(datacenter.datacenterId);
|
datacenter.connection = new TcpConnection(datacenter.datacenterId);
|
||||||
datacenter.connection.delegate = this;
|
|
||||||
datacenter.connection.transportRequestClass = RPCRequest.RPCRequestClassGeneric;
|
datacenter.connection.transportRequestClass = RPCRequest.RPCRequestClassGeneric;
|
||||||
}
|
}
|
||||||
|
datacenter.connection.delegate = this;
|
||||||
|
|
||||||
processedMessageIds = new ArrayList<Long>();
|
processedMessageIds = new ArrayList<Long>();
|
||||||
authNonce = null;
|
authNonce = null;
|
||||||
|
@ -566,8 +566,14 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tcpConnectionClosed(TcpConnection connection) {
|
public void tcpConnectionClosed(final TcpConnection connection) {
|
||||||
wasDisconnect = true;
|
wasDisconnect = true;
|
||||||
|
Utilities.stageQueue.postRunnable(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
connection.connect();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -591,9 +597,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length) {
|
public void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length) {
|
||||||
|
|
||||||
long keyId = data.readInt64();
|
long keyId = data.readInt64();
|
||||||
|
|
||||||
if (keyId == 0) {
|
if (keyId == 0) {
|
||||||
long messageId = data.readInt64();
|
long messageId = data.readInt64();
|
||||||
if (processedMessageIds.contains(messageId)) {
|
if (processedMessageIds.contains(messageId)) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class RPCRequest {
|
||||||
public static int RPCRequestClassCanCompress = 32;
|
public static int RPCRequestClassCanCompress = 32;
|
||||||
public static int RPCRequestClassPush = 64;
|
public static int RPCRequestClassPush = 64;
|
||||||
public static int RPCRequestClassWithoutLogin = 128;
|
public static int RPCRequestClassWithoutLogin = 128;
|
||||||
|
public static int RPCRequestClassDownloadMedia2 = 256;
|
||||||
|
|
||||||
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
|
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
package org.telegram.messenger;
|
package org.telegram.messenger;
|
||||||
|
|
||||||
public class TLObject {
|
public class TLObject {
|
||||||
|
public boolean disableFree = false;
|
||||||
|
|
||||||
public TLObject () {
|
public TLObject () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8136,6 +8136,9 @@ public class TLRPC {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void freeResources() {
|
public void freeResources() {
|
||||||
|
if (disableFree) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
|
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
|
||||||
bytes = null;
|
bytes = null;
|
||||||
|
@ -8287,6 +8290,9 @@ public class TLRPC {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void freeResources() {
|
public void freeResources() {
|
||||||
|
if (disableFree) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
result.freeResources();
|
result.freeResources();
|
||||||
}
|
}
|
||||||
|
@ -9171,6 +9177,9 @@ public class TLRPC {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void freeResources() {
|
public void freeResources() {
|
||||||
|
if (disableFree) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
|
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
|
||||||
bytes = null;
|
bytes = null;
|
||||||
|
@ -9198,6 +9207,9 @@ public class TLRPC {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void freeResources() {
|
public void freeResources() {
|
||||||
|
if (disableFree) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
|
BuffersStorage.getInstance().reuseFreeBuffer(bytes);
|
||||||
bytes = null;
|
bytes = null;
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.telegram.messenger.ScreenReceiver;
|
||||||
import org.telegram.messenger.UserConfig;
|
import org.telegram.messenger.UserConfig;
|
||||||
import org.telegram.messenger.Utilities;
|
import org.telegram.messenger.Utilities;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class ApplicationLoader extends Application {
|
public class ApplicationLoader extends Application {
|
||||||
|
@ -151,10 +150,14 @@ public class ApplicationLoader extends Application {
|
||||||
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
|
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 19) {
|
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);
|
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0);
|
||||||
AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
|
AlarmManager alarm = (AlarmManager)applicationContext.getSystemService(Context.ALARM_SERVICE);
|
||||||
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent);
|
alarm.cancel(pintent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stopPushService();
|
stopPushService();
|
||||||
|
|
|
@ -1624,7 +1624,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
currentPathObject = null;
|
currentPathObject = null;
|
||||||
currentThumb = null;
|
currentThumb = null;
|
||||||
centerImage.setImageBitmap((Bitmap)null);
|
centerImage.setImageBitmap((Bitmap)null);
|
||||||
leftImage.setImageBitmap((Bitmap) null);
|
leftImage.setImageBitmap((Bitmap)null);
|
||||||
rightImage.setImageBitmap((Bitmap)null);
|
rightImage.setImageBitmap((Bitmap)null);
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 11 && object != null) {
|
if (android.os.Build.VERSION.SDK_INT >= 11 && object != null) {
|
||||||
object.imageReceiver.setVisible(true, true);
|
object.imageReceiver.setVisible(true, true);
|
||||||
|
|
Loading…
Reference in a new issue