Skip to content

Commit

Permalink
Update to 5.13.0 (1820)
Browse files Browse the repository at this point in the history
Merged some parts of #1541
  • Loading branch information
DrKLO committed Jan 1, 2020
1 parent cc1dc35 commit 1eea3ab
Show file tree
Hide file tree
Showing 25 changed files with 206 additions and 105 deletions.
3 changes: 3 additions & 0 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ void reuse(JNIEnv *env, jclass c, jlong address) {

jobject getJavaByteBuffer(JNIEnv *env, jclass c, jlong address) {
NativeByteBuffer *buffer = (NativeByteBuffer *) (intptr_t) address;
if (buffer == nullptr) {
return nullptr;
}
return buffer->getJavaByteBuffer();
}

Expand Down
5 changes: 2 additions & 3 deletions TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2018,9 +2018,8 @@ void ConnectionsManager::requestSaltsForDatacenter(Datacenter *datacenter, bool
if (iter != requestingSaltsForDc.end()) {
requestingSaltsForDc.erase(iter);
}
if (error == nullptr) {
TL_future_salts *res = (TL_future_salts *) response;
datacenter->mergeServerSalts(res->salts, media);
if (response != nullptr) {
datacenter->mergeServerSalts((TL_future_salts *) response, media);
saveConfig();
}
}, nullptr, RequestFlagWithoutLogin | RequestFlagEnableUnauthorized | RequestFlagUseUnboundKey, datacenter->getDatacenterId(), connectionType, true);
Expand Down
12 changes: 6 additions & 6 deletions TMessagesProj/jni/tgnet/Datacenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ int64_t Datacenter::getServerSalt(bool media) {
return result;
}

void Datacenter::mergeServerSalts(std::vector<std::unique_ptr<TL_future_salt>> &newSalts, bool media) {
if (newSalts.empty()) {
void Datacenter::mergeServerSalts(TL_future_salts *futureSalts, bool media) {
if (futureSalts->salts.empty()) {
return;
}
std::vector<std::unique_ptr<TL_future_salt>> &salts = media ? mediaServerSalts : serverSalts;
Expand All @@ -694,11 +694,11 @@ void Datacenter::mergeServerSalts(std::vector<std::unique_ptr<TL_future_salt>> &
existingSalts.push_back(salts[a]->salt);
}
bool added = false;
size = newSalts.size();
size = futureSalts->salts.size();
for (uint32_t a = 0; a < size; a++) {
int64_t value = newSalts[a]->salt;
if (std::find(existingSalts.begin(), existingSalts.end(), value) == existingSalts.end() && newSalts[a]->valid_until > date) {
salts.push_back(std::unique_ptr<TL_future_salt>(std::move(newSalts[a])));
int64_t value = futureSalts->salts[a]->salt;
if (std::find(existingSalts.begin(), existingSalts.end(), value) == existingSalts.end() && futureSalts->salts[a]->valid_until > date) {
salts.push_back(std::unique_ptr<TL_future_salt>(std::move(futureSalts->salts[a])));
added = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion TMessagesProj/jni/tgnet/Datacenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TL_future_salt;
class Connection;
class NativeByteBuffer;
class TL_future_salt;
class TL_future_salts;
class TL_help_configSimple;
class ByteArray;
class TLObject;
Expand All @@ -41,7 +42,7 @@ class Datacenter : public HandshakeDelegate {
void clearAuthKey(HandshakeType type);
void clearServerSalts(bool media);
int64_t getServerSalt(bool media);
void mergeServerSalts(std::vector<std::unique_ptr<TL_future_salt>> &newSalts, bool media);
void mergeServerSalts(TL_future_salts *newSalts, bool media);
void addServerSalt(std::unique_ptr<TL_future_salt> &serverSalt, bool media);
bool containsServerSalt(int64_t value, bool media);
void suspendConnections(bool suspendPush);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BuildVars {
public static boolean USE_CLOUD_STRINGS = true;
public static boolean CHECK_UPDATES = true;
public static boolean TON_WALLET_STANDALONE = false;
public static int BUILD_VERSION = 1819;
public static int BUILD_VERSION = 1820;
public static String BUILD_VERSION_STRING = "5.13.0";
public static int APP_ID = 4;
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ private void requestReference(RequestInfo requestInfo) {
}

protected void startDownloadRequest() {
if (paused ||
if (paused || reuploadingCdn ||
state != stateDownloading ||
streamPriorityStartOffset == 0 && (
!nextPartWasPreloaded && (requestInfos.size() + delayedRequestInfos.size() >= currentMaxDownloadRequests) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ public String getPathToAttach() {
}
}

AudioManager.OnAudioFocusChangeListener audioRecordFocusChangedListener = focusChange -> {
if (focusChange != AudioManager.AUDIOFOCUS_GAIN) {
hasRecordAudioFocus = false;
}
};

public final static int VIDEO_BITRATE_1080 = 6800_000;
public final static int VIDEO_BITRATE_720 = 2621_440;
public final static int VIDEO_BITRATE_480 = 1000_000;
Expand Down Expand Up @@ -340,6 +346,7 @@ public String getPathToAttach() {
private float[] linearAcceleration = new float[3];

private int hasAudioFocus;
private boolean hasRecordAudioFocus;
private boolean callInProgress;
private int audioFocus = AUDIO_NO_FOCUS_NO_DUCK;
private boolean resumeAudioOnFocusGain;
Expand All @@ -350,7 +357,19 @@ public String getPathToAttach() {
private static final int AUDIO_NO_FOCUS_CAN_DUCK = 1;
private static final int AUDIO_FOCUSED = 2;

private ArrayList<MessageObject> videoConvertQueue = new ArrayList<>();
private class VideoConvertMessage {
public MessageObject messageObject;
public VideoEditedInfo videoEditedInfo;
public int currentAccount;

public VideoConvertMessage(MessageObject object, VideoEditedInfo info) {
messageObject = object;
currentAccount = messageObject.currentAccount;
videoEditedInfo = info;
}
}

private ArrayList<VideoConvertMessage> videoConvertQueue = new ArrayList<>();
private final Object videoQueueSync = new Object();
private HashMap<String, MessageObject> generatingWaveform = new HashMap<>();

Expand Down Expand Up @@ -2821,7 +2840,13 @@ public void startRecording(final int currentAccount, final long dialog_id, final
boolean paused = false;
if (playingMessageObject != null && isPlayingMessage(playingMessageObject) && !isMessagePaused()) {
paused = true;
pauseMessage(playingMessageObject);
}

if (!hasRecordAudioFocus) {
int result = NotificationsController.audioManager.requestAudioFocus(audioRecordFocusChangedListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
hasRecordAudioFocus = true;
}
}

try {
Expand Down Expand Up @@ -2960,12 +2985,20 @@ private void stopRecordingInternal(final int send, boolean notify, int scheduleD
NotificationCenter.getInstance(recordingCurrentAccount).postNotificationName(NotificationCenter.audioRecordTooShort, recordingGuid, false);
recordingAudioFileToSend.delete();
}
if (hasRecordAudioFocus) {
NotificationsController.audioManager.abandonAudioFocus(audioRecordFocusChangedListener);
hasRecordAudioFocus = false;
}
});
});
} else {
if (recordingAudioFile != null) {
recordingAudioFile.delete();
}
if (hasRecordAudioFocus) {
NotificationsController.audioManager.abandonAudioFocus(audioRecordFocusChangedListener);
hasRecordAudioFocus = false;
}
}
try {
if (audioRecorder != null) {
Expand Down Expand Up @@ -3490,7 +3523,7 @@ public boolean scheduleVideoConvert(MessageObject messageObject, boolean isEmpty
} else if (isEmpty) {
new File(messageObject.messageOwner.attachPath).delete();
}
videoConvertQueue.add(messageObject);
videoConvertQueue.add(new VideoConvertMessage(messageObject, messageObject.videoEditedInfo));
if (videoConvertQueue.size() == 1) {
startVideoConvertFromQueue();
}
Expand All @@ -3501,11 +3534,12 @@ public void cancelVideoConvert(MessageObject messageObject) {
if (messageObject != null) {
if (!videoConvertQueue.isEmpty()) {
for (int a = 0; a < videoConvertQueue.size(); a++) {
MessageObject object = videoConvertQueue.get(a);
if (object.getId() == messageObject.getId() && object.currentAccount == messageObject.currentAccount) {
VideoConvertMessage videoConvertMessage = videoConvertQueue.get(a);
MessageObject object = videoConvertMessage.messageObject;
if (object.equals(messageObject) && object.currentAccount == messageObject.currentAccount) {
if (a == 0) {
synchronized (videoConvertSync) {
messageObject.videoEditedInfo.canceled = true;
videoConvertMessage.videoEditedInfo.canceled = true;
}
} else {
videoConvertQueue.remove(a);
Expand All @@ -3519,10 +3553,12 @@ public void cancelVideoConvert(MessageObject messageObject) {

private boolean startVideoConvertFromQueue() {
if (!videoConvertQueue.isEmpty()) {
MessageObject messageObject = videoConvertQueue.get(0);
VideoConvertMessage videoConvertMessage = videoConvertQueue.get(0);
MessageObject messageObject = videoConvertMessage.messageObject;
VideoEditedInfo videoEditedInfo = videoConvertMessage.videoEditedInfo;
synchronized (videoConvertSync) {
if (messageObject != null && messageObject.videoEditedInfo != null) {
messageObject.videoEditedInfo.canceled = false;
if (videoEditedInfo != null) {
videoEditedInfo.canceled = false;
}
}
Intent intent = new Intent(ApplicationLoader.applicationContext, VideoEncodingService.class);
Expand All @@ -3544,7 +3580,7 @@ private boolean startVideoConvertFromQueue() {
FileLog.e(e);
}
}
VideoConvertRunnable.runConversion(messageObject);
VideoConvertRunnable.runConversion(videoConvertMessage);
return true;
}
return false;
Expand Down Expand Up @@ -3624,44 +3660,44 @@ public static int findTrack(MediaExtractor extractor, boolean audio) {
return -5;
}

private void didWriteData(final MessageObject messageObject, final File file, final boolean last, long availableSize, final boolean error, final float progress) {
final boolean firstWrite = messageObject.videoEditedInfo.videoConvertFirstWrite;
private void didWriteData(final VideoConvertMessage message, final File file, final boolean last, long availableSize, final boolean error, final float progress) {
final boolean firstWrite = message.videoEditedInfo.videoConvertFirstWrite;
if (firstWrite) {
messageObject.videoEditedInfo.videoConvertFirstWrite = false;
message.videoEditedInfo.videoConvertFirstWrite = false;
}
AndroidUtilities.runOnUIThread(() -> {
if (error || last) {
synchronized (videoConvertSync) {
messageObject.videoEditedInfo.canceled = false;
message.videoEditedInfo.canceled = false;
}
videoConvertQueue.remove(messageObject);
videoConvertQueue.remove(message);
startVideoConvertFromQueue();
}
if (error) {
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.filePreparingFailed, messageObject, file.toString(), progress);
NotificationCenter.getInstance(message.currentAccount).postNotificationName(NotificationCenter.filePreparingFailed, message.messageObject, file.toString(), progress);
} else {
if (firstWrite) {
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.filePreparingStarted, messageObject, file.toString(), progress);
NotificationCenter.getInstance(message.currentAccount).postNotificationName(NotificationCenter.filePreparingStarted, message.messageObject, file.toString(), progress);
}
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.fileNewChunkAvailable, messageObject, file.toString(), availableSize, last ? file.length() : 0, progress);
NotificationCenter.getInstance(message.currentAccount).postNotificationName(NotificationCenter.fileNewChunkAvailable, message.messageObject, file.toString(), availableSize, last ? file.length() : 0, progress);
}
});
}

private static class VideoConvertRunnable implements Runnable {

private MessageObject messageObject;
private VideoConvertMessage convertMessage;

private VideoConvertRunnable(MessageObject message) {
messageObject = message;
private VideoConvertRunnable(VideoConvertMessage message) {
convertMessage = message;
}

@Override
public void run() {
MediaController.getInstance().convertVideo(messageObject);
MediaController.getInstance().convertVideo(convertMessage);
}

public static void runConversion(final MessageObject obj) {
public static void runConversion(final VideoConvertMessage obj) {
new Thread(() -> {
try {
VideoConvertRunnable wrapper = new VideoConvertRunnable(obj);
Expand All @@ -3676,8 +3712,9 @@ public static void runConversion(final MessageObject obj) {
}


private boolean convertVideo(final MessageObject messageObject) {
VideoEditedInfo info = messageObject.videoEditedInfo;
private boolean convertVideo(final VideoConvertMessage convertMessage) {
MessageObject messageObject = convertMessage.messageObject;
VideoEditedInfo info = convertMessage.videoEditedInfo;
if (messageObject == null || info == null) {
return false;
}
Expand Down Expand Up @@ -3767,7 +3804,7 @@ public void didWriteData(long availableSize, float progress) {
}

lastAvailableSize = availableSize;
MediaController.this.didWriteData(messageObject, cacheFile, false, availableSize, false, progress);
MediaController.this.didWriteData(convertMessage, cacheFile, false, availableSize, false, progress);
}
};

Expand Down Expand Up @@ -3795,7 +3832,7 @@ public void didWriteData(long availableSize, float progress) {
}

preferences.edit().putBoolean("isPreviousOk", true).apply();
didWriteData(messageObject, cacheFile, true, cacheFile.length(), error || canceled, 1f);
didWriteData(convertMessage, cacheFile, true, cacheFile.length(), error || canceled, 1f);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,11 @@ private void searchMessagesInChat(String query, final long dialogId, final long
searchResultMessagesMap[0].clear();
searchResultMessagesMap[1].clear();
messagesSearchCount[0] = 0;
getNotificationCenter().postNotificationName(NotificationCenter.chatSearchResultsLoading, guid);
}
boolean added = false;
for (int a = 0; a < Math.min(res.messages.size(), 20); a++) {
int N = Math.min(res.messages.size(), 20);
for (int a = 0; a < N; a++) {
TLRPC.Message message = res.messages.get(a);
added = true;
MessageObject messageObject = new MessageObject(currentAccount, message, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5520,10 +5520,10 @@ public static void ensureMediaThumbExists(boolean isEncrypted, TLObject object,
}

public static String getKeyForPhotoSize(TLRPC.PhotoSize photoSize, Bitmap[] bitmap, boolean blur, boolean forceCache) {
if (photoSize == null) {
if (photoSize == null || photoSize.location == null) {
return null;
}
Point point = ChatMessageCell.getMessageSize(photoSize.w,photoSize.h);
Point point = ChatMessageCell.getMessageSize(photoSize.w, photoSize.h);

if (bitmap != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ public static int getDevicePerfomanceClass() {
int androidVersion = Build.VERSION.SDK_INT;
int cpuCount = ConnectionsManager.CPU_COUNT;
int memoryClass = ((ActivityManager) ApplicationLoader.applicationContext.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
if (androidVersion < 21 || cpuCount <= 2 || memoryClass <= 100 || cpuCount <= 4 && maxCpuFreq != -1 && maxCpuFreq <= 1250 || cpuCount <= 4 && maxCpuFreq <= 1600 && memoryClass <= 128 && androidVersion <= 21) {
if (androidVersion < 21 || cpuCount <= 2 || memoryClass <= 100 || cpuCount <= 4 && maxCpuFreq != -1 && maxCpuFreq <= 1250 || cpuCount <= 4 && maxCpuFreq <= 1600 && memoryClass <= 128 && androidVersion <= 21 || cpuCount <= 4 && maxCpuFreq <= 1300 && memoryClass <= 128 && androidVersion <= 24) {
devicePerformanceClass = PERFORMANCE_CLASS_LOW;
} else if (cpuCount < 8 || memoryClass <= 160 || maxCpuFreq != -1 && maxCpuFreq <= 1650 || maxCpuFreq == -1 && cpuCount == 8 && androidVersion <= 23) {
devicePerformanceClass = PERFORMANCE_CLASS_AVERAGE;
Expand Down
Loading

3 comments on commit 1eea3ab

@PoliNetwork
Copy link

Choose a reason for hiding this comment

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

is there any chance you'll open "issue" tab so we can report bugs in an easier way? @DrKLO

@HitaloM
Copy link

@HitaloM HitaloM commented on 1eea3ab Jan 1, 2020

Choose a reason for hiding this comment

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

@PoliNetwork i think it's a great idea 😗

@AlexandrKozlovskiy
Copy link

Choose a reason for hiding this comment

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

Thank you very much for merging of part of my pull request #1541 . Now telegram become more accessible for blind users.

Please sign in to comment.