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