From c4e113dc67d5cffb982f3eeb9bc8b7aa5e5271cc Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sat, 5 Apr 2014 17:27:42 +0400 Subject: [PATCH] Fixed native library checking, fixed preview sending for gif documents --- TMessagesProj/build.gradle | 4 +- .../messenger/MessagesController.java | 6 +- .../org/telegram/messenger/NativeLoader.java | 192 ++++++++++-------- 3 files changed, 112 insertions(+), 90 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 61046e2a8..bb138c880 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 226 - versionName "1.4.11" + versionCode 229 + versionName "1.4.12" } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index cbe28efbf..51812cfe7 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -1935,7 +1935,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter reqSend.media.last_name = user.last_name; performSendMessageRequest(reqSend, newMsgObj); } else if (type == 7) { - reqSend.media = new TLRPC.TL_inputMediaUploadedDocument(); + if (document.thumb.location != null && document.thumb.location instanceof TLRPC.TL_fileLocation) { + reqSend.media = new TLRPC.TL_inputMediaUploadedThumbDocument(); + } else { + reqSend.media = new TLRPC.TL_inputMediaUploadedDocument(); + } reqSend.media.mime_type = document.mime_type; reqSend.media.file_name = document.file_name; DelayedMessage delayedMessage = new DelayedMessage(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java index 40b5a3dc7..52a14210f 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java @@ -9,6 +9,7 @@ package org.telegram.messenger; import android.content.Context; +import android.content.pm.ApplicationInfo; import android.os.Build; import java.io.File; @@ -29,119 +30,136 @@ public class NativeLoader { private static volatile boolean nativeLoaded = false; + private static File getNativeLibraryDir(Context context) { + File f = null; + if (context != null) { + try { + f = (File) ApplicationInfo.class.getField("nativeLibraryDir").get(context.getApplicationInfo()); + } catch (Throwable th) { + th.printStackTrace(); + } + } + if (f == null) { + f = new File(context.getApplicationInfo().dataDir, "lib"); + } + if (f != null && f.isDirectory()) { + return f; + } + return null; + } + + public static synchronized void initNativeLibs(Context context) { if (nativeLoaded) { return; } - if (Build.VERSION.SDK_INT >= 9) { - try { - String folder = null; - long libSize = 0; - long libSize2 = 0; + try { + String folder = null; + long libSize = 0; + long libSize2 = 0; - try { - if (Build.CPU_ABI.equalsIgnoreCase("armeabi-v7a")) { - folder = "armeabi-v7a"; - libSize = sizes[1]; - libSize2 = sizes[0]; - } else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) { - folder = "armeabi"; - libSize = sizes[0]; - libSize2 = sizes[1]; - } else if (Build.CPU_ABI.equalsIgnoreCase("x86")) { - folder = "x86"; - libSize = sizes[2]; - } else if (Build.CPU_ABI.equalsIgnoreCase("mips")) { - folder = "mips"; - libSize = sizes[3]; - } else { - folder = "armeabi"; - libSize = sizes[0]; - libSize2 = sizes[1]; - FileLog.e("tmessages", "Unsupported arch: " + Build.CPU_ABI); - } - } catch (Exception e) { - FileLog.e("tmessages", e); + try { + if (Build.CPU_ABI.equalsIgnoreCase("armeabi-v7a")) { + folder = "armeabi-v7a"; + libSize = sizes[1]; + libSize2 = sizes[0]; + } else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) { folder = "armeabi"; libSize = sizes[0]; libSize2 = sizes[1]; + } else if (Build.CPU_ABI.equalsIgnoreCase("x86")) { + folder = "x86"; + libSize = sizes[2]; + } else if (Build.CPU_ABI.equalsIgnoreCase("mips")) { + folder = "mips"; + libSize = sizes[3]; + } else { + folder = "armeabi"; + libSize = sizes[0]; + libSize2 = sizes[1]; + FileLog.e("tmessages", "Unsupported arch: " + Build.CPU_ABI); } + } catch (Exception e) { + FileLog.e("tmessages", e); + folder = "armeabi"; + libSize = sizes[0]; + libSize2 = sizes[1]; + } - File destFile = new File(context.getApplicationInfo().nativeLibraryDir + "/libtmessages.so"); - if (destFile.exists() && (destFile.length() == libSize || libSize2 != 0 && destFile.length() == libSize2)) { - FileLog.d("tmessages", "Load normal lib"); + File destFile = getNativeLibraryDir(context); + if (destFile != null && destFile.exists() && (destFile.length() == libSize || libSize2 != 0 && destFile.length() == libSize2)) { + FileLog.d("tmessages", "Load normal lib"); + try { + System.loadLibrary("tmessages"); + nativeLoaded = true; + return; + } catch (Exception e) { + e.printStackTrace(); + } + } + + File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so"); + if (destLocalFile.exists()) { + if (destLocalFile.length() == libSize) { try { - System.loadLibrary("tmessages"); + FileLog.d("tmessages", "Load local lib"); + System.load(destLocalFile.getAbsolutePath()); nativeLoaded = true; return; } catch (Exception e) { e.printStackTrace(); } + } else { + destLocalFile.delete(); } + } - File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so"); - if (destLocalFile.exists()) { - if (destLocalFile.length() == libSize) { - try { - FileLog.d("tmessages", "Load local lib"); - System.load(destLocalFile.getAbsolutePath()); - nativeLoaded = true; - return; - } catch (Exception e) { - e.printStackTrace(); - } - } else { - destLocalFile.delete(); - } + FileLog.e("tmessages", "Library not found, arch = " + folder); + + ZipFile zipFile = null; + InputStream stream = null; + try { + zipFile = new ZipFile(context.getApplicationInfo().sourceDir); + ZipEntry entry = zipFile.getEntry("lib/" + folder + "/libtmessages.so"); + if (entry == null) { + throw new Exception("Unable to find file in apk:" + "lib/" + folder + "/libtmessages.so"); } + stream = zipFile.getInputStream(entry); - FileLog.e("tmessages", "Library not found, arch = " + folder); - - ZipFile zipFile = null; - InputStream stream = null; - try { - zipFile = new ZipFile(context.getApplicationInfo().sourceDir); - ZipEntry entry = zipFile.getEntry("lib/" + folder + "/libtmessages.so"); - if (entry == null) { - throw new Exception("Unable to find file in apk:" + "lib/" + folder + "/libtmessages.so"); - } - stream = zipFile.getInputStream(entry); - - OutputStream out = new FileOutputStream(destLocalFile); - byte[] buf = new byte[4096]; - int len; - while ((len = stream.read(buf)) > 0) { - Thread.yield(); - out.write(buf, 0, len); - } - out.close(); - - System.load(destLocalFile.getAbsolutePath()); - nativeLoaded = true; - return; - } catch (Exception e) { - FileLog.e("tmessages", e); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - if (zipFile != null) { - try { - zipFile.close(); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } + OutputStream out = new FileOutputStream(destLocalFile); + byte[] buf = new byte[4096]; + int len; + while ((len = stream.read(buf)) > 0) { + Thread.yield(); + out.write(buf, 0, len); } + out.close(); + + System.load(destLocalFile.getAbsolutePath()); + nativeLoaded = true; + return; } catch (Exception e) { FileLog.e("tmessages", e); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + if (zipFile != null) { + try { + zipFile.close(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } } + } catch (Throwable e) { + e.printStackTrace(); } System.loadLibrary("tmessages");