Skip to content

Commit

Permalink
Update to 3.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Apr 22, 2016
1 parent a7513b3 commit 0647377
Show file tree
Hide file tree
Showing 732 changed files with 12,482 additions and 6,470 deletions.
10 changes: 6 additions & 4 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repositories {
}

dependencies {
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:support-v4:23.3.0'
compile "com.google.android.gms:play-services-gcm:8.4.0"
compile "com.google.android.gms:play-services-maps:8.4.0"
compile 'net.hockeyapp.android:HockeySDK:3.6.+'
Expand All @@ -14,7 +14,7 @@ dependencies {

android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
buildToolsVersion '23.0.3'

useLibrary 'org.apache.http.legacy'
defaultConfig.applicationId = "org.telegram.messenger"
Expand Down Expand Up @@ -63,7 +63,7 @@ android {
}
}

defaultConfig.versionCode = 767
defaultConfig.versionCode = 787

sourceSets.main {
jniLibs.srcDir 'libs'
Expand Down Expand Up @@ -114,6 +114,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionName "3.7.0"
versionName "3.8.1"
}
}

apply plugin: 'com.google.gms.google-services'
75 changes: 75 additions & 0 deletions TMessagesProj/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"project_info": {
"project_id": "tmessages2",
"project_number": "760348033671",
"name": "Telegram"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:760348033671:android:f6afd7b67eae3860",
"client_id": "android:org.telegram.messenger",
"client_type": 1,
"android_client_info": {
"package_name": "org.telegram.messenger",
"certificate_hash": []
}
},
"oauth_client": [],
"api_key": [],
"services": {
"analytics_service": {
"status": 1
},
"cloud_messaging_service": {
"status": 2,
"apns_config": []
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"google_signin_service": {
"status": 1
},
"ads_service": {
"status": 1
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:760348033671:android:dc022572c167a16c",
"client_id": "android:org.telegram.messenger.beta",
"client_type": 1,
"android_client_info": {
"package_name": "org.telegram.messenger.beta",
"certificate_hash": []
}
},
"oauth_client": [],
"api_key": [],
"services": {
"analytics_service": {
"status": 1
},
"cloud_messaging_service": {
"status": 2,
"apns_config": []
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"google_signin_service": {
"status": 1
},
"ads_service": {
"status": 1
}
}
}
],
"client_info": [],
"ARTIFACT_VERSION": "1"
}
4 changes: 2 additions & 2 deletions TMessagesProj/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false

LOCAL_MODULE := tmessages.20
LOCAL_MODULE := tmessages.21
LOCAL_CFLAGS := -w -std=c11 -Os -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
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 -ffast-math -D__STDC_CONSTANT_MACROS
LOCAL_CPPFLAGS := -DBSD=1 -ffast-math -Os -funroll-loops -std=c++11
LOCAL_LDLIBS := -ljnigraphics -llog -lz
LOCAL_LDLIBS := -ljnigraphics -llog -lz -latomic
LOCAL_STATIC_LIBRARIES := webp sqlite tgnet breakpad avformat avcodec avutil

LOCAL_SRC_FILES := \
Expand Down
11 changes: 8 additions & 3 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ void setNetworkAvailable(JNIEnv *env, jclass c, jboolean value) {
ConnectionsManager::getInstance().setNetworkAvailable(value);
}

void setPushConnectionEnabled(JNIEnv *env, jclass c, jboolean value) {
ConnectionsManager::getInstance().setPushConnectionEnabled(value);
}

