Skip to content

Commit b653810

Browse files
authored
Update call quality string.
1 parent 7e46028 commit b653810

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

app/src/main/java/org/thoughtcrime/securesms/calls/quality/CallQuality.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.signal.ringrtc.CallSummary
1010
import org.signal.ringrtc.GroupCall
1111
import org.signal.storageservice.protos.calls.quality.SubmitCallQualitySurveyRequest
1212
import org.thoughtcrime.securesms.keyvalue.SignalStore
13+
import org.thoughtcrime.securesms.util.LocaleRemoteConfig
1314
import org.thoughtcrime.securesms.util.RemoteConfig
1415
import kotlin.time.Duration.Companion.days
1516
import kotlin.time.Duration.Companion.milliseconds
@@ -71,10 +72,19 @@ object CallQuality {
7172
}
7273
}
7374

75+
/**
76+
* Consumes any pending request. We will automatically filter out requests if they're over five minutes old.
77+
*/
7478
fun consumeQualityRequest(): SubmitCallQualitySurveyRequest? {
75-
val request = SignalStore.callQuality.surveyRequest
79+
val request = SignalStore.callQuality.surveyRequest ?: return null
7680
SignalStore.callQuality.surveyRequest = null
77-
return if (isFeatureEnabled()) request else null
81+
82+
val fiveMinutesAgo = System.currentTimeMillis().milliseconds - 5.minutes
83+
return if (!isFeatureEnabled() || request.end_timestamp.milliseconds < fiveMinutesAgo) {
84+
null
85+
} else {
86+
request
87+
}
7888
}
7989

8090
private fun isCallQualitySurveyRequired(callSummary: CallSummary): Boolean {
@@ -109,8 +119,8 @@ object CallQuality {
109119
return true
110120
}
111121

112-
val chance = RemoteConfig.callQualitySurveyPercent
113-
val roll = (0 until 100).random()
122+
val chance = LocaleRemoteConfig.getCallQualitySurveyPartsPerMillion()
123+
val roll = (0 until 1_000_000).random()
114124

115125
if (roll < chance) {
116126
return true

app/src/main/java/org/thoughtcrime/securesms/util/LocaleRemoteConfig.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public static boolean isDeviceSpecificNotificationEnabled() {
8282
return isEnabledPartsPerMillion(RemoteConfig.DEVICE_SPECIFIC_NOTIFICATION_CONFIG, DeviceSpecificNotificationConfig.getCurrentConfig().getLocalePercent());
8383
}
8484

85+
public static long getCallQualitySurveyPartsPerMillion() {
86+
return getPartsPerMillion(RemoteConfig.callQualitySurveyPPM());
87+
}
88+
8589
/**
8690
* Parses a comma-separated list of country codes and area codes to check if self's e164 starts with
8791
* one of them. For example, "33,1555" will return turn for e164's that start with 33 or look like 1-555-xxx-xxx.
@@ -104,6 +108,17 @@ static boolean isEnabledE164Start(@NonNull String serialized, @NonNull String e1
104108
return countryAndAreaCodes.stream().anyMatch(e164Numbers::startsWith);
105109
}
106110

111+
private static long getPartsPerMillion(@NonNull String serialized) {
112+
Map<String, Integer> countryCodeValues = parseCountryValues(serialized, 0);
113+
Recipient self = Recipient.self();
114+
115+
if (countryCodeValues.isEmpty() || !self.getE164().isPresent() || !self.getServiceId().isPresent()) {
116+
return 0L;
117+
}
118+
119+
return getCountryValue(countryCodeValues, self.getE164().orElse(""), 0);
120+
}
121+
107122
/**
108123
* Parses a comma-separated list of country codes colon-separated from how many buckets out of 1 million
109124
* should be enabled to see this megaphone in that country code. At the end of the list, an optional
@@ -112,15 +127,9 @@ static boolean isEnabledE164Start(@NonNull String serialized, @NonNull String e1
112127
* the world should see the megaphone.
113128
*/
114129
private static boolean isEnabledPartsPerMillion(@NonNull String flag, @NonNull String serialized) {
115-
Map<String, Integer> countryCodeValues = parseCountryValues(serialized, 0);
116-
Recipient self = Recipient.self();
117-
118-
if (countryCodeValues.isEmpty() || !self.getE164().isPresent() || !self.getServiceId().isPresent()) {
119-
return false;
120-
}
121-
122-
long countEnabled = getCountryValue(countryCodeValues, self.getE164().orElse(""), 0);
123-
long currentUserBucket = BucketingUtil.bucket(flag, self.requireAci().getRawUuid(), 1_000_000);
130+
Recipient self = Recipient.self();
131+
long countEnabled = getPartsPerMillion(serialized);
132+
long currentUserBucket = BucketingUtil.bucket(flag, self.requireAci().getRawUuid(), 1_000_000);
124133

125134
return countEnabled > currentUserBucket;
126135
}

app/src/main/java/org/thoughtcrime/securesms/util/RemoteConfig.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,16 +1226,16 @@ object RemoteConfig {
12261226
@JvmStatic
12271227
@get:JvmName("callQualitySurvey")
12281228
val callQualitySurvey: Boolean by remoteBoolean(
1229-
key = "android.callQualitySurvey.3",
1229+
key = "android.callQualitySurvey.4",
12301230
defaultValue = false,
12311231
hotSwappable = true
12321232
)
12331233

12341234
@JvmStatic
1235-
@get:JvmName("callQualitySurveyPercent")
1236-
val callQualitySurveyPercent: Int by remoteInt(
1237-
key = "android.callQualitySurveyPercent",
1238-
defaultValue = 1,
1235+
@get:JvmName("callQualitySurveyPPM")
1236+
val callQualitySurveyPPM: String by remoteString(
1237+
key = "android.callQualitySurveyPPM",
1238+
defaultValue = "*:10000",
12391239
hotSwappable = true
12401240
)
12411241
// endregion

app/src/test/java/org/thoughtcrime/securesms/util/LocaleRemoteConfigTest_getCountryValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,4 @@ public LocaleRemoteConfigTest_getCountryValue(@NonNull String phoneNumber,
7979
public void determineCountEnabled() {
8080
assertEquals(output, LocaleRemoteConfig.getCountryValue(countryCounts, phoneNumber, 0));
8181
}
82-
8382
}

0 commit comments

Comments
 (0)