KBS remote feature flag.

This commit is contained in:
Alan Evans
2020-01-24 18:38:48 -05:00
committed by Greyson Parrelli
parent ba6e1ab15a
commit fea2b6253f
5 changed files with 74 additions and 40 deletions

View File

@@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.annimon.stream.Stream;
import com.google.android.collect.Sets;
import org.json.JSONException;
import org.json.JSONObject;
@@ -20,7 +21,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
/**
@@ -50,6 +50,7 @@ public final class FeatureFlags {
private static final String PROFILE_DISPLAY = generateKey("profileDisplay");
private static final String MESSAGE_REQUESTS = generateKey("messageRequests");
private static final String USERNAMES = generateKey("usernames");
private static final String KBS = generateKey("kbs");
private static final String STORAGE_SERVICE = generateKey("storageService");
private static final String REACTION_SENDING = generateKey("reactionSending");
@@ -73,14 +74,15 @@ public final class FeatureFlags {
* will be updated arbitrarily at runtime. This will make values more responsive, but also places
* more burden on the reader to ensure that the app experience remains consistent.
*/
private static final Set<String> HOT_SWAPPABLE = new TreeSet<String>() {{
}};
private static final Set<String> HOT_SWAPPABLE = Sets.newHashSet(
KBS
);
/**
* Flags in this set will stay true forever once they receive a true value from a remote config.
*/
private static final Set<String> STICKY = new HashSet<String>() {{
}};
private static final Set<String> STICKY = Sets.newHashSet(
);
private static final Map<String, Boolean> REMOTE_VALUES = new TreeMap<>();
@@ -139,9 +141,16 @@ public final class FeatureFlags {
return value;
}
/** Storage service. */
public static synchronized boolean storageService() {
return getValue(STORAGE_SERVICE, false);
/** Set or migrate PIN to KBS */
public static boolean kbs() {
return getValue(KBS, false);
}
/** Storage service. Requires {@link #kbs()}. */
public static boolean storageService() {
boolean value = getValue(STORAGE_SERVICE, false);
if (value && !kbs()) throw new MissingFlagRequirementError();
return value;
}
/** Send support for reactions. */

View File

@@ -16,15 +16,12 @@ import androidx.core.app.NotificationCompat;
import org.greenrobot.eventbus.EventBus;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.jobmanager.impl.SqlCipherMigrationConstraintObserver;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.lock.RegistrationLockReminders;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.whispersystems.libsignal.util.Medium;
import org.whispersystems.signalservice.api.RegistrationLockData;
import org.whispersystems.signalservice.api.util.UuidUtil;
import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse;
import java.io.IOException;
import java.security.SecureRandom;
@@ -162,8 +159,9 @@ public class TextSecurePreferences {
@Deprecated
private static final String REGISTRATION_LOCK_PIN_PREF_V1 = "pref_registration_lock_pin";
private static final String REGISTRATION_LOCK_LAST_REMINDER_TIME = "pref_registration_lock_last_reminder_time_2";
private static final String REGISTRATION_LOCK_NEXT_REMINDER_INTERVAL = "pref_registration_lock_next_reminder_interval";
private static final String REGISTRATION_LOCK_LAST_REMINDER_TIME = "pref_registration_lock_last_reminder_time";
private static final String REGISTRATION_LOCK_LAST_REMINDER_TIME_POST_KBS = "pref_registration_lock_last_reminder_time_post_kbs";
private static final String REGISTRATION_LOCK_NEXT_REMINDER_INTERVAL = "pref_registration_lock_next_reminder_interval";
private static final String SERVICE_OUTAGE = "pref_service_outage";
private static final String LAST_OUTAGE_CHECK_TIME = "pref_last_outage_check_time";
@@ -271,11 +269,16 @@ public class TextSecurePreferences {
}
public static long getRegistrationLockLastReminderTime(@NonNull Context context) {
return getLongPreference(context, REGISTRATION_LOCK_LAST_REMINDER_TIME, 0);
return getLongPreference(context, getAppropriateReminderKey(), 0);
}
public static void setRegistrationLockLastReminderTime(@NonNull Context context, long time) {
setLongPreference(context, REGISTRATION_LOCK_LAST_REMINDER_TIME, time);
setLongPreference(context, getAppropriateReminderKey(), time);
}
private static String getAppropriateReminderKey() {
return FeatureFlags.kbs() ? REGISTRATION_LOCK_LAST_REMINDER_TIME_POST_KBS
: REGISTRATION_LOCK_LAST_REMINDER_TIME;
}
public static long getRegistrationLockNextReminderInterval(@NonNull Context context) {