Skip to content

Commit 1dcd153

Browse files
committed
update to 9.5.2
1 parent 1a48adb commit 1dcd153

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+587
-142
lines changed

‎TMessagesProj/jni/voip/webrtc/modules/utility/source/jvm_android.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ NativeRegistration::NativeRegistration(JNIEnv* jni, jclass clazz)
136136

137137
NativeRegistration::~NativeRegistration() {
138138
RTC_LOG(LS_INFO) << "NativeRegistration::dtor";
139-
jni_->UnregisterNatives(j_class_);
139+
//jni_->UnregisterNatives(j_class_);
140140
CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives";
141141
}
142142

‎TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java

+24-11
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,7 @@ public static ArrayList<File> getDataDirs() {
18781878
}
18791879

18801880
public static ArrayList<File> getRootDirs() {
1881+
HashSet<String> pathes = new HashSet<>();
18811882
ArrayList<File> result = null;
18821883
if (Build.VERSION.SDK_INT >= 19) {
18831884
File[] dirs = ApplicationLoader.applicationContext.getExternalFilesDirs(null);
@@ -1898,7 +1899,10 @@ public static ArrayList<File> getRootDirs() {
18981899
continue;
18991900
}
19001901
}
1901-
result.add(file);
1902+
if (file != null && !pathes.contains(file.getAbsolutePath())) {
1903+
pathes.add(file.getAbsolutePath());
1904+
result.add(file);
1905+
}
19021906
}
19031907
}
19041908
}
@@ -1907,7 +1911,10 @@ public static ArrayList<File> getRootDirs() {
19071911
result = new ArrayList<>();
19081912
}
19091913
if (result.isEmpty()) {
1910-
result.add(Environment.getExternalStorageDirectory());
1914+
File dir = Environment.getExternalStorageDirectory();
1915+
if (dir != null && !pathes.contains(dir.getAbsolutePath())) {
1916+
result.add(dir);
1917+
}
19111918
}
19121919
return result;
19131920
}
@@ -1919,7 +1926,9 @@ public static File getCacheDir() {
19191926
} catch (Exception e) {
19201927
FileLog.e(e);
19211928
}
1929+
19221930
if (state == null || state.startsWith(Environment.MEDIA_MOUNTED)) {
1931+
FileLog.d("external dir mounted");
19231932
try {
19241933
File file;
19251934
if (Build.VERSION.SDK_INT >= 19) {
@@ -1936,16 +1945,20 @@ public static File getCacheDir() {
19361945
} else {
19371946
file = ApplicationLoader.applicationContext.getExternalCacheDir();
19381947
}
1948+
FileLog.d("check dir " + (file == null ? null : file.getPath()) + " ");
19391949
if (file != null && (file.exists() || file.mkdirs()) && file.canWrite()) {
1940-
boolean canWrite = true;
1941-
try {
1942-
AndroidUtilities.createEmptyFile(new File(file, ".nomedia"));
1943-
} catch (Exception e) {
1944-
canWrite = false;
1945-
}
1946-
if (canWrite) {
1947-
return file;
1948-
}
1950+
// boolean canWrite = true;
1951+
// try {
1952+
// AndroidUtilities.createEmptyFile(new File(file, ".nomedia"));
1953+
// } catch (Exception e) {
1954+
// canWrite = false;
1955+
// }
1956+
// if (canWrite) {
1957+
// return file;
1958+
// }
1959+
return file;
1960+
} else if (file != null) {
1961+
FileLog.d("check dir file exist " + file.exists() + " can write " + file.canWrite());
19491962
}
19501963
} catch (Exception e) {
19511964
FileLog.e(e);

‎TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class BuildVars {
2424
public static boolean USE_CLOUD_STRINGS = true;
2525
public static boolean CHECK_UPDATES = true;
2626
public static boolean NO_SCOPED_STORAGE = Build.VERSION.SDK_INT <= 29;
27-
public static int BUILD_VERSION = 3199;
28-
public static String BUILD_VERSION_STRING = "9.5.1";
27+
public static int BUILD_VERSION = 3208;
28+
public static String BUILD_VERSION_STRING = "9.5.2";
2929
public static int APP_ID = 4;
3030
public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103";
3131

‎TMessagesProj/src/main/java/org/telegram/messenger/CacheByChatsController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static int getDefault(int type) {
4141
} else if (type == KEEP_MEDIA_TYPE_GROUP) {
4242
return KEEP_MEDIA_ONE_MONTH;
4343
} else if (type == KEEP_MEDIA_TYPE_CHANNEL) {
44-
return KEEP_MEDIA_ONE_MONTH;
44+
return KEEP_MEDIA_ONE_WEEK;
4545
}
4646
return SharedConfig.keepMedia;
4747
}

‎TMessagesProj/src/main/java/org/telegram/messenger/DatabaseMigrationHelper.java

+7
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,13 @@ public static int migrate(MessagesStorage messagesStorage, int version) throws E
12341234
version = 113;
12351235
}
12361236

1237+
if (version == 113) {
1238+
//fix issue when database file was deleted
1239+
//just reload dialogs
1240+
messagesStorage.reset();
1241+
database.executeFast("PRAGMA user_version = 114").stepThis().dispose();
1242+
version = 114;
1243+
}
12371244
return version;
12381245
}
12391246

‎TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,9 @@ private void addPart(ArrayList<Range> ranges, long start, long end, boolean save
545545
filePartsStream.write(filesQueueByteBuffer.buf, 0, bufferSize);
546546
}
547547
} catch (Exception e) {
548+
FileLog.e(e, false);
548549
if (AndroidUtilities.isENOSPC(e)) {
549550
LaunchActivity.checkFreeDiscSpaceStatic(1);
550-
} else {
551-
FileLog.e(e);
552551
}
553552
}
554553
totalTime += System.currentTimeMillis() - time;
@@ -881,6 +880,7 @@ public boolean start(final FileLoadOperationStream stream, final long streamOffs
881880
} catch (Exception e) {
882881
if (AndroidUtilities.isENOSPC(e)) {
883882
LaunchActivity.checkFreeDiscSpaceStatic(1);
883+
FileLog.e(e, false);
884884
} else {
885885
FileLog.e(e);
886886
}
@@ -1044,6 +1044,7 @@ public boolean start(final FileLoadOperationStream stream, final long streamOffs
10441044
requestedBytesCount = downloadedBytes = 0;
10451045
if (AndroidUtilities.isENOSPC(e)) {
10461046
LaunchActivity.checkFreeDiscSpaceStatic(1);
1047+
FileLog.e(e, false);
10471048
} else {
10481049
FileLog.e(e);
10491050
}
@@ -1059,12 +1060,11 @@ public boolean start(final FileLoadOperationStream stream, final long streamOffs
10591060
fileOutputStream.seek(downloadedBytes);
10601061
}
10611062
} catch (Exception e) {
1063+
FileLog.e(e, false);
10621064
if (AndroidUtilities.isENOSPC(e)) {
10631065
LaunchActivity.checkFreeDiscSpaceStatic(1);
10641066
onFail(true, -1);
10651067
return false;
1066-
} else {
1067-
FileLog.e(e, false);
10681068
}
10691069
}
10701070
if (fileOutputStream == null) {
@@ -1091,11 +1091,11 @@ public boolean start(final FileLoadOperationStream stream, final long streamOffs
10911091
delegate.saveFilePath(pathSaveData, null);
10921092
}
10931093
} catch (Exception e) {
1094+
FileLog.e(e, false);
10941095
if (AndroidUtilities.isENOSPC(e)) {
10951096
LaunchActivity.checkFreeDiscSpaceStatic(1);
10961097
onFail(true, -1);
10971098
} else {
1098-
FileLog.e(e, false);
10991099
onFail(true, 0);
11001100
}
11011101
}
@@ -1772,10 +1772,10 @@ protected boolean processRequestResult(RequestInfo requestInfo, TLRPC.TL_error e
17721772
startDownloadRequest();
17731773
}
17741774
} catch (Exception e) {
1775+
FileLog.e(e, !AndroidUtilities.isFilNotFoundException(e) && !AndroidUtilities.isENOSPC(e));
17751776
if (AndroidUtilities.isENOSPC(e)) {
17761777
onFail(false, -1);
17771778
} else {
1778-
FileLog.e(e, !AndroidUtilities.isFilNotFoundException(e));
17791779
onFail(false, 0);
17801780
}
17811781
}
@@ -1835,6 +1835,9 @@ protected void onFail(boolean thread, final int reason) {
18351835
cleanup();
18361836
state = reason == 1 ? stateCanceled : stateFailed;
18371837
if (delegate != null) {
1838+
if (BuildVars.LOGS_ENABLED) {
1839+
FileLog.d("failed downloading file to " + cacheFileFinal + " reason = " + reason + " time = " + (System.currentTimeMillis() - startTime) + " dc = " + datacenterId + " size = " + AndroidUtilities.formatFileSize(totalBytesCount));
1840+
}
18381841
if (thread) {
18391842
Utilities.stageQueue.postRunnable(() -> delegate.didFailedLoadingFile(FileLoadOperation.this, reason));
18401843
} else {

‎TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,9 @@ public static long bytesToLong(byte[] bytes) {
16791679

16801680
Runnable dumpFilesQueueRunnable = () -> {
16811681
for (int i = 0; i < smallFilesQueue.length; i++) {
1682-
FileLog.d("download queue: dc" + (i + 1) + " account=" + currentAccount + " small_operations=" + smallFilesQueue[i].allOperations.size() + " large_operations=" + largeFilesQueue[i].allOperations.size());
1682+
if (smallFilesQueue[i].allOperations.size() > 0 || largeFilesQueue[i].allOperations.size() > 0) {
1683+
FileLog.d("download queue: dc" + (i + 1) + " account=" + currentAccount + " small_operations=" + smallFilesQueue[i].allOperations.size() + " large_operations=" + largeFilesQueue[i].allOperations.size());
1684+
}
16831685
}
16841686
dumpFilesQueue();
16851687
};

‎TMessagesProj/src/main/java/org/telegram/messenger/ImageLoader.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -2176,9 +2176,18 @@ public void onReceive(Context arg0, Intent intent) {
21762176
}
21772177

21782178
public void checkMediaPaths() {
2179+
checkMediaPaths(null);
2180+
}
2181+
2182+
public void checkMediaPaths(Runnable after) {
21792183
cacheOutQueue.postRunnable(() -> {
21802184
final SparseArray<File> paths = createMediaPaths();
2181-
AndroidUtilities.runOnUIThread(() -> FileLoader.setMediaDirs(paths));
2185+
AndroidUtilities.runOnUIThread(() -> {
2186+
FileLoader.setMediaDirs(paths);
2187+
if (after != null) {
2188+
after.run();
2189+
}
2190+
});
21822191
});
21832192
}
21842193

‎TMessagesProj/src/main/java/org/telegram/messenger/LiteMode.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ public class LiteMode {
6161
FLAG_ANIMATED_EMOJI_REACTIONS_PREMIUM |
6262
FLAG_ANIMATED_EMOJI_CHAT |
6363
FLAG_CHAT_FORUM_TWOCOLUMN |
64-
FLAG_CHAT_BLUR |
6564
FLAG_CALLS_ANIMATIONS |
6665
FLAG_AUTOPLAY_VIDEOS |
6766
FLAG_AUTOPLAY_GIFS
68-
); // 8031
67+
); // 7775
6968
public static int PRESET_HIGH = (
7069
FLAGS_ANIMATED_STICKERS |
7170
FLAGS_ANIMATED_EMOJI |
@@ -255,7 +254,7 @@ public static void loadPreference() {
255254
}
256255

257256
public static void savePreference() {
258-
MessagesController.getGlobalMainSettings().edit().putInt("lite_mode", value).putInt("lite_mode_battery_level", powerSaverLevel).apply();
257+
MessagesController.getGlobalMainSettings().edit().putInt("lite_mode2", value).putInt("lite_mode_battery_level", powerSaverLevel).apply();
259258
}
260259

261260
public static int getPowerSaverLevel() {

‎TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java

+81-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.telephony.TelephonyManager;
1919
import android.text.TextUtils;
2020
import android.text.format.DateFormat;
21+
import android.util.Log;
2122
import android.util.Xml;
2223

2324
import androidx.annotation.StringRes;
@@ -39,7 +40,9 @@
3940
import java.util.Currency;
4041
import java.util.Date;
4142
import java.util.HashMap;
43+
import java.util.HashSet;
4244
import java.util.Locale;
45+
import java.util.Map;
4346
import java.util.TimeZone;
4447

4548
public class LocaleController {
@@ -487,17 +490,65 @@ public void reloadCurrentRemoteLocale(int currentAccount, String langCode, boole
487490
}
488491
}
489492

493+
private boolean checkingUpdateForCurrentRemoteLocale;
494+
490495
public void checkUpdateForCurrentRemoteLocale(int currentAccount, int version, int baseVersion) {
491496
if (currentLocaleInfo == null || !currentLocaleInfo.isRemote() && !currentLocaleInfo.isUnofficial()) {
492497
return;
493498
}
494499
if (currentLocaleInfo.hasBaseLang()) {
495500
if (currentLocaleInfo.baseVersion < baseVersion) {
496-
applyRemoteLanguage(currentLocaleInfo, currentLocaleInfo.baseLangCode, false, currentAccount, null);
501+
checkingUpdateForCurrentRemoteLocale = true;
502+
applyRemoteLanguage(currentLocaleInfo, currentLocaleInfo.baseLangCode, false, currentAccount, () -> {
503+
checkingUpdateForCurrentRemoteLocale = false;
504+
checkPatchLangpack(currentAccount);
505+
});
497506
}
498507
}
499508
if (currentLocaleInfo.version < version) {
500-
applyRemoteLanguage(currentLocaleInfo, currentLocaleInfo.shortName, false, currentAccount, null);
509+
checkingUpdateForCurrentRemoteLocale = true;
510+
applyRemoteLanguage(currentLocaleInfo, currentLocaleInfo.shortName, false, currentAccount, () -> {
511+
checkingUpdateForCurrentRemoteLocale = false;
512+
checkPatchLangpack(currentAccount);
513+
});
514+
}
515+
}
516+
517+
public int calculateTranslatedCount(HashMap<String, String> map) {
518+
int count = 0;
519+
HashSet<String> added = new HashSet<>();
520+
for (String k : map.keySet()) {
521+
if (k == null) {
522+
continue;
523+
}
524+
String real = null;
525+
if (k.endsWith("_other")) {
526+
real = k.substring(0, k.length() - 6);
527+
} else if (k.endsWith("_zero") || k.endsWith("_many")) {
528+
real = k.substring(0, k.length() - 5);
529+
} else if (k.endsWith("_one") || k.endsWith("_two") || k.endsWith("_few")) {
530+
real = k.substring(0, k.length() - 4);
531+
}
532+
if (real == null) {
533+
count++;
534+
} else if (!added.contains(real)) {
535+
added.add(real);
536+
count++;
537+
}
538+
}
539+
added.clear();
540+
return count;
541+
}
542+
543+
public void checkPatchLangpack(int currentAccount) {
544+
if (currentLocaleInfo == null || checkingUpdateForCurrentRemoteLocale) {
545+
return;
546+
}
547+
if (shouldReinstallLangpack(currentLocaleInfo.shortName)) {
548+
if (BuildVars.LOGS_ENABLED) {
549+
FileLog.d("reload locale because locale file is not enough");
550+
}
551+
AndroidUtilities.runOnUIThread(() -> reloadCurrentRemoteLocale(currentAccount, null, true, null));
501552
}
502553
}
503554

@@ -943,7 +994,7 @@ public int applyLanguage(final LocaleInfo localeInfo, boolean override, boolean
943994
config.locale = currentLocale;
944995
ApplicationLoader.applicationContext.getResources().updateConfiguration(config, ApplicationLoader.applicationContext.getResources().getDisplayMetrics());
945996
changingConfiguration = false;
946-
if (reloadLastFile) {
997+
if (reloadLastFile || !isLoadingRemote && !force && shouldReinstallLangpack(localeInfo.shortName)) {
947998
if (BuildVars.LOGS_ENABLED) {
948999
FileLog.d("reload locale because one of file is corrupted " + pathToFile + " " + pathToBaseFile);
9491000
}
@@ -2316,6 +2367,7 @@ private int applyRemoteLanguage(LocaleInfo localeInfo, String langCode, boolean
23162367
onDone.run();
23172368
}
23182369
};
2370+
patched(localeInfo.shortName);
23192371
if (localeInfo.hasBaseLang() && (langCode == null || langCode.equals(localeInfo.baseLangCode))) {
23202372
if (localeInfo.baseVersion != 0 && !force) {
23212373
if (localeInfo.hasBaseLang()) {
@@ -3261,6 +3313,25 @@ public static String formatDistance(float distance, int type) {
32613313
return formatDistance(distance, type, null);
32623314
}
32633315

3316+
// patch to force reinstalling of langpack in case some strings are missing after 9.0
3317+
private boolean shouldReinstallLangpack(String lng) {
3318+
int mustBeCount = MessagesController.getInstance(UserConfig.selectedAccount).checkResetLangpack;
3319+
if (mustBeCount <= 0) {
3320+
return false;
3321+
}
3322+
boolean alreadyPatched = MessagesController.getGlobalMainSettings().getBoolean("lngpack_patched_" + lng, false);
3323+
if (alreadyPatched) {
3324+
return false;
3325+
}
3326+
int count = calculateTranslatedCount(localeValues);
3327+
if (count >= mustBeCount) {
3328+
return false;
3329+
}
3330+
FileLog.e("reinstalling " + lng + " langpack because of patch (" + count + " keys, must be at least " + mustBeCount + ")");
3331+
patched(lng);
3332+
return true;
3333+
}
3334+
32643335
public static String formatDistance(float distance, int type, Boolean useImperial) {
32653336
ensureImperialSystemInit();
32663337
boolean imperial = useImperial != null && useImperial || useImperial == null && useImperialSystemType;
@@ -3324,4 +3395,11 @@ public static String formatDistance(float distance, int type, Boolean useImperia
33243395
}
33253396
}
33263397
}
3398+
3399+
private void patched(String lng) {
3400+
if (BuildVars.LOGS_ENABLED) {
3401+
FileLog.d("set as patched " + lng + " langpack");
3402+
}
3403+
MessagesController.getGlobalMainSettings().edit().putBoolean("lngpack_patched_" + lng, true).apply();
3404+
}
33273405
}

0 commit comments

Comments
 (0)