Skip to content

Commit

Permalink
Update to 7.5.0 (2245)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKLO committed Feb 24, 2021
1 parent 31b5801 commit c44841a
Show file tree
Hide file tree
Showing 31 changed files with 197 additions and 55 deletions.
2 changes: 1 addition & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ android {
}
}

defaultConfig.versionCode = 2244
defaultConfig.versionCode = 2245

applicationVariants.all { variant ->
variant.outputs.all { output ->
Expand Down
2 changes: 1 addition & 1 deletion TMessagesProj/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ target_compile_definitions(sqlite PUBLIC
#voip
include(${CMAKE_HOME_DIRECTORY}/voip/CMakeLists.txt)

set(NATIVE_LIB "tmessages.35")
set(NATIVE_LIB "tmessages.36")

#tmessages
add_library(${NATIVE_LIB} SHARED
Expand Down
6 changes: 3 additions & 3 deletions TMessagesProj/jni/TgNetWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ void updateDcSettings(JNIEnv *env, jclass c, jint instanceNum) {
ConnectionsManager::getInstance(instanceNum).updateDcSettings(0, false);
}

void setUseIpv6(JNIEnv *env, jclass c, jint instanceNum, jboolean value) {
ConnectionsManager::getInstance(instanceNum).setUseIpv6(value);
void setIpStrategy(JNIEnv *env, jclass c, jint instanceNum, jbyte value) {
ConnectionsManager::getInstance(instanceNum).setIpStrategy((uint8_t) value);
}

void setNetworkAvailable(JNIEnv *env, jclass c, jint instanceNum, jboolean value, jint networkType, jboolean slow) {
Expand Down Expand Up @@ -448,7 +448,7 @@ static JNINativeMethod ConnectionsManagerMethods[] = {
{"native_pauseNetwork", "(I)V", (void *) pauseNetwork},
{"native_resumeNetwork", "(IZ)V", (void *) resumeNetwork},
{"native_updateDcSettings", "(I)V", (void *) updateDcSettings},
{"native_setUseIpv6", "(IZ)V", (void *) setUseIpv6},
{"native_setIpStrategy", "(IB)V", (void *) setIpStrategy},
{"native_setNetworkAvailable", "(IZIZ)V", (void *) setNetworkAvailable},
{"native_setPushConnectionEnabled", "(IZ)V", (void *) setPushConnectionEnabled},
{"native_setJava", "(Z)V", (void *) setJava},
Expand Down
12 changes: 11 additions & 1 deletion TMessagesProj/jni/tgnet/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,17 @@ void Connection::connect() {
connectionInProcess = true;
connectionState = TcpConnectionStageConnecting;
isMediaConnection = false;
uint32_t ipv6 = ConnectionsManager::getInstance(currentDatacenter->instanceNum).isIpv6Enabled() ? TcpAddressFlagIpv6 : 0;
uint8_t strategy = ConnectionsManager::getInstance(currentDatacenter->instanceNum).getIpStratagy();
uint32_t ipv6;
if (strategy == USE_IPV6_ONLY) {
ipv6 = TcpAddressFlagIpv6;
} else if (strategy == USE_IPV4_IPV6_RANDOM) {
uint8_t value;
RAND_bytes(&value, 1);
ipv6 = value % 2 == 0 ? TcpAddressFlagIpv6 : 0;
} else {
ipv6 = 0;
}
uint32_t isStatic = connectionType == ConnectionTypeProxy || !ConnectionsManager::getInstance(currentDatacenter->instanceNum).proxyAddress.empty() ? TcpAddressFlagStatic : 0;
TcpAddress *tcpAddress = nullptr;
if (isMediaConnectionType(connectionType)) {
Expand Down
8 changes: 4 additions & 4 deletions TMessagesProj/jni/tgnet/ConnectionsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,8 +1660,8 @@ void ConnectionsManager::sendPing(Datacenter *datacenter, bool usePushConnection
connection->sendData(transportData, false, true);
}

bool ConnectionsManager::isIpv6Enabled() {
return ipv6Enabled;
uint8_t ConnectionsManager::getIpStratagy() {
return ipStrategy;
}

void ConnectionsManager::initDatacenters() {
Expand Down Expand Up @@ -3419,9 +3419,9 @@ void ConnectionsManager::setNetworkAvailable(bool value, int32_t type, bool slow
});
}

void ConnectionsManager::setUseIpv6(bool value) {
void ConnectionsManager::setIpStrategy(uint8_t value) {
scheduleTask([&, value] {
ipv6Enabled = value;
ipStrategy = value;
});
}

Expand Down
6 changes: 3 additions & 3 deletions TMessagesProj/jni/tgnet/ConnectionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ConnectionsManager {
void resumeNetwork(bool partial);
void pauseNetwork();
void setNetworkAvailable(bool value, int32_t type, bool slow);
void setUseIpv6(bool value);
void setIpStrategy(uint8_t value);
void init(uint32_t version, int32_t layer, int32_t apiId, std::string deviceModel, std::string systemVersion, std::string appVersion, std::string langCode, std::string systemLangCode, std::string configPath, std::string logPath, std::string regId, std::string cFingerprint, std::string installerId, int32_t timezoneOffset, int32_t userId, bool isPaused, bool enablePushConnection, bool hasNetwork, int32_t networkType);
void setProxySettings(std::string address, uint16_t port, std::string username, std::string password, std::string secret);
void setLangCode(std::string langCode);
Expand Down Expand Up @@ -123,7 +123,7 @@ class ConnectionsManager {
void onDatacenterHandshakeComplete(Datacenter *datacenter, HandshakeType type, int32_t timeDiff);
void onDatacenterExportAuthorizationComplete(Datacenter *datacenter);
int64_t generateMessageId();
bool isIpv6Enabled();
uint8_t getIpStratagy();
bool isNetworkAvailable();

void scheduleCheckProxyInternal(ProxyCheckInfo *proxyCheckInfo);
Expand Down Expand Up @@ -192,7 +192,7 @@ class ConnectionsManager {
int64_t lastOutgoingMessageId = 0;
bool networkAvailable = true;
bool networkSlow = false;
bool ipv6Enabled = false;
uint8_t ipStrategy = USE_IPV4_ONLY;
std::vector<ConnectionSocket *> activeConnections;
std::vector<ConnectionSocket *> activeConnectionsCopy;
int epolFd;
Expand Down
3 changes: 2 additions & 1 deletion TMessagesProj/jni/tgnet/Datacenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,8 @@ bool Datacenter::isExportingAuthorization() {

bool Datacenter::hasMediaAddress() {
std::vector<TcpAddress> *addresses;
if (ConnectionsManager::getInstance(instanceNum).isIpv6Enabled()) {
int strategy = ConnectionsManager::getInstance(instanceNum).getIpStratagy();
if (strategy == USE_IPV6_ONLY) {
addresses = &addressesIpv6Download;
} else {
addresses = &addressesIpv4Download;
Expand Down
4 changes: 4 additions & 0 deletions TMessagesProj/jni/tgnet/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#define MAX_ACCOUNT_COUNT 3
#define USE_DELEGATE_HOST_RESOLVE

#define USE_IPV4_ONLY 0
#define USE_IPV6_ONLY 1
#define USE_IPV4_IPV6_RANDOM 2

#define NETWORK_TYPE_MOBILE 0
#define NETWORK_TYPE_WIFI 1
#define NETWORK_TYPE_ROAMING 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BuildVars {
public static boolean LOGS_ENABLED = false;
public static boolean USE_CLOUD_STRINGS = true;
public static boolean CHECK_UPDATES = true;
public static int BUILD_VERSION = 2244;
public static int BUILD_VERSION = 2245;
public static String BUILD_VERSION_STRING = "7.5.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 @@ -41,6 +41,7 @@ public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidge
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
ApplicationLoader.postInitApplication();
SharedPreferences preferences = context.getSharedPreferences("shortcut_widget", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
for (int a = 0; a < appWidgetIds.length; a++) {
Expand All @@ -58,15 +59,16 @@ public void onDeleted(Context context, int[] appWidgetIds) {

private static int getCellsForSize(int size) {
int n = 2;
while (70 * n - 30 < size) {
while (72 * n < size) {
++n;
}
return n - 1;
}

public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, boolean edit) {
ApplicationLoader.postInitApplication();
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
int rows = getCellsForSize(minHeight);

Intent intent2 = new Intent(context, ChatsWidgetService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
super.onDeleted(context, appWidgetIds);
ApplicationLoader.postInitApplication();
SharedPreferences preferences = context.getSharedPreferences("shortcut_widget", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
for (int a = 0; a < appWidgetIds.length; a++) {
Expand All @@ -58,16 +59,17 @@ public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidge

private static int getCellsForSize(int size) {
int n = 2;
while (86 * n - 30 < size) {
while (86 * n < size) {
++n;
}
return n - 1;
}

public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, boolean edit) {
ApplicationLoader.postInitApplication();
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
int rows = getCellsForSize(minHeight);
int maxHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT);
int rows = getCellsForSize(maxHeight);

Intent intent2 = new Intent(context, ContactsWidgetService.class);
intent2.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ public RemoteViews getViewAt(int position) {
}
} else {
chat = accountInstance.getMessagesController().getChat(-(int) (long) id);
name = chat.title;
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
photoPath = chat.photo.photo_small;
if (chat != null) {
name = chat.title;
if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) {
photoPath = chat.photo.photo_small;
}
} else {
name = "";
}
}
rv.setTextViewText(a == 0 ? R.id.contacts_widget_item_text1 : R.id.contacts_widget_item_text2, name);
Expand Down Expand Up @@ -175,7 +179,13 @@ public RemoteViews getViewAt(int position) {
TLRPC.Dialog dialog = dialogs.get(id);

if (dialog != null && dialog.unread_count > 0) {
rv.setTextViewText(a == 0 ? R.id.contacts_widget_item_badge1 : R.id.contacts_widget_item_badge2, String.format("%d", dialog.unread_count));
String count;
if (dialog.unread_count > 99) {
count = String.format("%d+", 99);
} else {
count = String.format("%d", dialog.unread_count);
}
rv.setTextViewText(a == 0 ? R.id.contacts_widget_item_badge1 : R.id.contacts_widget_item_badge2, count);
rv.setViewVisibility(a == 0 ? R.id.contacts_widget_item_badge_bg1 : R.id.contacts_widget_item_badge_bg2, View.VISIBLE);
} else {
rv.setViewVisibility(a == 0 ? R.id.contacts_widget_item_badge_bg1 : R.id.contacts_widget_item_badge_bg2, View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3486,7 +3486,7 @@ private void savePeerSettings(long dialogId, TLRPC.TL_peerSettings settings, boo
editor.remove("dialog_bar_distance" + dialogId);
}
}
editor.commit();
editor.apply();
getNotificationCenter().postNotificationName(NotificationCenter.peerSettingsDidLoad, dialogId);
}

Expand Down Expand Up @@ -9713,6 +9713,9 @@ protected void getChannelDifference(final int channelId, final int newDialogType

for (int a = 0; a < res.new_messages.size(); a++) {
TLRPC.Message message = res.new_messages.get(a);
if (message instanceof TLRPC.TL_messageEmpty) {
continue;
}
message.unread = !(channelFinal != null && channelFinal.left || (message.out ? outboxValue : inboxValue) >= message.id || message.action instanceof TLRPC.TL_messageActionChannelCreate);

boolean isDialogCreated = createdDialogIds.contains(dialog_id);
Expand Down Expand Up @@ -9949,6 +9952,9 @@ public void getDifference(int pts, final int date, final int qts, boolean slice)
int clientUserId = getUserConfig().getClientUserId();
for (int a = 0; a < res.new_messages.size(); a++) {
TLRPC.Message message = res.new_messages.get(a);
if (message instanceof TLRPC.TL_messageEmpty) {
continue;
}
MessageObject.getDialogId(message);

if ((int) message.dialog_id != 0) {
Expand Down Expand Up @@ -11355,6 +11361,9 @@ public boolean processUpdateArray(ArrayList<TLRPC.Update> updates, final ArrayLi
message.out = true;
}
}
if (message instanceof TLRPC.TL_messageEmpty) {
continue;
}
TLRPC.Chat chat = null;
int chat_id = 0;
int user_id = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8267,6 +8267,9 @@ private void putMessagesInternal(final ArrayList<TLRPC.Message> messages, final

for (int a = 0; a < messages.size(); a++) {
TLRPC.Message message = messages.get(a);
if (message instanceof TLRPC.TL_messageEmpty) {
continue;
}
fixUnsupportedMedia(message);

state_messages.requery();
Expand Down Expand Up @@ -10166,6 +10169,9 @@ public void putMessages(final TLRPC.messages_Messages messages, final long dialo
int count = messages.messages.size();
for (int a = 0; a < count; a++) {
TLRPC.Message message = messages.messages.get(a);
if (message instanceof TLRPC.TL_messageEmpty) {
continue;
}

long messageId = message.id;
if (channelId == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class NativeLoader {

private final static int LIB_VERSION = 35;
private final static int LIB_VERSION = 36;
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,9 @@ public int sendMessage(ArrayList<MessageObject> messages, final long peer, boole
newMsg.flags |= 8388608;
}
newMsg.message = msgObj.messageOwner.message;
if (newMsg.message == null) {
newMsg.message = "";
}
newMsg.fwd_msg_id = msgObj.getId();
newMsg.attachPath = msgObj.messageOwner.attachPath;
newMsg.entities = msgObj.messageOwner.entities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class ConnectionsManager extends BaseController {
public final static int ConnectionStateConnectingToProxy = 4;
public final static int ConnectionStateUpdating = 5;

public final static byte USE_IPV4_ONLY = 0;
public final static byte USE_IPV6_ONLY = 1;
public final static byte USE_IPV4_IPV6_RANDOM = 2;

private static long lastDnsRequestTime;

public final static int DEFAULT_DATACENTER_ID = Integer.MAX_VALUE;
Expand Down Expand Up @@ -333,7 +337,7 @@ public void setUserId(int id) {
}

public void checkConnection() {
native_setUseIpv6(currentAccount, useIpv6Address());
native_setIpStrategy(currentAccount, getIpStrategy());
native_setNetworkAvailable(currentAccount, ApplicationLoader.isNetworkOnline(), ApplicationLoader.getCurrentNetworkType(), ApplicationLoader.isConnectionSlow());
}

Expand Down Expand Up @@ -656,7 +660,7 @@ public static void setProxySettings(boolean enabled, String address, int port, S
public static native void native_switchBackend(int currentAccount);
public static native int native_isTestBackend(int currentAccount);
public static native void native_pauseNetwork(int currentAccount);
public static native void native_setUseIpv6(int currentAccount, boolean value);
public static native void native_setIpStrategy(int currentAccount, byte value);
public static native void native_updateDcSettings(int currentAccount);
public static native void native_setNetworkAvailable(int currentAccount, boolean value, int networkType, boolean slow);
public static native void native_resumeNetwork(int currentAccount, boolean partial);
Expand Down Expand Up @@ -701,9 +705,9 @@ public void setIsUpdating(final boolean value) {
}

@SuppressLint("NewApi")
protected static boolean useIpv6Address() {
protected static byte getIpStrategy() {
if (Build.VERSION.SDK_INT < 19) {
return false;
return USE_IPV4_ONLY;
}
if (BuildVars.LOGS_ENABLED) {
try {
Expand Down Expand Up @@ -741,6 +745,7 @@ protected static boolean useIpv6Address() {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
boolean hasIpv4 = false;
boolean hasIpv6 = false;
boolean hasStrangeIpv4 = false;
while (networkInterfaces.hasMoreElements()) {
networkInterface = networkInterfaces.nextElement();
if (!networkInterface.isUp() || networkInterface.isLoopback()) {
Expand All @@ -759,18 +764,25 @@ protected static boolean useIpv6Address() {
String addrr = inetAddress.getHostAddress();
if (!addrr.startsWith("192.0.0.")) {
hasIpv4 = true;
} else {
hasStrangeIpv4 = true;
}
}
}
}
if (!hasIpv4 && hasIpv6) {
return true;
if (hasIpv6) {
if (hasStrangeIpv4) {
return USE_IPV4_IPV6_RANDOM;
}
if (!hasIpv4) {
return USE_IPV6_ONLY;
}
}
} catch (Throwable e) {
FileLog.e(e);
}

return false;
return USE_IPV4_ONLY;
}

private static class ResolveHostByNameTask extends AsyncTask<Void, Void, ResolvedDomain> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ public boolean onTouchEvent(MotionEvent event) {
if (isAvatarVisible && avatarImage.isInsideImage(x, y + getTop())) {
avatarPressed = true;
result = true;
} else if (psaButtonVisible && psaHelpX != -1 && x >= psaHelpX && x <= psaHelpX + AndroidUtilities.dp(40) && y >= psaHelpY && y <= psaHelpY + AndroidUtilities.dp(40)) {
} else if (psaButtonVisible && hasPsaHint && x >= psaHelpX && x <= psaHelpX + AndroidUtilities.dp(40) && y >= psaHelpY && y <= psaHelpY + AndroidUtilities.dp(40)) {
psaHintPressed = true;
createSelectorDrawable(0);
selectorDrawableMaskType[0] = 3;
Expand Down
Loading

0 comments on commit c44841a

Please sign in to comment.