Commit a87968ce authored by DrKLO's avatar DrKLO

Log and send native lib load error with HA crashes, fixed emoji scale with...

Log and send native lib load error with HA crashes, fixed emoji scale with custom font size, removed all lib dependency in native code
parent 68aeaeef
......@@ -81,7 +81,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 256
versionName "1.5.3"
versionCode 257
versionName "1.5.4"
}
}
......@@ -3,11 +3,11 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE := tmessages
LOCAL_CFLAGS := -w -std=gnu99 -O3 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
LOCAL_CFLAGS := -w -std=gnu99 -O3 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLOG_DISABLED
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT
LOCAL_CPPFLAGS := -DBSD=1 -ffast-math -O3 -funroll-loops
LOCAL_LDLIBS := -llog -lm
#LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := \
./opus/src/opus.c \
......
......@@ -5,10 +5,17 @@
#include <jni.h>
#define LOG_TAG "tmessages_native"
#ifndef LOG_DISABLED
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#else
#define LOGI(...)
#define LOGD(...)
#define LOGE(...)
#define LOGV(...)
#endif
#ifndef max
#define max(x, y) ((x) > (y)) ? (x) : (y)
......
......@@ -347,9 +347,14 @@ public class Emoji {
canvas.drawRect(getBounds(), placeholderPaint);
return;
}
int size = fullSize ? bigImgSize : drawImgSize;
float scale = (float)size / (float)emojiFullSize;
int offset = (getBounds().width() - size) / 2;
float scale = 1;
int offset = 0;
if (fullSize) {
scale = (float) bigImgSize / (float) emojiFullSize;
offset = (getBounds().width() - bigImgSize) / 2;
} else {
scale = (float) getBounds().width() / (float) emojiFullSize;
}
canvas.save();
canvas.scale(scale, scale);
......@@ -461,12 +466,17 @@ public class Emoji {
public static class EmojiSpan extends ImageSpan {
private Paint.FontMetricsInt fontMetrics = null;
private int size = Utilities.dp(20);
int size = Utilities.dp(20);
public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) {
super(d, verticalAlignment);
fontMetrics = original;
size = s;
if (original != null) {
size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent);
if (size == 0) {
size = Utilities.dp(20);
}
}
}
@Override
......@@ -495,6 +505,9 @@ public class Emoji {
fm.top = fontMetrics.top;
fm.bottom = fontMetrics.bottom;
}
if (getDrawable() != null) {
getDrawable().setBounds(0, 0, size, size);
}
return size;
}
}
......
......@@ -16,6 +16,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
......@@ -30,6 +31,49 @@ public class NativeLoader {
private static volatile boolean nativeLoaded = false;
public static void cleanNativeLog(Context context) {
try {
File sdCard = context.getFilesDir();
if (sdCard == null) {
return;
}
File file = new File(sdCard, "nativeer.log");
if (file == null || !file.exists()) {
return;
}
file.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeNativeError(Context context, String info, Throwable throwable) {
try {
File sdCard = context.getFilesDir();
if (sdCard == null) {
return;
}
File file = new File(sdCard, "nativeer.log");
if (file == null) {
return;
}
FileOutputStream stream = new FileOutputStream(file);
OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
streamWriter.write("info" + "\n");
streamWriter.write(throwable + "\n");
StackTraceElement[] stack = throwable.getStackTrace();
for (StackTraceElement el : stack) {
streamWriter.write(el + "\n");
}
streamWriter.flush();
streamWriter.close();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static File getNativeLibraryDir(Context context) {
File f = null;
if (context != null) {
......@@ -48,6 +92,55 @@ public class NativeLoader {
return null;
}
private static boolean loadFromZip(Context context, File destLocalFile, String 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();
try {
System.load(destLocalFile.getAbsolutePath());
nativeLoaded = true;
} catch (Error e) {
FileLog.e("tmessages", e);
writeNativeError(context, "after zip", e);
}
return true;
} catch (Exception e) {
FileLog.e("tmessages", e);
writeNativeError(context, "zip", 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);
}
}
}
return false;
}
public static synchronized void initNativeLibs(Context context) {
if (nativeLoaded) {
......@@ -55,6 +148,8 @@ public class NativeLoader {
}
try {
cleanNativeLog(context);
String folder = null;
long libSize = 0;
long libSize2 = 0;
......@@ -82,6 +177,7 @@ public class NativeLoader {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
writeNativeError(context, "arch", e);
folder = "armeabi";
libSize = sizes[0];
libSize2 = sizes[1];
......@@ -98,6 +194,7 @@ public class NativeLoader {
return;
} catch (Error e) {
FileLog.e("tmessages", e);
writeNativeError(context, "normal", e);
}
}
}
......@@ -112,6 +209,7 @@ public class NativeLoader {
return;
} catch (Error e) {
FileLog.e("tmessages", e);
writeNativeError(context, "local", e);
}
} else {
destLocalFile.delete();
......@@ -120,58 +218,20 @@ public class NativeLoader {
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();
try {
System.load(destLocalFile.getAbsolutePath());
nativeLoaded = true;
} catch (Error e) {
FileLog.e("tmessages", e);
}
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);
}
}
if (!loadFromZip(context, destLocalFile, folder) && folder.equals("armeabi-v7a")) {
folder = "armeabi";
loadFromZip(context, destLocalFile, folder);
}
} catch (Throwable e) {
e.printStackTrace();
writeNativeError(context, "", e);
}
try {
System.loadLibrary("tmessages");
nativeLoaded = true;
} catch (Error e) {
writeNativeError(context, "last chance", e);
FileLog.e("tmessages", e);
}
}
......
......@@ -34,10 +34,12 @@ import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;
import net.hockeyapp.android.UpdateManager;
import org.telegram.ui.ApplicationLoader;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
......@@ -45,6 +47,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
......@@ -986,7 +989,47 @@ public class Utilities {
}
public static void checkForCrashes(Activity context) {
CrashManager.register(context, BuildVars.HOCKEY_APP_HASH);
CrashManager.register(context, BuildVars.HOCKEY_APP_HASH, new CrashManagerListener() {
@Override
public boolean includeDeviceData() {
return true;
}
@Override
public String getDescription() {
String description = "";
try {
File sdCard = ApplicationLoader.applicationContext.getFilesDir();
if (sdCard == null) {
return description;
}
File file = new File(sdCard, "nativeer.log");
if (file == null || !file.exists()) {
return description;
}
FileInputStream inputStream = new FileInputStream(file);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append("\n");
}
bufferedReader.close();
inputStream.close();
description = log.toString();
NativeLoader.cleanNativeLog(ApplicationLoader.applicationContext);
} catch (Exception e) {
e.printStackTrace();
}
return description;
}
});
}
public static void checkForUpdates(Activity context) {
......
......@@ -20,7 +20,6 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Handler;
......@@ -295,12 +294,14 @@ public class ApplicationLoader extends Application {
UserConfig.pushString = regid;
UserConfig.registeredForPush = !isNew;
UserConfig.saveConfig(false);
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().registerForPush(regid);
}
});
if (UserConfig.getClientUserId() != 0) {
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().registerForPush(regid);
}
});
}
}
});
}
......
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