Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYi0526 committed Jun 17, 2024
2 parents 1e9d7bf + bd0153a commit dfe6255
Show file tree
Hide file tree
Showing 611 changed files with 23,802 additions and 6,173 deletions.
211 changes: 211 additions & 0 deletions .gitea/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: "Debug Build"

# Controls when the action will run.
on:
push:
branches:
- dev
paths-ignore:
- '**.md'
- '.github/**'

jobs:
ffmpeg:
name: Native Build (FFmpeg)
runs-on: ndk21
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch Status
run: |
sed -i 's/\/\///g' settings.gradle
git submodule status TMessagesProj/jni/ffmpeg > ffmpeg_status
git submodule status TMessagesProj/jni/libvpx > libvpx_status
- name: FFmpeg Cache
id: cache
uses: actions/cache@v4
with:
path: |
TMessagesProj/jni/ffmpeg/build
TMessagesProj/jni/libvpx/build
key: ${{ hashFiles('ffmpeg_status', 'libvpx_status', 'TMessagesProj/jni/*ffmpeg*.sh', 'TMessagesProj/jni/*libvpx*.sh', 'TMessagesProj/jni/patches/ffmpeg/*') }}
- name: Install NDK
if: steps.cache.outputs.cache-hit != 'true'
run: |
echo "sdk.dir=${ANDROID_HOME}" > local.properties
echo "ndk.dir=${ANDROID_HOME}/ndk/21.4.7075529" >> local.properties
- name: Native Build
if: steps.cache.outputs.cache-hit != 'true'
run: |
sudo apt-get install yasm -y
./run init libs libvpx
./run init libs ffmpeg
boringssl:
name: Native Build (BoringSSL)
runs-on: ndk21
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch Status
run: |
sed -i 's/\/\///g' settings.gradle
git submodule status TMessagesProj/jni/boringssl > boringssl_status
- name: BoringSSL Cache
id: cache
uses: actions/cache@v4
with:
path: |
TMessagesProj/jni/boringssl/build
key: ${{ hashFiles('boringssl_status') }}
- name: Install NDK
if: steps.cache.outputs.cache-hit != 'true'
run: |
echo "sdk.dir=${ANDROID_HOME}" > local.properties
echo "ndk.dir=${ANDROID_HOME}/ndk/21.4.7075529" >> local.properties
- name: Native Build
if: steps.cache.outputs.cache-hit != 'true'
run: |
apt install golang -y
./run init action boringssl
./run init libs boringssl
native:
name: Native Build (Telegram)
runs-on: ndk21
needs:
- ffmpeg
- boringssl
strategy:
matrix:
flavor:
- armeabi-v7a
- arm64-v8a
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch Status
run: |
sed -i 's/\/\///g' settings.gradle
git submodule status TMessagesProj/jni/ffmpeg > ffmpeg_status
git submodule status TMessagesProj/jni/libvpx > libvpx_status
git submodule status TMessagesProj/jni/boringssl > boringssl_status
- name: Native Cache
id: cache
uses: actions/cache@v4
with:
path: |
TMessagesProj/src/main/libs
key: ${{ hashFiles('TMessagesProj/jni/**', 'ffmpeg_status', 'boringssl_status') }}-${{ matrix.flavor }}
- name: Checkout Library
if: steps.cache.outputs.cache-hit != 'true'
run: |
git submodule update --init 'TMessagesProj/jni/*'
- name: FFmpeg Cache
uses: actions/cache@v4
if: steps.cache.outputs.cache-hit != 'true'
with:
path: |
TMessagesProj/jni/ffmpeg/build
TMessagesProj/jni/libvpx/build
key: ${{ hashFiles('ffmpeg_status', 'libvpx_status', 'TMessagesProj/jni/*ffmpeg*.sh', 'TMessagesProj/jni/*libvpx*.sh', 'TMessagesProj/jni/patches/ffmpeg/*') }}
- name: BoringSSL Cache
uses: actions/cache@v4
if: steps.cache.outputs.cache-hit != 'true'
with:
path: |
TMessagesProj/jni/boringssl/build
key: ${{ hashFiles('boringssl_status') }}
- name: Install NDK
if: steps.cache.outputs.cache-hit != 'true'
run: |
echo "sdk.dir=${ANDROID_HOME}" > local.properties
echo "ndk.dir=${ANDROID_HOME}/ndk/21.4.7075529" >> local.properties
- name: Fix BoringSSL
if: steps.cache.outputs.cache-hit != 'true'
run: |
cd TMessagesProj/jni
./patch_boringssl.sh
- name: Native Build
if: steps.cache.outputs.cache-hit != 'true'
run: |
export NATIVE_TARGET="${{ matrix.flavor }}"
./run libs native
build:
name: Gradle Build
runs-on: ndk21
needs:
- native
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install NDK
run: |
echo "sdk.dir=${ANDROID_HOME}" > local.properties
echo "ndk.dir=${ANDROID_HOME}/ndk/21.4.7075529" >> local.properties
- name: Fetch Status
run: |
sed -i 's/\/\///g' settings.gradle
git submodule status TMessagesProj/jni/ffmpeg > ffmpeg_status
git submodule status TMessagesProj/jni/boringssl > boringssl_status
- name: Native Cache (armeabi-v7a)
uses: actions/cache@v4
with:
path: |
TMessagesProj/src/main/libs
key: ${{ hashFiles('TMessagesProj/jni/**', 'ffmpeg_status', 'boringssl_status') }}-armeabi-v7a
- name: Native Cache (arm64-v8a)
uses: actions/cache@v4
with:
path: |
TMessagesProj/src/main/libs
key: ${{ hashFiles('TMessagesProj/jni/**', 'ffmpeg_status', 'boringssl_status') }}-arm64-v8a
- name: Configure Gradle
run: |
sed -i -e "s/16384/6144/g" gradle.properties
echo "sdk.dir=${ANDROID_HOME}" >> local.properties
- name: Gradle cache
uses: actions/cache@v4
with:
path: ~/.gradle
key: gradle-${{ hashFiles('**/*.gradle') }}
- name: Debug Build
run: |
export LOCAL_PROPERTIES="${{ secrets.LOCAL_PROPERTIES }}"
./gradlew TMessagesProj:assembleRelease
APK=$(find TMessagesProj/build/outputs/apk -name '*arm64-v8a*.apk')
APK=$(dirname $APK)
echo "APK=$APK" >> $GITHUB_ENV
- uses: actions/upload-artifact@v3
with:
name: Release
path: ${{ env.APK }}
upload:
name: Upload debug
if: github.event.inputs.upload != 'y'
runs-on: ndk21
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Donwload Artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Send to Telegram
run: |
# send release via telegram bot api
export mini64=$(find artifacts -name "*arm64-v8a.apk")
export mini32=$(find artifacts -name "*armeabi-v7a.apk")
echo $mini64
echo $mini32
python -m pip install -r bin/scripts/requirements.txt
git log -1 --pretty=format:"%s%n%n%b" > artifacts/caption.txt
python bin/scripts/upload.py ${{ secrets.HELPER_BOT_TOKEN }} ${{ secrets.HELPER_BOT_TARGET }} test
13 changes: 8 additions & 5 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ repositories {
}
}

