Merge pull request #1583 from oxen-io/feature/blinded-version

Feature/blinded version
This commit is contained in:
ThomasSession
2024-07-30 15:42:07 +10:00
committed by GitHub
11 changed files with 217 additions and 4 deletions

View File

@@ -86,6 +86,7 @@ import org.thoughtcrime.securesms.sskenvironment.ProfileManager;
import org.thoughtcrime.securesms.sskenvironment.ReadReceiptManager;
import org.thoughtcrime.securesms.sskenvironment.TypingStatusRepository;
import org.thoughtcrime.securesms.util.Broadcaster;
import org.thoughtcrime.securesms.util.VersionUtil;
import org.thoughtcrime.securesms.util.dynamiclanguage.LocaleParseHelper;
import org.thoughtcrime.securesms.webrtc.CallMessageProcessor;
import org.webrtc.PeerConnectionFactory;
@@ -142,6 +143,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
private HandlerThread conversationListHandlerThread;
private Handler conversationListHandler;
private PersistentLogger persistentLogger;
private VersionUtil versionUtil;
@Inject LokiAPIDatabase lokiAPIDatabase;
@Inject public Storage storage;
@@ -248,6 +250,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
resubmitProfilePictureIfNeeded();
loadEmojiSearchIndexIfNeeded();
EmojiSource.refresh();
versionUtil = new VersionUtil(textSecurePreferences);
NetworkConstraint networkConstraint = new NetworkConstraint.Factory(this).create();
HTTP.INSTANCE.setConnectedToNetwork(networkConstraint::isMet);
@@ -274,6 +277,9 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
OpenGroupManager.INSTANCE.startPolling();
});
// fetch last version data
versionUtil.startTimedVersionCheck();
}
@Override
@@ -286,12 +292,14 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
poller.stopIfNeeded();
}
ClosedGroupPollerV2.getShared().stopAll();
versionUtil.stopTimedVersionCheck();
}
@Override
public void onTerminate() {
stopKovenant(); // Loki
OpenGroupManager.INSTANCE.stopPolling();
versionUtil.clear();
super.onTerminate();
}

View File

@@ -18,7 +18,7 @@ fun showMuteDialog(
private enum class Option(@StringRes val stringRes: Int, val getTime: () -> Long) {
ONE_HOUR(R.string.arrays__mute_for_one_hour, duration = TimeUnit.HOURS.toMillis(1)),
TWO_HOURS(R.string.arrays__mute_for_two_hours, duration = TimeUnit.DAYS.toMillis(2)),
TWO_HOURS(R.string.arrays__mute_for_two_hours, duration = TimeUnit.HOURS.toMillis(2)),
ONE_DAY(R.string.arrays__mute_for_one_day, duration = TimeUnit.DAYS.toMillis(1)),
SEVEN_DAYS(R.string.arrays__mute_for_seven_days, duration = TimeUnit.DAYS.toMillis(7)),
FOREVER(R.string.arrays__mute_forever, getTime = { Long.MAX_VALUE });

View File

@@ -22,7 +22,7 @@ public class MemoryFileUtil {
int fd = field.getInt(fileDescriptor);
return ParcelFileDescriptor.adoptFd(fd);
return ParcelFileDescriptor.fromFd(fd);
} catch (IllegalAccessException e) {
throw new IOException(e);
} catch (InvocationTargetException e) {

View File

@@ -0,0 +1,68 @@
package org.thoughtcrime.securesms.util
import android.os.Handler
import android.os.Looper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.session.libsession.messaging.file_server.FileServerApi
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsignal.utilities.Log
import java.util.concurrent.TimeUnit
class VersionUtil(
private val prefs: TextSecurePreferences
) {
private val TAG: String = VersionUtil::class.java.simpleName
private val FOUR_HOURS: Long = TimeUnit.HOURS.toMillis(4)
private val handler = Handler(Looper.getMainLooper())
private val runnable: Runnable
private val scope = CoroutineScope(Dispatchers.Default)
private var job: Job? = null
init {
runnable = Runnable {
fetchAndScheduleNextVersionCheck()
}
}
fun startTimedVersionCheck() {
handler.post(runnable)
}
fun stopTimedVersionCheck() {
handler.removeCallbacks(runnable)
}
fun clear() {
job?.cancel()
stopTimedVersionCheck()
}
private fun fetchAndScheduleNextVersionCheck() {
fetchVersionData()
handler.postDelayed(runnable, FOUR_HOURS)
}
private fun fetchVersionData() {
// only perform this if at least 4h has elapsed since th last successful check
val lastCheck = System.currentTimeMillis() - prefs.getLastVersionCheck()
if (lastCheck < FOUR_HOURS) return
job?.cancel()
job = scope.launch {
try {
// perform the version check
val clientVersion = FileServerApi.getClientVersion()
Log.i(TAG, "Fetched version data: $clientVersion")
prefs.setLastVersionCheck()
} catch (e: Exception) {
// we can silently ignore the error
Log.e(TAG, "Error fetching version data: $e")
}
}
}
}