Require desktop clients to send the new gv2-2 capability flag.
This commit is contained in:
parent
f79c998f95
commit
77de0f86dc
|
@ -140,13 +140,7 @@ public class Account implements Principal {
|
|||
public boolean isGroupsV2Supported() {
|
||||
return devices.stream()
|
||||
.filter(Device::isEnabled)
|
||||
.allMatch(device -> {
|
||||
if (device.getApnId() != null || device.getVoipApnId() != null) {
|
||||
return device.getCapabilities() != null && device.getCapabilities().isGv2_2();
|
||||
} else {
|
||||
return device.getCapabilities() != null && (device.getCapabilities().isGv2() || device.getCapabilities().isGv2_2());
|
||||
}
|
||||
});
|
||||
.allMatch(Device::isGroupsV2Supported);
|
||||
}
|
||||
|
||||
public boolean isStorageSupported() {
|
||||
|
|
|
@ -251,6 +251,14 @@ public class Device {
|
|||
return this.userAgent;
|
||||
}
|
||||
|
||||
public boolean isGroupsV2Supported() {
|
||||
if (this.getGcmId() != null) {
|
||||
return this.capabilities != null && (this.capabilities.isGv2() || this.capabilities.isGv2_2());
|
||||
} else {
|
||||
return this.capabilities != null && this.capabilities.isGv2_2();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof Device)) return false;
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import junitparams.JUnitParamsRunner;
|
||||
import junitparams.Parameters;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(JUnitParamsRunner.class)
|
||||
public class DeviceTest {
|
||||
|
||||
@Test
|
||||
@Parameters(method = "argumentsForTestIsGroupsV2Supported")
|
||||
public void testIsGroupsV2Supported(final String gcmId, final boolean gv2Capability, final boolean gv2_2Capability, final boolean expectGv2Supported) {
|
||||
final Device.DeviceCapabilities capabilities = new Device.DeviceCapabilities(gv2Capability, gv2_2Capability, false, false);
|
||||
final Device device = new Device(1, "test", "auth-token", "salt", "signaling-key", gcmId, "apn-id", "apn-voip-id", false, 1, null, 0, 0, "user-agent", 0, capabilities);
|
||||
|
||||
assertEquals(expectGv2Supported, device.isGroupsV2Supported());
|
||||
}
|
||||
|
||||
private static Object argumentsForTestIsGroupsV2Supported() {
|
||||
return new Object[] {
|
||||
new Object[] { "gcm-id", false, false, false },
|
||||
new Object[] { "gcm-id", true, false, true },
|
||||
new Object[] { "gcm-id", false, true, true },
|
||||
new Object[] { "gcm-id", true, true, true },
|
||||
new Object[] { null, false, false, false },
|
||||
new Object[] { null, true, false, false },
|
||||
new Object[] { null, false, true, true },
|
||||
new Object[] { null, true, true, true }
|
||||
};
|
||||
}
|
||||
}
|
|
@ -51,15 +51,15 @@ public class AccountTest {
|
|||
when(oldSecondaryDevice.isEnabled()).thenReturn(false);
|
||||
when(oldSecondaryDevice.getId()).thenReturn(2L);
|
||||
|
||||
when(gv2CapableDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(true, false, true, true));
|
||||
when(gv2CapableDevice.isGroupsV2Supported()).thenReturn(true);
|
||||
when(gv2CapableDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
|
||||
when(gv2CapableDevice.isEnabled()).thenReturn(true);
|
||||
|
||||
when(gv2IncapableDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(false, false, false, false));
|
||||
when(gv2IncapableDevice.isGroupsV2Supported()).thenReturn(false);
|
||||
when(gv2IncapableDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
|
||||
when(gv2IncapableDevice.isEnabled()).thenReturn(true);
|
||||
|
||||
when(gv2IncapableExpiredDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(false, false, false, false));
|
||||
when(gv2IncapableExpiredDevice.isGroupsV2Supported()).thenReturn(false);
|
||||
when(gv2IncapableExpiredDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31));
|
||||
when(gv2IncapableExpiredDevice.isEnabled()).thenReturn(false);
|
||||
}
|
||||
|
@ -182,64 +182,8 @@ public class AccountTest {
|
|||
|
||||
@Test
|
||||
public void isGroupsV2Supported() {
|
||||
{
|
||||
final Device gv2CapableDevice = mock(Device.class);
|
||||
final Device secondGv2CapableDevice = mock(Device.class);
|
||||
final Device.DeviceCapabilities gv2Capabilities = mock(Device.DeviceCapabilities.class);
|
||||
final Device.DeviceCapabilities secondGv2Capabilities = mock(Device.DeviceCapabilities.class);
|
||||
|
||||
when(gv2CapableDevice.isEnabled()).thenReturn(true);
|
||||
when(gv2CapableDevice.getCapabilities()).thenReturn(gv2Capabilities);
|
||||
when(gv2Capabilities.isGv2()).thenReturn(true);
|
||||
|
||||
when(secondGv2CapableDevice.isEnabled()).thenReturn(true);
|
||||
when(secondGv2CapableDevice.getCapabilities()).thenReturn(secondGv2Capabilities);
|
||||
when(secondGv2Capabilities.isGv2()).thenReturn(true);
|
||||
|
||||
final Account account = new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice, secondGv2CapableDevice), "1234".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
assertTrue(account.isGroupsV2Supported());
|
||||
}
|
||||
|
||||
{
|
||||
final Device gv2CapableDevice = mock(Device.class);
|
||||
final Device nonGv2CapableDevice = mock(Device.class);
|
||||
final Device.DeviceCapabilities gv2Capabilities = mock(Device.DeviceCapabilities.class);
|
||||
final Device.DeviceCapabilities nonGv2Capabilities = mock(Device.DeviceCapabilities.class);
|
||||
|
||||
when(gv2CapableDevice.isEnabled()).thenReturn(true);
|
||||
when(gv2CapableDevice.getCapabilities()).thenReturn(gv2Capabilities);
|
||||
when(gv2Capabilities.isGv2()).thenReturn(true);
|
||||
|
||||
when(nonGv2CapableDevice.isEnabled()).thenReturn(true);
|
||||
when(nonGv2CapableDevice.getCapabilities()).thenReturn(nonGv2Capabilities);
|
||||
when(nonGv2Capabilities.isGv2()).thenReturn(false);
|
||||
|
||||
final Account account = new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice, nonGv2CapableDevice), "1234".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
assertFalse(account.isGroupsV2Supported());
|
||||
}
|
||||
|
||||
{
|
||||
final Device iosGv2Device = mock(Device.class);
|
||||
final Device iosGv2_2Device = mock(Device.class);
|
||||
final Device.DeviceCapabilities gv2Capabilities = mock(Device.DeviceCapabilities.class);
|
||||
final Device.DeviceCapabilities gv2_2Capabilities = mock(Device.DeviceCapabilities.class);
|
||||
|
||||
when(iosGv2Device.getApnId()).thenReturn("apn-id");
|
||||
when(iosGv2Device.isEnabled()).thenReturn(true);
|
||||
when(iosGv2Device.getCapabilities()).thenReturn(gv2Capabilities);
|
||||
when(gv2Capabilities.isGv2()).thenReturn(true);
|
||||
when(gv2Capabilities.isGv2_2()).thenReturn(false);
|
||||
|
||||
when(iosGv2Device.getApnId()).thenReturn("different-apn-id");
|
||||
when(iosGv2_2Device.isEnabled()).thenReturn(true);
|
||||
when(iosGv2_2Device.getCapabilities()).thenReturn(gv2_2Capabilities);
|
||||
when(gv2_2Capabilities.isGv2()).thenReturn(true);
|
||||
when(gv2_2Capabilities.isGv2_2()).thenReturn(true);
|
||||
|
||||
assertFalse(new Account("+18005551234", UUID.randomUUID(), Set.of(iosGv2Device, iosGv2_2Device), "1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(iosGv2_2Device), "1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
}
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
assertTrue(new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice, gv2IncapableExpiredDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
assertFalse(new Account("+18005551234", UUID.randomUUID(), Set.of(gv2CapableDevice, gv2IncapableDevice), "1234".getBytes(StandardCharsets.UTF_8)).isGroupsV2Supported());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue