Commit dff666fc authored by DrKLO's avatar DrKLO

Update to 2.4.0

parent 2fcef37b
......@@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 416
versionName "2.3.3"
versionCode 423
versionName "2.4.0"
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -149,6 +149,7 @@
<service android:name="org.telegram.android.NotificationsService" android:enabled="true"/>
<service android:name="org.telegram.android.NotificationRepeat" android:exported="false"/>
<service android:name="org.telegram.android.NotificationDelay" android:exported="false"/>
<service android:name="org.telegram.android.VideoEncodingService" android:enabled="true"/>
<receiver android:name="org.telegram.android.AppStartReceiver" android:enabled="true">
......
......@@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Static library version of {@link android.util.LruCache}. Used to write apps
......@@ -41,8 +40,8 @@ public class LruCache {
throw new IllegalArgumentException("maxSize <= 0");
}
this.maxSize = maxSize;
this.map = new LinkedHashMap<String, BitmapDrawable>(0, 0.75f, true);
this.mapFilters = new LinkedHashMap<String, ArrayList<String>>();
this.map = new LinkedHashMap<>(0, 0.75f, true);
this.mapFilters = new LinkedHashMap<>();
}
/**
......@@ -69,7 +68,7 @@ public class LruCache {
public ArrayList<String> getFilterKeys(String key) {
ArrayList<String> arr = mapFilters.get(key);
if (arr != null) {
return new ArrayList<String>(arr);
return new ArrayList<>(arr);
}
return null;
}
......@@ -98,14 +97,17 @@ public class LruCache {
if (args.length > 1) {
ArrayList<String> arr = mapFilters.get(args[0]);
if (arr == null) {
arr = new ArrayList<String>();
arr = new ArrayList<>();
mapFilters.put(args[0], arr);
}
if (!arr.contains(args[1])) {
arr.add(args[1]);
}
}
if (previous != null) {
entryRemoved(false, key, previous, value);
ImageLoader.getInstance().callGC();
}
trimToSize(maxSize, key);
......@@ -137,15 +139,16 @@ public class LruCache {
if (args.length > 1) {
ArrayList<String> arr = mapFilters.get(args[0]);
if (arr != null) {
arr.remove(key);
arr.remove(args[1]);
if (arr.isEmpty()) {
mapFilters.remove(args[1]);
mapFilters.remove(args[0]);
}
}
}
entryRemoved(true, key, value, null);
}
ImageLoader.getInstance().callGC();
}
}
......@@ -172,14 +175,15 @@ public class LruCache {
if (args.length > 1) {
ArrayList<String> arr = mapFilters.get(args[0]);
if (arr != null) {
arr.remove(key);
arr.remove(args[1]);
if (arr.isEmpty()) {
mapFilters.remove(args[1]);
mapFilters.remove(args[0]);
}
}
}
entryRemoved(false, key, previous, null);
ImageLoader.getInstance().callGC();
}
return previous;
......
......@@ -122,6 +122,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public String bucketName;
public PhotoEntry coverPhoto;
public ArrayList<PhotoEntry> photos = new ArrayList<>();
public HashMap<Integer, PhotoEntry> photosByIds = new HashMap<>();
public AlbumEntry(int bucketId, String bucketName, PhotoEntry coverPhoto) {
this.bucketId = bucketId;
......@@ -131,6 +132,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public void addPhoto(PhotoEntry photoEntry) {
photos.add(photoEntry);
photosByIds.put(photoEntry.imageId, photoEntry);
}
}
......@@ -140,6 +142,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public long dateTaken;
public String path;
public int orientation;
public String thumbPath;
public String imagePath;
public PhotoEntry(int bucketId, int imageId, long dateTaken, String path, int orientation) {
this.bucketId = bucketId;
......@@ -1095,11 +1099,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
@Override
public void onSensorChanged(SensorEvent event) {
if (audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] == 0))) {
if (proximitySensor != null && audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] < proximitySensor.getMaximumRange() / 10))) {
return;
}
ignoreProximity = true;
useFrontSpeaker = event.values[0] == 0;
useFrontSpeaker = event.values[0] < proximitySensor.getMaximumRange() / 10;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
MessageObject currentMessageObject = playingMessageObject;
float progress = playingMessageObject.audioProgress;
......@@ -2450,12 +2454,16 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
decoder.start();
final int TIMEOUT_USEC = 2500;
ByteBuffer[] decoderInputBuffers = decoder.getInputBuffers();
ByteBuffer[] encoderOutputBuffers = encoder.getOutputBuffers();
ByteBuffer[] decoderInputBuffers = null;
ByteBuffer[] encoderOutputBuffers = null;
ByteBuffer[] encoderInputBuffers = null;
if (Build.VERSION.SDK_INT < 21) {
decoderInputBuffers = decoder.getInputBuffers();
encoderOutputBuffers = encoder.getOutputBuffers();
if (Build.VERSION.SDK_INT < 18) {
encoderInputBuffers = encoder.getInputBuffers();
}
}
checkConversionCanceled();
......@@ -2467,7 +2475,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (index == videoIndex) {
int inputBufIndex = decoder.dequeueInputBuffer(TIMEOUT_USEC);
if (inputBufIndex >= 0) {
ByteBuffer inputBuf = decoderInputBuffers[inputBufIndex];
ByteBuffer inputBuf = null;
if (Build.VERSION.SDK_INT < 21) {
inputBuf = decoderInputBuffers[inputBufIndex];
} else {
inputBuf = decoder.getInputBuffer(inputBufIndex);
}
int chunkSize = extractor.readSampleData(inputBuf, 0);
if (chunkSize < 0) {
decoder.queueInputBuffer(inputBufIndex, 0, 0, 0L, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
......@@ -2497,7 +2510,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (encoderStatus == MediaCodec.INFO_TRY_AGAIN_LATER) {
encoderOutputAvailable = false;
} else if (encoderStatus == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
if (Build.VERSION.SDK_INT < 21) {
encoderOutputBuffers = encoder.getOutputBuffers();
}
} else if (encoderStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
MediaFormat newFormat = encoder.getOutputFormat();
if (videoTrackIndex == -5) {
......@@ -2506,7 +2521,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else if (encoderStatus < 0) {
throw new RuntimeException("unexpected result from encoder.dequeueOutputBuffer: " + encoderStatus);
} else {
ByteBuffer encodedData = encoderOutputBuffers[encoderStatus];
ByteBuffer encodedData = null;
if (Build.VERSION.SDK_INT < 21) {
encodedData = encoderOutputBuffers[encoderStatus];
} else {
encodedData = encoder.getOutputBuffer(encoderStatus);
}
if (encodedData == null) {
throw new RuntimeException("encoderOutputBuffer " + encoderStatus + " was null");
}
......
......@@ -52,6 +52,8 @@ public class NotificationCenter {
public static final int httpFileDidLoaded = totalEvents++;
public static final int httpFileDidFailedLoad = totalEvents++;
public static final int messageThumbGenerated = totalEvents++;
public static final int wallpapersDidLoaded = totalEvents++;
public static final int closeOtherAppActivities = totalEvents++;
public static final int didUpdatedConnectionState = totalEvents++;
......@@ -70,16 +72,16 @@ public class NotificationCenter {
public static final int FileNewChunkAvailable = totalEvents++;
public static final int FilePreparingFailed = totalEvents++;
public final static int audioProgressDidChanged = totalEvents++;
public final static int audioDidReset = totalEvents++;
public final static int recordProgressChanged = totalEvents++;
public final static int recordStarted = totalEvents++;
public final static int recordStartError = totalEvents++;
public final static int recordStopped = totalEvents++;
public final static int screenshotTook = totalEvents++;
public final static int albumsDidLoaded = totalEvents++;
public final static int audioDidSent = totalEvents++;
public final static int audioDidStarted = totalEvents++;
public static final int audioProgressDidChanged = totalEvents++;
public static final int audioDidReset = totalEvents++;
public static final int recordProgressChanged = totalEvents++;
public static final int recordStarted = totalEvents++;
public static final int recordStartError = totalEvents++;
public static final int recordStopped = totalEvents++;
public static final int screenshotTook = totalEvents++;
public static final int albumsDidLoaded = totalEvents++;
public static final int audioDidSent = totalEvents++;
public static final int audioDidStarted = totalEvents++;
public static final int audioRouteChanged = totalEvents++;
final private HashMap<Integer, ArrayList<Object>> observers = new HashMap<>();
......
/*
* This is the source code of Telegram for Android v. 2.0.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-2014.
*/
package org.telegram.android;
import android.app.IntentService;
import android.content.Intent;
public class NotificationDelay extends IntentService {
public NotificationDelay() {
super("NotificationDelay");
}
@Override
protected void onHandleIntent(Intent intent) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationsController.getInstance().notificationDelayReached();
}
});
}
}
/*
* This is the source code of Telegram for Android v. 1.3.2.
* 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.
*/
package org.telegram.android;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Utilities;
import java.nio.ByteBuffer;
import java.util.ArrayList;
public class PhotoObject {
public TLRPC.PhotoSize photoOwner;
public Bitmap image;
public PhotoObject(TLRPC.PhotoSize photo, int preview, boolean secret) {
photoOwner = photo;
if (preview != 0 && photo instanceof TLRPC.TL_photoCachedSize) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
opts.inDither = false;
opts.outWidth = photo.w;
opts.outHeight = photo.h;
try {
if (photo.location.ext != null) {
ByteBuffer buffer = ByteBuffer.allocateDirect(photo.bytes.length);
buffer.put(photo.bytes);
image = Utilities.loadWebpImage(buffer, buffer.limit(), null);
} else {
image = BitmapFactory.decodeByteArray(photoOwner.bytes, 0, photoOwner.bytes.length, opts);
}
if (image != null) {
if (preview == 2) {
if (secret) {
Utilities.blurBitmap(image, 7);
Utilities.blurBitmap(image, 7);
Utilities.blurBitmap(image, 7);
} else {
if (photo.location.ext != null) {
Utilities.blurBitmap(image, 1);
} else {
Utilities.blurBitmap(image, 3);
}
}
}
if (ImageLoader.getInstance().runtimeHack != null) {
ImageLoader.getInstance().runtimeHack.trackFree(image.getRowBytes() * image.getHeight());
}
}
} catch (Throwable throwable) {
FileLog.e("tmessages", throwable);
}
}
}
public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int side) {
if (arr == null) {
return null;
}
int lastSide = 0;
PhotoObject closestObject = null;
for (PhotoObject obj : arr) {
if (obj == null || obj.photoOwner == null) {
continue;
}
int currentSide = obj.photoOwner.w >= obj.photoOwner.h ? obj.photoOwner.w : obj.photoOwner.h;
if (closestObject == null || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
closestObject = obj;
lastSide = currentSide;
}
}
return closestObject;
}
}
......@@ -478,7 +478,7 @@ public class SecretChatHelper {
reqSend.action.ttl_seconds = encryptedChat.ttl;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
MessageObject newMsgObj = new MessageObject(message, null);
MessageObject newMsgObj = new MessageObject(message, null, false);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(newMsgObj);
......@@ -514,7 +514,7 @@ public class SecretChatHelper {
reqSend.action.random_ids = random_ids;
message = createServiceSecretMessage(encryptedChat, reqSend.action);
MessageObject newMsgObj = new MessageObject(message, null);
MessageObject newMsgObj = new MessageObject(message, null, false);
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENDING;
ArrayList<MessageObject> objArr = new ArrayList<>();
objArr.add(newMsgObj);
......@@ -547,7 +547,7 @@ public class SecretChatHelper {
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.photo, 3);
//MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.photo, 3);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaVideo && newMsg.media.video != null) {
TLRPC.Video video = newMsg.media.video;
newMsg.media.video = new TLRPC.TL_videoEncrypted();
......@@ -578,7 +578,7 @@ public class SecretChatHelper {
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.video, 5);
//MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.video, 5);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaDocument && newMsg.media.document != null) {
TLRPC.Document document = newMsg.media.document;
newMsg.media.document = new TLRPC.TL_documentEncrypted();
......@@ -605,7 +605,7 @@ public class SecretChatHelper {
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.document, 4);
//MessagesStorage.getInstance().putSentFile(originalPath, newMsg.media.document, 4);
} else if (newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
TLRPC.Audio audio = newMsg.media.audio;
newMsg.media.audio = new TLRPC.TL_audioEncrypted();
......@@ -656,7 +656,8 @@ public class SecretChatHelper {
TLObject toEncryptObject = null;
if (AndroidUtilities.getPeerLayerVersion(chat.layer) >= 17) {
TLRPC.TL_decryptedMessageLayer layer = new TLRPC.TL_decryptedMessageLayer();
layer.layer = Math.min(17, AndroidUtilities.getPeerLayerVersion(chat.layer));
int myLayer = Math.max(17, AndroidUtilities.getMyLayerVersion(chat.layer));
layer.layer = Math.min(myLayer, AndroidUtilities.getPeerLayerVersion(chat.layer));
layer.message = req;
layer.random_bytes = new byte[Math.max(1, (int) Math.ceil(Utilities.random.nextDouble() * 16))];
Utilities.random.nextBytes(layer.random_bytes);
......@@ -698,6 +699,7 @@ public class SecretChatHelper {
toEncryptObject = req;
}
int len = toEncryptObject.getObjectSize();
ByteBufferDesc toEncrypt = BuffersStorage.getInstance().getFreeBuffer(4 + len);
toEncrypt.writeInt32(len);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment