Update to 5.2.1

This commit is contained in:
DrKLO 2019-01-23 20:03:33 +03:00
parent 75d782181e
commit ae90d60e0c
1513 changed files with 124094 additions and 70006 deletions

View file

@ -1,17 +1,18 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* This is the source code of Telegram for Android v. 5.x.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2017.
* Copyright Nikolai Kudashov, 2013-2018.
*/
package org.telegram.messenger;
import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.BaseDataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.TransferListener;
@ -22,40 +23,44 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.concurrent.CountDownLatch;
public class FileStreamLoadOperation implements DataSource {
public class FileStreamLoadOperation extends BaseDataSource {
private final TransferListener listener;
private FileLoadOperation loadOperation;
private Uri uri;
private DataSpec dataSpec;
private long bytesRemaining;
private boolean opened;
private int currentOffset;
private CountDownLatch countDownLatch;
private RandomAccessFile file;
private TLRPC.Document document;
private Object parentObject;
private int currentAccount;
public FileStreamLoadOperation() {
this(null);
super(/* isNetwork= */ false);
}
public FileStreamLoadOperation(TransferListener listener) {
this.listener = listener;
@Deprecated
public FileStreamLoadOperation(@Nullable TransferListener listener) {
this();
if (listener != null) {
addTransferListener(listener);
}
}
@Override
public long open(DataSpec dataSpec) throws IOException {
uri = dataSpec.uri;
this.dataSpec = dataSpec;
currentAccount = Utilities.parseInt(uri.getQueryParameter("account"));
parentObject = FileLoader.getInstance(currentAccount).getParentObject(Utilities.parseInt(uri.getQueryParameter("rid")));
document = new TLRPC.TL_document();
document.access_hash = Utilities.parseLong(uri.getQueryParameter("hash"));
document.id = Utilities.parseLong(uri.getQueryParameter("id"));
document.size = Utilities.parseInt(uri.getQueryParameter("size"));
document.dc_id = Utilities.parseInt(uri.getQueryParameter("dc"));
document.mime_type = uri.getQueryParameter("mime");
document.file_reference = Utilities.hexToBytes(uri.getQueryParameter("reference"));
TLRPC.TL_documentAttributeFilename filename = new TLRPC.TL_documentAttributeFilename();
filename.file_name = uri.getQueryParameter("name");
document.attributes.add(filename);
@ -64,15 +69,13 @@ public class FileStreamLoadOperation implements DataSource {
} else if (document.mime_type.startsWith("audio")) {
document.attributes.add(new TLRPC.TL_documentAttributeAudio());
}
loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, currentOffset = (int) dataSpec.position);
loadOperation = FileLoader.getInstance(currentAccount).loadStreamFile(this, document, parentObject, currentOffset = (int) dataSpec.position);
bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? document.size - dataSpec.position : dataSpec.length;
if (bytesRemaining < 0) {
throw new EOFException();
}
opened = true;
if (listener != null) {
listener.onTransferStart(this, dataSpec, false);
}
transferStarted(dataSpec);
file = new RandomAccessFile(loadOperation.getCurrentFile(), "r");
file.seek(currentOffset);
return bytesRemaining;
@ -94,7 +97,7 @@ public class FileStreamLoadOperation implements DataSource {
availableLength = loadOperation.getDownloadedLengthFromOffset(currentOffset, readLength);
if (availableLength == 0) {
if (loadOperation.isPaused()) {
FileLoader.getInstance(currentAccount).loadStreamFile(this, document, currentOffset);
FileLoader.getInstance(currentAccount).loadStreamFile(this, document, parentObject, currentOffset);
}
countDownLatch = new CountDownLatch(1);
countDownLatch.await();
@ -103,9 +106,7 @@ public class FileStreamLoadOperation implements DataSource {
file.readFully(buffer, offset, availableLength);
currentOffset += availableLength;
bytesRemaining -= availableLength;
if (listener != null) {
listener.onBytesTransferred(this, dataSpec, false, availableLength);
}
bytesTransferred(availableLength);
} catch (Exception e) {
throw new IOException(e);
}
@ -137,9 +138,7 @@ public class FileStreamLoadOperation implements DataSource {
uri = null;
if (opened) {
opened = false;
if (listener != null) {
listener.onTransferEnd(this, dataSpec, false);
}
transferEnded();
}
}