Commit 331a0bb7 authored by DrKLO's avatar DrKLO

Merge branch 'dev'

parents 2cb6bb3e e2a6511f
...@@ -3,10 +3,10 @@ buildscript { ...@@ -3,10 +3,10 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:0.11.+' classpath 'com.android.tools.build:gradle:0.12.+'
} }
} }
apply plugin: 'android' apply plugin: 'com.android.application'
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -20,13 +20,15 @@ dependencies { ...@@ -20,13 +20,15 @@ dependencies {
compile 'com.android.support:support-v4:19.0.+' compile 'com.android.support:support-v4:19.0.+'
compile 'com.google.android.gms:play-services:4.1.+' compile 'com.google.android.gms:play-services:4.1.+'
compile 'net.hockeyapp.android:HockeySDK:3.0.1' compile 'net.hockeyapp.android:HockeySDK:3.0.1'
compile 'com.googlecode.mp4parser:isoparser:1.0.+'
} }
android { android {
compileSdkVersion 19 compileSdkVersion 19
buildToolsVersion '19.1.0' buildToolsVersion '19.1.0'
aaptOptions.useAaptPngCruncher = true useAaptPngCruncher = true
useOldManifestMerger true
signingConfigs { signingConfigs {
debug { debug {
...@@ -81,7 +83,7 @@ android { ...@@ -81,7 +83,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 267 versionCode 288
versionName "1.5.7" versionName "1.6.1"
} }
} }
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<activity android:name="net.hockeyapp.android.UpdateActivity" /> <activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver <receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver" android:name="org.telegram.android.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" > android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<activity android:name="net.hockeyapp.android.UpdateActivity" /> <activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver <receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver" android:name="org.telegram.android.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" > android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
......
...@@ -234,6 +234,7 @@ LOCAL_SRC_FILES += \ ...@@ -234,6 +234,7 @@ LOCAL_SRC_FILES += \
./audio.c \ ./audio.c \
./gif.c \ ./gif.c \
./utils.c \ ./utils.c \
./image.c ./image.c \
./fake.c
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file
...@@ -504,7 +504,7 @@ int writeFrame(uint8_t *framePcmBytes, unsigned int frameByteCount) { ...@@ -504,7 +504,7 @@ int writeFrame(uint8_t *framePcmBytes, unsigned int frameByteCount) {
return 1; return 1;
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *env, jclass class, jstring path) { JNIEXPORT int Java_org_telegram_android_MediaController_startRecord(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0); const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = initRecorder(pathStr); int result = initRecorder(pathStr);
...@@ -516,12 +516,12 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *en ...@@ -516,12 +516,12 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *en
return result; return result;
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_writeFrame(JNIEnv *env, jclass class, jobject frame, jint len) { JNIEXPORT int Java_org_telegram_android_MediaController_writeFrame(JNIEnv *env, jclass class, jobject frame, jint len) {
jbyte *frameBytes = (*env)->GetDirectBufferAddress(env, frame); jbyte *frameBytes = (*env)->GetDirectBufferAddress(env, frame);
return writeFrame(frameBytes, len); return writeFrame(frameBytes, len);
} }
JNIEXPORT void Java_org_telegram_messenger_MediaController_stopRecord(JNIEnv *env, jclass class) { JNIEXPORT void Java_org_telegram_android_MediaController_stopRecord(JNIEnv *env, jclass class) {
cleanupRecorder(); cleanupRecorder();
} }
...@@ -618,22 +618,22 @@ void fillBuffer(uint8_t *buffer, int capacity, int *args) { ...@@ -618,22 +618,22 @@ void fillBuffer(uint8_t *buffer, int capacity, int *args) {
} }
} }
JNIEXPORT jlong Java_org_telegram_messenger_MediaController_getTotalPcmDuration(JNIEnv *env, jclass class) { JNIEXPORT jlong Java_org_telegram_android_MediaController_getTotalPcmDuration(JNIEnv *env, jclass class) {
return _totalPcmDuration; return _totalPcmDuration;
} }
JNIEXPORT void Java_org_telegram_messenger_MediaController_readOpusFile(JNIEnv *env, jclass class, jobject buffer, jint capacity, jintArray args) { JNIEXPORT void Java_org_telegram_android_MediaController_readOpusFile(JNIEnv *env, jclass class, jobject buffer, jint capacity, jintArray args) {
jint *argsArr = (*env)->GetIntArrayElements(env, args, 0); jint *argsArr = (*env)->GetIntArrayElements(env, args, 0);
jbyte *bufferBytes = (*env)->GetDirectBufferAddress(env, buffer); jbyte *bufferBytes = (*env)->GetDirectBufferAddress(env, buffer);
fillBuffer(bufferBytes, capacity, argsArr); fillBuffer(bufferBytes, capacity, argsArr);
(*env)->ReleaseIntArrayElements(env, args, argsArr, 0); (*env)->ReleaseIntArrayElements(env, args, argsArr, 0);
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_seekOpusFile(JNIEnv *env, jclass class, jfloat position) { JNIEXPORT int Java_org_telegram_android_MediaController_seekOpusFile(JNIEnv *env, jclass class, jfloat position) {
return seekPlayer(position); return seekPlayer(position);
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *env, jclass class, jstring path) { JNIEXPORT int Java_org_telegram_android_MediaController_openOpusFile(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0); const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = initPlayer(pathStr); int result = initPlayer(pathStr);
...@@ -645,11 +645,11 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *e ...@@ -645,11 +645,11 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *e
return result; return result;
} }
JNIEXPORT void Java_org_telegram_messenger_MediaController_closeOpusFile(JNIEnv *env, jclass class) { JNIEXPORT void Java_org_telegram_android_MediaController_closeOpusFile(JNIEnv *env, jclass class) {
cleanupPlayer(); cleanupPlayer();
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_isOpusFile(JNIEnv *env, jclass class, jstring path) { JNIEXPORT int Java_org_telegram_android_MediaController_isOpusFile(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0); const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = 0; int result = 0;
......
#include <stdio.h>
void fakeFunction() {
printf("some androids has buggy native loader, so i should check size of libs in java to know that native library is correct. So each changed native library should has diffrent size in different app versions. This function will increase lib size for few bytes :)");
printf("bla blablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla");
}
...@@ -30,67 +30,21 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) { ...@@ -30,67 +30,21 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) {
gifOnJNIUnload(vm, reserved); gifOnJNIUnload(vm, reserved);
} }
JNIEXPORT jbyteArray Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jbyteArray _what, jbyteArray _key, jbyteArray _iv, jboolean encrypt, jboolean changeIv, jint l) { JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jobject buffer, jbyteArray key, jbyteArray iv, jboolean encrypt, int offset, int length) {
unsigned char *what = (unsigned char *)(*env)->GetByteArrayElements(env, _what, NULL); jbyte *what = (*env)->GetDirectBufferAddress(env, buffer) + offset;
unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL); unsigned char *keyBuff = (unsigned char *)(*env)->GetByteArrayElements(env, key, NULL);
unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL); unsigned char *ivBuff = (unsigned char *)(*env)->GetByteArrayElements(env, iv, NULL);
unsigned char *iv = 0;
if (!changeIv) {
iv = (unsigned char *)malloc((*env)->GetArrayLength(env, _iv));
memcpy(iv, __iv, (*env)->GetArrayLength(env, _iv));
} else {
iv = __iv;
}
int len = l == 0 ? (*env)->GetArrayLength(env, _what) : l;
AES_KEY akey; AES_KEY akey;
if (!encrypt) { if (!encrypt) {
AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey); AES_set_decrypt_key(keyBuff, 32 * 8, &akey);
AES_ige_encrypt(what, what, len, &akey, iv, AES_DECRYPT); AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_DECRYPT);
} else {
AES_set_encrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, len, &akey, iv, AES_ENCRYPT);
}
(*env)->ReleaseByteArrayElements(env, _what, what, 0);
(*env)->ReleaseByteArrayElements(env, _key, key, JNI_ABORT);
if (!changeIv) {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, JNI_ABORT);
free(iv);
} else {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, 0);
}
return _what;
}
JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption2(JNIEnv *env, jclass class, jobject _what, jbyteArray _key, jbyteArray _iv, jboolean encrypt, jboolean changeIv, jint l) {
jbyte *what = (*env)->GetDirectBufferAddress(env, _what);
unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL);
unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL);
unsigned char *iv = 0;
if (!changeIv) {
iv = (unsigned char *)malloc((*env)->GetArrayLength(env, _iv));
memcpy(iv, __iv, (*env)->GetArrayLength(env, _iv));
} else {
iv = __iv;
}
AES_KEY akey;
if (!encrypt) {
AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, l, &akey, iv, AES_DECRYPT);
} else {
AES_set_encrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, l, &akey, iv, AES_ENCRYPT);
}
(*env)->ReleaseByteArrayElements(env, _key, key, JNI_ABORT);
if (!changeIv) {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, JNI_ABORT);
free(iv);
} else { } else {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, 0); AES_set_encrypt_key(keyBuff, 32 * 8, &akey);
AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_ENCRYPT);
} }
(*env)->ReleaseByteArrayElements(env, key, keyBuff, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, iv, ivBuff, 0);
} }
uint64_t gcd(uint64_t a, uint64_t b){ uint64_t gcd(uint64_t a, uint64_t b){
......
...@@ -48,7 +48,7 @@ jstring Java_org_telegram_SQLite_SQLiteCursor_columnStringValue(JNIEnv *env, job ...@@ -48,7 +48,7 @@ jstring Java_org_telegram_SQLite_SQLiteCursor_columnStringValue(JNIEnv *env, job
} }
jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex) { jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex) {
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle; sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
void *buf = sqlite3_column_blob(handle, columnIndex); void *buf = sqlite3_column_blob(handle, columnIndex);
int length = sqlite3_column_bytes(handle, columnIndex); int length = sqlite3_column_bytes(handle, columnIndex);
if (buf != 0 && length > 0) { if (buf != 0 && length > 0) {
...@@ -58,3 +58,22 @@ jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *en ...@@ -58,3 +58,22 @@ jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *en
} }
return 0; return 0;
} }
int Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayLength(JNIEnv *env, jobject object, int statementHandle, int columnIndex) {
return sqlite3_column_bytes((sqlite3_stmt *)statementHandle, columnIndex);
}
int Java_org_telegram_SQLite_SQLiteCursor_columnByteBufferValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex, jobject buffer) {
if (!buffer) {
return 0;
}
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
void *buf = sqlite3_column_blob(handle, columnIndex);
int length = sqlite3_column_bytes(handle, columnIndex);
if (buf != 0 && length > 0) {
jbyte *byteBuff = (*env)->GetDirectBufferAddress(env, buffer);
memcpy(byteBuff, buf, length);
return length;
}
return 0;
}
...@@ -62,20 +62,14 @@ void Java_org_telegram_SQLite_SQLitePreparedStatement_finalize(JNIEnv *env, jobj ...@@ -62,20 +62,14 @@ void Java_org_telegram_SQLite_SQLitePreparedStatement_finalize(JNIEnv *env, jobj
} }
} }
void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteArray(JNIEnv *env, jobject object, int statementHandle, int index, jbyteArray value) { void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteBuffer(JNIEnv *env, jobject object, int statementHandle, int index, jobject value, int length) {
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle; sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
jbyte *buf = (*env)->GetDirectBufferAddress(env, value);
const void *buf = (*env)->GetByteArrayElements(env, value, 0);
int length = (*env)->GetArrayLength(env, value);
int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC); int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC);
if (SQLITE_OK != errcode) { if (SQLITE_OK != errcode) {
throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode);
} }
if (buf != 0) {
(*env)->ReleaseByteArrayElements(env, value, buf, 0);
}
} }
void Java_org_telegram_SQLite_SQLitePreparedStatement_bindString(JNIEnv *env, jobject object, int statementHandle, int index, jstring value) { void Java_org_telegram_SQLite_SQLitePreparedStatement_bindString(JNIEnv *env, jobject object, int statementHandle, int index, jstring value) {
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEND"/> <action android:name="android.intent.action.SEND"/>
...@@ -100,14 +101,23 @@ ...@@ -100,14 +101,23 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
</activity> </activity>
<activity
android:name="org.telegram.ui.PopupNotificationActivity"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize|stateHidden"
android:taskAffinity=""
android:theme="@style/Theme.TMessages.PopupNotification">
</activity>
<receiver android:name="org.telegram.messenger.SmsListener"> <receiver android:name="org.telegram.android.SmsListener">
<intent-filter> <intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" /> <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service android:name="org.telegram.messenger.AuthenticatorService" <service android:name="org.telegram.android.AuthenticatorService"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/> <action android:name="android.accounts.AccountAuthenticator"/>
...@@ -116,7 +126,7 @@ ...@@ -116,7 +126,7 @@
android:resource="@xml/auth"/> android:resource="@xml/auth"/>
</service> </service>
<service android:name="org.telegram.messenger.ContactsSyncAdapterService" <service android:name="org.telegram.android.ContactsSyncAdapterService"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.content.SyncAdapter" /> <action android:name="android.content.SyncAdapter" />
...@@ -127,15 +137,22 @@ ...@@ -127,15 +137,22 @@
android:resource="@xml/contacts" /> android:resource="@xml/contacts" />
</service> </service>
<service android:name="org.telegram.messenger.NotificationsService" android:enabled="true"/> <service android:name="org.telegram.android.NotificationsService" android:enabled="true"/>
<receiver android:name="org.telegram.messenger.AppStartReceiver" android:enabled="true"> <receiver android:name="org.telegram.android.AppStartReceiver" android:enabled="true">
<intent-filter> <intent-filter>
<action android:name="org.telegram.start" /> <action android:name="org.telegram.start" />
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<uses-library android:name="com.sec.android.app.multiwindow" android:required="false" />
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632dp" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598dp" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632dp" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598dp" />
</application> </application>
</manifest> </manifest>
...@@ -10,6 +10,8 @@ package org.telegram.SQLite; ...@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import java.nio.ByteBuffer;
public class SQLiteCursor { public class SQLiteCursor {
public static final int FIELD_TYPE_INT = 1; public static final int FIELD_TYPE_INT = 1;
...@@ -55,28 +57,21 @@ public class SQLiteCursor { ...@@ -55,28 +57,21 @@ public class SQLiteCursor {
return columnByteArrayValue(preparedStatement.getStatementHandle(), columnIndex); return columnByteArrayValue(preparedStatement.getStatementHandle(), columnIndex);
} }
public int byteArrayLength(int columnIndex) throws SQLiteException {
checkRow();
return columnByteArrayLength(preparedStatement.getStatementHandle(), columnIndex);
}
public int byteBufferValue(int columnIndex, ByteBuffer buffer) throws SQLiteException {
checkRow();
return columnByteBufferValue(preparedStatement.getStatementHandle(), columnIndex, buffer);
}
public int getTypeOf(int columnIndex) throws SQLiteException { public int getTypeOf(int columnIndex) throws SQLiteException {
checkRow(); checkRow();
return columnType(preparedStatement.getStatementHandle(), columnIndex); return columnType(preparedStatement.getStatementHandle(), columnIndex);
} }
public Object objectValue(int columnIndex) throws SQLiteException {
checkRow();
int type = columnType(preparedStatement.getStatementHandle(), columnIndex);
switch (type) {
case FIELD_TYPE_INT:
return intValue(columnIndex);
case FIELD_TYPE_BYTEARRAY:
return byteArrayValue(columnIndex);
case FIELD_TYPE_FLOAT:
return doubleValue(columnIndex);
case FIELD_TYPE_STRING:
return stringValue(columnIndex);
}
return null;
}
public boolean next() throws SQLiteException { public boolean next() throws SQLiteException {
int res = preparedStatement.step(preparedStatement.getStatementHandle()); int res = preparedStatement.step(preparedStatement.getStatementHandle());
if(res == -1) { if(res == -1) {
...@@ -122,4 +117,6 @@ public class SQLiteCursor { ...@@ -122,4 +117,6 @@ public class SQLiteCursor {
native double columnDoubleValue(int statementHandle, int columnIndex); native double columnDoubleValue(int statementHandle, int columnIndex);
native String columnStringValue(int statementHandle, int columnIndex); native String columnStringValue(int statementHandle, int columnIndex);
native byte[] columnByteArrayValue(int statementHandle, int columnIndex); native byte[] columnByteArrayValue(int statementHandle, int columnIndex);
native int columnByteArrayLength(int statementHandle, int columnIndex);
native int columnByteBufferValue(int statementHandle, int columnIndex, ByteBuffer buffer);
} }
...@@ -10,6 +10,8 @@ package org.telegram.SQLite; ...@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import java.nio.ByteBuffer;
public class SQLitePreparedStatement { public class SQLitePreparedStatement {
private boolean isFinalized = false; private boolean isFinalized = false;
private int sqliteStatementHandle; private int sqliteStatementHandle;
...@@ -26,35 +28,34 @@ public class SQLitePreparedStatement { ...@@ -26,35 +28,34 @@ public class SQLitePreparedStatement {
sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql); sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql);
} }
public SQLiteCursor query(Object[] args) throws SQLiteException {
if (args == null || args.length != queryArgsCount) {
throw new IllegalArgumentException();
}
checkFinalized(); public SQLiteCursor query(Object[] args) throws SQLiteException {
if (args == null || args.length != queryArgsCount) {
reset(sqliteStatementHandle); throw new IllegalArgumentException();
}
int i = 1; checkFinalized();
for (Object obj : args) {
if (obj == null) { reset(sqliteStatementHandle);
bindNull(sqliteStatementHandle, i);
} else if (obj instanceof Integer) { int i = 1;
bindInt(sqliteStatementHandle, i, (Integer)obj); for (Object obj : args) {
} else if (obj instanceof Double) { if (obj == null) {
bindDouble(sqliteStatementHandle, i, (Double)obj); bindNull(sqliteStatementHandle, i);
} else if (obj instanceof String) { } else if (obj instanceof Integer) {
bindString(sqliteStatementHandle, i, (String)obj); bindInt(sqliteStatementHandle, i, (Integer)obj);
} else if (obj instanceof byte[]) { } else if (obj instanceof Double) {
bindByteArray(sqliteStatementHandle, i, (byte[])obj); bindDouble(sqliteStatementHandle, i, (Double)obj);
} else { } else if (obj instanceof String) {
throw new IllegalArgumentException(); bindString(sqliteStatementHandle, i, (String)obj);
} } else {
i++; throw new IllegalArgumentException();
} }
i++;
}
return new SQLiteCursor(this); return new SQLiteCursor(this);
} }
public int step() throws SQLiteException { public int step() throws SQLiteException {
return step(sqliteStatementHandle); return step(sqliteStatementHandle);
...@@ -102,8 +103,8 @@ public class SQLitePreparedStatement { ...@@ -102,8 +103,8 @@ public class SQLitePreparedStatement {
bindDouble(sqliteStatementHandle, index, value); bindDouble(sqliteStatementHandle, index, value);
} }
public void bindByteArray(int index, byte[] value) throws SQLiteException { public void bindByteBuffer(int index, ByteBuffer value) throws SQLiteException {
bindByteArray(sqliteStatementHandle, index, value); bindByteBuffer(sqliteStatementHandle, index, value, value.limit());
} }
public void bindString(int index, String value) throws SQLiteException { public void bindString(int index, String value) throws SQLiteException {
...@@ -114,7 +115,7 @@ public class SQLitePreparedStatement { ...@@ -114,7 +115,7 @@ public class SQLitePreparedStatement {
bindLong(sqliteStatementHandle, index, value); bindLong(sqliteStatementHandle, index, value);
} }
native void bindByteArray(int statementHandle, int index, byte[] value) throws SQLiteException; native void bindByteBuffer(int statementHandle, int index, ByteBuffer value, int length) throws SQLiteException;
native void bindString(int statementHandle, int index, String value) throws SQLiteException; native void bindString(int statementHandle, int index, String value) throws SQLiteException;
native void bindInt(int statementHandle, int index, int value) throws SQLiteException; native void bindInt(int statementHandle, int index, int value) throws SQLiteException;
native void bindLong(int statementHandle, int index, long value) throws SQLiteException; native void bindLong(int statementHandle, int index, long value) throws SQLiteException;
......
/*
* This is the source code of Telegram for Android v. 1.4.x.
* 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-2014.
*/
package org.telegram.android;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Environment;
import android.view.Display;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.util.Hashtable;
public class AndroidUtilities {
private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>();
private static int prevOrientation = -10;
private static boolean waitingForSms = false;
private static final Integer smsLock = 2;
public static int externalCacheNotAvailableState = 0;
public static int statusBarHeight = 0;
public static float density = 1;
public static Point displaySize = new Point();
static {
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
checkDisplaySize();
}
public static void lockOrientation(Activity activity) {
if (prevOrientation != -10) {
return;
}
try {
prevOrientation = activity.getRequestedOrientation();
WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
int orientation = activity.getResources().getConfiguration().orientation;
if (rotation == Surface.ROTATION_270) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
} else if (rotation == Surface.ROTATION_90) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_0) {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static void unlockOrientation(Activity activity) {
try {
if (prevOrientation != -10) {
activity.setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static Typeface getTypeface(String assetPath) {
synchronized (typefaceCache) {
if (!typefaceCache.containsKey(assetPath)) {
try {
Typeface t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
typefaceCache.put(assetPath, t);
} catch (Exception e) {
FileLog.e("Typefaces", "Could not get typeface '" + assetPath + "' because " + e.getMessage());
return null;
}
}
return typefaceCache.get(assetPath);
}
}
public static boolean isWaitingForSms() {
boolean value = false;
synchronized (smsLock) {
value = waitingForSms;
}
return value;
}
public static void setWaitingForSms(boolean value) {
synchronized (smsLock) {
waitingForSms = value;
}
}
public static void showKeyboard(View view) {
if (view == null) {
return;
}
InputMethodManager inputManager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);
}
public static boolean isKeyboardShowed(View view) {
if (view == null) {
return false;
}
InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return inputManager.isActive(view);
}
public static void hideKeyboard(View view) {
if (view == null) {
return;
}
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (!imm.isActive()) {
return;
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
public static File getCacheDir() {
if (externalCacheNotAvailableState == 1 || externalCacheNotAvailableState == 0 && Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
externalCacheNotAvailableState = 1;
try {
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
if (file != null) {
return file;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
externalCacheNotAvailableState = 2;
try {
File file = ApplicationLoader.applicationContext.getCacheDir();
if (file != null) {
return file;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return new File("");
}
public static int dp(int value) {
return (int)(Math.max(1, density * value));
}
public static int dpf(float value) {
return (int)Math.ceil(density * value);
}
public static void checkDisplaySize() {
try {
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
if (manager != null) {
Display display = manager.getDefaultDisplay();
if (display != null) {
if(android.os.Build.VERSION.SDK_INT < 13) {
displaySize.set(display.getWidth(), display.getHeight());
} else {
display.getSize(displaySize);
}
FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class AppStartReceiver extends BroadcastReceiver { public class AppStartReceiver extends BroadcastReceiver {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.accounts.AbstractAccountAuthenticator; import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account; import android.accounts.Account;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
...@@ -20,6 +20,16 @@ import android.provider.ContactsContract; ...@@ -20,6 +20,16 @@ import android.provider.ContactsContract;
import android.util.SparseArray; import android.util.SparseArray;
import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -151,6 +161,18 @@ public class ContactsController { ...@@ -151,6 +161,18 @@ public class ContactsController {
} }
} }
public void deleteAllAppAccounts() {
try {
AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
Account[] accounts = am.getAccountsByType("org.telegram.account");
for (Account c : accounts) {
am.removeAccount(c, null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void checkContacts() { public void checkContacts() {
Utilities.globalQueue.postRunnable(new Runnable() { Utilities.globalQueue.postRunnable(new Runnable() {
@Override @Override
...@@ -720,7 +742,7 @@ public class ContactsController { ...@@ -720,7 +742,7 @@ public class ContactsController {
}); });
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress); }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
} }
} else { } else {
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
...@@ -815,7 +837,7 @@ public class ContactsController { ...@@ -815,7 +837,7 @@ public class ContactsController {
processLoadedContacts(res.contacts, res.users, 0); processLoadedContacts(res.contacts, res.users, 0);
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); }, true, RPCRequest.RPCRequestClassGeneric);
} }
} }
...@@ -1540,7 +1562,7 @@ public class ContactsController { ...@@ -1540,7 +1562,7 @@ public class ContactsController {
} }
}); });
} }
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress); }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
} }
public void deleteContact(final ArrayList<TLRPC.User> users) { public void deleteContact(final ArrayList<TLRPC.User> users) {
...@@ -1607,6 +1629,6 @@ public class ContactsController { ...@@ -1607,6 +1629,6 @@ public class ContactsController {
} }
}); });
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); }, true, RPCRequest.RPCRequestClassGeneric);
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.OperationCanceledException; import android.accounts.OperationCanceledException;
...@@ -19,6 +19,8 @@ import android.content.SyncResult; ...@@ -19,6 +19,8 @@ import android.content.SyncResult;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import org.telegram.messenger.FileLog;
public class ContactsSyncAdapterService extends Service { public class ContactsSyncAdapterService extends Service {
private static SyncAdapterImpl sSyncAdapter = null; private static SyncAdapterImpl sSyncAdapter = null;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
...@@ -26,6 +26,9 @@ import android.view.View; ...@@ -26,6 +26,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class Emoji { public class Emoji {
...@@ -202,17 +205,17 @@ public class Emoji { ...@@ -202,17 +205,17 @@ public class Emoji {
0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}}; 0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}};
static { static {
if (Utilities.density <= 1.0f) { if (AndroidUtilities.density <= 1.0f) {
emojiFullSize = 30; emojiFullSize = 30;
} else if (Utilities.density <= 1.5f) { } else if (AndroidUtilities.density <= 1.5f) {
emojiFullSize = 45; emojiFullSize = 45;
} else if (Utilities.density <= 2.0f) { } else if (AndroidUtilities.density <= 2.0f) {
emojiFullSize = 60; emojiFullSize = 60;
} else { } else {
emojiFullSize = 90; emojiFullSize = 90;
} }
drawImgSize = Utilities.dp(20); drawImgSize = AndroidUtilities.dp(20);
bigImgSize = Utilities.dp(30); bigImgSize = AndroidUtilities.dp(30);
for (int j = 1; j < data.length; j++) { for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) { for (int i = 0; i < data[j].length; i++) {
...@@ -228,13 +231,13 @@ public class Emoji { ...@@ -228,13 +231,13 @@ public class Emoji {
try { try {
float scale = 1.0f; float scale = 1.0f;
int imageResize = 1; int imageResize = 1;
if (Utilities.density <= 1.0f) { if (AndroidUtilities.density <= 1.0f) {
scale = 2.0f; scale = 2.0f;
imageResize = 2; imageResize = 2;
} else if (Utilities.density <= 1.5f) { } else if (AndroidUtilities.density <= 1.5f) {
scale = 3.0f; scale = 3.0f;
imageResize = 2; imageResize = 2;
} else if (Utilities.density <= 2.0f) { } else if (AndroidUtilities.density <= 2.0f) {
scale = 2.0f; scale = 2.0f;
} else { } else {
scale = 3.0f; scale = 3.0f;
...@@ -466,7 +469,7 @@ public class Emoji { ...@@ -466,7 +469,7 @@ public class Emoji {
public static class EmojiSpan extends ImageSpan { public static class EmojiSpan extends ImageSpan {
private Paint.FontMetricsInt fontMetrics = null; private Paint.FontMetricsInt fontMetrics = null;
int size = Utilities.dp(20); int size = AndroidUtilities.dp(20);
public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) { public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) {
super(d, verticalAlignment); super(d, verticalAlignment);
...@@ -474,7 +477,7 @@ public class Emoji { ...@@ -474,7 +477,7 @@ public class Emoji {
if (original != null) { if (original != null) {
size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent); size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent);
if (size == 0) { if (size == 0) {
size = Utilities.dp(20); size = AndroidUtilities.dp(20);
} }
} }
} }
...@@ -488,8 +491,8 @@ public class Emoji { ...@@ -488,8 +491,8 @@ public class Emoji {
if (fontMetrics == null) { if (fontMetrics == null) {
int sz = super.getSize(paint, text, start, end, fm); int sz = super.getSize(paint, text, start, end, fm);
int offset = Utilities.dp(8); int offset = AndroidUtilities.dp(8);
int w = Utilities.dp(10); int w = AndroidUtilities.dp(10);
fm.top = -w - offset; fm.top = -w - offset;
fm.bottom = w - offset; fm.bottom = w - offset;
fm.ascent = -w - offset; fm.ascent = -w - offset;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
...@@ -14,6 +14,9 @@ import android.content.Context; ...@@ -14,6 +14,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.json.JSONObject; import org.json.JSONObject;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class GcmBroadcastReceiver extends BroadcastReceiver { public class GcmBroadcastReceiver extends BroadcastReceiver {
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.os.Build; import android.os.Build;
import org.telegram.messenger.FileLog;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
...@@ -22,9 +24,9 @@ import java.util.zip.ZipFile; ...@@ -22,9 +24,9 @@ import java.util.zip.ZipFile;
public class NativeLoader { public class NativeLoader {
private static final long sizes[] = new long[] { private static final long sizes[] = new long[] {
795280, //armeabi 799376, //armeabi
844452, //armeabi-v7a 848548, //armeabi-v7a
1242164, //x86 1246260, //x86
0, //mips 0, //mips
}; };
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class NotificationsService extends Service { public class NotificationsService extends Service {
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class ScreenReceiver extends BroadcastReceiver { public class ScreenReceiver extends BroadcastReceiver {
...@@ -19,13 +21,11 @@ public class ScreenReceiver extends BroadcastReceiver { ...@@ -19,13 +21,11 @@ public class ScreenReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
FileLog.e("tmessages", "screen off"); FileLog.e("tmessages", "screen off");
if (ConnectionsManager.lastPauseTime == 0) { ConnectionsManager.getInstance().setAppPaused(true, true);
ConnectionsManager.lastPauseTime = System.currentTimeMillis();
}
ApplicationLoader.isScreenOn = false; ApplicationLoader.isScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
FileLog.e("tmessages", "screen on"); FileLog.e("tmessages", "screen on");
ConnectionsManager.resetLastPauseTime(); ConnectionsManager.getInstance().setAppPaused(false, true);
ApplicationLoader.isScreenOn = true; ApplicationLoader.isScreenOn = true;
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
...@@ -15,6 +15,9 @@ import android.content.SharedPreferences; ...@@ -15,6 +15,9 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SmsMessage; import android.telephony.SmsMessage;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -25,7 +28,7 @@ public class SmsListener extends BroadcastReceiver { ...@@ -25,7 +28,7 @@ public class SmsListener extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
if (!Utilities.isWaitingForSms()) { if (!AndroidUtilities.isWaitingForSms()) {
return; return;
} }
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
......
...@@ -25,6 +25,4 @@ public class Action { ...@@ -25,6 +25,4 @@ public class Action {
public void cancel() { public void cancel() {
} }
public int state;
} }
...@@ -18,6 +18,8 @@ public class BuffersStorage { ...@@ -18,6 +18,8 @@ public class BuffersStorage {
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 final ArrayList<ByteBufferDesc> freeBuffersBig;
private boolean isThreadSafe;
private final static Integer sync = 1;
private static volatile BuffersStorage Instance = null; private static volatile BuffersStorage Instance = null;
public static BuffersStorage getInstance() { public static BuffersStorage getInstance() {
...@@ -26,14 +28,15 @@ public class BuffersStorage { ...@@ -26,14 +28,15 @@ public class BuffersStorage {
synchronized (BuffersStorage.class) { synchronized (BuffersStorage.class) {
localInstance = Instance; localInstance = Instance;
if (localInstance == null) { if (localInstance == null) {
Instance = localInstance = new BuffersStorage(); Instance = localInstance = new BuffersStorage(true);
} }
} }
} }
return localInstance; return localInstance;
} }
public BuffersStorage() { public BuffersStorage(boolean threadSafe) {
isThreadSafe = threadSafe;
freeBuffers128 = new ArrayList<ByteBufferDesc>(); freeBuffers128 = new ArrayList<ByteBufferDesc>();
freeBuffers1024 = new ArrayList<ByteBufferDesc>(); freeBuffers1024 = new ArrayList<ByteBufferDesc>();
freeBuffers4096 = new ArrayList<ByteBufferDesc>(); freeBuffers4096 = new ArrayList<ByteBufferDesc>();
...@@ -44,91 +47,58 @@ public class BuffersStorage { ...@@ -44,91 +47,58 @@ public class BuffersStorage {
for (int a = 0; a < 5; a++) { for (int a = 0; a < 5; a++) {
freeBuffers128.add(new ByteBufferDesc(128)); freeBuffers128.add(new ByteBufferDesc(128));
} }
// for (int a = 0; a < 5; a++) {
// freeBuffers1024.add(new ByteBufferDesc(1024 + 200));
// }
// for (int a = 0; a < 2; a++) {
// freeBuffers4096.add(new ByteBufferDesc(4096 + 200));
// }
// for (int a = 0; a < 2; a++) {
// freeBuffers16384.add(new ByteBufferDesc(16384 + 200));
// }
// for (int a = 0; a < 2; a++) {
// freeBuffers32768.add(new ByteBufferDesc(40000));
// }
} }
public ByteBufferDesc getFreeBuffer(int size) { public ByteBufferDesc getFreeBuffer(int size) {
if (size <= 0) {
return null;
}
int byteCount = 0;
ArrayList<ByteBufferDesc> arrayToGetFrom = null;
ByteBufferDesc buffer = null; ByteBufferDesc buffer = null;
if (size <= 128) { if (size <= 128) {
synchronized (freeBuffers128) { arrayToGetFrom = freeBuffers128;
if (freeBuffers128.size() > 0) { byteCount = 128;
buffer = freeBuffers128.get(0);
freeBuffers128.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(128);
FileLog.e("tmessages", "create new 128 buffer");
}
} else if (size <= 1024 + 200) { } else if (size <= 1024 + 200) {
synchronized (freeBuffers1024) { arrayToGetFrom = freeBuffers1024;
if (freeBuffers1024.size() > 0) { byteCount = 1024 + 200;
buffer = freeBuffers1024.get(0);
freeBuffers1024.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(1024 + 200);
FileLog.e("tmessages", "create new 1024 buffer");
}
} else if (size <= 4096 + 200) { } else if (size <= 4096 + 200) {
synchronized (freeBuffers4096) { arrayToGetFrom = freeBuffers4096;
if (freeBuffers4096.size() > 0) { byteCount = 4096 + 200;
buffer = freeBuffers4096.get(0);
freeBuffers4096.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(4096 + 200);
FileLog.e("tmessages", "create new 4096 buffer");
}
} else if (size <= 16384 + 200) { } else if (size <= 16384 + 200) {
synchronized (freeBuffers16384) { arrayToGetFrom = freeBuffers16384;
if (freeBuffers16384.size() > 0) { byteCount = 16384 + 200;
buffer = freeBuffers16384.get(0);
freeBuffers16384.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(16384 + 200);
FileLog.e("tmessages", "create new 16384 buffer");
}
} else if (size <= 40000) { } else if (size <= 40000) {
synchronized (freeBuffers32768) { arrayToGetFrom = freeBuffers32768;
if (freeBuffers32768.size() > 0) { byteCount = 40000;
buffer = freeBuffers32768.get(0);
freeBuffers32768.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(40000);
FileLog.e("tmessages", "create new 40000 buffer");
}
} else if (size <= 280000) { } else if (size <= 280000) {
synchronized (freeBuffersBig) { arrayToGetFrom = freeBuffersBig;
if (freeBuffersBig.size() > 0) { byteCount = 280000;
buffer = freeBuffersBig.get(0); } else {
freeBuffersBig.remove(0); buffer = new ByteBufferDesc(size);
}
if (arrayToGetFrom != null) {
if (isThreadSafe) {
synchronized (sync) {
if (arrayToGetFrom.size() > 0) {
buffer = arrayToGetFrom.get(0);
arrayToGetFrom.remove(0);
}
}
} else {
if (arrayToGetFrom.size() > 0) {
buffer = arrayToGetFrom.get(0);
arrayToGetFrom.remove(0);
} }
} }
if (buffer == null) { if (buffer == null) {
buffer = new ByteBufferDesc(280000); buffer = new ByteBufferDesc(byteCount);
FileLog.e("tmessages", "create new big buffer"); FileLog.e("tmessages", "create new " + byteCount + " buffer");
} }
} else {
buffer = new ByteBufferDesc(size);
} }
buffer.buffer.limit(size).rewind(); buffer.buffer.limit(size).rewind();
return buffer; return buffer;
} }
...@@ -137,40 +107,34 @@ public class BuffersStorage { ...@@ -137,40 +107,34 @@ public class BuffersStorage {
if (buffer == null) { if (buffer == null) {
return; return;
} }
int maxCount = 10;
ArrayList<ByteBufferDesc> arrayToReuse = null;
if (buffer.buffer.capacity() == 128) { if (buffer.buffer.capacity() == 128) {
synchronized (freeBuffers128) { arrayToReuse = freeBuffers128;
if (freeBuffers128.size() < 10) {
freeBuffers128.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 1024 + 200) { } else if (buffer.buffer.capacity() == 1024 + 200) {
synchronized (freeBuffers1024) { arrayToReuse = freeBuffers1024;
if (freeBuffers1024.size() < 10) { } if (buffer.buffer.capacity() == 4096 + 200) {
freeBuffers1024.add(buffer); arrayToReuse = freeBuffers4096;
}
}
} else if (buffer.buffer.capacity() == 4096 + 200) {
synchronized (freeBuffers4096) {
if (freeBuffers4096.size() < 10) {
freeBuffers4096.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 16384 + 200) { } else if (buffer.buffer.capacity() == 16384 + 200) {
synchronized (freeBuffers16384) { arrayToReuse = freeBuffers16384;
if (freeBuffers16384.size() < 10) {
freeBuffers16384.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 40000) { } else if (buffer.buffer.capacity() == 40000) {
synchronized (freeBuffers32768) { arrayToReuse = freeBuffers32768;
if (freeBuffers32768.size() < 10) {
freeBuffers32768.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 280000) { } else if (buffer.buffer.capacity() == 280000) {
synchronized (freeBuffersBig) { arrayToReuse = freeBuffersBig;
if (freeBuffersBig.size() < 4) { maxCount = 10;
freeBuffersBig.add(buffer); }
if (arrayToReuse != null) {
if (isThreadSafe) {
synchronized (sync) {
if (arrayToReuse.size() < maxCount) {
arrayToReuse.add(buffer);
} else {
FileLog.e("tmessages", "too more");
}
}
} else {
if (arrayToReuse.size() < maxCount) {
arrayToReuse.add(buffer);
} }
} }
} }
......
...@@ -25,6 +25,11 @@ public class ByteBufferDesc extends AbsSerializedData { ...@@ -25,6 +25,11 @@ public class ByteBufferDesc extends AbsSerializedData {
justCalc = calculate; justCalc = calculate;
} }
public ByteBufferDesc(byte[] bytes) {
buffer = ByteBuffer.wrap(bytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
}
public int position() { public int position() {
return buffer.position(); return buffer.position();
} }
...@@ -397,11 +402,13 @@ public class ByteBufferDesc extends AbsSerializedData { ...@@ -397,11 +402,13 @@ public class ByteBufferDesc extends AbsSerializedData {
sl = 4; sl = 4;
} }
ByteBufferDesc b = BuffersStorage.getInstance().getFreeBuffer(l); ByteBufferDesc b = BuffersStorage.getInstance().getFreeBuffer(l);
int old = buffer.limit(); if (b != null) {
buffer.limit(buffer.position() + l); int old = buffer.limit();
b.buffer.put(buffer); buffer.limit(buffer.position() + l);
buffer.limit(old); b.buffer.put(buffer);
b.buffer.position(0); buffer.limit(old);
b.buffer.position(0);
}
int i = sl; int i = sl;
while((l + i) % 4 != 0) { while((l + i) % 4 != 0) {
buffer.get(); buffer.get();
......
...@@ -74,6 +74,9 @@ public class ConnectionContext extends PyroClientAdapter { ...@@ -74,6 +74,9 @@ public class ConnectionContext extends PyroClientAdapter {
} }
public void addMessageToConfirm(long messageId) { public void addMessageToConfirm(long messageId) {
if (messagesIdsForConfirmation.contains(messageId)) {
return;
}
messagesIdsForConfirmation.add(messageId); messagesIdsForConfirmation.add(messageId);
} }
......
...@@ -35,7 +35,7 @@ public class Datacenter { ...@@ -35,7 +35,7 @@ public class Datacenter {
private volatile int currentAddressNum = 0; private volatile int currentAddressNum = 0;
public TcpConnection connection; public TcpConnection connection;
private ArrayList<TcpConnection> downloadConnections = new ArrayList<TcpConnection>(); private TcpConnection downloadConnection;
private TcpConnection uploadConnection; private TcpConnection uploadConnection;
public TcpConnection pushConnection; public TcpConnection pushConnection;
...@@ -327,7 +327,7 @@ public class Datacenter { ...@@ -327,7 +327,7 @@ public class Datacenter {
if (uploadConnection != null) { if (uploadConnection != null) {
uploadConnection.suspendConnection(true); uploadConnection.suspendConnection(true);
} }
for (TcpConnection downloadConnection : downloadConnections) { if (downloadConnection != null) {
downloadConnection.suspendConnection(true); downloadConnection.suspendConnection(true);
} }
} }
...@@ -339,7 +339,7 @@ public class Datacenter { ...@@ -339,7 +339,7 @@ public class Datacenter {
if (uploadConnection != null) { if (uploadConnection != null) {
sessions.add(uploadConnection.getSissionId()); sessions.add(uploadConnection.getSissionId());
} }
for (TcpConnection downloadConnection : downloadConnections) { if (downloadConnection != null) {
sessions.add(downloadConnection.getSissionId()); sessions.add(downloadConnection.getSissionId());
} }
} }
...@@ -351,26 +351,21 @@ public class Datacenter { ...@@ -351,26 +351,21 @@ public class Datacenter {
if (uploadConnection != null) { if (uploadConnection != null) {
uploadConnection.recreateSession(); uploadConnection.recreateSession();
} }
for (TcpConnection downloadConnection : downloadConnections) { if (downloadConnection != null) {
downloadConnection.recreateSession(); downloadConnection.recreateSession();
} }
} }
public TcpConnection getDownloadConnection(int num, TcpConnection.TcpConnectionDelegate delegate) { public TcpConnection getDownloadConnection(TcpConnection.TcpConnectionDelegate delegate) {
if (num >= 0 && authKey != null) { if (authKey != null) {
TcpConnection downloadConnection = null; if (downloadConnection == null) {
if (num < downloadConnections.size()) {
downloadConnection = downloadConnections.get(num);
} else {
downloadConnection = new TcpConnection(datacenterId); downloadConnection = new TcpConnection(datacenterId);
downloadConnection.delegate = delegate; downloadConnection.delegate = delegate;
downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia; downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia;
downloadConnections.add(downloadConnection);
} }
downloadConnection.connect(); downloadConnection.connect();
return downloadConnection;
} }
return null; return downloadConnection;
} }
public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) { public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) {
......
...@@ -41,6 +41,24 @@ public class DispatchQueue extends Thread { ...@@ -41,6 +41,24 @@ public class DispatchQueue extends Thread {
} }
} }
public void cancelRunnable(Runnable runnable) {
if (handler == null) {
synchronized (handlerSyncObject) {
if (handler == null) {
try {
handlerSyncObject.wait();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
if (handler != null) {
handler.removeCallbacks(runnable);
}
}
public void postRunnable(Runnable runnable) { public void postRunnable(Runnable runnable) {
postRunnable(runnable, 0); postRunnable(runnable, 0);
} }
......
...@@ -54,7 +54,7 @@ public class ExportAuthorizationAction extends Action { ...@@ -54,7 +54,7 @@ public class ExportAuthorizationAction extends Action {
} }
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); });
} }
void beginImport() { void beginImport() {
......
...@@ -18,6 +18,7 @@ import android.net.Uri; ...@@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import org.telegram.android.AndroidUtilities;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.ImageReceiver; import org.telegram.ui.Views.ImageReceiver;
...@@ -291,10 +292,8 @@ public class FileLoader { ...@@ -291,10 +292,8 @@ public class FileLoader {
if (runtimeHack != null) { if (runtimeHack != null) {
runtimeHack.trackAlloc(oldBitmap.getRowBytes() * oldBitmap.getHeight()); runtimeHack.trackAlloc(oldBitmap.getRowBytes() * oldBitmap.getHeight());
} }
if (Build.VERSION.SDK_INT < 11) { if (!oldBitmap.isRecycled()) {
if (!oldBitmap.isRecycled()) { oldBitmap.recycle();
oldBitmap.recycle();
}
} }
} }
} }
...@@ -466,6 +465,7 @@ public class FileLoader { ...@@ -466,6 +465,7 @@ public class FileLoader {
} }
FileLoadOperation operation = loadOperationPaths.get(fileName); FileLoadOperation operation = loadOperationPaths.get(fileName);
if (operation != null) { if (operation != null) {
loadOperationPaths.remove(fileName);
if (audio != null) { if (audio != null) {
audioLoadOperationQueue.remove(operation); audioLoadOperationQueue.remove(operation);
} else if (photo != null) { } else if (photo != null) {
...@@ -946,8 +946,14 @@ public class FileLoader { ...@@ -946,8 +946,14 @@ public class FileLoader {
} }
} }
}; };
boolean isLocalFile = false;
if (httpUrl != null && !httpUrl.startsWith("http")) {
isLocalFile = true;
}
img.loadOperation = loadOperation; img.loadOperation = loadOperation;
if (runningOperation.size() < maxConcurentLoadingOpertaionsCount) { if (runningOperation.size() < maxConcurentLoadingOpertaionsCount || isLocalFile) {
loadOperation.start(); loadOperation.start();
runningOperation.add(loadOperation); runningOperation.add(loadOperation);
} else { } else {
...@@ -1119,7 +1125,7 @@ public class FileLoader { ...@@ -1119,7 +1125,7 @@ public class FileLoader {
try { try {
if (!cache) { if (!cache) {
String fileName = location.volume_id + "_" + location.local_id + ".jpg"; String fileName = location.volume_id + "_" + location.local_id + ".jpg";
final File cacheFile = new File(Utilities.getCacheDir(), fileName); final File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
FileOutputStream stream = new FileOutputStream(cacheFile); FileOutputStream stream = new FileOutputStream(cacheFile);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream); scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
size.size = (int)stream.getChannel().size(); size.size = (int)stream.getChannel().size();
...@@ -1129,10 +1135,8 @@ public class FileLoader { ...@@ -1129,10 +1135,8 @@ public class FileLoader {
size.bytes = stream.toByteArray(); size.bytes = stream.toByteArray();
size.size = size.bytes.length; size.size = size.bytes.length;
} }
if (Build.VERSION.SDK_INT < 11) { if (scaledBitmap != bitmap) {
if (scaledBitmap != bitmap) { scaledBitmap.recycle();
scaledBitmap.recycle();
}
} }
return size; return size;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -11,6 +11,7 @@ package org.telegram.messenger; ...@@ -11,6 +11,7 @@ package org.telegram.messenger;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import org.telegram.android.FastDateFormat;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import java.io.File; import java.io.File;
......
...@@ -31,7 +31,7 @@ public class FileUploadOperation { ...@@ -31,7 +31,7 @@ public class FileUploadOperation {
private byte[] key; private byte[] key;
private byte[] iv; private byte[] iv;
private byte[] ivChange; private byte[] ivChange;
private int fingerprint; private int fingerprint = 0;
private boolean isBigFile = false; private boolean isBigFile = false;
FileInputStream stream; FileInputStream stream;
MessageDigest mdEnc = null; MessageDigest mdEnc = null;
...@@ -57,11 +57,9 @@ public class FileUploadOperation { ...@@ -57,11 +57,9 @@ public class FileUploadOperation {
System.arraycopy(key, 0, arr, 0, 32); System.arraycopy(key, 0, arr, 0, 32);
System.arraycopy(iv, 0, arr, 32, 32); System.arraycopy(iv, 0, arr, 32, 32);
byte[] digest = md.digest(arr); byte[] digest = md.digest(arr);
byte[] fingerprintBytes = new byte[4];
for (int a = 0; a < 4; a++) { for (int a = 0; a < 4; a++) {
fingerprintBytes[a] = (byte)(digest[a] ^ digest[a + 4]); fingerprint |= ((digest[a] ^ digest[a + 4]) & 0xFF) << (a * 8);
} }
fingerprint = Utilities.bytesToInt(fingerprintBytes);
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
...@@ -138,7 +136,7 @@ public class FileUploadOperation { ...@@ -138,7 +136,7 @@ public class FileUploadOperation {
for (int a = 0; a < toAdd; a++) { for (int a = 0; a < toAdd; a++) {
sendBuffer.writeByte(0); sendBuffer.writeByte(0);
} }
Utilities.aesIgeEncryption2(sendBuffer.buffer, key, ivChange, true, true, readed + toAdd); Utilities.aesIgeEncryption(sendBuffer.buffer, key, ivChange, true, true, 0, readed + toAdd);
} }
sendBuffer.rewind(); sendBuffer.rewind();
if (!isBigFile) { if (!isBigFile) {
...@@ -211,11 +209,6 @@ public class FileUploadOperation { ...@@ -211,11 +209,6 @@ public class FileUploadOperation {
delegate.didFailedUploadingFile(FileUploadOperation.this); delegate.didFailedUploadingFile(FileUploadOperation.this);
} }
} }
}, new RPCRequest.RPCProgressDelegate() {
@Override
public void progress(int length, int progress) {
}
}, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID); }, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID);
} }
} }
...@@ -14,9 +14,6 @@ public class RPCRequest { ...@@ -14,9 +14,6 @@ public class RPCRequest {
public interface RPCRequestDelegate { public interface RPCRequestDelegate {
void run(TLObject response, TLRPC.TL_error error); void run(TLObject response, TLRPC.TL_error error);
} }
public interface RPCProgressDelegate {
void progress(int length, int progress);
}
public interface RPCQuickAckDelegate { public interface RPCQuickAckDelegate {
void quickAck(); void quickAck();
} }
...@@ -29,7 +26,7 @@ public class RPCRequest { ...@@ -29,7 +26,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; public static int RPCRequestClassTryDifferentDc = 256;
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia); static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
...@@ -38,14 +35,15 @@ public class RPCRequest { ...@@ -38,14 +35,15 @@ public class RPCRequest {
int serverFailureCount; int serverFailureCount;
int flags; int flags;
public int retryCount = 0; protected int retryCount = 0;
protected int lastResendTime = 0;
protected boolean completed = false;
TLObject rawRequest; TLObject rawRequest;
TLObject rpcRequest; TLObject rpcRequest;
int serializedLength; int serializedLength;
RPCRequestDelegate completionBlock; RPCRequestDelegate completionBlock;
RPCProgressDelegate progressBlock;
RPCQuickAckDelegate quickAckBlock; RPCQuickAckDelegate quickAckBlock;
boolean requiresCompletion; boolean requiresCompletion;
......
...@@ -412,6 +412,14 @@ public class TLClassStore { ...@@ -412,6 +412,14 @@ public class TLClassStore {
classStore.put(TLRPC.TL_decryptedMessageActionFlushHistory.constructor, TLRPC.TL_decryptedMessageActionFlushHistory.class); classStore.put(TLRPC.TL_decryptedMessageActionFlushHistory.constructor, TLRPC.TL_decryptedMessageActionFlushHistory.class);
classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class); classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class);
classStore.put(TLRPC.TL_messageEcryptedAction.constructor, TLRPC.TL_messageEcryptedAction.class); classStore.put(TLRPC.TL_messageEcryptedAction.constructor, TLRPC.TL_messageEcryptedAction.class);
classStore.put(TLRPC.TL_decryptedMessageActionNotifyLayer.constructor, TLRPC.TL_decryptedMessageActionNotifyLayer.class);
classStore.put(TLRPC.TL_decryptedMessageActionReadMessages.constructor, TLRPC.TL_decryptedMessageActionReadMessages.class);
classStore.put(TLRPC.TL_updateNotifySettings.constructor, TLRPC.TL_updateNotifySettings.class);
classStore.put(TLRPC.TL_updateUserBlocked.constructor, TLRPC.TL_updateUserBlocked.class);
classStore.put(TLRPC.TL_notifyAll.constructor, TLRPC.TL_notifyAll.class);
classStore.put(TLRPC.TL_notifyChats.constructor, TLRPC.TL_notifyChats.class);
classStore.put(TLRPC.TL_notifyUsers.constructor, TLRPC.TL_notifyUsers.class);
classStore.put(TLRPC.TL_notifyPeer.constructor, TLRPC.TL_notifyPeer.class);
classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class); classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class);
classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class); classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);
...@@ -427,6 +435,10 @@ public class TLClassStore { ...@@ -427,6 +435,10 @@ public class TLClassStore {
classStore.put(TLRPC.TL_messageActionLoginUnknownLocation.constructor, TLRPC.TL_messageActionLoginUnknownLocation.class); classStore.put(TLRPC.TL_messageActionLoginUnknownLocation.constructor, TLRPC.TL_messageActionLoginUnknownLocation.class);
classStore.put(TLRPC.TL_encryptedChat_old.constructor, TLRPC.TL_encryptedChat_old.class); classStore.put(TLRPC.TL_encryptedChat_old.constructor, TLRPC.TL_encryptedChat_old.class);
classStore.put(TLRPC.TL_encryptedChatRequested_old.constructor, TLRPC.TL_encryptedChatRequested_old.class); classStore.put(TLRPC.TL_encryptedChatRequested_old.constructor, TLRPC.TL_encryptedChatRequested_old.class);
classStore.put(TLRPC.TL_decryptedMessageMediaVideo_old.constructor, TLRPC.TL_decryptedMessageMediaVideo_old.class);
classStore.put(TLRPC.TL_decryptedMessageMediaAudio_old.constructor, TLRPC.TL_decryptedMessageMediaAudio_old.class);
classStore.put(TLRPC.TL_audio_old.constructor, TLRPC.TL_audio_old.class);
classStore.put(TLRPC.TL_video_old.constructor, TLRPC.TL_video_old.class);
} }
static TLClassStore store = null; static TLClassStore store = null;
......
...@@ -42,4 +42,10 @@ public class TLObject { ...@@ -42,4 +42,10 @@ public class TLObject {
public void freeResources() { public void freeResources() {
} }
public int getObjectSize() {
ByteBufferDesc bufferDesc = new ByteBufferDesc(true);
serializeToStream(bufferDesc);
return bufferDesc.length();
}
} }
...@@ -12,6 +12,7 @@ import android.content.Context; ...@@ -12,6 +12,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Base64; import android.util.Base64;
import org.telegram.android.MessagesStorage;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import java.io.File; import java.io.File;
...@@ -197,6 +198,5 @@ public class UserConfig { ...@@ -197,6 +198,5 @@ public class UserConfig {
contactsVersion = 1; contactsVersion = 1;
saveIncomingPhotos = false; saveIncomingPhotos = false;
saveConfig(true); saveConfig(true);
MessagesController.getInstance().deleteAllAppAccounts();
} }
} }
...@@ -14,10 +14,10 @@ import android.view.View; ...@@ -14,10 +14,10 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ContactsController; import org.telegram.android.ContactsController;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.SectionedBaseAdapter; import org.telegram.ui.Views.SectionedBaseAdapter;
......
...@@ -13,9 +13,9 @@ import android.view.View; ...@@ -13,9 +13,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ContactsController; import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.ChatOrUserCell;
......
...@@ -20,11 +20,11 @@ import android.widget.Button; ...@@ -20,11 +20,11 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.LocaleController; import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.ActionBar.BaseFragment;
public class ChatProfileChangeNameActivity extends BaseFragment { public class ChatProfileChangeNameActivity extends BaseFragment {
...@@ -108,14 +108,14 @@ public class ChatProfileChangeNameActivity extends BaseFragment { ...@@ -108,14 +108,14 @@ public class ChatProfileChangeNameActivity extends BaseFragment {
boolean animations = preferences.getBoolean("view_animations", true); boolean animations = preferences.getBoolean("view_animations", true);
if (!animations) { if (!animations) {
firstNameField.requestFocus(); firstNameField.requestFocus();
Utilities.showKeyboard(firstNameField); AndroidUtilities.showKeyboard(firstNameField);
} }
} }
@Override @Override
public void onOpenAnimationEnd() { public void onOpenAnimationEnd() {
firstNameField.requestFocus(); firstNameField.requestFocus();
Utilities.showKeyboard(firstNameField); AndroidUtilities.showKeyboard(firstNameField);
} }
private void saveName() { private void saveName() {
......
...@@ -24,7 +24,7 @@ import android.widget.ListView; ...@@ -24,7 +24,7 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.ui.Adapters.BaseFragmentAdapter; import org.telegram.ui.Adapters.BaseFragmentAdapter;
......
...@@ -24,7 +24,7 @@ import android.view.animation.AnimationUtils; ...@@ -24,7 +24,7 @@ import android.view.animation.AnimationUtils;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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