Commit 458517e4 authored by DrKLO's avatar DrKLO

Improved files download speed

parent 70882c5d
...@@ -81,7 +81,7 @@ android { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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);
}
}
} }
} }
} }
...@@ -35,8 +35,8 @@ public class 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 { ...@@ -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;
}
} }
...@@ -52,9 +52,9 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti ...@@ -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 ...@@ -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 ...@@ -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 { ...@@ -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 @@ ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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; ...@@ -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 { ...@@ -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 ...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment