Skip to content

Commit

Permalink
Update to 7.8.2 (2376)
Browse files Browse the repository at this point in the history
Thanks to @alabiaga and @marcelpinto for help with improvements for Android 12.
#1633
#1636
#1630
  • Loading branch information
DrKLO committed Jul 19, 2021
1 parent 3ac3c37 commit 7a60f94
Show file tree
Hide file tree
Showing 83 changed files with 1,033 additions and 872 deletions.
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM gradle:6.7.1-jdk8
FROM gradle:6.7.1-jdk11

ENV ANDROID_SDK_URL https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
ENV ANDROID_API_LEVEL android-30
ENV ANDROID_BUILD_TOOLS_VERSION 30.0.3
ENV ANDROID_SDK_URL https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip
ENV ANDROID_API_LEVEL android-31
ENV ANDROID_BUILD_TOOLS_VERSION 31.0.0
ENV ANDROID_HOME /usr/local/android-sdk-linux
ENV ANDROID_NDK_VERSION 21.4.7075529
ENV ANDROID_VERSION 30
ENV ANDROID_VERSION 31
ENV ANDROID_NDK_HOME ${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}/
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools

Expand All @@ -15,12 +15,15 @@ RUN mkdir "$ANDROID_HOME" .android && \
unzip sdk.zip && \
rm sdk.zip

RUN yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses
RUN $ANDROID_HOME/tools/bin/sdkmanager --update
RUN $ANDROID_HOME/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
RUN yes | ${ANDROID_HOME}/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --licenses
RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME --update
RUN $ANDROID_HOME/cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_HOME "build-tools;30.0.3" \
"build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
"platforms;android-${ANDROID_VERSION}" \
"platform-tools" \
"ndk;$ANDROID_NDK_VERSION"
RUN cp $ANDROID_HOME/build-tools/30.0.3/dx $ANDROID_HOME/build-tools/31.0.0/dx
RUN cp $ANDROID_HOME/build-tools/30.0.3/lib/dx.jar $ANDROID_HOME/build-tools/31.0.0/lib/dx.jar
ENV PATH ${ANDROID_NDK_HOME}:$PATH
ENV PATH ${ANDROID_NDK_HOME}/prebuilt/linux-x86_64/bin/:$PATH

Expand Down
8 changes: 4 additions & 4 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ dependencies {
}

android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
compileSdkVersion 31
buildToolsVersion '31.0.0'
ndkVersion "21.4.7075529"

defaultConfig.applicationId = "org.telegram.messenger"
Expand Down Expand Up @@ -299,7 +299,7 @@ android {
}
}

defaultConfig.versionCode = 2372
defaultConfig.versionCode = 2376

applicationVariants.all { variant ->
variant.outputs.all { output ->
Expand All @@ -318,7 +318,7 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionName "7.8.1"
versionName "7.8.2"

vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']

Expand Down
13 changes: 7 additions & 6 deletions TMessagesProj/jni/tgnet/Handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void Handshake::processHandshakeResponse(TLObject *message, int64_t messageId) {
uint32_t paddedDataSize = 192;
uint32_t encryptedDataSize = keySize + paddedDataSize + SHA256_DIGEST_LENGTH;
uint32_t additionalSize = innerDataSize < paddedDataSize ? paddedDataSize - innerDataSize : 0;
NativeByteBuffer *innerDataBuffer = BuffersStorage::getInstance().getFreeBuffer(encryptedDataSize + paddedDataSize + ivSize + SHA256_DIGEST_LENGTH);
NativeByteBuffer *innerDataBuffer = BuffersStorage::getInstance().getFreeBuffer(encryptedDataSize + paddedDataSize + ivSize + SHA256_DIGEST_LENGTH + 256);

innerDataBuffer->position(encryptedDataSize);
innerData->serializeToStream(innerDataBuffer);
Expand Down Expand Up @@ -518,12 +518,13 @@ void Handshake::processHandshakeResponse(TLObject *message, int64_t messageId) {
}

bool ok = false;
size_t resLen = BN_bn2bin(rsaKey->n, innerDataBuffer->bytes() + encryptedDataSize);
uint32_t offset = encryptedDataSize + paddedDataSize + ivSize + SHA256_DIGEST_LENGTH;
size_t resLen = BN_bn2bin(rsaKey->n, innerDataBuffer->bytes() + offset);
const auto shift = (256 - resLen);

for (auto i = 0; i != 256; ++i) {
const auto a = innerDataBuffer->bytes()[i];
const auto b = (i < shift) ? 0 : innerDataBuffer->bytes()[encryptedDataSize + i - shift];
const auto b = (i < shift) ? 0 : innerDataBuffer->bytes()[offset + i - shift];
if (a > b) {
break;
} else if (a < b) {
Expand All @@ -544,9 +545,9 @@ void Handshake::processHandshakeResponse(TLObject *message, int64_t messageId) {
BN_mod_exp(r, a, rsaKey->e, rsaKey->n, bnContext);
uint32_t size = BN_num_bytes(r);
auto rsaEncryptedData = new ByteArray(size >= 256 ? size : 256);
size_t resLen = BN_bn2bin(r, rsaEncryptedData->bytes);
if (256 - resLen > 0) {
memset(rsaEncryptedData->bytes + resLen, 0, 256 - resLen);
BN_bn2bin(r, rsaEncryptedData->bytes + (size < 256 ? (256 - size) : 0));
if (256 - size > 0) {
memset(rsaEncryptedData->bytes, 0, 256 - size);
}
BN_free(a);
BN_free(r);
Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/jni/voip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ add_library(tgcalls STATIC
voip/tgcalls/VideoCaptureInterface.cpp
voip/tgcalls/VideoCaptureInterfaceImpl.cpp
voip/tgcalls/AudioDeviceHelper.cpp
voip/tgcalls/SctpDataChannelProviderInterfaceImpl.cpp
voip/tgcalls/TurnCustomizerImpl.cpp
voip/tgcalls/reference/InstanceImplReference.cpp
voip/tgcalls/legacy/InstanceImplLegacy.cpp
voip/tgcalls/group/GroupNetworkManager.cpp
Expand Down
8 changes: 1 addition & 7 deletions TMessagesProj/jni/voip/tgcalls/CodecSelectHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int FormatPriority(const VideoFormat &format, const std::vector<std::string> &pr
}
return result;
}();

for (int i = 0; i < preferredCodecs.size(); i++) {
for (const auto &name : kSupported) {
if (absl::EqualsIgnoreCase(format.name, preferredCodecs[i]) && absl::EqualsIgnoreCase(format.name, name)) {
Expand Down Expand Up @@ -114,12 +114,6 @@ std::vector<VideoFormat>::const_iterator FindEqualFormat(
});
}

bool ContainsEqualFormat(
const std::vector<VideoFormat> &list,
const VideoFormat &format) {
return FindEqualFormat(list, format) != list.end();
}

void AddDefaultFeedbackParams(cricket::VideoCodec *codec) {
// Don't add any feedback params for RED and ULPFEC.
if (codec->name == cricket::kRedCodecName || codec->name == cricket::kUlpfecCodecName)
Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/voip/tgcalls/EncryptedConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ void EncryptedConnection::appendAdditionalMessages(rtc::CopyOnWriteBuffer &buffe
}

const auto now = rtc::TimeMillis();
auto someWereNotAdded = false;
for (auto &resending : _myNotYetAckedMessages) {
const auto sent = resending.lastSent;
const auto when = sent
Expand Down Expand Up @@ -471,6 +470,7 @@ auto EncryptedConnection::processPacket(
}
const auto success = reader.ReadUInt32(&currentSeq);
assert(success);
(void)success;
currentCounter = CounterFromSeq(currentSeq);

additionalMessage = true;
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/jni/voip/tgcalls/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void Serialize(rtc::ByteBufferWriter &to, const cricket::Candidate &from) {
std::string serialized;
const auto success = iceCandidate.ToString(&serialized);
assert(success);
(void)success;
Serialize(to, serialized);
}

Expand Down
19 changes: 1 addition & 18 deletions TMessagesProj/jni/voip/tgcalls/NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "api/jsep_ice_candidate.h"
#include "rtc_base/network_monitor_factory.h"

#include "TurnCustomizerImpl.h"
#include "platform/PlatformInterface.h"

extern "C" {
Expand Down Expand Up @@ -61,24 +62,6 @@ class TgCallsCryptStringImpl : public rtc::CryptStringImpl {
std::string _value;
};

class TurnCustomizerImpl : public webrtc::TurnCustomizer {
public:
TurnCustomizerImpl() {
}

virtual ~TurnCustomizerImpl() {
}

void MaybeModifyOutgoingStunMessage(cricket::PortInterface* port,
cricket::StunMessage* message) override {
message->AddAttribute(std::make_unique<cricket::StunByteStringAttribute>(cricket::STUN_ATTR_SOFTWARE, "Telegram "));
}

bool AllowChannelData(cricket::PortInterface* port, const void *data, size_t size, bool payload) override {
return true;
}
};

NetworkManager::NetworkManager(
rtc::Thread *thread,
EncryptionKey encryptionKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include "SctpDataChannelProviderInterfaceImpl.h"

#include "p2p/base/dtls_transport.h"

namespace tgcalls {

SctpDataChannelProviderInterfaceImpl::SctpDataChannelProviderInterfaceImpl(
cricket::DtlsTransport *transportChannel,
bool isOutgoing,
std::function<void(bool)> onStateChanged,
std::function<void()> onTerminated,
std::function<void(std::string const &)> onMessageReceived,
std::shared_ptr<Threads> threads
) :
_threads(std::move(threads)),
_onStateChanged(onStateChanged),
_onTerminated(onTerminated),
_onMessageReceived(onMessageReceived) {
assert(_threads->getNetworkThread()->IsCurrent());

_sctpTransportFactory.reset(new cricket::SctpTransportFactory(_threads->getNetworkThread()));

_sctpTransport = _sctpTransportFactory->CreateSctpTransport(transportChannel);
_sctpTransport->SignalReadyToSendData.connect(this, &SctpDataChannelProviderInterfaceImpl::sctpReadyToSendData);
_sctpTransport->SignalDataReceived.connect(this, &SctpDataChannelProviderInterfaceImpl::sctpDataReceived);
_sctpTransport->SignalClosedAbruptly.connect(this, &SctpDataChannelProviderInterfaceImpl::sctpClosedAbruptly);

webrtc::InternalDataChannelInit dataChannelInit;
dataChannelInit.id = 0;
dataChannelInit.open_handshake_role = isOutgoing ? webrtc::InternalDataChannelInit::kOpener : webrtc::InternalDataChannelInit::kAcker;
_dataChannel = webrtc::SctpDataChannel::Create(
this,
"data",
dataChannelInit,
_threads->getNetworkThread(),
_threads->getNetworkThread()
);

_dataChannel->RegisterObserver(this);
}


SctpDataChannelProviderInterfaceImpl::~SctpDataChannelProviderInterfaceImpl() {
assert(_threads->getNetworkThread()->IsCurrent());

_dataChannel->UnregisterObserver();
_dataChannel->Close();
_dataChannel = nullptr;

_sctpTransport = nullptr;
_sctpTransportFactory.reset();
}

void SctpDataChannelProviderInterfaceImpl::sendDataChannelMessage(std::string const &message) {
assert(_threads->getNetworkThread()->IsCurrent());

if (_isDataChannelOpen) {
RTC_LOG(LS_INFO) << "Outgoing DataChannel message: " << message;

webrtc::DataBuffer buffer(message);
_dataChannel->Send(buffer);
} else {
RTC_LOG(LS_INFO) << "Could not send an outgoing DataChannel message: the channel is not open";
}
}

void SctpDataChannelProviderInterfaceImpl::OnStateChange() {
assert(_threads->getNetworkThread()->IsCurrent());

auto state = _dataChannel->state();
bool isDataChannelOpen = state == webrtc::DataChannelInterface::DataState::kOpen;
if (_isDataChannelOpen != isDataChannelOpen) {
_isDataChannelOpen = isDataChannelOpen;
_onStateChanged(_isDataChannelOpen);
}
}

void SctpDataChannelProviderInterfaceImpl::OnMessage(const webrtc::DataBuffer& buffer) {
assert(_threads->getNetworkThread()->IsCurrent());

if (!buffer.binary) {
std::string messageText(buffer.data.data(), buffer.data.data() + buffer.data.size());
RTC_LOG(LS_INFO) << "Incoming DataChannel message: " << messageText;

_onMessageReceived(messageText);
}
}

void SctpDataChannelProviderInterfaceImpl::updateIsConnected(bool isConnected) {
assert(_threads->getNetworkThread()->IsCurrent());

if (isConnected) {
if (!_isSctpTransportStarted) {
_isSctpTransportStarted = true;
_sctpTransport->Start(5000, 5000, 262144);
}
}
}

void SctpDataChannelProviderInterfaceImpl::sctpReadyToSendData() {
assert(_threads->getNetworkThread()->IsCurrent());

_dataChannel->OnTransportReady(true);
}

void SctpDataChannelProviderInterfaceImpl::sctpClosedAbruptly() {
assert(_threads->getNetworkThread()->IsCurrent());

if (_onTerminated) {
_onTerminated();
}
}

void SctpDataChannelProviderInterfaceImpl::sctpDataReceived(const cricket::ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& buffer) {
assert(_threads->getNetworkThread()->IsCurrent());

_dataChannel->OnDataReceived(params, buffer);
}

bool SctpDataChannelProviderInterfaceImpl::SendData(int sid, const webrtc::SendDataParams& params, const rtc::CopyOnWriteBuffer& payload, cricket::SendDataResult* result) {
assert(_threads->getNetworkThread()->IsCurrent());

return _sctpTransport->SendData(sid, params, payload);
}

bool SctpDataChannelProviderInterfaceImpl::ConnectDataChannel(webrtc::SctpDataChannel *data_channel) {
assert(_threads->getNetworkThread()->IsCurrent());

return true;
}

void SctpDataChannelProviderInterfaceImpl::DisconnectDataChannel(webrtc::SctpDataChannel* data_channel) {
assert(_threads->getNetworkThread()->IsCurrent());

return;
}

void SctpDataChannelProviderInterfaceImpl::AddSctpDataStream(int sid) {
assert(_threads->getNetworkThread()->IsCurrent());

_sctpTransport->OpenStream(sid);
}

void SctpDataChannelProviderInterfaceImpl::RemoveSctpDataStream(int sid) {
assert(_threads->getNetworkThread()->IsCurrent());

_threads->getNetworkThread()->Invoke<void>(RTC_FROM_HERE, [this, sid]() {
_sctpTransport->ResetStream(sid);
});
}

bool SctpDataChannelProviderInterfaceImpl::ReadyToSendData() const {
assert(_threads->getNetworkThread()->IsCurrent());

return _sctpTransport->ReadyToSendData();
}

}
Loading

1 comment on commit 7a60f94

@behnejad
Copy link

@behnejad behnejad commented on 7a60f94 Jul 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have few suggestions for app:

  • add a button to [never share with] section to clear the list instead of deleting one by one.
  • same thing with [always share]
  • add a new policy to profile picture which never share pic to anyone except a list user. we have to select my contact and adding all contacts to never share list then adding few contacts to always share.

Please sign in to comment.