def verName = "10.12.0"
def verCode = 1175
def verName = "10.13.1"
def verCode = 1180


def officialVer = "10.12.0"
def officialCode = 4710
def officialVer = "10.13.1"
def officialCode = 4845

def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")

Expand Down Expand Up @@ -312,6 +312,9 @@ dependencies {
implementation "com.jakewharton:process-phoenix:2.1.2"
implementation 'com.google.guava:guava:31.1-android'

implementation 'com.airbnb.android:lottie:6.4.0'
implementation 'com.google.android.play:integrity:1.3.0'

implementation 'com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1'
implementation 'com.google.android.gms:play-services-mlkit-image-labeling:16.0.8'

Expand All @@ -332,7 +335,7 @@ dependencies {

implementation "com.google.firebase:firebase-messaging:$fcmVersion"
implementation "com.google.firebase:firebase-crashlytics:$crashlyticsVersion"
implementation "com.google.android.play:core:$playCoreVersion"
// implementation "com.google.android.play:core:$playCoreVersion"

implementation 'com.android.billingclient:billing:5.1.0'

Expand Down
54 changes: 54 additions & 0 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include "tgnet/MTProtoScheme.h"
#include "tgnet/ConnectionSocket.h"
#include "tgnet/FileLog.h"
#include "tgnet/Handshake.h"
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/bn.h>
#include <openssl/pem.h>
#include <openssl/aes.h>

JavaVM *java;

Expand All @@ -31,6 +37,7 @@ jmethodID jclass_ConnectionsManager_onProxyError;
jmethodID jclass_ConnectionsManager_getHostByName;
jmethodID jclass_ConnectionsManager_getInitFlags;
jmethodID jclass_ConnectionsManager_onPremiumFloodWait;
jmethodID jclass_ConnectionsManager_onIntegrityCheckClassic;

bool check_utf8(const char *data, size_t len);

Expand Down Expand Up @@ -134,6 +141,40 @@ void failNotRunningRequest(JNIEnv *env, jclass c, jint instanceNum, jint token)
return ConnectionsManager::getInstance(instanceNum).failNotRunningRequest(token);
}

void receivedIntegrityCheckClassic(JNIEnv *env, jclass c, jint instanceNum, jint requestToken, jstring nonce, jstring token) {
const char* nonceStr = env->GetStringUTFChars(nonce, 0);
const char* tokenStr = env->GetStringUTFChars(token, 0);
std::string nonceString = nonceStr;
std::string tokenString = tokenStr;
ConnectionsManager::getInstance(instanceNum).receivedIntegrityCheckClassic(requestToken, nonceString, tokenString);
if (nonceStr != nullptr) {
env->ReleaseStringUTFChars(nonce, nonceStr);
}
if (tokenStr != nullptr) {
env->ReleaseStringUTFChars(token, tokenStr);
}
}

jboolean isGoodPrime(JNIEnv *env, jclass c, jbyteArray prime, jint g) {
jsize length = env->GetArrayLength(prime);
jbyte *bytes = env->GetByteArrayElements(prime, NULL);
if (bytes == NULL) {
DEBUG_E("isGoodPrime: failed to get byte array");
return false;
}
unsigned char *unsignedBytes = (unsigned char *)bytes;
BIGNUM *bn = BN_bin2bn(unsignedBytes, length, NULL);
if (bn == NULL) {
env->ReleaseByteArrayElements(prime, bytes, 0);
DEBUG_E("isGoodPrime: failed to convert byte array into BIGNUM");
return false;
}
bool result = Handshake::isGoodPrime(bn, g);
BN_free(bn);
env->ReleaseByteArrayElements(prime, bytes, 0);
return result;
}

void cleanUp(JNIEnv *env, jclass c, jint instanceNum, jboolean resetKeys) {
return ConnectionsManager::getInstance(instanceNum).cleanUp(resetKeys, -1);
}
Expand Down Expand Up @@ -376,6 +417,13 @@ class Delegate : public ConnectiosManagerDelegate {
void onPremiumFloodWait(int32_t instanceNum, int32_t requestToken, bool isUpload) {
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onPremiumFloodWait, instanceNum, requestToken, isUpload);
}

void onIntegrityCheckClassic(int32_t instanceNum, int32_t requestToken, std::string nonce) {
jstring nonceStr = jniEnv[instanceNum]->NewStringUTF(nonce.c_str());
jniEnv[instanceNum]->CallStaticVoidMethod(jclass_ConnectionsManager, jclass_ConnectionsManager_onIntegrityCheckClassic, instanceNum, requestToken, nonceStr);
jniEnv[instanceNum]->DeleteLocalRef(nonceStr);
}

};

