diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index b170ae70a..c5289bb1a 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -277,7 +277,7 @@ android { } } - defaultConfig.versionCode = 2040 + defaultConfig.versionCode = 2042 def tgVoipDexFileName = "libtgvoip.dex" def tgVoipDexClasses = ["AudioRecordJNI", "AudioTrackJNI", "NativeTgVoipDelegate", "NativeTgVoipInstance", "TgVoipNativeLoader", "Resampler", "VLog"] diff --git a/TMessagesProj/jni/Android.mk b/TMessagesProj/jni/Android.mk index b95472bb6..241c4f507 100755 --- a/TMessagesProj/jni/Android.mk +++ b/TMessagesProj/jni/Android.mk @@ -353,7 +353,7 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_PRELINK_MODULE := false -LOCAL_MODULE := tmessages.30 +LOCAL_MODULE := tmessages.31 LOCAL_CFLAGS := -w -std=c11 -Os -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math -D__STDC_CONSTANT_MACROS diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index 0e31ff4a0..be36c89ba 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -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 = 2040; + public static int BUILD_VERSION = 2042; public static String BUILD_VERSION_STRING = "6.3.0"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java b/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java index f2d386256..84ebc8f30 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/DispatchQueue.java @@ -65,21 +65,21 @@ public class DispatchQueue extends Thread { } } - public void postRunnable(Runnable runnable) { - postRunnable(runnable, 0); + public boolean postRunnable(Runnable runnable) { lastTaskTime = SystemClock.elapsedRealtime(); + return postRunnable(runnable, 0); } - public void postRunnable(Runnable runnable, long delay) { + public boolean postRunnable(Runnable runnable, long delay) { try { syncLatch.await(); } catch (Exception e) { FileLog.e(e); } if (delay <= 0) { - handler.post(runnable); + return handler.post(runnable); } else { - handler.postDelayed(runnable, delay); + return handler.postDelayed(runnable, delay); } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java index ce360f73d..d0c8d0ee5 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java @@ -75,6 +75,9 @@ public class FileLoadOperation { private final static int preloadMaxBytes = 2 * 1024 * 1024; + private String fileName; + private int currentQueueType; + private SparseArray preloadedBytesRanges; private SparseIntArray requestedPreloadedBytesRanges; private RandomAccessFile preloadStream; @@ -130,6 +133,8 @@ public class FileLoadOperation { private SparseArray cdnHashes; + private boolean forceBig; + private byte[] encryptKey; private byte[] encryptIv; @@ -174,6 +179,7 @@ public class FileLoadOperation { public FileLoadOperation(ImageLocation imageLocation, Object parent, String extension, int size) { parentObject = parent; + forceBig = imageLocation.imageType == FileLoader.IMAGE_TYPE_ANIMATION; if (imageLocation.isEncrypted()) { location = new TLRPC.TL_inputEncryptedFileLocation(); location.id = imageLocation.location.volume_id; @@ -357,10 +363,16 @@ public class FileLoadOperation { return priority; } - public void setPaths(int instance, File store, File temp) { + public void setPaths(int instance, String name, int queueType, File store, File temp) { storePath = store; tempPath = temp; currentAccount = instance; + fileName = name; + currentQueueType = queueType; + } + + public int getQueueType() { + return currentQueueType; } public boolean wasStarted() { @@ -555,11 +567,7 @@ public class FileLoadOperation { } public String getFileName() { - if (location != null) { - return location.volume_id + "_" + location.local_id + "." + ext; - } else { - return Utilities.MD5(webFile.url) + "." + ext; - } + return fileName; } protected void removeStreamListener(final FileLoadOperationStream operation) { @@ -591,8 +599,8 @@ public class FileLoadOperation { public boolean start(final FileLoadOperationStream stream, final int streamOffset, final boolean steamPriority) { if (currentDownloadChunkSize == 0) { - currentDownloadChunkSize = totalBytesCount >= bigFileSizeFrom ? downloadChunkSizeBig : downloadChunkSize; - currentMaxDownloadRequests = totalBytesCount >= bigFileSizeFrom ? maxDownloadRequestsBig : maxDownloadRequests; + currentDownloadChunkSize = totalBytesCount >= bigFileSizeFrom || forceBig ? downloadChunkSizeBig : downloadChunkSize; + currentMaxDownloadRequests = totalBytesCount >= bigFileSizeFrom || forceBig ? maxDownloadRequestsBig : maxDownloadRequests; } final boolean alreadyStarted = state != stateIdle; final boolean wasPaused = paused; @@ -1449,7 +1457,7 @@ public class FileLoadOperation { if (location != null) { FileLog.e("invalid cdn hash " + location + " id = " + location.id + " local_id = " + location.local_id + " access_hash = " + location.access_hash + " volume_id = " + location.volume_id + " secret = " + location.secret); } else if (webLocation != null) { - FileLog.e("invalid cdn hash " + webLocation + " id = " + getFileName()); + FileLog.e("invalid cdn hash " + webLocation + " id = " + fileName); } } onFail(false, 0); @@ -1536,7 +1544,7 @@ public class FileLoadOperation { if (location != null) { FileLog.e(error.text + " " + location + " id = " + location.id + " local_id = " + location.local_id + " access_hash = " + location.access_hash + " volume_id = " + location.volume_id + " secret = " + location.secret); } else if (webLocation != null) { - FileLog.e(error.text + " " + webLocation + " id = " + getFileName()); + FileLog.e(error.text + " " + webLocation + " id = " + fileName); } } onFail(false, 0); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java index 673ee73e9..1c41de0e3 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java @@ -48,6 +48,10 @@ public class FileLoader extends BaseController { public static final int IMAGE_TYPE_SVG_WHITE = 4; public static final int IMAGE_TYPE_THEME_PREVIEW = 5; + public static final int QUEUE_TYPE_FILE = 0; + public static final int QUEUE_TYPE_IMAGE = 1; + public static final int QUEUE_TYPE_AUDIO = 2; + public final static long MAX_FILE_SIZE = 1024L * 1024L * 2000L; private volatile static DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue"); @@ -59,12 +63,12 @@ public class FileLoader extends BaseController { private int currentUploadOperationsCount = 0; private int currentUploadSmallOperationsCount = 0; - private SparseArray> loadOperationQueues = new SparseArray<>(); + private SparseArray> fileLoadOperationQueues = new SparseArray<>(); private SparseArray> audioLoadOperationQueues = new SparseArray<>(); - private SparseArray> photoLoadOperationQueues = new SparseArray<>(); - private SparseIntArray currentLoadOperationsCount = new SparseIntArray(); - private SparseIntArray currentAudioLoadOperationsCount = new SparseIntArray(); - private SparseIntArray currentPhotoLoadOperationsCount = new SparseIntArray(); + private SparseArray> imageLoadOperationQueues = new SparseArray<>(); + private SparseIntArray fileLoadOperationsCount = new SparseIntArray(); + private SparseIntArray audioLoadOperationsCount = new SparseIntArray(); + private SparseIntArray imageLoadOperationsCount = new SparseIntArray(); private ConcurrentHashMap loadOperationPaths = new ConcurrentHashMap<>(); private ArrayList activeFileLoadOperation = new ArrayList<>(); @@ -73,6 +77,8 @@ public class FileLoader extends BaseController { private HashMap loadingVideos = new HashMap<>(); + private String forceLoadingFile; + private static SparseArray mediaDirs = null; private FileLoaderDelegate delegate = null; @@ -357,31 +363,73 @@ public class FileLoader extends BaseController { }); } - private LinkedList getAudioLoadOperationQueue(int datacenterId) { - LinkedList audioLoadOperationQueue = audioLoadOperationQueues.get(datacenterId); - if (audioLoadOperationQueue == null) { - audioLoadOperationQueue = new LinkedList<>(); - audioLoadOperationQueues.put(datacenterId, audioLoadOperationQueue); + private LinkedList getLoadOperationQueue(int datacenterId, int type) { + SparseArray> queues; + if (type == QUEUE_TYPE_AUDIO) { + queues = audioLoadOperationQueues; + } else if (type == QUEUE_TYPE_IMAGE) { + queues = imageLoadOperationQueues; + } else { + queues = fileLoadOperationQueues; } - return audioLoadOperationQueue; + LinkedList queue = queues.get(datacenterId); + if (queue == null) { + queue = new LinkedList<>(); + queues.put(datacenterId, queue); + } + return queue; } - private LinkedList getPhotoLoadOperationQueue(int datacenterId) { - LinkedList photoLoadOperationQueue = photoLoadOperationQueues.get(datacenterId); - if (photoLoadOperationQueue == null) { - photoLoadOperationQueue = new LinkedList<>(); - photoLoadOperationQueues.put(datacenterId, photoLoadOperationQueue); + private SparseIntArray getLoadOperationCount(int type) { + SparseArray> queues; + if (type == QUEUE_TYPE_AUDIO) { + return audioLoadOperationsCount; + } else if (type == QUEUE_TYPE_IMAGE) { + return imageLoadOperationsCount; + } else { + return fileLoadOperationsCount; } - return photoLoadOperationQueue; } - private LinkedList getLoadOperationQueue(int datacenterId) { - LinkedList loadOperationQueue = loadOperationQueues.get(datacenterId); - if (loadOperationQueue == null) { - loadOperationQueue = new LinkedList<>(); - loadOperationQueues.put(datacenterId, loadOperationQueue); + public void setForceStreamLoadingFile(TLRPC.FileLocation location, String ext) { + if (location == null) { + return; } - return loadOperationQueue; + fileLoaderQueue.postRunnable(() -> { + forceLoadingFile = getAttachFileName(location, ext); + FileLoadOperation operation = loadOperationPaths.get(forceLoadingFile); + if (operation != null) { + if (operation.isPreloadVideoOperation()) { + operation.setIsPreloadVideoOperation(false); + } + operation.setForceRequest(true); + int datacenterId = operation.getDatacenterId(); + int queueType = operation.getQueueType(); + LinkedList downloadQueue = getLoadOperationQueue(datacenterId, queueType); + SparseIntArray count = getLoadOperationCount(queueType); + if (downloadQueue != null) { + int index = downloadQueue.indexOf(operation); + if (index >= 0) { + downloadQueue.remove(index); + if (operation.start()) { + count.put(datacenterId, count.get(datacenterId) + 1); + } + if (queueType == QUEUE_TYPE_FILE) { + if (operation.wasStarted() && !activeFileLoadOperation.contains(operation)) { + pauseCurrentFileLoadOperations(operation); + activeFileLoadOperation.add(operation); + } + } + } else { + pauseCurrentFileLoadOperations(operation); + operation.start(); + if (queueType == QUEUE_TYPE_FILE && !activeFileLoadOperation.contains(operation)) { + activeFileLoadOperation.add(operation); + } + } + } + } + }); } public void cancelLoadFile(TLRPC.Document document) { @@ -427,22 +475,14 @@ public class FileLoader extends BaseController { fileLoaderQueue.postRunnable(() -> { FileLoadOperation operation = loadOperationPaths.remove(fileName); if (operation != null) { + int queueType = operation.getQueueType(); int datacenterId = operation.getDatacenterId(); - if (MessageObject.isVoiceDocument(document) || MessageObject.isVoiceWebDocument(webDocument)) { - LinkedList audioLoadOperationQueue = getAudioLoadOperationQueue(datacenterId); - if (!audioLoadOperationQueue.remove(operation)) { - currentAudioLoadOperationsCount.put(datacenterId, currentAudioLoadOperationsCount.get(datacenterId) - 1); - } - } else if (secureDocument != null || location != null || MessageObject.isImageWebDocument(webDocument)) { - LinkedList photoLoadOperationQueue = getPhotoLoadOperationQueue(datacenterId); - if (!photoLoadOperationQueue.remove(operation)) { - currentPhotoLoadOperationsCount.put(datacenterId, currentPhotoLoadOperationsCount.get(datacenterId) - 1); - } - } else { - LinkedList loadOperationQueue = getLoadOperationQueue(datacenterId); - if (!loadOperationQueue.remove(operation)) { - currentLoadOperationsCount.put(datacenterId, currentLoadOperationsCount.get(datacenterId) - 1); - } + LinkedList queue = getLoadOperationQueue(datacenterId, queueType); + if (!queue.remove(operation)) { + SparseIntArray count = getLoadOperationCount(queueType); + count.put(datacenterId, count.get(datacenterId) - 1); + } + if (queueType == QUEUE_TYPE_FILE) { activeFileLoadOperation.remove(operation); } operation.cancel(); @@ -500,23 +540,25 @@ public class FileLoader extends BaseController { private void pauseCurrentFileLoadOperations(FileLoadOperation newOperation) { for (int a = 0; a < activeFileLoadOperation.size(); a++) { FileLoadOperation operation = activeFileLoadOperation.get(a); - if (operation == newOperation || operation.getDatacenterId() != newOperation.getDatacenterId()) { + if (operation == newOperation || operation.getDatacenterId() != newOperation.getDatacenterId() || operation.getFileName().equals(forceLoadingFile)) { continue; } activeFileLoadOperation.remove(operation); a--; int datacenterId = operation.getDatacenterId(); - LinkedList loadOperationQueue = getLoadOperationQueue(datacenterId); - loadOperationQueue.add(0, operation); + int queueType = operation.getQueueType(); + LinkedList downloadQueue = getLoadOperationQueue(datacenterId, queueType); + SparseIntArray count = getLoadOperationCount(queueType); + downloadQueue.add(0, operation); if (operation.wasStarted()) { - currentLoadOperationsCount.put(datacenterId, currentLoadOperationsCount.get(datacenterId) - 1); + count.put(datacenterId, count.get(datacenterId) - 1); } operation.pause(); } } private FileLoadOperation loadFileInternal(final TLRPC.Document document, final SecureDocument secureDocument, final WebFile webDocument, TLRPC.TL_fileLocationToBeDeprecated location, final ImageLocation imageLocation, Object parentObject, final String locationExt, final int locationSize, final int priority, final FileLoadOperationStream stream, final int streamOffset, boolean streamPriority, final int cacheType) { - String fileName = null; + String fileName; if (location != null) { fileName = getAttachFileName(location, locationExt); } else if (secureDocument != null) { @@ -525,6 +567,8 @@ public class FileLoader extends BaseController { fileName = getAttachFileName(document); } else if (webDocument != null) { fileName = getAttachFileName(webDocument); + } else { + fileName = null; } if (fileName == null || fileName.contains("" + Integer.MIN_VALUE)) { return null; @@ -533,45 +577,27 @@ public class FileLoader extends BaseController { loadOperationPathsUI.put(fileName, true); } - FileLoadOperation operation; - operation = loadOperationPaths.get(fileName); + FileLoadOperation operation = loadOperationPaths.get(fileName); if (operation != null) { if (cacheType != 10 && operation.isPreloadVideoOperation()) { operation.setIsPreloadVideoOperation(false); } if (stream != null || priority > 0) { int datacenterId = operation.getDatacenterId(); - - LinkedList audioLoadOperationQueue = getAudioLoadOperationQueue(datacenterId); - LinkedList photoLoadOperationQueue = getPhotoLoadOperationQueue(datacenterId); - LinkedList loadOperationQueue = getLoadOperationQueue(datacenterId); - operation.setForceRequest(true); - LinkedList downloadQueue; - if (MessageObject.isVoiceDocument(document) || MessageObject.isVoiceWebDocument(webDocument)) { - downloadQueue = audioLoadOperationQueue; - } else if (secureDocument != null || location != null || MessageObject.isImageWebDocument(webDocument)) { - downloadQueue = photoLoadOperationQueue; - } else { - downloadQueue = loadOperationQueue; - } + + int queueType = operation.getQueueType(); + LinkedList downloadQueue = getLoadOperationQueue(datacenterId, queueType); + SparseIntArray count = getLoadOperationCount(queueType); if (downloadQueue != null) { int index = downloadQueue.indexOf(operation); if (index >= 0) { downloadQueue.remove(index); if (stream != null) { - if (downloadQueue == audioLoadOperationQueue) { - if (operation.start(stream, streamOffset, streamPriority)) { - currentAudioLoadOperationsCount.put(datacenterId, currentAudioLoadOperationsCount.get(datacenterId) + 1); - } - } else if (downloadQueue == photoLoadOperationQueue) { - if (operation.start(stream, streamOffset, streamPriority)) { - currentPhotoLoadOperationsCount.put(datacenterId, currentPhotoLoadOperationsCount.get(datacenterId) + 1); - } - } else { - if (operation.start(stream, streamOffset, streamPriority)) { - currentLoadOperationsCount.put(datacenterId, currentLoadOperationsCount.get(datacenterId) + 1); - } + if (operation.start(stream, streamOffset, streamPriority)) { + count.put(datacenterId, count.get(datacenterId) + 1); + } + if (queueType == QUEUE_TYPE_FILE) { if (operation.wasStarted() && !activeFileLoadOperation.contains(operation)) { if (stream != null) { pauseCurrentFileLoadOperations(operation); @@ -587,7 +613,7 @@ public class FileLoader extends BaseController { pauseCurrentFileLoadOperations(operation); } operation.start(stream, streamOffset, streamPriority); - if (downloadQueue == loadOperationQueue && !activeFileLoadOperation.contains(operation)) { + if (queueType == QUEUE_TYPE_FILE && !activeFileLoadOperation.contains(operation)) { activeFileLoadOperation.add(operation); } } @@ -600,6 +626,14 @@ public class FileLoader extends BaseController { File tempDir = getDirectory(MEDIA_DIR_CACHE); File storeDir = tempDir; int type = MEDIA_DIR_CACHE; + int queueType; + if (type == MEDIA_DIR_AUDIO) { + queueType = QUEUE_TYPE_AUDIO; + } else if (secureDocument != null || location != null && (imageLocation == null || imageLocation.imageType != IMAGE_TYPE_ANIMATION) || MessageObject.isImageWebDocument(webDocument)) { + queueType = QUEUE_TYPE_IMAGE; + } else { + queueType = QUEUE_TYPE_FILE; + } if (secureDocument != null) { operation = new FileLoadOperation(secureDocument); @@ -633,12 +667,11 @@ public class FileLoader extends BaseController { } else if (cacheType == 2) { operation.setEncryptFile(true); } - operation.setPaths(currentAccount, storeDir, tempDir); + operation.setPaths(currentAccount, fileName, queueType, storeDir, tempDir); if (cacheType == 10) { operation.setIsPreloadVideoOperation(true); } - final String finalFileName = fileName; final int finalType = type; FileLoadOperation.FileLoadOperationDelegate fileLoadOperationDelegate = new FileLoadOperation.FileLoadOperationDelegate() { @Override @@ -647,27 +680,27 @@ public class FileLoader extends BaseController { return; } if (!operation.isPreloadVideoOperation()) { - loadOperationPathsUI.remove(finalFileName); + loadOperationPathsUI.remove(fileName); if (delegate != null) { - delegate.fileDidLoaded(finalFileName, finalFile, finalType); + delegate.fileDidLoaded(fileName, finalFile, finalType); } } - checkDownloadQueue(operation.getDatacenterId(), document, webDocument, location, finalFileName); + checkDownloadQueue(operation.getDatacenterId(), queueType, fileName); } @Override public void didFailedLoadingFile(FileLoadOperation operation, int reason) { - loadOperationPathsUI.remove(finalFileName); - checkDownloadQueue(operation.getDatacenterId(), document, webDocument, location, finalFileName); + loadOperationPathsUI.remove(fileName); + checkDownloadQueue(operation.getDatacenterId(), queueType, fileName); if (delegate != null) { - delegate.fileDidFailedLoad(finalFileName, reason); + delegate.fileDidFailedLoad(fileName, reason); } } @Override public void didChangedLoadProgress(FileLoadOperation operation, long uploadedSize, long totalSize) { if (delegate != null) { - delegate.fileLoadProgressChanged(finalFileName, uploadedSize, totalSize); + delegate.fileLoadProgressChanged(fileName, uploadedSize, totalSize); } } }; @@ -675,47 +708,42 @@ public class FileLoader extends BaseController { int datacenterId = operation.getDatacenterId(); - LinkedList audioLoadOperationQueue = getAudioLoadOperationQueue(datacenterId); - LinkedList photoLoadOperationQueue = getPhotoLoadOperationQueue(datacenterId); - LinkedList loadOperationQueue = getLoadOperationQueue(datacenterId); - loadOperationPaths.put(fileName, operation); operation.setPriority(priority); - if (type == MEDIA_DIR_AUDIO) { + + boolean started; + if (queueType == QUEUE_TYPE_AUDIO) { int maxCount = priority > 0 ? 3 : 1; - int count = currentAudioLoadOperationsCount.get(datacenterId); - if (stream != null || count < maxCount) { + int count = audioLoadOperationsCount.get(datacenterId); + if (started = (stream != null || count < maxCount)) { if (operation.start(stream, streamOffset, streamPriority)) { - currentAudioLoadOperationsCount.put(datacenterId, count + 1); + audioLoadOperationsCount.put(datacenterId, count + 1); } - } else { - addOperationToQueue(operation, audioLoadOperationQueue); } - } else if (location != null || MessageObject.isImageWebDocument(webDocument)) { + } else if (queueType == QUEUE_TYPE_IMAGE) { int maxCount = priority > 0 ? 6 : 2; - int count = currentPhotoLoadOperationsCount.get(datacenterId); - if (stream != null || count < maxCount) { + int count = imageLoadOperationsCount.get(datacenterId); + if (started = (stream != null || count < maxCount)) { if (operation.start(stream, streamOffset, streamPriority)) { - currentPhotoLoadOperationsCount.put(datacenterId, count + 1); + imageLoadOperationsCount.put(datacenterId, count + 1); } - } else { - addOperationToQueue(operation, photoLoadOperationQueue); } } else { int maxCount = priority > 0 ? 4 : 1; - int count = currentLoadOperationsCount.get(datacenterId); - if (stream != null || count < maxCount) { + int count = fileLoadOperationsCount.get(datacenterId); + if (started = (stream != null || count < maxCount)) { if (operation.start(stream, streamOffset, streamPriority)) { - currentLoadOperationsCount.put(datacenterId, count + 1); + fileLoadOperationsCount.put(datacenterId, count + 1); activeFileLoadOperation.add(operation); } if (operation.wasStarted() && stream != null) { pauseCurrentFileLoadOperations(operation); } - } else { - addOperationToQueue(operation, loadOperationQueue); } } + if (!started) { + addOperationToQueue(operation, getLoadOperationQueue(datacenterId, queueType)); + } return operation; } @@ -768,92 +796,53 @@ public class FileLoader extends BaseController { return result[0]; } - private void checkDownloadQueue(final int datacenterId, final TLRPC.Document document, final WebFile webDocument, final TLRPC.FileLocation location, final String arg1) { + private void checkDownloadQueue(int datacenterId, int queueType, String fileName) { fileLoaderQueue.postRunnable(() -> { - LinkedList audioLoadOperationQueue = getAudioLoadOperationQueue(datacenterId); - LinkedList photoLoadOperationQueue = getPhotoLoadOperationQueue(datacenterId); - LinkedList loadOperationQueue = getLoadOperationQueue(datacenterId); - - FileLoadOperation operation = loadOperationPaths.remove(arg1); - if (MessageObject.isVoiceDocument(document) || MessageObject.isVoiceWebDocument(webDocument)) { - int count = currentAudioLoadOperationsCount.get(datacenterId); - if (operation != null) { - if (operation.wasStarted()) { - count--; - currentAudioLoadOperationsCount.put(datacenterId, count); - } else { - audioLoadOperationQueue.remove(operation); - } + FileLoadOperation operation = loadOperationPaths.remove(fileName); + LinkedList queue = getLoadOperationQueue(datacenterId, queueType); + SparseIntArray operationCount = getLoadOperationCount(queueType); + int count = operationCount.get(datacenterId); + if (operation != null) { + if (operation.wasStarted()) { + count--; + operationCount.put(datacenterId, count); + } else { + queue.remove(operation); } - while (!audioLoadOperationQueue.isEmpty()) { - operation = audioLoadOperationQueue.get(0); - int maxCount = operation.getPriority() != 0 ? 3 : 1; - if (count < maxCount) { - operation = audioLoadOperationQueue.poll(); - if (operation != null && operation.start()) { - count++; - currentAudioLoadOperationsCount.put(datacenterId, count); - } - } else { - break; - } - } - } else if (location != null || MessageObject.isImageWebDocument(webDocument)) { - int count = currentPhotoLoadOperationsCount.get(datacenterId); - if (operation != null) { - if (operation.wasStarted()) { - count--; - currentPhotoLoadOperationsCount.put(datacenterId, count); - } else { - photoLoadOperationQueue.remove(operation); - } - } - while (!photoLoadOperationQueue.isEmpty()) { - operation = photoLoadOperationQueue.get(0); - int maxCount = operation.getPriority() != 0 ? 6 : 2; - if (count < maxCount) { - operation = photoLoadOperationQueue.poll(); - if (operation != null && operation.start()) { - count++; - currentPhotoLoadOperationsCount.put(datacenterId, count); - } - } else { - break; - } - } - } else { - int count = currentLoadOperationsCount.get(datacenterId); - if (operation != null) { - if (operation.wasStarted()) { - count--; - currentLoadOperationsCount.put(datacenterId, count); - } else { - loadOperationQueue.remove(operation); - } + if (queueType == QUEUE_TYPE_FILE) { activeFileLoadOperation.remove(operation); } - while (!loadOperationQueue.isEmpty()) { - operation = loadOperationQueue.get(0); - int maxCount = operation.isForceRequest() ? 3 : 1; - if (count < maxCount) { - operation = loadOperationQueue.poll(); - if (operation != null && operation.start()) { - count++; - currentLoadOperationsCount.put(datacenterId, count); + } + while (!queue.isEmpty()) { + operation = queue.get(0); + int maxCount; + if (queueType == QUEUE_TYPE_AUDIO) { + maxCount = operation.getPriority() != 0 ? 3 : 1; + } else if (queueType == QUEUE_TYPE_IMAGE) { + maxCount = operation.getPriority() != 0 ? 6 : 2; + } else { + maxCount = operation.isForceRequest() ? 3 : 1; + } + if (count < maxCount) { + operation = queue.poll(); + if (operation != null && operation.start()) { + count++; + operationCount.put(datacenterId, count); + if (queueType == QUEUE_TYPE_FILE) { if (!activeFileLoadOperation.contains(operation)) { activeFileLoadOperation.add(operation); } } - } else { - break; } + } else { + break; } } }); } - public void setDelegate(FileLoaderDelegate delegate) { - this.delegate = delegate; + public void setDelegate(FileLoaderDelegate fileLoaderDelegate) { + delegate = fileLoaderDelegate; } public static String getMessageFileName(TLRPC.Message message) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java index 2fe573a90..9761231db 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java @@ -1270,7 +1270,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, } } else if (id == NotificationCenter.mediaDidLoad) { int guid = (Integer) args[3]; - if (guid == playlistClassGuid) { + if (guid == playlistClassGuid && playingMessageObject != null) { long did = (Long) args[0]; int type = (Integer) args[4]; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index b19f9b01f..1bf658238 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -943,9 +943,6 @@ public class MessagesStorage extends BaseController { } public void cleanup(final boolean isLogin) { - if (!isLogin) { - storageQueue.cleanupQueue(); - } storageQueue.postRunnable(() -> { cleanupInternal(true); openDatabase(1); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java index 4bd3b1bed..f0c2620d3 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java @@ -22,7 +22,7 @@ import java.util.zip.ZipFile; public class NativeLoader { - private final static int LIB_VERSION = 30; + private final static int LIB_VERSION = 31; private final static String LIB_NAME = "tmessages." + LIB_VERSION; private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so"; private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java index f51d3537c..b38c519ce 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationsController.java @@ -226,7 +226,11 @@ public class NotificationsController extends BaseController { notificationChannel.enableLights(false); notificationChannel.enableVibration(false); notificationChannel.setSound(null, null); - systemNotificationManager.createNotificationChannel(notificationChannel); + try { + systemNotificationManager.createNotificationChannel(notificationChannel); + } catch (Exception e) { + FileLog.e(e); + } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java index 32a62989a..0a86f6d52 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java @@ -244,9 +244,16 @@ public class ChatActionCell extends BaseCell implements DownloadController.FileD protected void onDetachedFromWindow() { super.onDetachedFromWindow(); DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this); + imageReceiver.onDetachedFromWindow(); wasLayout = false; } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + imageReceiver.onAttachedToWindow(); + } + @Override public boolean onTouchEvent(MotionEvent event) { if (currentMessageObject == null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/StatisticPostInfoCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/StatisticPostInfoCell.java index cc824515f..5ad6cfc56 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/StatisticPostInfoCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/StatisticPostInfoCell.java @@ -73,7 +73,7 @@ public class StatisticPostInfoCell extends FrameLayout { linearLayout.addView(date, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f, Gravity.NO_GRAVITY, 0, 0, 8, 0)); linearLayout.addView(shares, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); - contentLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.TOP, 0, 2, 0, 0)); + contentLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.TOP, 0, 2, 0, 8)); addView(contentLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.NO_GRAVITY, 72, 0, 12, 0)); @@ -83,12 +83,6 @@ public class StatisticPostInfoCell extends FrameLayout { shares.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3)); } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(56), MeasureSpec.EXACTLY)); - } - public void setData(StatisticActivity.RecentPostInfo postInfo) { MessageObject messageObject = postInfo.message; if (messageObject.photoThumbs != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertPhotoLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertPhotoLayout.java index fe05ac2c0..8cae714f9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertPhotoLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertPhotoLayout.java @@ -780,7 +780,7 @@ public class ChatAttachAlertPhotoLayout extends ChatAttachAlert.AttachAlertLayou }; AndroidUtilities.lockOrientation(parentAlert.baseFragment.getParentActivity()); CameraController.getInstance().recordVideo(cameraView.getCameraSession(), outputFile, parentAlert.avatarPicker != 0, (thumbPath, duration) -> { - if (outputFile == null || parentAlert.baseFragment == null) { + if (outputFile == null || parentAlert.baseFragment == null || cameraView == null) { return; } mediaFromExternalCamera = false; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/FilterGLThread.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/FilterGLThread.java index 5d1bd8c58..435fe0386 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/FilterGLThread.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/FilterGLThread.java @@ -379,13 +379,13 @@ public class FilterGLThread extends DispatchQueue { } public Bitmap getTexture() { - if (!initied) { + if (!initied || !isAlive()) { return null; } final CountDownLatch countDownLatch = new CountDownLatch(1); final Bitmap[] object = new Bitmap[1]; try { - postRunnable(() -> { + if (postRunnable(() -> { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, filterShaders.getRenderFrameBuffer()); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, filterShaders.getRenderTexture(blurred ? 0 : 1), 0); GLES20.glClear(0); @@ -393,8 +393,9 @@ public class FilterGLThread extends DispatchQueue { countDownLatch.countDown(); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glClear(0); - }); - countDownLatch.await(); + })) { + countDownLatch.await(); + } } catch (Exception e) { FileLog.e(e); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ProfileGalleryView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ProfileGalleryView.java index 2e762d3e5..fc106b11d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ProfileGalleryView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ProfileGalleryView.java @@ -111,6 +111,10 @@ public class ProfileGalleryView extends CircularViewPager implements Notificatio imageReceiver.setAllowStartAnimation(true); imageReceiver.startAnimation(); } + ImageLocation location = videoLocations.get(p); + if (location != null) { + FileLoader.getInstance(currentAccount).setForceStreamLoadingFile(location.location, "mp4"); + } } else { if (currentAllow) { AnimatedFileDrawable fileDrawable = imageReceiver.getAnimation(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 641a00830..7340151dc 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -2019,7 +2019,11 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. } if (layout) { measureChildWithMargins(listView, widthMeasureSpec, 0, heightMeasureSpec, 0); - listView.layout(0, actionBarHeight, listView.getMeasuredWidth(), actionBarHeight + listView.getMeasuredHeight()); + try { + listView.layout(0, actionBarHeight, listView.getMeasuredWidth(), actionBarHeight + listView.getMeasuredHeight()); + } catch (Exception e) { + FileLog.e(e); + } } ignoreLayout = false; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/StatisticActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/StatisticActivity.java index 6a8866b86..23f8118e0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/StatisticActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/StatisticActivity.java @@ -480,7 +480,7 @@ public class StatisticActivity extends BaseFragment implements NotificationCente recyclerListView.setOnItemLongClickListener((view, position) -> { if (position >= adapter.topAdminsStartRow && position <= adapter.topAdminsEndRow) { int i = position - adapter.topAdminsStartRow; - topMembersVisible.get(i).onLongClick(chat, this, progressDialog); + topAdmins.get(i).onLongClick(chat, this, progressDialog); return true; } else if (position >= adapter.topMembersStartRow && position <= adapter.topMembersEndRow) { int i = position - adapter.topMembersStartRow; @@ -1355,6 +1355,9 @@ public class StatisticActivity extends BaseFragment implements NotificationCente } private void zoomOut(boolean animated) { + if (data.chartData.x == null) { + return; + } chartHeaderView.zoomOut(chartView, animated); chartView.legendSignatureView.chevron.setAlpha(1f); zoomedChartView.setHeader(null);