Skip to content

Commit

Permalink
merge official 8.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
luvletter2333 committed Jul 6, 2022
2 parents 4f85d02 + 6cb1cdf commit a0f3ad4
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 162 deletions.
6 changes: 3 additions & 3 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import cn.hutool.core.util.RuntimeUtil
apply plugin: "com.android.application"
apply plugin: "kotlin-android"

def verName = "8.8.3-preview01"
def verName = "8.8.5-preview01"
def verCode = 640

if (System.getenv("DEBUG_BUILD") == "true") {
verName += "-" + RuntimeUtil.execForStr("git log --pretty=format:'%h' -n 1").trim()
}

def officialVer = "8.8.3"
def officialCode = 2705
def officialVer = "8.8.5"
def officialCode = 2721

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,7 @@ public static void checkForUpdates() {
}

public static void appCenterLog(Throwable e) {

}

public static boolean shouldShowClipboardToast() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class AnimatedFileDrawableStream implements FileLoadOperationStream {

private FileLoadOperation loadOperation;
private final FileLoadOperation loadOperation;
private CountDownLatch countDownLatch;
private TLRPC.Document document;
private ImageLocation location;
Expand All @@ -20,8 +20,6 @@ public class AnimatedFileDrawableStream implements FileLoadOperationStream {
private boolean finishedLoadingFile;
private String finishedFilePath;

private boolean ignored;

public AnimatedFileDrawableStream(TLRPC.Document d, ImageLocation l, Object p, int a, boolean prev) {
document = d;
location = l;
Expand Down Expand Up @@ -63,6 +61,7 @@ public int read(int offset, int readLength) {
}
synchronized (sync) {
if (canceled) {
FileLoader.getInstance(currentAccount).cancelLoadFile(document);
return 0;
}
countDownLatch = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public void onCreate() {

if (BuildVars.LOGS_ENABLED) {
FileLog.d("app start time = " + (startTime = SystemClock.elapsedRealtime()));
FileLog.d("buildVersion = " + BuildVars.BUILD_VERSION);
}
if (applicationContext == null) {
applicationContext = getApplicationContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ private PreloadRange(long o, long l) {
private int cdnChunkCheckSize = 1024 * 128;
private int maxDownloadRequests = 4;
private int maxDownloadRequestsBig = 4;
private int bigFileSizeFrom = 1024 * 1024;
private int bigFileSizeFrom = 10 * 1024 * 1024;
private int maxCdnParts = (int) (FileLoader.DEFAULT_MAX_FILE_SIZE / downloadChunkSizeBig);

//load small parts for stream
private int downloadChunkSizeAnimation = 1024 * 128;
private int maxDownloadRequestsAnimation = 4;

private final static int preloadMaxBytes = 2 * 1024 * 1024;

private String fileName;
Expand Down Expand Up @@ -136,7 +140,7 @@ private PreloadRange(long o, long l) {

private HashMap<Long, TLRPC.TL_fileHash> cdnHashes;

private boolean forceBig;
private boolean isStream;

private byte[] encryptKey;
private byte[] encryptIv;
Expand Down Expand Up @@ -174,17 +178,19 @@ private PreloadRange(long o, long l) {

private int currentType;
public FilePathDatabase.PathData pathSaveData;
private long startTime;

public interface FileLoadOperationDelegate {
void didFinishLoadingFile(FileLoadOperation operation, File finalFile);
void didFailedLoadingFile(FileLoadOperation operation, int state);
void didChangedLoadProgress(FileLoadOperation operation, long uploadedSize, long totalSize);
void saveFilePath(FilePathDatabase.PathData pathSaveData, File cacheFileFinal);
boolean hasAnotherRefOnFile(String path);
}

private void updateParams() {
if (MessagesController.getInstance(currentAccount).getfileExperimentalParams) {
downloadChunkSizeBig = 1024 * 128;
downloadChunkSizeBig = 1024 * 512;
maxDownloadRequests = 8;
maxDownloadRequestsBig = 8;
} else {
Expand All @@ -198,7 +204,7 @@ private void updateParams() {
public FileLoadOperation(ImageLocation imageLocation, Object parent, String extension, long size) {
updateParams();
parentObject = parent;
forceBig = imageLocation.imageType == FileLoader.IMAGE_TYPE_ANIMATION;
isStream = imageLocation.imageType == FileLoader.IMAGE_TYPE_ANIMATION;
if (imageLocation.isEncrypted()) {
location = new TLRPC.TL_inputEncryptedFileLocation();
location.id = imageLocation.location.volume_id;
Expand Down Expand Up @@ -632,10 +638,15 @@ public boolean start() {
}

public boolean start(final FileLoadOperationStream stream, final long streamOffset, final boolean steamPriority) {
startTime = System.currentTimeMillis();
updateParams();
if (currentDownloadChunkSize == 0) {
currentDownloadChunkSize = totalBytesCount >= bigFileSizeFrom || forceBig ? downloadChunkSizeBig : downloadChunkSize;
currentMaxDownloadRequests = totalBytesCount >= bigFileSizeFrom || forceBig ? maxDownloadRequestsBig : maxDownloadRequests;
if (isStream) {
currentDownloadChunkSize = downloadChunkSizeAnimation;
currentMaxDownloadRequests = maxDownloadRequestsAnimation;
}
currentDownloadChunkSize = totalBytesCount >= bigFileSizeFrom || isStream ? downloadChunkSizeBig : downloadChunkSize;
currentMaxDownloadRequests = totalBytesCount >= bigFileSizeFrom || isStream ? maxDownloadRequestsBig : maxDownloadRequests;
}
final boolean alreadyStarted = state != stateIdle;
final boolean wasPaused = paused;
Expand Down Expand Up @@ -782,7 +793,9 @@ public boolean start(final FileLoadOperationStream stream, final long streamOffs
}
boolean finalFileExist = cacheFileFinal.exists();
if (finalFileExist && (parentObject instanceof TLRPC.TL_theme || totalBytesCount != 0 && totalBytesCount != cacheFileFinal.length())) {
cacheFileFinal.delete();
if (!delegate.hasAnotherRefOnFile(cacheFileFinal.toString())) {
cacheFileFinal.delete();
}
finalFileExist = false;
}

Expand Down Expand Up @@ -1311,7 +1324,7 @@ private void onFinishLoadingFile(final boolean increment) {
}
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("finished downloading file to " + cacheFileFinal);
FileLog.d("finished downloading file to " + cacheFileFinal + " time = " + (System.currentTimeMillis() - startTime));
}
if (increment) {
if (currentType == ConnectionsManager.FileTypeAudio) {
Expand Down Expand Up @@ -1435,7 +1448,7 @@ private void requestFileOffsets(long offset) {
protected boolean processRequestResult(RequestInfo requestInfo, TLRPC.TL_error error) {
if (state != stateDownloading) {
if (BuildVars.DEBUG_VERSION) {
FileLog.d("trying to write to finished file " + cacheFileFinal + " offset " + requestInfo.offset);
FileLog.e(new Exception("trying to write to finished file " + cacheFileFinal + " offset " + requestInfo.offset));
}
return false;
}
Expand Down
27 changes: 22 additions & 5 deletions TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public interface FileLoaderDelegate {

private ConcurrentHashMap<String, FileLoadOperation> loadOperationPaths = new ConcurrentHashMap<>();
private ArrayList<FileLoadOperation> activeFileLoadOperation = new ArrayList<>();
private ConcurrentHashMap<String, Boolean> loadOperationPathsUI = new ConcurrentHashMap<>(10, 1, 2);
private ConcurrentHashMap<String, LoadOperationUIObject> loadOperationPathsUI = new ConcurrentHashMap<>(10, 1, 2);
private HashMap<String, Long> uploadSizes = new HashMap<>();

private HashMap<String, Boolean> loadingVideos = new HashMap<>();
Expand Down Expand Up @@ -524,7 +524,12 @@ private void cancelLoadFile(final TLRPC.Document document, final SecureDocument
} else {
fileName = name;
}
boolean removed = loadOperationPathsUI.remove(fileName) != null;
LoadOperationUIObject uiObject = loadOperationPathsUI.remove(fileName);
Runnable runnable = uiObject != null ? uiObject.loadInternalRunnable : null;
boolean removed = uiObject != null;
if (runnable != null) {
fileLoaderQueue.cancelRunnable(runnable);
}
fileLoaderQueue.postRunnable(() -> {
FileLoadOperation operation = loadOperationPaths.remove(fileName);
if (operation != null) {
Expand Down Expand Up @@ -632,7 +637,7 @@ private FileLoadOperation loadFileInternal(final TLRPC.Document document, final
return null;
}
if (cacheType != 10 && !TextUtils.isEmpty(fileName) && !fileName.contains("" + Integer.MIN_VALUE)) {
loadOperationPathsUI.put(fileName, true);
loadOperationPathsUI.put(fileName, new LoadOperationUIObject());
}

if (document != null && parentObject instanceof MessageObject && ((MessageObject) parentObject).putInDownloadsStore && !((MessageObject) parentObject).isAnyKindOfSticker()) {
Expand Down Expand Up @@ -845,6 +850,11 @@ public void didChangedLoadProgress(FileLoadOperation operation, long uploadedSiz
public void saveFilePath(FilePathDatabase.PathData pathSaveData, File cacheFileFinal) {
getFileDatabase().putPath(pathSaveData.id, pathSaveData.dc, pathSaveData.type, cacheFileFinal != null ? cacheFileFinal.toString() : null);
}

@Override
public boolean hasAnotherRefOnFile(String path) {
return getFileDatabase().hasAnotherRefOnFile(path);
}
};
operation.setDelegate(fileLoadOperationDelegate);

Expand Down Expand Up @@ -970,10 +980,13 @@ private void loadFile(final TLRPC.Document document, final SecureDocument secure
} else {
fileName = null;
}
Runnable runnable = () -> loadFileInternal(document, secureDocument, webDocument, location, imageLocation, parentObject, locationExt, locationSize, priority, null, 0, false, cacheType);
if (cacheType != 10 && !TextUtils.isEmpty(fileName) && !fileName.contains("" + Integer.MIN_VALUE)) {
loadOperationPathsUI.put(fileName, true);
LoadOperationUIObject uiObject = new FileLoader.LoadOperationUIObject();
uiObject.loadInternalRunnable = runnable;
loadOperationPathsUI.put(fileName, uiObject);
}
fileLoaderQueue.postRunnable(() -> loadFileInternal(document, secureDocument, webDocument, location, imageLocation, parentObject, locationExt, locationSize, priority, null, 0, false, cacheType));
fileLoaderQueue.postRunnable(runnable);
}

protected FileLoadOperation loadStreamFile(final FileLoadOperationStream stream, final TLRPC.Document document, final ImageLocation location, final Object parentObject, final int offset, final boolean priority) {
Expand Down Expand Up @@ -1664,4 +1677,8 @@ public static boolean checkUploadFileSize(int currentAccount, long length) {
}
return false;
}

private static class LoadOperationUIObject {
Runnable loadInternalRunnable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FilePathDatabase {
private File cacheFile;
private File shmCacheFile;

private final static int LAST_DB_VERSION = 1;
private final static int LAST_DB_VERSION = 2;

private final static String DATABASE_NAME = "file_to_path";
private final static String DATABASE_BACKUP_NAME = "file_to_path_backup";
Expand Down Expand Up @@ -57,6 +57,7 @@ public void createDatabase(int tryCount, boolean fromBackup) {

if (createTable) {
database.executeFast("CREATE TABLE paths(document_id INTEGER, dc_id INTEGER, type INTEGER, path TEXT, PRIMARY KEY(document_id, dc_id, type));").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS path_in_paths ON paths(path);").stepThis().dispose();
database.executeFast("PRAGMA user_version = " + LAST_DB_VERSION).stepThis().dispose();
} else {
int version = database.executeInt("PRAGMA user_version");
Expand All @@ -66,6 +67,7 @@ public void createDatabase(int tryCount, boolean fromBackup) {
if (version == 0) {
throw new Exception("malformed");
}
migrateDatabase(version);
//migration
}
if (!fromBackup) {
Expand All @@ -89,6 +91,14 @@ public void createDatabase(int tryCount, boolean fromBackup) {
}
}

private void migrateDatabase(int version) throws SQLiteException {
if (version == 1) {
database.executeFast("CREATE INDEX IF NOT EXISTS path_in_paths ON paths(path);").stepThis().dispose();
database.executeFast("PRAGMA user_version = " + 2).stepThis().dispose();
version = 2;
}
}

private void createBackup() {
File filesDir = ApplicationLoader.getFilesDirFixed();
if (currentAccount != 0) {
Expand Down Expand Up @@ -117,7 +127,7 @@ private boolean restoreBackup() {
try {
return AndroidUtilities.copyFile(backupCacheFile, cacheFile);
} catch (IOException e) {
FileLog.e(e);
FileLog.e(e);
}
return false;
}
Expand Down Expand Up @@ -182,6 +192,7 @@ public void putPath(long id, int dc, int type, String path) {
SQLitePreparedStatement state = null;
try {
if (path != null) {
database.executeFast("DELETE FROM paths WHERE path = '" + path + "'");
state = database.executeFast("REPLACE INTO paths VALUES(?, ?, ?, ?)");
state.requery();
state.bindLong(1, id);
Expand Down Expand Up @@ -243,6 +254,29 @@ public void clear() {
});
}

public boolean hasAnotherRefOnFile(String path) {
CountDownLatch syncLatch = new CountDownLatch(1);
boolean[] res = new boolean[]{false};
dispatchQueue.postRunnable(() -> {
try {
SQLiteCursor cursor = database.queryFinalized("SELECT document_id FROM paths WHERE path = '" + path + "'");
if (cursor.next()) {
res[0] = true;
}
} catch (Exception e) {
FileLog.e(e);
}
syncLatch.countDown();
});

try {
syncLatch.await();
} catch (InterruptedException e) {
FileLog.e(e);
}
return res[0];
}

public static class PathData {
public final long id;
public final int dc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1742,12 +1742,12 @@ public void setImageAndClear(final Drawable image, String decrementKey) {
final ArrayList<ImageReceiver> finalImageReceiverArray = new ArrayList<>(imageReceiverArray);
final ArrayList<Integer> finalImageReceiverGuidsArray = new ArrayList<>(imageReceiverGuidsArray);
AndroidUtilities.runOnUIThread(() -> {
if (image instanceof AnimatedFileDrawable) {
if (image instanceof AnimatedFileDrawable && !((AnimatedFileDrawable) image).isWebmSticker) {
boolean imageSet = false;
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) image;
for (int a = 0; a < finalImageReceiverArray.size(); a++) {
ImageReceiver imgView = finalImageReceiverArray.get(a);
AnimatedFileDrawable toSet = fileDrawable;
AnimatedFileDrawable toSet = (a == 0 ? fileDrawable : fileDrawable.makeCopy());
if (imgView.setImageBitmapByKey(toSet, key, type, false, finalImageReceiverGuidsArray.get(a))) {
if (toSet == fileDrawable) {
imageSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ private void clear() {
private ArrayList<Runnable> loadingOperations = new ArrayList<>();
private boolean attachedToWindow;
private boolean videoThumbIsSame;
private boolean allowLoadingOnAttachedOnly;
private boolean shouldLoadOnAttach;

public int animatedFileDrawableRepeatMaxCount;

Expand Down Expand Up @@ -410,6 +412,23 @@ public void setImage(ImageLocation fileLocation, String fileFilter, ImageLocatio
}

public void setImage(ImageLocation mediaLocation, String mediaFilter, ImageLocation imageLocation, String imageFilter, ImageLocation thumbLocation, String thumbFilter, Drawable thumb, long size, String ext, Object parentObject, int cacheType) {
if (allowLoadingOnAttachedOnly && !attachedToWindow) {
if (setImageBackup == null) {
setImageBackup = new SetImageBackup();
}
setImageBackup.mediaLocation = mediaLocation;
setImageBackup.mediaFilter = mediaFilter;
setImageBackup.imageLocation = imageLocation;
setImageBackup.imageFilter = imageFilter;
setImageBackup.thumbLocation = thumbLocation;
setImageBackup.thumbFilter = thumbFilter;
setImageBackup.thumb = thumb;
setImageBackup.size = size;
setImageBackup.ext = ext;
setImageBackup.cacheType = cacheType;
setImageBackup.parentObject = parentObject;
return;
}
if (ignoreImageSet) {
return;
}
Expand Down Expand Up @@ -625,7 +644,11 @@ public void setImage(ImageLocation mediaLocation, String mediaFilter, ImageLocat
if (delegate != null) {
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
}
loadImage();
isRoundVideo = parentObject instanceof MessageObject && ((MessageObject) parentObject).isRoundVideo();
}

private void loadImage() {
ImageLoader.getInstance().loadImageForImageReceiver(this);
if (parentView != null) {
if (invalidateAll) {
Expand All @@ -634,8 +657,6 @@ public void setImage(ImageLocation mediaLocation, String mediaFilter, ImageLocat
parentView.invalidate((int) imageX, (int) imageY, (int) (imageX + imageW), (int) (imageY + imageH));
}
}

isRoundVideo = parentObject instanceof MessageObject && ((MessageObject) parentObject).isRoundVideo();
}

public boolean canInvertBitmap() {
Expand Down Expand Up @@ -2518,4 +2539,8 @@ public void setVideoThumbIsSame(boolean b) {
videoThumbIsSame = b;
}

public void setAllowLoadingOnAttachedOnly(boolean b) {
allowLoadingOnAttachedOnly = b;
}

}
Loading

0 comments on commit a0f3ad4

Please sign in to comment.