void
Expand Down Expand Up @@ -541,6 +589,8 @@ static JNINativeMethod ConnectionsManagerMethods[] = {
{"native_onHostNameResolved", "(Ljava/lang/String;JLjava/lang/String;Z)V", (void *) onHostNameResolved},
{"native_discardConnection", "(III)V", (void *) discardConnection},
{"native_failNotRunningRequest", "(II)V", (void *) failNotRunningRequest},
{"native_receivedIntegrityCheckClassic", "(IILjava/lang/String;Ljava/lang/String;)V", (void *) receivedIntegrityCheckClassic},
{"native_isGoodPrime", "([BI)Z", (void *) isGoodPrime},
};

inline int registerNativeMethods(JNIEnv *env, const char *className, JNINativeMethod *methods,
Expand Down Expand Up @@ -669,6 +719,10 @@ extern "C" int registerNativeTgNetFunctions(JavaVM *vm, JNIEnv *env) {
if (jclass_ConnectionsManager_onPremiumFloodWait == 0) {
return JNI_FALSE;
}
jclass_ConnectionsManager_onIntegrityCheckClassic = env->GetStaticMethodID(jclass_ConnectionsManager, "onIntegrityCheckClassic", "(IILjava/lang/String;)V");
if (jclass_ConnectionsManager_onIntegrityCheckClassic == 0) {
return JNI_FALSE;
}

return JNI_TRUE;
}
Expand Down
16 changes: 16 additions & 0 deletions TMessagesProj/jni/tgnet/ApiScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,9 @@ MessageEntity *MessageEntity::TLdeserialize(NativeByteBuffer *stream, uint32_t c
result = new TL_messageEntityStrike();
break;
case 0x20df5d0:
result = new TL_messageEntityBlockquote_layer180();
break;
case 0xf1ccaaac:
result = new TL_messageEntityBlockquote();
break;
case 0x9c4e7e8b:
Expand Down Expand Up @@ -1001,11 +1004,24 @@ void TL_messageEntityStrike::serializeToStream(NativeByteBuffer *stream) {
}

void TL_messageEntityBlockquote::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
flags = stream->readInt32(&error);
offset = stream->readInt32(&error);
length = stream->readInt32(&error);
}

void TL_messageEntityBlockquote_layer180::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
offset = stream->readInt32(&error);
length = stream->readInt32(&error);
}

void TL_messageEntityBlockquote::serializeToStream(NativeByteBuffer *stream) {
stream->writeInt32(constructor);
stream->writeInt32(flags);
stream->writeInt32(offset);
stream->writeInt32(length);
}

void TL_messageEntityBlockquote_layer180::serializeToStream(NativeByteBuffer *stream) {
stream->writeInt32(constructor);
stream->writeInt32(offset);
stream->writeInt32(length);
Expand Down
Loading

0 comments on commit dfe6255

Please sign in to comment.