class Delegate : public ConnectiosManagerDelegate {

void onUpdate() {
Expand Down Expand Up @@ -194,15 +198,15 @@ class Delegate : public ConnectiosManagerDelegate {
}
};

void init(JNIEnv *env, jclass c, jint version, jint layer, jint apiId, jstring deviceModel, jstring systemVersion, jstring appVersion, jstring langCode, jstring configPath, jstring logPath, jint userId) {
void init(JNIEnv *env, jclass c, jint version, jint layer, jint apiId, jstring deviceModel, jstring systemVersion, jstring appVersion, jstring langCode, jstring configPath, jstring logPath, jint userId, jboolean enablePushConnection) {
const char *deviceModelStr = env->GetStringUTFChars(deviceModel, 0);
const char *systemVersionStr = env->GetStringUTFChars(systemVersion, 0);
const char *appVersionStr = env->GetStringUTFChars(appVersion, 0);
const char *langCodeStr = env->GetStringUTFChars(langCode, 0);
const char *configPathStr = env->GetStringUTFChars(configPath, 0);
const char *logPathStr = env->GetStringUTFChars(logPath, 0);

ConnectionsManager::getInstance().init(version, layer, apiId, std::string(deviceModelStr), std::string(systemVersionStr), std::string(appVersionStr), std::string(langCodeStr), std::string(configPathStr), std::string(logPathStr), userId, true);
ConnectionsManager::getInstance().init(version, layer, apiId, std::string(deviceModelStr), std::string(systemVersionStr), std::string(appVersionStr), std::string(langCodeStr), std::string(configPathStr), std::string(logPathStr), userId, true, enablePushConnection);

if (deviceModelStr != 0) {
env->ReleaseStringUTFChars(deviceModel, deviceModelStr);
Expand Down Expand Up @@ -242,13 +246,14 @@ static JNINativeMethod ConnectionsManagerMethods[] = {
{"native_applyDatacenterAddress", "(ILjava/lang/String;I)V", (void *) applyDatacenterAddress},
{"native_getConnectionState", "()I", (void *) getConnectionState},
{"native_setUserId", "(I)V", (void *) setUserId},
{"native_init", "(IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V", (void *) init},
{"native_init", "(IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V", (void *) init},
{"native_switchBackend", "()V", (void *) switchBackend},
{"native_pauseNetwork", "()V", (void *) pauseNetwork},
{"native_resumeNetwork", "(Z)V", (void *) resumeNetwork},
{"native_updateDcSettings", "()V", (void *) updateDcSettings},
{"native_setUseIpv6", "(Z)V", (void *) setUseIpv6},
{"native_setNetworkAvailable", "(Z)V", (void *) setNetworkAvailable},
{"native_setPushConnectionEnabled", "(Z)V", (void *) setPushConnectionEnabled},
{"native_setJava", "(Z)V", (void *) setJava}
};

Expand Down
4 changes: 2 additions & 2 deletions TMessagesProj/jni/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass

JNIEXPORT int Java_org_telegram_messenger_Utilities_pinBitmap(JNIEnv *env, jclass class, jobject bitmap) {
if (bitmap == NULL) {
return;
return 0;
}
unsigned char *pixels;
return AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 ? 1 : 0;
}

JNIEXPORT int Java_org_telegram_messenger_Utilities_unpinBitmap(JNIEnv *env, jclass class, jobject bitmap) {
JNIEXPORT void Java_org_telegram_messenger_Utilities_unpinBitmap(JNIEnv *env, jclass class, jobject bitmap) {
if (bitmap == NULL) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/tgnet/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void Connection::onDisconnected(int reason) {
ConnectionsManager::getInstance().onConnectionClosed(this);

uint32_t datacenterId = currentDatacenter->getDatacenterId();
if (connectionState == TcpConnectionStageIdle && connectionType == ConnectionTypeGeneric && (datacenterId == ConnectionsManager::getInstance().currentDatacenterId || datacenterId == ConnectionsManager::getInstance().movingToDatacenterId)) {
if (connectionState == TcpConnectionStageIdle && connectionType == ConnectionTypeGeneric && (currentDatacenter->isHandshaking() || datacenterId == ConnectionsManager::getInstance().currentDatacenterId || datacenterId == ConnectionsManager::getInstance().movingToDatacenterId)) {
connectionState = TcpConnectionStageReconnecting;
failedConnectionCount++;
if (failedConnectionCount == 1) {
Expand Down
64 changes: 40 additions & 24 deletions TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,24 @@ void ConnectionsManager::select() {
}

Datacenter *datacenter = getDatacenterWithId(currentDatacenterId);
if ((sendingPushPing && abs(now - lastPushPingTime) >= 30000) || abs(now - lastPushPingTime) >= 60000 * 3 + 10000) {
lastPushPingTime = 0;
sendingPushPing = false;
if (datacenter != nullptr) {
Connection *connection = datacenter->getPushConnection(false);
if (connection != nullptr) {
connection->suspendConnection();
if (pushConnectionEnabled) {
if ((sendingPushPing && abs(now - lastPushPingTime) >= 30000) || abs(now - lastPushPingTime) >= 60000 * 3 + 10000) {
lastPushPingTime = 0;
sendingPushPing = false;
if (datacenter != nullptr) {
Connection *connection = datacenter->getPushConnection(false);
if (connection != nullptr) {
connection->suspendConnection();
}
}
DEBUG_D("push ping timeout");
}
DEBUG_D("push ping timeout");
}
if (abs(now - lastPushPingTime) >= 60000 * 3) {
DEBUG_D("time for push ping");
lastPushPingTime = now;
if (datacenter != nullptr) {
sendPing(datacenter, true);
if (abs(now - lastPushPingTime) >= 60000 * 3) {
DEBUG_D("time for push ping");
lastPushPingTime = now;
if (datacenter != nullptr) {
sendPing(datacenter, true);
}
}
}

Expand Down Expand Up @@ -220,7 +222,7 @@ void ConnectionsManager::select() {
return;
} else {
lastPauseTime = now;
DEBUG_D("don't sleep 30 seconds because of salt, upload or download request");
DEBUG_D("don't sleep because of salt, upload or download request");
}
}
if (networkPaused) {
Expand Down Expand Up @@ -285,7 +287,7 @@ void *ConnectionsManager::ThreadProc(void *data) {
javaVm->AttachCurrentThread(&jniEnv, NULL);
#endif
ConnectionsManager *networkManager = (ConnectionsManager *) (data);
if (networkManager->currentUserId != 0) {
if (networkManager->currentUserId != 0 && networkManager->pushConnectionEnabled) {
Datacenter *datacenter = networkManager->getDatacenterWithId(networkManager->currentDatacenterId);
if (datacenter != nullptr) {
datacenter->createPushConnection()->setSessionId(networkManager->pushSessionId);
Expand Down Expand Up @@ -595,7 +597,6 @@ void ConnectionsManager::onConnectionConnected(Connection *connection) {
} else {
if (networkPaused && lastPauseTime != 0) {
lastPauseTime = getCurrentTimeMillis();
nextSleepTimeout = 30000;
}
processRequestQueue(connection->getConnectionType(), datacenter->getDatacenterId());
}
Expand Down Expand Up @@ -1210,7 +1211,6 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag
if (connection->connectionType == ConnectionTypePush) {
if (networkPaused) {
lastPauseTime = getCurrentTimeMillis();
nextSleepTimeout = 30000;
DEBUG_D("received internal push: wakeup network in background");
} else if (lastPauseTime != 0) {
lastPauseTime = getCurrentTimeMillis();
Expand All @@ -1234,7 +1234,7 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag
}

void ConnectionsManager::sendPing(Datacenter *datacenter, bool usePushConnection) {
if (usePushConnection && currentUserId == 0) {
if (usePushConnection && (currentUserId == 0 || !usePushConnection)) {
return;
}
Connection *connection = nullptr;
Expand Down Expand Up @@ -1401,7 +1401,7 @@ void ConnectionsManager::sendRequest(TLObject *object, onCompleteFunc onComplete
request->ptr1 = ptr1;
request->ptr2 = ptr2;
request->rpcRequest = wrapInLayer(object, getDatacenterWithId(datacenterId), request);
DEBUG_D("send request wrapped %p - %s", request->rpcRequest.get(), typeid(*request->rpcRequest.get()).name());
DEBUG_D("send request wrapped %p - %s", request->rpcRequest.get(), typeid(*(request->rpcRequest.get())).name());
requestsQueue.push_back(std::unique_ptr<Request>(request));
if (immediate) {
processRequestQueue(0, 0);
Expand Down Expand Up @@ -1452,7 +1452,7 @@ void ConnectionsManager::setUserId(int32_t userId) {
if (currentUserId != userId && userId != 0) {
updateDcSettings(0);
}
if (currentUserId != 0) {
if (currentUserId != 0 && pushConnectionEnabled) {
Datacenter *datacenter = getDatacenterWithId(currentDatacenterId);
if (datacenter != nullptr) {
datacenter->createPushConnection()->setSessionId(pushSessionId);
Expand Down Expand Up @@ -2121,7 +2121,7 @@ void ConnectionsManager::processRequestQueue(uint32_t connectionTypes, uint32_t
request->outgoingQuery = message->outgoingBody;
message->outgoingBody = nullptr;
} else {
DEBUG_D("wrap body(%p, %s) to TL_invokeAfterMsg", message->body.get(), typeid(*message->body.get()).name());
DEBUG_D("wrap body(%p, %s) to TL_invokeAfterMsg", message->body.get(), typeid(*(message->body.get())).name());
request->query = std::move(message->body);
}
message->body = std::unique_ptr<TLObject>(request);
Expand Down Expand Up @@ -2390,7 +2390,23 @@ void ConnectionsManager::setDelegate(ConnectiosManagerDelegate *connectiosManage
delegate = connectiosManagerDelegate;
}

void ConnectionsManager::init(uint32_t version, int32_t layer, int32_t apiId, std::string deviceModel, std::string systemVersion, std::string appVersion, std::string langCode, std::string configPath, std::string logPath, int32_t userId, bool isPaused) {
void ConnectionsManager::setPushConnectionEnabled(bool value) {
pushConnectionEnabled = value;
Datacenter *datacenter = getDatacenterWithId(currentDatacenterId);
if (datacenter != nullptr) {
if (!pushConnectionEnabled) {
Connection *connection = datacenter->getPushConnection(false);
if (connection != nullptr) {
connection->suspendConnection();
}
} else {
datacenter->createPushConnection()->setSessionId(pushSessionId);
sendPing(datacenter, true);
}
}
}

void ConnectionsManager::init(uint32_t version, int32_t layer, int32_t apiId, std::string deviceModel, std::string systemVersion, std::string appVersion, std::string langCode, std::string configPath, std::string logPath, int32_t userId, bool isPaused, bool enablePushConnection) {
currentVersion = version;
currentLayer = layer;
currentApiId = apiId;
Expand All @@ -2401,6 +2417,7 @@ void ConnectionsManager::init(uint32_t version, int32_t layer, int32_t apiId, st
currentLangCode = langCode;
currentUserId = userId;
currentLogPath = logPath;
pushConnectionEnabled = enablePushConnection;
if (isPaused) {
lastPauseTime = getCurrentTimeMillis();
}
Expand All @@ -2423,7 +2440,6 @@ void ConnectionsManager::resumeNetwork(bool partial) {
if (partial) {
if (networkPaused) {
lastPauseTime = getCurrentTimeMillis();
nextSleepTimeout = 30000;
networkPaused = false;
DEBUG_D("wakeup network in background");
} else if (lastPauseTime != 0) {
Expand Down
6 changes: 4 additions & 2 deletions TMessagesProj/jni/tgnet/ConnectionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class ConnectionsManager {
void pauseNetwork();
void setNetworkAvailable(bool value);
void setUseIpv6(bool value);
void init(uint32_t version, int32_t layer, int32_t apiId, std::string deviceModel, std::string systemVersion, std::string appVersion, std::string langCode, std::string configPath, std::string logPath, int32_t userId, bool isPaused);
void init(uint32_t version, int32_t layer, int32_t apiId, std::string deviceModel, std::string systemVersion, std::string appVersion, std::string langCode, std::string configPath, std::string logPath, int32_t userId, bool isPaused, bool enablePushConnection);
void updateDcSettings(uint32_t datacenterId);
void setPushConnectionEnabled(bool value);

#ifdef ANDROID
void sendRequest(TLObject *object, onCompleteFunc onComplete, onQuickAckFunc onQuickAck, uint32_t flags, uint32_t datacenterId, ConnectionType connetionType, bool immediate, int32_t requestToken, jobject ptr1, jobject ptr2);
Expand Down Expand Up @@ -133,7 +134,7 @@ class ConnectionsManager {
int32_t lastDcUpdateTime = 0;
int64_t lastPingTime = getCurrentTimeMillis();
bool networkPaused = false;
int32_t nextSleepTimeout = 30000;
int32_t nextSleepTimeout = CONNECTION_BACKGROUND_KEEP_TIME;
int64_t lastPauseTime = 0;
ConnectionState connectionState = ConnectionStateConnecting;
std::unique_ptr<ByteArray> movingAuthorization;
Expand Down Expand Up @@ -172,6 +173,7 @@ class ConnectionsManager {
std::string currentLogPath;
int32_t currentUserId = 0;
bool registeredForInternalPush = false;
bool pushConnectionEnabled = true;

ConnectiosManagerDelegate *delegate;

Expand Down
3 changes: 2 additions & 1 deletion TMessagesProj/jni/tgnet/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@

#define USE_DEBUG_SESSION false
#define READ_BUFFER_SIZE 1024 * 128
#define DEBUG_VERSION
//#define DEBUG_VERSION
#define DEFAULT_DATACENTER_ID INT_MAX
#define DC_UPDATE_TIME 60 * 60
#define DOWNLOAD_CONNECTIONS_COUNT 2
#define CONNECTION_BACKGROUND_KEEP_TIME 10000

class TLObject;
class TL_error;
Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@

<receiver android:name=".WearReplyReceiver" android:enabled="true"/>

<receiver android:name=".ShareBroadcastReceiver" android:enabled="true"/>

<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" />
Expand Down
Loading

0 comments on commit 0647377

Please sign in to comment.