| 5 | #include "tgnet/ConnectionsManager.h" |
| 6 | #include "tgnet/MTProtoScheme.h" |
| 7 | #include "tgnet/FileLoadOperation.h" |
| 8 |
| 9 | JavaVM *java; |
| 10 | jclass jclass_RequestDelegateInternal; |
| 11 | jmethodID jclass_RequestDelegateInternal_run; |
| 12 |
| 13 | jclass jclass_QuickAckDelegate; |
| 14 | jmethodID jclass_QuickAckDelegate_run; |
| 15 |
| 16 | jclass jclass_FileLoadOperationDelegate; |
| 17 | jmethodID jclass_FileLoadOperationDelegate_onFinished; |
| 18 | jmethodID jclass_FileLoadOperationDelegate_onFailed; |
| 19 | jmethodID jclass_FileLoadOperationDelegate_onProgressChanged; |
| 20 |
| 21 | jclass jclass_ConnectionsManager; |
| 22 | jmethodID jclass_ConnectionsManager_onUnparsedMessageReceived; |
| 23 | jmethodID jclass_ConnectionsManager_onUpdate; |
| 24 | jmethodID jclass_ConnectionsManager_onSessionCreated; |
| 25 | jmethodID jclass_ConnectionsManager_onLogout; |
| 26 | jmethodID jclass_ConnectionsManager_onConnectionStateChanged; |
| 27 | jmethodID jclass_ConnectionsManager_onInternalPushReceived; |
| 28 | jmethodID jclass_ConnectionsManager_onUpdateConfig; |
| 29 |
| 30 | jint createLoadOpetation(JNIEnv *env, jclass c, jint dc_id, jlong id, jlong volume_id, jlong access_hash, jint local_id, jbyteArray encKey, jbyteArray encIv, jstring extension, jint version, jint size, jstring dest, jstring temp, jobject delegate) { |
| 31 | if (encKey != nullptr && encIv == nullptr || encKey == nullptr && encIv != nullptr || extension == nullptr || dest == nullptr || temp == nullptr) { |
| 32 | return 0; |
| 33 | } |
| 34 | FileLoadOperation *loadOperation = nullptr; |
| 35 | bool error = false; |
| 36 |
| 37 | const char *extensionStr = env->GetStringUTFChars(extension, NULL); |
| 38 | const char *destStr = env->GetStringUTFChars(dest, NULL); |
| 39 | const char *tempStr = env->GetStringUTFChars(temp, NULL); |
| 40 |
| 41 | if (extensionStr == nullptr || destStr == nullptr || tempStr == nullptr) { |
| 42 | error = true; |
| 43 | } |
| 44 |
| 45 | jbyte *keyBuff = nullptr; |
| 46 | jbyte *ivBuff = nullptr; |
| 47 |
| 48 | if (!error && encKey != nullptr) { |
| 49 | keyBuff = env->GetByteArrayElements(encKey, NULL); |
| 50 | ivBuff = env->GetByteArrayElements(encIv, NULL); |
| 51 | if (keyBuff == nullptr || ivBuff == nullptr) { |
| 52 | error = true; |
| 53 | } |
| 54 | } |
| 55 | if (!error) { |
| 56 | if (delegate != nullptr) { |
| 57 | delegate = env->NewGlobalRef(delegate); |
| 58 | } |
| 59 | loadOperation = new FileLoadOperation(dc_id, id, volume_id, access_hash, local_id, (uint8_t *) keyBuff, (uint8_t *) ivBuff, extensionStr, version, size, destStr, tempStr); |
| 60 | loadOperation->setDelegate([delegate](std::string path) { |
| 61 | jstring pathText = jniEnv->NewStringUTF(path.c_str()); |
| 62 | if (delegate != nullptr) { |
| 63 | jniEnv->CallVoidMethod(delegate, jclass_FileLoadOperationDelegate_onFinished, pathText); |
| 64 | } |
| 65 | if (pathText != nullptr) { |
| 66 | jniEnv->DeleteLocalRef(pathText); |
| 67 | } |
| 68 | }, [delegate](FileLoadFailReason reason) { |
| 69 | if (delegate != nullptr) { |
| 70 | jniEnv->CallVoidMethod(delegate, jclass_FileLoadOperationDelegate_onFailed, reason); |
| 71 | } |
| 72 | }, [delegate](float progress) { |
| 73 | if (delegate != nullptr) { |
| 74 | jniEnv->CallVoidMethod(delegate, jclass_FileLoadOperationDelegate_onProgressChanged, progress); |
| 75 | } |
| 76 | }); |
| 77 | loadOperation->ptr1 = delegate; |
| 78 | } |
| 79 | if (keyBuff != nullptr) { |
| 80 | env->ReleaseByteArrayElements(encKey, keyBuff, JNI_ABORT); |
| 81 | } |
| 82 | if (ivBuff != nullptr) { |
| 83 | env->ReleaseByteArrayElements(encIv, ivBuff, JNI_ABORT); |
| 84 | } |
| 85 | if (extensionStr != nullptr) { |
| 86 | env->ReleaseStringUTFChars(extension, extensionStr); |
| 87 | } |
| 88 | if (destStr != nullptr) { |
| 89 | env->ReleaseStringUTFChars(dest, destStr); |
| 90 | } |
| 91 | if (tempStr != nullptr) { |
| 92 | env->ReleaseStringUTFChars(temp, tempStr); |
| 93 | } |
| 94 |
| 95 | return (jint) loadOperation; |
| 96 | } |
| 97 |
| 98 | void startLoadOperation(JNIEnv *env, jclass c, jint address) { |
| 99 | if (address != 0) { |
| 100 | ((FileLoadOperation *) address)->start(); |
| 101 | } |
| 102 | } |
| 103 |
| 104 | void cancelLoadOperation(JNIEnv *env, jclass c, jint address) { |
| 105 | if (address != 0) { |
| 106 | ((FileLoadOperation *) address)->cancel(); |
| 107 | } |
| 108 | } |
| 109 |
| 110 | static const char *FileLoadOperationClassPathName = "org/telegram/tgnet/FileLoadOperation"; |
| 111 | static JNINativeMethod FileLoadOperationMethods[] = { |
| 112 | {"native_createLoadOpetation", "(IJJJI[B[BLjava/lang/String;IILjava/lang/String;Ljava/lang/String;Ljava/lang/Object;)I", (void *) createLoadOpetation}, |
| 113 | {"native_startLoadOperation", "(I)V", (void *) startLoadOperation}, |
| 114 | {"native_cancelLoadOperation", "(I)V", (void *) cancelLoadOperation} |
| 115 | }; |
| 116 |
| 117 | jint getFreeBuffer(JNIEnv *env, jclass c, jint length) { |
| 118 | return (jint) BuffersStorage::getInstance().getFreeBuffer(length); |
| 119 | } |
| 120 |
| 121 | jint limit(JNIEnv *env, jclass c, jint address) { |
| 122 | NativeByteBuffer *buffer = (NativeByteBuffer *) address; |
| 123 | return buffer->limit(); |
| 124 | } |
| 125 |
| 126 | jint position(JNIEnv *env, jclass c, jint address) { |
| 127 | NativeByteBuffer *buffer = (NativeByteBuffer *) address; |
| 128 | return buffer->position(); |
| 129 | } |
| 130 |
| 131 | void reuse(JNIEnv *env, jclass c, jint address) { |
| 132 | NativeByteBuffer *buffer = (NativeByteBuffer *) address; |
| 133 | buffer->reuse(); |
| 134 | } |
| 135 |
| 136 | jobject getJavaByteBuffer(JNIEnv *env, jclass c, jint address) { |
| 137 | NativeByteBuffer *buffer = (NativeByteBuffer *) address; |
| 138 | return buffer->getJavaByteBuffer(); |
| 139 | } |
| 140 |
| 141 | static const char *NativeByteBufferClassPathName = "org/telegram/tgnet/NativeByteBuffer"; |
| 142 | static JNINativeMethod NativeByteBufferMethods[] = { |
| 143 | {"native_getFreeBuffer", "(I)I", (void *) getFreeBuffer}, |
| 144 | {"native_limit", "(I)I", (void *) limit}, |
| 145 | {"native_position", "(I)I", (void *) position}, |
| 146 | {"native_reuse", "(I)V", (void *) reuse}, |
| 147 | {"native_getJavaByteBuffer", "(I)Ljava/nio/ByteBuffer;", (void *) getJavaByteBuffer} |
| 148 | }; |
| 149 |
| 150 | jlong getCurrentTimeMillis(JNIEnv *env, jclass c) { |
| 151 | return ConnectionsManager::getInstance().getCurrentTimeMillis(); |
| 152 | } |
| 153 |
| 154 | jint getCurrentTime(JNIEnv *env, jclass c) { |
| 155 | return ConnectionsManager::getInstance().getCurrentTime(); |
| 156 | } |
| 157 |
| 158 | jint getTimeDifference(JNIEnv *env, jclass c) { |
| 159 | return ConnectionsManager::getInstance().getTimeDifference(); |
| 160 | } |
| 161 |
| 162 | void sendRequest(JNIEnv *env, jclass c, jint object, jobject onComplete, jobject onQuickAck, jint flags, jint datacenterId, jint connetionType, jboolean immediate, jint token) { |
| 163 | TL_api_request *request = new TL_api_request(); |
| 164 | request->request = (NativeByteBuffer *) object; |
| 165 | if (onComplete != nullptr) { |
| 166 | onComplete = env->NewGlobalRef(onComplete); |
| 167 | } |
| 168 | if (onQuickAck != nullptr) { |
| 169 | onQuickAck = env->NewGlobalRef(onQuickAck); |
| 170 | } |
| 171 | ConnectionsManager::getInstance().sendRequest(request, ([onComplete](TLObject *response, TL_error *error) { |
| 172 | TL_api_response *resp = (TL_api_response *) response; |
| 173 | jint ptr = 0; |
| 174 | jint errorCode = 0; |
| 175 | jstring errorText = nullptr; |
| 176 | if (resp != nullptr) { |
| 177 | ptr = (jint) resp->response.get(); |
| 178 | } else if (error != nullptr) { |
| 179 | errorCode = error->code; |
| 180 | errorText = jniEnv->NewStringUTF(error->text.c_str()); |
| 181 | } |
| 182 | if (onComplete != nullptr) { |
| 183 | jniEnv->CallVoidMethod(onComplete, jclass_RequestDelegateInternal_run, ptr, errorCode, errorText); |
| 184 | } |
| 185 | if (errorText != nullptr) { |
| 186 | jniEnv->DeleteLocalRef(errorText); |
| 187 | } |
| 188 | }), ([onQuickAck] { |
| 189 | if (onQuickAck != nullptr) { |
| 190 | jniEnv->CallVoidMethod(onQuickAck, jclass_QuickAckDelegate_run); |
| 191 | } |
| 192 | }), flags, datacenterId, (ConnectionType) connetionType, immediate, token, onComplete, onQuickAck); |
| 193 | } |
| 194 |
| 195 | void cancelRequest(JNIEnv *env, jclass c, jint token, jboolean notifyServer) { |
| 196 | return ConnectionsManager::getInstance().cancelRequest(token, notifyServer); |
| 197 | } |
| 198 |
| 199 | void cleanUp(JNIEnv *env, jclass c) { |
| 200 | return ConnectionsManager::getInstance().cleanUp(); |
| 201 | } |
| 202 |
| 203 | void cancelRequestsForGuid(JNIEnv *env, jclass c, jint guid) { |
| 204 | return ConnectionsManager::getInstance().cancelRequestsForGuid(guid); |
| 205 | } |
| 206 |
| 207 | void bindRequestToGuid(JNIEnv *env, jclass c, jint requestToken, jint guid) { |
| 208 | return ConnectionsManager::getInstance().bindRequestToGuid(requestToken, guid); |
| 209 | } |
| 210 |
| 211 | void applyDatacenterAddress(JNIEnv *env, jclass c, jint datacenterId, jstring ipAddress, jint port) { |
| 212 | const char *valueStr = env->GetStringUTFChars(ipAddress, 0); |
| 213 |
| 214 | ConnectionsManager::getInstance().applyDatacenterAddress(datacenterId, std::string(valueStr), port); |
| 215 |
| 216 | if (valueStr != 0) { |
| 217 | env->ReleaseStringUTFChars(ipAddress, valueStr); |
| 218 | } |
| 219 | } |
| 220 |
| 221 | jint getConnectionState(JNIEnv *env, jclass c) { |
| 222 | return ConnectionsManager::getInstance().getConnectionState(); |
| 223 | } |
| 224 |
| 225 | void setUserId(JNIEnv *env, jclass c, int32_t id) { |
| 226 | ConnectionsManager::getInstance().setUserId(id); |
| 227 | } |
| 228 |
| 229 | void switchBackend(JNIEnv *env, jclass c) { |
| 230 | ConnectionsManager::getInstance().switchBackend(); |
| 231 | } |
| 232 |
| 233 | void pauseNetwork(JNIEnv *env, jclass c) { |
| 234 | ConnectionsManager::getInstance().pauseNetwork(); |
| 235 | } |
| 236 |
| 237 | void resumeNetwork(JNIEnv *env, jclass c, jboolean partial) { |
| 238 | ConnectionsManager::getInstance().resumeNetwork(partial); |
| 239 | } |
| 240 |
| 241 | void updateDcSettings(JNIEnv *env, jclass c) { |
| 242 | ConnectionsManager::getInstance().updateDcSettings(0); |
| 243 | } |
| 244 |
| 245 | void setUseIpv6(JNIEnv *env, jclass c, bool value) { |
| 246 | ConnectionsManager::getInstance().setUseIpv6(value); |
| 247 | } |
| 248 |
| 249 | void setNetworkAvailable(JNIEnv *env, jclass c, jboolean value) { |
| 250 | ConnectionsManager::getInstance().setNetworkAvailable(value); |
| 251 | } |
| 252 |
| 253 | void setPushConnectionEnabled(JNIEnv *env, jclass c, jboolean value) { |
| 254 | ConnectionsManager::getInstance().setPushConnectionEnabled(value); |
| 255 | } |
| 256 |
| 257 | class Delegate : public ConnectiosManagerDelegate { |
| 258 |
| 259 | void onUpdate() { |
| 260 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onUpdate); |
| 261 | } |
| 262 |
| 263 | void onSessionCreated() { |
| 264 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onSessionCreated); |
| 265 | } |
| 266 |
| 267 | void onConnectionStateChanged(ConnectionState state) { |
| 268 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onConnectionStateChanged, state); |
| 269 | } |
| 270 |
| 271 | void onUnparsedMessageReceived(int64_t reqMessageId, NativeByteBuffer *buffer, ConnectionType connectionType) { |
| 272 | if (connectionType == ConnectionTypeGeneric) { |
| 273 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onUnparsedMessageReceived, buffer); |
| 274 | } |
| 275 | } |
| 276 |
| 277 | void onLogout() { |
| 278 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onLogout); |
| 279 | } |
| 280 |
| 281 | void onUpdateConfig(TL_config *config) { |
| 282 | NativeByteBuffer *buffer = BuffersStorage::getInstance().getFreeBuffer(config->getObjectSize()); |
| 283 | config->serializeToStream(buffer); |
| 284 | buffer->position(0); |
| 285 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onUpdateConfig, buffer); |
| 286 | buffer->reuse(); |
| 287 | } |
| 288 |
| 289 | void onInternalPushReceived() { |
| 290 | jniEnv->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onInternalPushReceived); |
| 291 | } |
| 292 | }; |
| 293 |
| 294 | 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) { |
| 295 | const char *deviceModelStr = env->GetStringUTFChars(deviceModel, 0); |
| 296 | const char *systemVersionStr = env->GetStringUTFChars(systemVersion, 0); |
| 297 | const char *appVersionStr = env->GetStringUTFChars(appVersion, 0); |
| 298 | const char *langCodeStr = env->GetStringUTFChars(langCode, 0); |
| 299 | const char *configPathStr = env->GetStringUTFChars(configPath, 0); |
| 300 | const char *logPathStr = env->GetStringUTFChars(logPath, 0); |
| 301 |
| 302 | 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); |
| 303 |
| 304 | if (deviceModelStr != 0) { |
| 305 | env->ReleaseStringUTFChars(deviceModel, deviceModelStr); |
| 306 | } |
| 307 | if (systemVersionStr != 0) { |
| 308 | env->ReleaseStringUTFChars(systemVersion, systemVersionStr); |
| 309 | } |
| 310 | if (appVersionStr != 0) { |
| 311 | env->ReleaseStringUTFChars(appVersion, appVersionStr); |
| 312 | } |
| 313 | if (langCodeStr != 0) { |
| 314 | env->ReleaseStringUTFChars(langCode, langCodeStr); |
| 315 | } |
| 316 | if (configPathStr != 0) { |
| 317 | env->ReleaseStringUTFChars(configPath, configPathStr); |
| 318 | } |
| 319 | if (logPathStr != 0) { |
| 320 | env->ReleaseStringUTFChars(logPath, logPathStr); |
| 321 | } |
| 322 | } |
| 323 |
| 324 | void setJava(JNIEnv *env, jclass c, jboolean useJavaByteBuffers) { |
| 325 | ConnectionsManager::useJavaVM(java, useJavaByteBuffers); |
| 326 | ConnectionsManager::getInstance().setDelegate(new Delegate()); |
| 327 | } |
| 328 |
| 329 | static const char *ConnectionsManagerClassPathName = "org/telegram/tgnet/ConnectionsManager"; |
| 330 | static JNINativeMethod ConnectionsManagerMethods[] = { |
| 331 | {"native_getCurrentTimeMillis", "()J", (void *) getCurrentTimeMillis}, |
| 332 | {"native_getCurrentTime", "()I", (void *) getCurrentTime}, |
| 333 | {"native_getTimeDifference", "()I", (void *) getTimeDifference}, |
| 334 | {"native_sendRequest", "(ILorg/telegram/tgnet/RequestDelegateInternal;Lorg/telegram/tgnet/QuickAckDelegate;IIIZI)V", (void *) sendRequest}, |
| 335 | {"native_cancelRequest", "(IZ)V", (void *) cancelRequest}, |
| 336 | {"native_cleanUp", "()V", (void *) cleanUp}, |
| 337 | {"native_cancelRequestsForGuid", "(I)V", (void *) cancelRequestsForGuid}, |
| 338 | {"native_bindRequestToGuid", "(II)V", (void *) bindRequestToGuid}, |
| 339 | {"native_applyDatacenterAddress", "(ILjava/lang/String;I)V", (void *) applyDatacenterAddress}, |
| 340 | {"native_getConnectionState", "()I", (void *) getConnectionState}, |
| 341 | {"native_setUserId", "(I)V", (void *) setUserId}, |
| 342 | {"native_init", "(IIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V", (void *) init}, |
| 343 | {"native_switchBackend", "()V", (void *) switchBackend}, |
| 344 | {"native_pauseNetwork", "()V", (void *) pauseNetwork}, |
| 345 | {"native_resumeNetwork", "(Z)V", (void *) resumeNetwork}, |
| 346 | {"native_updateDcSettings", "()V", (void *) updateDcSettings}, |
| 347 | {"native_setUseIpv6", "(Z)V", (void *) setUseIpv6}, |
| 348 | {"native_setNetworkAvailable", "(Z)V", (void *) setNetworkAvailable}, |
| 349 | {"native_setPushConnectionEnabled", "(Z)V", (void *) setPushConnectionEnabled}, |
| 350 | {"native_setJava", "(Z)V", (void *) setJava} |
| 351 | }; |
| 352 |
| 353 | inline int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods, int methodsCount) { |
| 354 | jclass clazz; |
| 355 | clazz = env->FindClass(className); |
| 356 | if (clazz == NULL) { |
| 357 | return JNI_FALSE; |
| 358 | } |
| 359 | if (env->RegisterNatives(clazz, methods, methodsCount) < 0) { |
| 360 | return JNI_FALSE; |
| 361 | } |
| 362 | return JNI_TRUE; |
| 363 | } |
| 364 |
| 365 | extern "C" int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env) { |
| 366 | java = vm; |
| 367 |
| 368 | if (!registerNativeMethods(env, NativeByteBufferClassPathName, NativeByteBufferMethods, sizeof(NativeByteBufferMethods) / sizeof(NativeByteBufferMethods[0]))) { |
| 369 | return JNI_FALSE; |
| 370 | } |
| 371 |
| 372 | if (!registerNativeMethods(env, FileLoadOperationClassPathName, FileLoadOperationMethods, sizeof(FileLoadOperationMethods) / sizeof(FileLoadOperationMethods[0]))) { |
| 373 | return JNI_FALSE; |
| 374 | } |
| 375 |
| 376 | if (!registerNativeMethods(env, ConnectionsManagerClassPathName, ConnectionsManagerMethods, sizeof(ConnectionsManagerMethods) / sizeof(ConnectionsManagerMethods[0]))) { |
| 377 | return JNI_FALSE; |
| 378 | } |
| 379 |
| 380 | jclass_RequestDelegateInternal = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/RequestDelegateInternal")); |
| 381 | if (jclass_RequestDelegateInternal == 0) { |
| 382 | return JNI_FALSE; |
| 383 | } |
| 384 | jclass_RequestDelegateInternal_run = env->GetMethodID(jclass_RequestDelegateInternal, "run", "(IILjava/lang/String;)V"); |
| 385 | if (jclass_RequestDelegateInternal_run == 0) { |
| 386 | return JNI_FALSE; |
| 387 | } |
| 388 |
| 389 | jclass_QuickAckDelegate = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/QuickAckDelegate")); |
| 390 | if (jclass_RequestDelegateInternal == 0) { |
| 391 | return JNI_FALSE; |
| 392 | } |
| 393 | jclass_QuickAckDelegate_run = env->GetMethodID(jclass_QuickAckDelegate, "run", "()V"); |
| 394 | if (jclass_QuickAckDelegate_run == 0) { |
| 395 | return JNI_FALSE; |
| 396 | } |
| 397 |
| 398 | jclass_FileLoadOperationDelegate = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/FileLoadOperationDelegate")); |
| 399 | if (jclass_FileLoadOperationDelegate == 0) { |
| 400 | return JNI_FALSE; |
| 401 | } |
| 402 |
| 403 | jclass_FileLoadOperationDelegate_onFinished = env->GetMethodID(jclass_FileLoadOperationDelegate, "onFinished", "(Ljava/lang/String;)V"); |
| 404 | if (jclass_FileLoadOperationDelegate_onFinished == 0) { |
| 405 | return JNI_FALSE; |
| 406 | } |
| 407 |
| 408 | jclass_FileLoadOperationDelegate_onFailed = env->GetMethodID(jclass_FileLoadOperationDelegate, "onFailed", "(I)V"); |
| 409 | if (jclass_FileLoadOperationDelegate_onFailed == 0) { |
| 410 | return JNI_FALSE; |
| 411 | } |
| 412 |
| 413 | jclass_FileLoadOperationDelegate_onProgressChanged = env->GetMethodID(jclass_FileLoadOperationDelegate, "onProgressChanged", "(F)V"); |
| 414 | if (jclass_FileLoadOperationDelegate_onProgressChanged == 0) { |
| 415 | return JNI_FALSE; |
| 416 | } |
| 417 |
| 418 | jclass_ConnectionsManager = (jclass) env->NewGlobalRef(env->FindClass("org/telegram/tgnet/ConnectionsManager")); |
| 419 | if (jclass_ConnectionsManager == 0) { |
| 420 | return JNI_FALSE; |
| 421 | } |
| 422 | jclass_ConnectionsManager_onUnparsedMessageReceived = env->GetStaticMethodID(jclass_ConnectionsManager, "onUnparsedMessageReceived", "(I)V"); |
| 423 | if (jclass_ConnectionsManager_onUnparsedMessageReceived == 0) { |
| 424 | return JNI_FALSE; |
| 425 | } |
| 426 | jclass_ConnectionsManager_onUpdate = env->GetStaticMethodID(jclass_ConnectionsManager, "onUpdate", "()V"); |
| 427 | if (jclass_ConnectionsManager_onUpdate == 0) { |
| 428 | return JNI_FALSE; |
| 429 | } |
| 430 | jclass_ConnectionsManager_onSessionCreated = env->GetStaticMethodID(jclass_ConnectionsManager, "onSessionCreated", "()V"); |
| 431 | if (jclass_ConnectionsManager_onSessionCreated == 0) { |
| 432 | return JNI_FALSE; |
| 433 | } |
| 434 | jclass_ConnectionsManager_onLogout = env->GetStaticMethodID(jclass_ConnectionsManager, "onLogout", "()V"); |
| 435 | if (jclass_ConnectionsManager_onLogout == 0) { |
| 436 | return JNI_FALSE; |
| 437 | } |
| 438 | jclass_ConnectionsManager_onConnectionStateChanged = env->GetStaticMethodID(jclass_ConnectionsManager, "onConnectionStateChanged", "(I)V"); |
| 439 | if (jclass_ConnectionsManager_onConnectionStateChanged == 0) { |
| 440 | return JNI_FALSE; |
| 441 | } |
| 442 | jclass_ConnectionsManager_onInternalPushReceived = env->GetStaticMethodID(jclass_ConnectionsManager, "onInternalPushReceived", "()V"); |
| 443 | if (jclass_ConnectionsManager_onInternalPushReceived == 0) { |
| 444 | return JNI_FALSE; |
| 445 | } |
| 446 | jclass_ConnectionsManager_onUpdateConfig = env->GetStaticMethodID(jclass_ConnectionsManager, "onUpdateConfig", "(I)V"); |
| 447 | if (jclass_ConnectionsManager_onUpdateConfig == 0) { |
| 448 | return JNI_FALSE; |
| 449 | } |
| 450 | ConnectionsManager::getInstance().setDelegate(new Delegate()); |
| 451 |
| 452 | return JNI_TRUE; |
| 453 | } |
| 454 |