Skip to content

Commit ef98206

Browse files
committed
Improved versioning of shared libaries + Renamed challegram.23 to tgxjni + Updated TDLib submodule
1 parent 4b794f4 commit ef98206

File tree

9 files changed

+176
-85
lines changed

9 files changed

+176
-85
lines changed

app/build.gradle.kts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ android {
4141

4242
defaultConfig {
4343
val versions = extra["versions"] as Properties
44-
val jniVersion = versions.getIntOrThrow("version.jni")
45-
val tdlibVersion = versions.getIntOrThrow("version.tdlib")
46-
val leveldbVersion = versions.getIntOrThrow("version.leveldb")
4744

48-
buildConfigInt("SO_VERSION", (jniVersion + tdlibVersion + leveldbVersion))
49-
buildConfigInt("TDLIB_VERSION", tdlibVersion)
45+
val ndkVersion = versions.getProperty("version.ndk")
46+
val jniVersion = versions.getProperty("version.jni")
47+
val leveldbVersion = versions.getProperty("version.leveldb")
48+
49+
buildConfigString("NDK_VERSION", ndkVersion)
50+
buildConfigString("JNI_VERSION", jniVersion)
51+
buildConfigString("LEVELDB_VERSION", leveldbVersion)
52+
5053
buildConfigString("TDLIB_REMOTE_URL", "https://github.com/tdlib/td")
5154

5255
buildConfigField("boolean", "EXPERIMENTAL", isExperimentalBuild.toString())

app/jni/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ endforeach()
869869

870870
# == Target ==
871871

872-
set(NATIVE_LIB "challegram.23")
872+
set(NATIVE_LIB "tgxjni")
873873
add_library(${NATIVE_LIB} SHARED
874874
log.cpp
875875

app/src/main/java/org/thunderdog/challegram/config/Config.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public static boolean useBundledWebp () {
6060

6161
public static final boolean TEST_NOTIFICATION_PROBLEM_RESOLUTION = false; // BuildConfig.DEBUG;
6262

63-
public static final boolean SO_SHARED = true;
64-
6563
public static final boolean NEED_TDLIB_CLEANUP = false;
6664

6765
public static final boolean FAKE_BACKGROUND_CONNECTION_STATE = true;

app/src/main/java/org/thunderdog/challegram/telegram/TdlibSettingsManager.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ public class TdlibSettingsManager implements CleanupStartupDelegate {
7373
public static final String DEVICE_TOKEN_TYPE_KEY = "registered_device_token_type";
7474
public static final String DEVICE_UID_KEY = "registered_device_uid";
7575
public static final String DEVICE_OTHER_UID_KEY = "registered_device_uid_other";
76-
public static final String DEVICE_TDLIB_VERSION_KEY = "registered_device_tdlib";
76+
@Deprecated
77+
@SuppressWarnings("DeprecatedIsStillUsed")
78+
public static final String __DEVICE_TDLIB_VERSION_KEY = "registered_device_tdlib";
79+
public static final String DEVICE_TDLIB_VERSION2_KEY = "registered_device_td";
7780

7881
public static final String NOTIFICATION_ERROR_KEY = "notification_error";
7982
public static final String NOTIFICATION_VERSION_KEY = "notification_version";
@@ -587,8 +590,8 @@ private static long getRegisteredDeviceUserId (int accountId) {
587590
return Settings.instance().getLong(key(DEVICE_UID_KEY, accountId), 0);
588591
}
589592

590-
private static int getRegisteredDeviceTdlibVersion (int accountId) {
591-
return Settings.instance().getInt(key(DEVICE_TDLIB_VERSION_KEY, accountId), 0);
593+
private static String getRegisteredDeviceTdlibVersion2 (int accountId) {
594+
return Settings.instance().getString(key(DEVICE_TDLIB_VERSION2_KEY, accountId), "");
592595
}
593596

594597
@Nullable
@@ -629,7 +632,7 @@ public static void setRegisteredDevice (int accountId, long userId, TdApi.Device
629632
}
630633
}
631634
pmc.putLong(key(DEVICE_UID_KEY, accountId), userId);
632-
pmc.putInt(key(DEVICE_TDLIB_VERSION_KEY, accountId), BuildConfig.TDLIB_VERSION);
635+
pmc.putString(key(DEVICE_TDLIB_VERSION2_KEY, accountId), BuildConfig.TDLIB_VERSION);
633636
if (otherUserIds != null && otherUserIds.length > 0) {
634637
pmc.putLongArray(key(DEVICE_OTHER_UID_KEY, accountId), otherUserIds);
635638
} else {
@@ -641,7 +644,7 @@ public static void setRegisteredDevice (int accountId, long userId, TdApi.Device
641644

642645
public static boolean checkRegisteredDeviceToken (int accountId, long userId, TdApi.DeviceToken token, long[] otherUserIds, boolean skipOtherUserIdsCheck) {
643646
return
644-
getRegisteredDeviceTdlibVersion(accountId) == BuildConfig.TDLIB_VERSION &&
647+
BuildConfig.TDLIB_VERSION.equals(getRegisteredDeviceTdlibVersion2(accountId)) &&
645648
getRegisteredDeviceUserId(accountId) == userId &&
646649
Td.equalsTo(getRegisteredDeviceToken(accountId), token) &&
647650
(skipOtherUserIdsCheck || Arrays.equals(getRegisteredDeviceOtherUserIds(accountId), otherUserIds != null && otherUserIds.length > 0 ? otherUserIds : null));
@@ -653,7 +656,7 @@ public static void unregisterDevice (int accountId) {
653656
.remove(key(DEVICE_TOKEN_TYPE_KEY, accountId))
654657
.remove(key(DEVICE_UID_KEY, accountId))
655658
.remove(key(DEVICE_OTHER_UID_KEY, accountId))
656-
.remove(key(DEVICE_TDLIB_VERSION_KEY, accountId))
659+
.remove(key(DEVICE_TDLIB_VERSION2_KEY, accountId))
657660
.apply();
658661
}
659662

app/src/main/java/org/thunderdog/challegram/unsorted/NLoader.java

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
import com.google.android.exoplayer2.ext.vp9.VpxLibrary;
3030

3131
import org.thunderdog.challegram.BuildConfig;
32-
import org.thunderdog.challegram.config.Config;
3332
import org.thunderdog.challegram.tool.UI;
3433
import org.thunderdog.challegram.voip.VoIPController;
3534

3635
import java.util.ArrayList;
37-
import java.util.List;
3836
import java.util.Locale;
3937

4038
import me.vkryl.leveldb.LevelDB;
@@ -56,33 +54,22 @@ public static NLoader instance () {
5654
return instance;
5755
}
5856

59-
public static boolean ensureLibraryLoaded () {
60-
return loaded || loadLibrary();
57+
private static void loadLibraryImpl (ReLinkerInstance reLinker, String library, @Nullable String version) {
58+
long ms = SystemClock.uptimeMillis();
59+
reLinker.loadLibrary(UI.getAppContext(), library, version);
60+
android.util.Log.v("tgx", "Loaded " + library + " in " + (SystemClock.uptimeMillis() - ms) + "ms");
6161
}
6262

6363
public static synchronized boolean loadLibrary () {
6464
if (!loaded) {
6565
try {
66-
long ms;
6766
ReLinkerInstance reLinker = ReLinker.recursively().log(NLoader.instance());
68-
int libCount = 2;
69-
if (Config.SO_SHARED) {
70-
libCount++;
71-
}
72-
List<String> libraries = new ArrayList<>(libCount);
73-
if (Config.SO_SHARED) {
74-
libraries.add("c++_shared");
75-
}
76-
libraries.add("crypto");
77-
libraries.add("ssl");
78-
libraries.add("tdjni");
79-
libraries.add("leveldbjni");
80-
libraries.add("challegram.23");
81-
for (String library : libraries) {
82-
ms = SystemClock.uptimeMillis();
83-
reLinker.loadLibrary(UI.getAppContext(), library, "1." + BuildConfig.SO_VERSION);
84-
android.util.Log.v("tgx", "Loaded " + library + " in " + (SystemClock.uptimeMillis() - ms) + "ms");
85-
}
67+
loadLibraryImpl(reLinker, "c++_shared", BuildConfig.NDK_VERSION);
68+
loadLibraryImpl(reLinker, "crypto", BuildConfig.OPENSSL_VERSION);
69+
loadLibraryImpl(reLinker, "ssl", BuildConfig.OPENSSL_VERSION);
70+
loadLibraryImpl(reLinker, "tdjni", BuildConfig.TDLIB_VERSION);
71+
loadLibraryImpl(reLinker, "leveldbjni", BuildConfig.LEVELDB_VERSION);
72+
loadLibraryImpl(reLinker, "tgxjni", BuildConfig.JNI_VERSION);
8673
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
8774
OpusLibrary.setLibraries(C.CRYPTO_TYPE_UNSUPPORTED);
8875
VpxLibrary.setLibraries(C.CRYPTO_TYPE_UNSUPPORTED);

0 commit comments

Comments
 (0)