Commit 51add404 authored by DrKLO's avatar DrKLO

update to 1.3.6

parent a65f5f9f
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.telegram.messenger"
android:versionCode="126"
android:versionName="1.3.5">
android:versionCode="129"
android:versionName="1.3.6">
<supports-screens android:anyDensity="true"
android:smallScreens="true"
......
......@@ -10,8 +10,10 @@ package org.telegram.messenger;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.util.Base64;
import org.telegram.TL.TLClassStore;
......@@ -23,6 +25,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
......@@ -30,6 +33,11 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.TcpConnectionDelegate {
public static boolean DEBUG_VERSION = false;
public static int APP_ID = 2458;
public static String APP_HASH = "5bce48dc7d331e62c955669eb7233217";
public static String HOCKEY_APP_HASH = "your-hockeyapp-api-key-here";
private HashMap<Integer, Datacenter> datacenters = new HashMap<Integer, Datacenter>();
private HashMap<Long, ArrayList<Long>> processedMessageIdsSet = new HashMap<Long, ArrayList<Long>>();
private HashMap<Long, Integer> nextSeqNoInSession = new HashMap<Long, Integer>();
......@@ -62,6 +70,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private boolean updatingDcSettings = false;
private int updatingDcStartTime = 0;
private int lastDcUpdateTime = 0;
private int currentAppVersion = 0;
public static ConnectionsManager Instance = new ConnectionsManager();
......@@ -73,6 +82,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private int nextSleepTimeout = 60000;
public ConnectionsManager() {
currentAppVersion = ApplicationLoader.getAppVersion();
lastOutgoingMessageId = 0;
movingToDatacenterId = DEFAULT_DATACENTER_ID;
loadSession();
......@@ -622,9 +632,36 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return performRpc(rpc, completionBlock, progressBlock, null, requiresCompletion, requestClass, datacenterId);
}
TLObject wrapInLayer(TLObject object) {
TLObject wrapInLayer(TLObject object, int datacenterId, RPCRequest request) {
if (object.layer() > 0) {
TLRPC.invokeWithLayer8 invoke = new TLRPC.invokeWithLayer8();
Datacenter datacenter = datacenterWithId(datacenterId);
if (datacenter.lastInitVersion != currentAppVersion) {
request.initRequest = true;
TLRPC.initConnection invoke = new TLRPC.initConnection();
invoke.query = object;
invoke.api_id = APP_ID;
try {
invoke.lang_code = Locale.getDefault().getCountry();
invoke.device_model = Build.MANUFACTURER + Build.MODEL;
if (invoke.device_model == null) {
invoke.device_model = "Android unknown";
}
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
invoke.app_version = pInfo.versionName;
if (invoke.app_version == null) {
invoke.app_version = "App version unknown";
}
invoke.system_version = "SDK " + Build.VERSION.SDK_INT;
} catch (Exception e) {
FileLog.e("tmessages", e);
invoke.lang_code = "en";
invoke.device_model = "Android unknown";
invoke.app_version = "App version unknown";
invoke.system_version = "SDK " + Build.VERSION.SDK_INT;
}
object = invoke;
}
TLRPC.invokeWithLayer11 invoke = new TLRPC.invokeWithLayer11();
invoke.query = object;
FileLog.d("wrap in layer", "" + object);
return invoke;
......@@ -647,7 +684,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
request.runningDatacenterId = datacenterId;
request.rawRequest = rpc;
request.rpcRequest = wrapInLayer(rpc);
request.rpcRequest = wrapInLayer(rpc, datacenterId, request);
request.completionBlock = completionBlock;
request.progressBlock = progressBlock;
request.quickAckBlock = quickAckBlock;
......@@ -1791,12 +1828,14 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
found = true;
boolean discardResponse = false;
boolean isError = false;
if (request.completionBlock != null) {
TLRPC.TL_error implicitError = null;
if (resultContainer.result instanceof TLRPC.TL_gzip_packed) {
TLRPC.TL_gzip_packed packet = (TLRPC.TL_gzip_packed)resultContainer.result;
TLObject uncomressed = Utilities.decompress(packet.packed_data, request.rawRequest);
if (uncomressed == null) {
System.gc();
uncomressed = Utilities.decompress(packet.packed_data, request.rawRequest);
}
if (uncomressed == null) {
......@@ -1871,6 +1910,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (!discardResponse) {
if (implicitError != null || resultContainer.result instanceof TLRPC.TL_error) {
isError = true;
request.completionBlock.run(null, implicitError != null ? implicitError : (TLRPC.TL_error) resultContainer.result);
} else {
request.completionBlock.run(resultContainer.result, null);
......@@ -1878,6 +1918,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
if (implicitError != null && implicitError.code == 401) {
isError = true;
if (datacenter.datacenterId == currentDatacenterId || datacenter.datacenterId == movingToDatacenterId) {
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
Utilities.RunOnUIThread(new Runnable() {
......@@ -1901,6 +1942,15 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
if (!discardResponse) {
if (request.initRequest && !isError) {
if (datacenter.lastInitVersion != currentAppVersion) {
datacenter.lastInitVersion = currentAppVersion;
saveSession();
FileLog.e("tmessages", "init connection completed");
} else {
FileLog.e("tmessages", "rpc is init, but init connection already completed");
}
}
rpcCompleted(resultMid);
} else {
request.runningMessageId = 0;
......@@ -2309,6 +2359,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
MessageKeyData keyData = Utilities.generateMessageKeyData(datacenter.authKey, messageKey, true);
byte[] messageData = is.readData(data.length - 24);
messageData = Utilities.aesIgeEncryption(messageData, keyData.aesKey, keyData.aesIv, false, false);
if (messageData == null) {
FileLog.e("tmessages", "Error: can't decrypt message data " + connection);
......@@ -2329,6 +2380,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
long messageId = messageIs.readInt64();
int messageSeqNo = messageIs.readInt32();
int messageLength = messageIs.readInt32();
if (isMessageIdProcessed(messageSessionId, messageId)) {
doNotProcess = true;
......@@ -2356,8 +2408,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
}
if (!doNotProcess) {
int messageLength = messageIs.readInt32();
int constructor = messageIs.readInt32();
TLObject message = TLClassStore.Instance().TLdeserialize(messageIs, constructor, getRequestWithMessageId(messageId));
......
......@@ -20,18 +20,19 @@ import java.util.Comparator;
import java.util.HashMap;
public class Datacenter {
private final int DATA_VERSION = 2;
private final int DATA_VERSION = 3;
public int datacenterId;
public ArrayList<String> addresses = new ArrayList<String>();
public HashMap<String, Integer> ports = new HashMap<String, Integer>();
public int[] defaultPorts = new int[] {-1, 80, -1, 88, -1, 443, -1, 80, -1, 443, -1};
public int[] defaultPorts = new int[] {-1, 80, -1, 443, -1, 443, -1, 80, -1, 443, -1};
public boolean authorized;
public long authSessionId;
public long authDownloadSessionId;
public long authUploadSessionId;
public byte[] authKey;
public byte[] authKeyId;
public int lastInitVersion = 0;
private volatile int currentPortNum = 0;
private volatile int currentAddressNum = 0;
......@@ -74,8 +75,11 @@ public class Datacenter {
}
} else if (version == 1) {
int currentVersion = data.readInt32();
if (currentVersion == 2) {
if (currentVersion == 2 || currentVersion == 3) {
datacenterId = data.readInt32();
if (currentVersion == 3) {
lastInitVersion = data.readInt32();
}
int len = data.readInt32();
for (int a = 0; a < len; a++) {
String address = data.readString();
......@@ -182,6 +186,7 @@ public class Datacenter {
public void SerializeToStream(SerializedData stream) {
stream.writeInt32(DATA_VERSION);
stream.writeInt32(datacenterId);
stream.writeInt32(lastInitVersion);
stream.writeInt32(addresses.size());
for (String address : addresses) {
stream.writeString(address);
......
......@@ -19,7 +19,6 @@ import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.Spanned;
import android.text.style.DynamicDrawableSpan;
import android.text.style.ImageSpan;
import android.view.View;
......@@ -510,9 +509,9 @@ public class Emoji {
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
emojiCount++;
if (c>= 0xDDE6 && c <= 0xDDFA) {
s.setSpan(span, i - 3, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(span, i - 3, i + 1, 0);
} else {
s.setSpan(span, i - 1, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(span, i - 1, i + 1, 0);
}
}
buf = 0;
......@@ -527,7 +526,7 @@ public class Emoji {
if(d != null) {
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
emojiCount++;
s.setSpan(span, i - 1, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(span, i - 1, i + 1, 0);
}
buf = 0;
}
......@@ -537,7 +536,7 @@ public class Emoji {
if(d != null){
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
emojiCount++;
s.setSpan(span, i, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
s.setSpan(span, i, i + 1, 0);
}
}
if (emojiCount >= 50) {
......
......@@ -42,6 +42,7 @@ public class FileLoadOperation {
private File cacheFileFinal;
private File cacheIvTemp;
private String ext;
private String httpUrl;
private URLConnection httpConnection;
public boolean needBitmapCreate = true;
......@@ -90,6 +91,34 @@ public class FileLoadOperation {
System.arraycopy(videoLocation.iv, 0, iv, 0, iv.length);
key = videoLocation.key;
}
ext = ".mp4";
}
public FileLoadOperation(TLRPC.Document documentLocation) {
if (documentLocation instanceof TLRPC.TL_document) {
location = new TLRPC.TL_inputDocumentFileLocation();
datacenter_id = documentLocation.dc_id;
location.id = documentLocation.id;
location.access_hash = documentLocation.access_hash;
} else if (documentLocation instanceof TLRPC.TL_documentEncrypted) {
location = new TLRPC.TL_inputEncryptedFileLocation();
location.id = documentLocation.id;
location.access_hash = documentLocation.access_hash;
datacenter_id = documentLocation.dc_id;
iv = new byte[32];
System.arraycopy(documentLocation.iv, 0, iv, 0, iv.length);
key = documentLocation.key;
}
ext = documentLocation.file_name;
int idx = -1;
if (ext == null || (idx = ext.lastIndexOf(".")) == -1) {
ext = "";
} else {
ext = ext.substring(idx);
if (ext.length() <= 1) {
ext = "";
}
}
}
public FileLoadOperation(String url) {
......@@ -112,13 +141,20 @@ public class FileLoadOperation {
}
boolean ignoreCache = false;
boolean onlyCache = false;
boolean isLocalFile = false;
String fileNameFinal = null;
String fileNameTemp = null;
String fileNameIv = null;
if (httpUrl != null) {
if (!httpUrl.startsWith("http")) {
onlyCache = true;
isLocalFile = true;
fileNameFinal = httpUrl;
} else {
fileNameFinal = Utilities.MD5(httpUrl);
fileNameTemp = fileNameFinal + "_temp.jpg";
fileNameFinal += ".jpg";
}
} else if (location.volume_id != 0 && location.local_id != 0) {
fileNameTemp = location.volume_id + "_" + location.local_id + "_temp.jpg";
fileNameFinal = location.volume_id + "_" + location.local_id + ".jpg";
......@@ -131,15 +167,20 @@ public class FileLoadOperation {
} else {
ignoreCache = true;
needBitmapCreate = false;
fileNameTemp = datacenter_id + "_" + location.id + "_temp.mp4";
fileNameFinal = datacenter_id + "_" + location.id + ".mp4";
fileNameTemp = datacenter_id + "_" + location.id + "_temp" + ext;
fileNameFinal = datacenter_id + "_" + location.id + ext;
if (key != null) {
fileNameIv = datacenter_id + "_" + location.id + ".iv";
}
}
boolean exist;
if (isLocalFile) {
cacheFileFinal = new File(fileNameFinal);
} else {
cacheFileFinal = new File(Utilities.getCacheDir(), fileNameFinal);
}
final boolean dontDelete = isLocalFile;
if ((exist = cacheFileFinal.exists()) && !ignoreCache) {
Utilities.cacheOutQueue.postRunnable(new Runnable() {
@Override
......@@ -184,7 +225,9 @@ public class FileLoadOperation {
image = BitmapFactory.decodeStream(is, null, opts);
is.close();
if (image == null) {
if (!dontDelete) {
cacheFileFinal.delete();
}
} else {
if (filter != null && image != null) {
float bitmapW = image.getWidth();
......@@ -213,7 +256,9 @@ public class FileLoadOperation {
}
});
} catch (Exception e) {
if (!dontDelete) {
cacheFileFinal.delete();
}
FileLog.e("tmessages", e);
}
}
......@@ -293,7 +338,9 @@ public class FileLoadOperation {
private void cleanup() {
if (httpUrl != null) {
try {
if (httpConnectionStream != null) {
httpConnectionStream.close();
}
httpConnection = null;
httpConnectionStream = null;
} catch (Exception e) {
......
......@@ -19,6 +19,7 @@ import android.view.View;
import android.widget.ImageView;
import org.telegram.TL.TLRPC;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.BackupImageView;
......@@ -388,8 +389,8 @@ public class FileLoader {
});
}
public void cancelLoadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo) {
if (video == null && photo == null) {
public void cancelLoadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document) {
if (video == null && photo == null && document == null) {
return;
}
Utilities.fileUploadQueue.postRunnable(new Runnable() {
......@@ -397,9 +398,14 @@ public class FileLoader {
public void run() {
String fileName = null;
if (video != null) {
fileName = video.dc_id + "_" + video.id + ".mp4";
fileName = MessageObject.getAttachFileName(video);
} else if (photo != null) {
fileName = photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
fileName = MessageObject.getAttachFileName(photo);
} else if (document != null) {
fileName = MessageObject.getAttachFileName(document);
}
if (fileName == null) {
return;
}
FileLoadOperation operation = loadOperationPaths.get(fileName);
if (operation != null) {
......@@ -414,15 +420,20 @@ public class FileLoader {
return loadOperationPaths.containsKey(fileName);
}
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo) {
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document) {
Utilities.fileUploadQueue.postRunnable(new Runnable() {
@Override
public void run() {
String fileName = null;
if (video != null) {
fileName = video.dc_id + "_" + video.id + ".mp4";
fileName = MessageObject.getAttachFileName(video);
} else if (photo != null) {
fileName = photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
fileName = MessageObject.getAttachFileName(photo);
} else if (document != null) {
fileName = MessageObject.getAttachFileName(document);
}
if (fileName == null) {
return;
}
if (loadOperationPaths.containsKey(fileName)) {
return;
......@@ -435,6 +446,9 @@ public class FileLoader {
operation = new FileLoadOperation(photo.location);
operation.totalBytesCount = photo.size;
operation.needBitmapCreate = false;
} else if (document != null) {
operation = new FileLoadOperation(document);
operation.totalBytesCount = document.size;
}
final String arg1 = fileName;
......@@ -536,24 +550,6 @@ public class FileLoader {
memCache.evictAll();
}
public void cleanDisk(boolean all) {
/*if (all) {
[cacheInQueue cancelAllOperations];
[[NSFileManager defaultManager] removeItemAtPath:diskCachePath error:nil];
[[NSFileManager defaultManager] createDirectoryAtPath:diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
} else {
NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-cacheMaxCacheAge];
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath];
for (NSString *fileName in fileEnumerator) {
NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName];
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
if ([[[attrs fileModificationDate] laterDate:expirationDate] isEqualToDate:expirationDate]) {
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}
}
}*/
}
public void cancelLoadingForImageView(final View imageView) {
if (imageView == null) {
return;
......@@ -598,10 +594,11 @@ public class FileLoader {
String key;
if (httpUrl != null) {
key = Utilities.MD5(httpUrl);
} else if (filter == null) {
key = url.volume_id + "_" + url.local_id;
} else {
key = url.volume_id + "_" + url.local_id + "@" + filter;
key = url.volume_id + "_" + url.local_id;
}
if (filter != null) {
key += "@" + filter;
}
Bitmap img = imageFromKey(key);
......@@ -664,10 +661,11 @@ public class FileLoader {
String key;
if (httpUrl != null) {
key = Utilities.MD5(httpUrl);
} else if (filter == null) {
key = url.volume_id + "_" + url.local_id;
} else {
key = url.volume_id + "_" + url.local_id + "@" + filter;
key = url.volume_id + "_" + url.local_id;
}
if (filter != null) {
key += "@" + filter;
}
Integer num = (Integer)imageView.getTag(R.string.CacheTag);
......
......@@ -20,8 +20,6 @@ import java.util.ArrayList;
import java.util.Locale;
public class FileLog {
public static boolean DEBUG_VERSION = true;
public static FileLog Instance = new FileLog();
private OutputStreamWriter streamWriter = null;
private FastDateFormat dateFormat = null;
......@@ -29,7 +27,7 @@ public class FileLog {
private File currentFile = null;
public FileLog() {
if (!DEBUG_VERSION) {
if (!ConnectionsManager.DEBUG_VERSION) {
return;
}
dateFormat = FastDateFormat.getInstance("dd_MM_yyyy_HH_mm_ss", Locale.US);
......@@ -59,7 +57,7 @@ public class FileLog {
}
public static void e(final String tag, final String message, final Throwable exception) {
if (!DEBUG_VERSION) {
if (!ConnectionsManager.DEBUG_VERSION) {
return;
}
Log.e(tag, message, exception);
......@@ -80,7 +78,7 @@ public class FileLog {
}
public static void e(final String tag, final String message) {
if (!DEBUG_VERSION) {
if (!ConnectionsManager.DEBUG_VERSION) {
return;
}
Log.e(tag, message);
......@@ -100,7 +98,7 @@ public class FileLog {
}
public static void e(final String tag, final Exception e) {
if (!DEBUG_VERSION) {
if (!ConnectionsManager.DEBUG_VERSION) {
return;
}
e.printStackTrace();
......@@ -124,7 +122,7 @@ public class FileLog {
}
public static void d(final String tag, final String message) {
if (!DEBUG_VERSION) {
if (!ConnectionsManager.DEBUG_VERSION) {
return;
}
Log.d(tag, message);
......
......@@ -77,9 +77,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
TLRPC.TL_req_pq reqPq = new TLRPC.TL_req_pq();
byte[] nonceBytes = new byte[16];
for (int a = 0; a < 16; a++) {
nonceBytes[a] = (byte)(MessagesController.random.nextDouble() * 255);
}
MessagesController.random.nextBytes(nonceBytes);
authNonce = reqPq.nonce = nonceBytes;
reqPQMsgData = sendMessageData(reqPq, generateMessageId());
}
......@@ -104,6 +102,45 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
new BigInteger("010001", 16)});
map.put("fingerprint", 0xc3b42b026ce86b21L);
serverPublicKeys.add(map);
map = new HashMap<String, Object>();
map.put("key", new BigInteger[]{
new BigInteger("c6aeda78b02a251db4b6441031f467fa871faed32526c436524b1fb3b5dc" +
"a28efb8c089dd1b46d92c895993d87108254951c5f001a0f055f3063dcd14d431a300eb9e29" +
"517e359a1c9537e5e87ab1b116faecf5d17546ebc21db234d9d336a693efcb2b6fbcca1e7d1" +
"a0be414dca408a11609b9c4269a920b09fed1f9a1597be02761430f09e4bc48fcafbe289054" +
"c99dba51b6b5eb7d9c3a2ab4e490545b4676bd620e93804bcac93bf94f73f92c729ca899477" +
"ff17625ef14a934d51dc11d5f8650a3364586b3a52fcff2fedec8a8406cac4e751705a472e5" +
"5707e3c8cd5594342b119c6c3293532d85dbe9271ed54a2fd18b4dc79c04a30951107d5639397", 16),
new BigInteger("010001", 16)});
map.put("fingerprint", 0x9a996a1db11c729bL);
serverPublicKeys.add(map);
map = new HashMap<String, Object>();
map.put("key", new BigInteger[]{
new BigInteger("b1066749655935f0a5936f517034c943bea7f3365a8931ae52c8bcb14856" +
"f004b83d26cf2839be0f22607470d67481771c1ce5ec31de16b20bbaa4ecd2f7d2ecf6b6356" +
"f27501c226984263edc046b89fb6d3981546b01d7bd34fedcfcc1058e2d494bda732ff813e5" +
"0e1c6ae249890b225f82b22b1e55fcb063dc3c0e18e91c28d0c4aa627dec8353eee6038a95a" +
"4fd1ca984eb09f94aeb7a2220635a8ceb450ea7e61d915cdb4eecedaa083aa3801daf071855" +
"ec1fb38516cb6c2996d2d60c0ecbcfa57e4cf1fb0ed39b2f37e94ab4202ecf595e167b3ca62" +
"669a6da520859fb6d6c6203dfdfc79c75ec3ee97da8774b2da903e3435f2cd294670a75a526c1", 16),
new BigInteger("010001", 16)});
map.put("fingerprint", 0xb05b2a6f70cdea78L);
serverPublicKeys.add(map);
map = new HashMap<String, Object>();
map.put("key", new BigInteger[]{
new BigInteger("c2a8c55b4a62e2b78a19b91cf692bcdc4ba7c23fe4d06f194e2a0c30f6d9" +
"996f7d1a2bcc89bc1ac4333d44359a6c433252d1a8402d9970378b5912b75bc8cc3fa76710a" +
"025bcb9032df0b87d7607cc53b928712a174ea2a80a8176623588119d42ffce40205c6d7216" +
"0860d8d80b22a8b8651907cf388effbef29cd7cf2b4eb8a872052da1351cfe7fec214ce4830" +
"4ea472bd66329d60115b3420d08f6894b0410b6ab9450249967617670c932f7cbdb5d6fbcce" +
"1e492c595f483109999b2661fcdeec31b196429b7834c7211a93c6789d9ee601c18c39e521f" +
"da9d7264e61e518add6f0712d2d5228204b851e13c4f322e5c5431c3b7f31089668486aadc59f", 16),
new BigInteger("010001", 16)});
map.put("fingerprint", 0x71e025b6c76033e3L);
serverPublicKeys.add(map);
}
}
......@@ -209,9 +246,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
innerData.q = reqDH.q;
byte[] nonceBytes = new byte[32];
for (int a = 0; a < 32; a++) {
nonceBytes[a] = (byte)(MessagesController.random.nextDouble() * 255);
}
MessagesController.random.nextBytes(nonceBytes);
innerData.new_nonce = authNewNonce = nonceBytes;
innerData.serializeToStream(os);
......@@ -340,9 +375,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
}
byte[] b = new byte[256];
for (int a = 0; a < 256; a++) {
b[a] = (byte)(MessagesController.random.nextDouble() * 255);
}
MessagesController.random.nextBytes(b);
BigInteger p = new BigInteger(1, dhInnerData.dh_prime);
BigInteger g_a = new BigInteger(1, dhInnerData.g_a);
......
......@@ -58,6 +58,8 @@ public class RPCRequest {
boolean confirmed;
boolean initRequest = false;
ArrayList<Long> respondsToMessageIds = new ArrayList<Long>();
public void addRespondMessageId(long messageId) {
......
......@@ -753,6 +753,18 @@ public class Utilities {
return result;
}
public static String formatFileSize(long size) {
if (size < 1024) {
return String.format("%d B", size);
} else if (size < 1024 * 1024) {
return String.format("%.1f KB", size / 1024.0f);
} else if (size < 1024 * 1024 * 1024) {
return String.format("%.1f MB", size / 1024.0f / 1024.0f);
} else {
return String.format("%.1f GB", size / 1024.0f / 1024.0f / 1024.0f);
}
}
public static String stringForMessageListDate(long date) {
Calendar rightNow = Calendar.getInstance();
int day = rightNow.get(Calendar.DAY_OF_YEAR);
......
......@@ -10,6 +10,7 @@ package org.telegram.objects;
import android.graphics.Bitmap;
import org.telegram.TL.TLObject;
import org.telegram.TL.TLRPC;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.MessagesController;
......@@ -211,6 +212,10 @@ public class MessageObject {
messageText = ApplicationLoader.applicationContext.getString(R.string.AttachContact);
} else if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
messageText = ApplicationLoader.applicationContext.getString(R.string.UnsuppotedMedia);
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
messageText = ApplicationLoader.applicationContext.getString(R.string.AttachDocument);
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
messageText = ApplicationLoader.applicationContext.getString(R.string.AttachAudio);
}
} else {
messageText = message.message;
......@@ -255,6 +260,12 @@ public class MessageObject {
} else {
type = 1;
}
} else if (message.media != null && message.media instanceof TLRPC.TL_messageMediaDocument) {
if (message.from_id == UserConfig.clientUserId) {
type = 16;
} else {
type = 17;
}
}
} else if (message instanceof TLRPC.TL_messageService) {
if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto || message.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
......@@ -277,4 +288,38 @@ public class MessageObject {
int dateMonth = rightNow.get(Calendar.MONTH);
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
}
public String getFileName() {
if (messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
return getAttachFileName(messageOwner.media.video);
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
return getAttachFileName(messageOwner.media.document);
}
return "";
}
public static String getAttachFileName(TLObject attach) {
if (attach instanceof TLRPC.Video) {
TLRPC.Video video = (TLRPC.Video)attach;
return video.dc_id + "_" + video.id + ".mp4";
} else if (attach instanceof TLRPC.Document) {
TLRPC.Document document = (TLRPC.Document)attach;
String ext = document.file_name;
int idx = -1;
if (ext == null || (idx = ext.lastIndexOf(".")) == -1) {
ext = "";
} else {
ext = ext.substring(idx);
}
if (ext.length() > 1) {
return document.dc_id + "_" + document.id + ext;
} else {
return document.dc_id + "_" + document.id;
}
} else if (attach instanceof TLRPC.PhotoSize) {
TLRPC.PhotoSize photo = (TLRPC.PhotoSize)attach;
return photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
}
return "";
}
}
......@@ -317,12 +317,12 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati
}
private void checkForCrashes() {
CrashManager.register(this, "your-hockeyapp-api-key-here");
CrashManager.register(this, ConnectionsManager.HOCKEY_APP_HASH);
}
private void checkForUpdates() {
if (FileLog.DEBUG_VERSION) {
UpdateManager.register(this, "your-hockeyapp-api-key-here");
if (ConnectionsManager.DEBUG_VERSION) {
UpdateManager.register(this, ConnectionsManager.HOCKEY_APP_HASH);
}
}
......
......@@ -150,7 +150,7 @@ public class ApplicationLoader extends Application {
return "";
}
int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
int currentVersion = getAppVersion(context);
int currentVersion = getAppVersion();
if (registeredVersion != currentVersion) {
FileLog.d("tmessages", "App version changed.");
return "";
......@@ -162,9 +162,9 @@ public class ApplicationLoader extends Application {
return getSharedPreferences(ApplicationLoader.class.getSimpleName(), Context.MODE_PRIVATE);
}
private static int getAppVersion(Context context) {
public static int getAppVersion() {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
PackageInfo packageInfo = applicationContext.getPackageManager().getPackageInfo(applicationContext.getPackageName(), 0);
return packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException("Could not get package name: " + e);
......@@ -223,7 +223,7 @@ public class ApplicationLoader extends Application {
private void storeRegistrationId(Context context, String regId) {
final SharedPreferences prefs = getGCMPreferences(context);
int appVersion = getAppVersion(context);
int appVersion = getAppVersion();
FileLog.e("tmessages", "Saving regId on app version " + appVersion);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PROPERTY_REG_ID, regId);
......
......@@ -924,9 +924,9 @@ public class GalleryImageViewer extends AbstractGalleryActivity implements Notif
}
if (loadFile) {
if (!FileLoader.Instance.isLoadingFile(fileName)) {
FileLoader.Instance.loadFile(message.messageOwner.media.video, null);
FileLoader.Instance.loadFile(message.messageOwner.media.video, null, null);
} else {
FileLoader.Instance.cancelLoadFile(message.messageOwner.media.video, null);
FileLoader.Instance.cancelLoadFile(message.messageOwner.media.video, null, null);
}
checkCurrentFile();
processViews(playButton, message);
......
......@@ -292,8 +292,6 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
updatePhoneField();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
......@@ -303,8 +301,8 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
public void onNextPressed() {
TLRPC.TL_auth_sendCode req = new TLRPC.TL_auth_sendCode();
String phone = PhoneFormat.stripExceptNumbers("" + codeField.getText() + phoneField.getText());
req.api_hash = "5bce48dc7d331e62c955669eb7233217";
req.api_id = 2458;
req.api_hash = ConnectionsManager.APP_HASH;
req.api_id = ConnectionsManager.APP_ID;
req.sms_type = 0;
req.phone_number = phone;
req.lang_code = Locale.getDefault().getCountry();
......
......@@ -382,7 +382,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
if (message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) {
if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) {
ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes;
boolean set = false;
// for (TLRPC.PhotoSize size : sizes) {
......
......@@ -102,7 +102,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
blockedRow = rowCount++;
backgroundRow = rowCount++;
supportSectionRow = rowCount++;
if (FileLog.DEBUG_VERSION) {
if (ConnectionsManager.DEBUG_VERSION) {
sendLogsRow = rowCount++;
}
askQuestionRow = rowCount++;
......
......@@ -248,11 +248,11 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
progressBar.setVisibility(View.VISIBLE);
loadingSize = size;
selectedColor = 0;
FileLoader.Instance.loadFile(null, size);
FileLoader.Instance.loadFile(null, size, null);
backgroundImage.setBackgroundColor(0);
} else {
if (loadingFile != null) {
FileLoader.Instance.cancelLoadFile(null, loadingSize);
FileLoader.Instance.cancelLoadFile(null, loadingSize, null);
}
loadingFileObject = null;
loadingFile = null;
......@@ -265,7 +265,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
}
} else {
if (loadingFile != null) {
FileLoader.Instance.cancelLoadFile(null, loadingSize);
FileLoader.Instance.cancelLoadFile(null, loadingSize, null);
}
if (selectedBackground == 1000001) {
backgroundImage.setImageResource(R.drawable.background_hd);
......
......@@ -150,6 +150,7 @@ public class FrameLayoutFixed extends FrameLayout {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
/*
* This is the source code of Telegram for Android v. 1.3.2.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.ui.Views;
import android.annotation.SuppressLint;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import com.google.android.gms.maps.SupportMapFragment;
public class NiceSupportMapFragment extends SupportMapFragment {
private View drawingView;
private boolean hasTextureViewSupport = false;
private boolean preventParentScrolling = true;
private boolean textureViewSupport() {
boolean exist = true;
try {
Class.forName("android.view.TextureView");
} catch (ClassNotFoundException e) {
exist = false;
}
return exist;
}
private View searchAndFindDrawingView(ViewGroup group) {
int childCount = group.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = group.getChildAt(i);
if (child instanceof ViewGroup) {
View view = searchAndFindDrawingView((ViewGroup) child);
if (view != null) {
return view;
}
}
if (child instanceof SurfaceView) {
return (View) child;
}
if (hasTextureViewSupport) { // if we have support for texture view
if (child instanceof TextureView) {
return (View) child;
}
}
}
return null;
}
@SuppressLint("NewApi")
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) super.onCreateView(inflater, container,
savedInstanceState);
view.setBackgroundColor(0x00000000); // Set Root View to be transparent
// to prevent black screen on
// load
hasTextureViewSupport = textureViewSupport(); // Find out if we support
// texture view on this
// device
drawingView = searchAndFindDrawingView(view); // Find the view the map
// is using for Open GL
if (drawingView == null)
return view; // If we didn't get anything then abort
drawingView.setBackgroundColor(0x00000000); // Stop black artifact from
// being left behind on
// scroll
// Create On Touch Listener for MapView Parent Scrolling Fix - Many thanks to Gemerson Ribas (gmribas) for help with this fix.
OnTouchListener touchListener = new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow Parent to intercept touch events.
view.getParent().requestDisallowInterceptTouchEvent(preventParentScrolling);
break;
case MotionEvent.ACTION_UP:
// Allow Parent to intercept touch events.
view.getParent().requestDisallowInterceptTouchEvent(!preventParentScrolling);
break;
}
// Handle View touch events.
view.onTouchEvent(event);
return false;
}
};
// texture view
if (hasTextureViewSupport) { // If we support texture view and the
// drawing view is a TextureView then
// tweak it and return the fragment view
if (drawingView instanceof TextureView) {
TextureView textureView = (TextureView) drawingView;
// Stop Containing Views from moving when a user is interacting
// with Map View Directly
textureView.setOnTouchListener(touchListener);
return view;
}
}
// Otherwise continue onto legacy surface view hack
final SurfaceView surfaceView = (SurfaceView) drawingView;
// Fix for reducing black view flash issues
SurfaceHolder holder = surfaceView.getHolder();
holder.setFormat(PixelFormat.RGB_888);
// Stop Containing Views from moving when a user is interacting with
// Map View Directly
surfaceView.setOnTouchListener(touchListener);
return view;
}
public boolean getPreventParentScrolling() {
return preventParentScrolling;
}
public void setPreventParentScrolling(boolean value) {
preventParentScrolling = value;
}
}
\ No newline at end of file
......@@ -87,6 +87,8 @@ public class TightTextView extends TextView {
if (w < getMeasuredWidth()) {
super.onMeasure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST), heightMeasureSpec);
}
} else {
super.onMeasure(MeasureSpec.makeMeasureSpec(Math.min(maxWidth, linesMaxWidth), MeasureSpec.AT_MOST), heightMeasureSpec);
}
}
}
......@@ -99,6 +101,7 @@ public class TightTextView extends TextView {
public void setMaxWidth(int maxpixels) {
super.setMaxWidth(maxpixels);
hasMaxWidth = true;
maxWidth = maxpixels;
}
@Override
......
<!--
~ This is the source code of Telegram for Android v. 1.3.2.
~ It is licensed under GNU GPL v. 2 or later.
~ You should have received a copy of the license in this archive (see LICENSE).
~
~ Copyright Nikolai Kudashov, 2013.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#802a2a2a" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip android:clipOrientation="horizontal" android:gravity="top|left">
<shape>
<solid android:color="#39b0dd" />
</shape>
</clip>
</item>
</layer-list>
\ No newline at end of file
<!--
~ This is the source code of Telegram for Android v. 1.3.2.
~ It is licensed under GNU GPL v. 2 or later.
~ You should have received a copy of the license in this archive (see LICENSE).
~
~ Copyright Nikolai Kudashov, 2013.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/HLRelativeLayout1"
android:layout_width="match_parent"
android:layout_height="64dp"
android:paddingLeft="13dp"
android:paddingRight="13dp">
<TextView
android:id="@+id/docs_item_type"
android:layout_width="55dp"
android:layout_height="42dp"
android:layout_marginTop="11dp"
android:background="#1A808080"
android:ellipsize="marquee"
android:gravity="center"
android:padding="5dp"
android:singleLine="true"
android:textColor="#919191"
android:textSize="16dp"
android:textStyle="bold"
android:layout_gravity="top|right"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="62dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="66dp"
android:gravity="center_vertical"
android:orientation="vertical"
android:layout_gravity="top|right">
<TextView
android:id="@+id/docs_item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:text="TextView"
android:textColor="#000"
android:textSize="18dp"
android:gravity="right"
android:layout_gravity="top|right"/>
<TextView
android:id="@+id/docs_item_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="TextView"
android:textColor="#a6a6a6"
android:textSize="16dp"
android:gravity="right"
android:layout_gravity="top|right"/>
</LinearLayout>
<org.telegram.ui.Views.BackupImageView
android:id="@+id/docs_item_thumb"
android:layout_width="55dp"
android:layout_height="42dp"
android:scaleType="centerCrop"
android:layout_marginTop="11dp"
android:layout_gravity="top|right"/>
<View
android:background="@color/divider"
android:layout_width="fill_parent"
android:layout_height="1px"
android:layout_gravity="bottom"
android:id="@+id/settings_row_divider"/>
</FrameLayout>
\ No newline at end of file
......@@ -16,6 +16,7 @@
android:id="@+id/chat_group_avatar_image"
android:scaleType="fitCenter"
android:layout_marginBottom="2dp"
android:layout_marginRight="4dp"
android:layout_gravity="bottom"/>
<LinearLayout
......@@ -27,7 +28,8 @@
android:baselineAligned="false"
android:id="@+id/chat_bubble_layout">
<FrameLayout android:layout_height="58dp"
<FrameLayout
android:layout_height="58dp"
android:layout_width="0dp"
android:id="@+id/shared_layout"
android:layout_weight="1">
......
......@@ -130,12 +130,13 @@
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="3dp"
android:layout_gravity="left|center_vertical"
android:progressDrawable="@drawable/photo_progress_chat"
style="?android:attr/progressBarStyleHorizontal"
android:progress="50"
android:layout_marginLeft="12dp"
android:layout_marginRight="36dp"
android:layout_gravity="center|left"
android:id="@+id/chat_view_action_progress"
android:max="100"/>
......
......@@ -2,7 +2,6 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dp"
......
......@@ -16,7 +16,8 @@
android:id="@+id/message_layout"
android:layout_gravity="top|left">
<TextView android:layout_height="wrap_content"
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#006fc8"
android:textSize="14dp"
......
......@@ -101,7 +101,8 @@
android:textStyle="bold"
android:layout_marginLeft="10dp"/>
<org.telegram.ui.Views.FrameLayoutFixed android:layout_height="wrap_content"
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="wrap_content"
android:layout_width="140dp"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
......@@ -120,12 +121,13 @@
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="3dp"
android:layout_gravity="left|center_vertical"
android:progressDrawable="@drawable/photo_progress_chat"
style="?android:attr/progressBarStyleHorizontal"
android:progress="50"
android:layout_marginLeft="12dp"
android:layout_marginRight="36dp"
android:layout_gravity="center|left"
android:id="@+id/chat_view_action_progress"
android:max="100"/>
......
......@@ -28,7 +28,7 @@
android:textSize="14dp"
android:id="@+id/searchEmptyView"
android:visibility="gone"
android:layout_centerInParent="true"/>
android:layout_gravity="center"/>
<include
layout="@layout/encrypted_chat_placeholder"
......
......@@ -2,7 +2,6 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dp"
......@@ -106,4 +105,5 @@
</FrameLayout>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
......@@ -29,12 +29,13 @@
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="3dp"
android:layout_gravity="right|center_vertical"
android:progressDrawable="@drawable/photo_progress_chat"
style="?android:attr/progressBarStyleHorizontal"
android:progress="50"
android:layout_marginLeft="36dp"
android:layout_marginRight="12dp"
android:layout_gravity="right|center"
android:id="@+id/chat_view_action_progress"
android:max="100"/>
......
This diff is collapsed.
This diff is collapsed.
......@@ -24,6 +24,11 @@
android:title="@string/ChatVideo"
android:id="@+id/attach_video"/>
<item
android:icon="@drawable/ic_ab_doc"
android:title="@string/ChatDocument"
android:id="@+id/attach_document"/>
<item
android:icon="@drawable/ic_attach_location"
android:title="@string/ChatLocation"
......
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