mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-22 20:18:36 +00:00
Save last-known server time offset.
This commit is contained in:
committed by
Clark Chen
parent
8372c699f7
commit
ebaa445bee
@@ -5,14 +5,13 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
|
||||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
|
import org.whispersystems.signalservice.api.RemoteConfigResult;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class RemoteConfigRefreshJob extends BaseJob {
|
public class RemoteConfigRefreshJob extends BaseJob {
|
||||||
@@ -52,8 +51,9 @@ public class RemoteConfigRefreshJob extends BaseJob {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> config = ApplicationDependencies.getSignalServiceAccountManager().getRemoteConfig();
|
RemoteConfigResult result = ApplicationDependencies.getSignalServiceAccountManager().getRemoteConfig();
|
||||||
FeatureFlags.update(config);
|
FeatureFlags.update(result.getConfig());
|
||||||
|
SignalStore.misc().setLastKnownServerTime(TimeUnit.SECONDS.toMillis(result.getServerEpochTimeSeconds()), System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public final class MiscellaneousValues extends SignalStoreValues {
|
|||||||
private static final String KEYBOARD_LANDSCAPE_HEIGHT = "misc.keyboard.landscape_height";
|
private static final String KEYBOARD_LANDSCAPE_HEIGHT = "misc.keyboard.landscape_height";
|
||||||
private static final String KEYBOARD_PORTRAIT_HEIGHT = "misc.keyboard.protrait_height";
|
private static final String KEYBOARD_PORTRAIT_HEIGHT = "misc.keyboard.protrait_height";
|
||||||
private static final String LAST_CONSISTENCY_CHECK_TIME = "misc.last_consistency_check_time";
|
private static final String LAST_CONSISTENCY_CHECK_TIME = "misc.last_consistency_check_time";
|
||||||
|
private static final String SERVER_TIME_OFFSET = "misc.server_time_offset";
|
||||||
|
private static final String LAST_SERVER_TIME_OFFSET_UPDATE = "misc.last_server_time_offset_update";
|
||||||
|
|
||||||
MiscellaneousValues(@NonNull KeyValueStore store) {
|
MiscellaneousValues(@NonNull KeyValueStore store) {
|
||||||
super(store);
|
super(store);
|
||||||
@@ -326,4 +328,31 @@ public final class MiscellaneousValues extends SignalStoreValues {
|
|||||||
public void setLastConsistencyCheckTime(long time) {
|
public void setLastConsistencyCheckTime(long time) {
|
||||||
putLong(LAST_CONSISTENCY_CHECK_TIME, time);
|
putLong(LAST_CONSISTENCY_CHECK_TIME, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the last-known server time.
|
||||||
|
*/
|
||||||
|
public void setLastKnownServerTime(long serverTime, long currentTime) {
|
||||||
|
getStore()
|
||||||
|
.beginWrite()
|
||||||
|
.putLong(SERVER_TIME_OFFSET, currentTime - serverTime)
|
||||||
|
.putLong(LAST_SERVER_TIME_OFFSET_UPDATE, System.currentTimeMillis())
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last-known offset between our local clock and the server. To get an estimate of the server time, take your current time and subtract this offset. e.g.
|
||||||
|
*
|
||||||
|
* estimatedServerTime = System.currentTimeMillis() - SignalStore.misc().getLastKnownServerTimeOffset()
|
||||||
|
*/
|
||||||
|
public long getLastKnownServerTimeOffset() {
|
||||||
|
return getLong(SERVER_TIME_OFFSET, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The last time (using our local clock) we updated the server time offset returned by {@link #getLastKnownServerTimeOffset()}}.
|
||||||
|
*/
|
||||||
|
public long getLastKnownServerTimeOffsetUpdateTime() {
|
||||||
|
return getLong(LAST_SERVER_TIME_OFFSET_UPDATE, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class LogSectionSystemInfo implements LogSection {
|
|||||||
builder.append("Emoji Version : ").append(getEmojiVersionString(context)).append("\n");
|
builder.append("Emoji Version : ").append(getEmojiVersionString(context)).append("\n");
|
||||||
builder.append("RenderBigEmoji : ").append(FontUtil.canRenderEmojiAtFontSize(1024)).append("\n");
|
builder.append("RenderBigEmoji : ").append(FontUtil.canRenderEmojiAtFontSize(1024)).append("\n");
|
||||||
builder.append("DontKeepActivities: ").append(getDontKeepActivities(context)).append("\n");
|
builder.append("DontKeepActivities: ").append(getDontKeepActivities(context)).append("\n");
|
||||||
|
builder.append("Server Time Offset: ").append(SignalStore.misc().getLastKnownServerTimeOffset()).append(" ms (last updated: ").append(SignalStore.misc().getLastKnownServerTimeOffsetUpdateTime()).append(")").append("\n");
|
||||||
builder.append("Telecom : ").append(AndroidTelecomUtil.getTelecomSupported()).append("\n");
|
builder.append("Telecom : ").append(AndroidTelecomUtil.getTelecomSupported()).append("\n");
|
||||||
builder.append("User-Agent : ").append(StandardUserAgentInterceptor.USER_AGENT).append("\n");
|
builder.append("User-Agent : ").append(StandardUserAgentInterceptor.USER_AGENT).append("\n");
|
||||||
builder.append("App : ");
|
builder.append("App : ");
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.groups.SelectionLimits;
|
|||||||
import org.thoughtcrime.securesms.jobs.RemoteConfigRefreshJob;
|
import org.thoughtcrime.securesms.jobs.RemoteConfigRefreshJob;
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.messageprocessingalarm.MessageProcessReceiver;
|
import org.thoughtcrime.securesms.messageprocessingalarm.MessageProcessReceiver;
|
||||||
|
import org.whispersystems.signalservice.api.RemoteConfigResult;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -293,8 +294,8 @@ public final class FeatureFlags {
|
|||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public static void refreshSync() throws IOException {
|
public static void refreshSync() throws IOException {
|
||||||
Map<String, Object> config = ApplicationDependencies.getSignalServiceAccountManager().getRemoteConfig();
|
RemoteConfigResult result = ApplicationDependencies.getSignalServiceAccountManager().getRemoteConfig();
|
||||||
FeatureFlags.update(config);
|
FeatureFlags.update(result.getConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void update(@NonNull Map<String, Object> config) {
|
public static synchronized void update(@NonNull Map<String, Object> config) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.whispersystems.signalservice.api
|
||||||
|
|
||||||
|
data class RemoteConfigResult(
|
||||||
|
val config: Map<String, Any>,
|
||||||
|
val serverEpochTimeSeconds: Long
|
||||||
|
)
|
||||||
@@ -626,7 +626,7 @@ public class SignalServiceAccountManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getRemoteConfig() throws IOException {
|
public RemoteConfigResult getRemoteConfig() throws IOException {
|
||||||
RemoteConfigResponse response = this.pushServiceSocket.getRemoteConfig();
|
RemoteConfigResponse response = this.pushServiceSocket.getRemoteConfig();
|
||||||
Map<String, Object> out = new HashMap<>();
|
Map<String, Object> out = new HashMap<>();
|
||||||
|
|
||||||
@@ -634,7 +634,7 @@ public class SignalServiceAccountManager {
|
|||||||
out.put(config.getName(), config.getValue() != null ? config.getValue() : config.isEnabled());
|
out.put(config.getName(), config.getValue() != null ? config.getValue() : config.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return new RemoteConfigResult(out, response.getServerEpochTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccountDataReport() throws IOException {
|
public String getAccountDataReport() throws IOException {
|
||||||
|
|||||||
@@ -8,10 +8,17 @@ public class RemoteConfigResponse {
|
|||||||
@JsonProperty
|
@JsonProperty
|
||||||
private List<Config> config;
|
private List<Config> config;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private long serverEpochTime;
|
||||||
|
|
||||||
public List<Config> getConfig() {
|
public List<Config> getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getServerEpochTime() {
|
||||||
|
return serverEpochTime;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Config {
|
public static class Config {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
Reference in New Issue
Block a user