diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java index 511d73650..758e9e112 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java @@ -140,7 +140,13 @@ public class Account implements Principal { public boolean isGroupsV2Supported() { return devices.stream() .filter(Device::isEnabled) - .allMatch(device -> device.getCapabilities() != null && device.getCapabilities().isGv2()); + .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()); + } + }); } public boolean isStorageSupported() { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java index 5235e3a22..788895982 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java @@ -19,12 +19,10 @@ package org.whispersystems.textsecuregcm.storage; import com.fasterxml.jackson.annotation.JsonProperty; import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials; -import org.whispersystems.textsecuregcm.entities.UserCapabilities; import org.whispersystems.textsecuregcm.entities.SignedPreKey; import org.whispersystems.textsecuregcm.util.Util; import javax.annotation.Nullable; -import javax.validation.constraints.Null; import java.util.concurrent.TimeUnit; public class Device { @@ -270,6 +268,9 @@ public class Device { @JsonProperty private boolean gv2; + @JsonProperty("gv2-2") + private boolean gv2_2; + @JsonProperty private boolean storage; @@ -278,8 +279,9 @@ public class Device { public DeviceCapabilities() {} - public DeviceCapabilities(boolean gv2, boolean storage, boolean transfer) { + public DeviceCapabilities(boolean gv2, final boolean gv2_2, boolean storage, boolean transfer) { this.gv2 = gv2; + this.gv2_2 = gv2_2; this.storage = storage; this.transfer = transfer; } @@ -288,6 +290,10 @@ public class Device { return gv2; } + public boolean isGv2_2() { + return gv2_2; + } + public boolean isStorage() { return storage; } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java index 0f1c6c875..0b657c956 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java @@ -223,7 +223,7 @@ public class DeviceControllerTest { @Test public void deviceDowngradeCapabilitiesTest() throws Exception { - Device.DeviceCapabilities deviceCapabilities = new Device.DeviceCapabilities(false, true, false); + Device.DeviceCapabilities deviceCapabilities = new Device.DeviceCapabilities(false, false, true, false); AccountAttributes accountAttributes = new AccountAttributes("keykeykeykey", false, 1234, null, null, null, null, true, deviceCapabilities); Response response = resources.getJerseyTest() .target("/v1/devices/5678901") diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java index 006e4ad23..f6a808c95 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java @@ -85,13 +85,13 @@ public class MessageControllerTest { @Before public void setup() throws Exception { Set singleDeviceList = new HashSet() {{ - add(new Device(1, null, "foo", "bar", "baz", "isgcm", null, null, false, 111, new SignedPreKey(333, "baz", "boop"), System.currentTimeMillis(), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(true, true, true))); + add(new Device(1, null, "foo", "bar", "baz", "isgcm", null, null, false, 111, new SignedPreKey(333, "baz", "boop"), System.currentTimeMillis(), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(true, false, true, true))); }}; Set multiDeviceList = new HashSet() {{ - add(new Device(1, null, "foo", "bar", "baz", "isgcm", null, null, false, 222, new SignedPreKey(111, "foo", "bar"), System.currentTimeMillis(), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(true, true, false))); - add(new Device(2, null, "foo", "bar", "baz", "isgcm", null, null, false, 333, new SignedPreKey(222, "oof", "rab"), System.currentTimeMillis(), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(true, true, false))); - add(new Device(3, null, "foo", "bar", "baz", "isgcm", null, null, false, 444, null, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(false, false, false))); + add(new Device(1, null, "foo", "bar", "baz", "isgcm", null, null, false, 222, new SignedPreKey(111, "foo", "bar"), System.currentTimeMillis(), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(true, false, true, false))); + add(new Device(2, null, "foo", "bar", "baz", "isgcm", null, null, false, 333, new SignedPreKey(222, "oof", "rab"), System.currentTimeMillis(), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(true, false, true, false))); + add(new Device(3, null, "foo", "bar", "baz", "isgcm", null, null, false, 444, null, System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31), System.currentTimeMillis(), "Test", 0, new Device.DeviceCapabilities(false, false, false, false))); }}; Account singleDeviceAccount = new Account(SINGLE_DEVICE_RECIPIENT, SINGLE_DEVICE_UUID, singleDeviceList, "1234".getBytes()); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java index 13ae221e3..a0c094930 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountTest.java @@ -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, true, true)); + when(gv2CapableDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(true, false, true, 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)); + when(gv2IncapableDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(false, false, false, 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)); + when(gv2IncapableExpiredDevice.getCapabilities()).thenReturn(new Device.DeviceCapabilities(false, false, false, false)); when(gv2IncapableExpiredDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31)); when(gv2IncapableExpiredDevice.isEnabled()).thenReturn(false); } @@ -219,5 +219,27 @@ public class AccountTest { 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()); + } } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java index 022ce7b51..37dcc512b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java @@ -266,7 +266,7 @@ public class AccountsTest { private Device generateDevice(long id) { Random random = new Random(System.currentTimeMillis()); SignedPreKey signedPreKey = new SignedPreKey(random.nextInt(), "testPublicKey-" + random.nextInt(), "testSignature-" + random.nextInt()); - return new Device(id, "testName-" + random.nextInt(), "testAuthToken-" + random.nextInt(), "testSalt-" + random.nextInt(), null, "testGcmId-" + random.nextInt(), "testApnId-" + random.nextInt(), "testVoipApnId-" + random.nextInt(), random.nextBoolean(), random.nextInt(), signedPreKey, random.nextInt(), random.nextInt(), "testUserAgent-" + random.nextInt() , 0, new Device.DeviceCapabilities(random.nextBoolean(), random.nextBoolean(), random.nextBoolean())); + return new Device(id, "testName-" + random.nextInt(), "testAuthToken-" + random.nextInt(), "testSalt-" + random.nextInt(), null, "testGcmId-" + random.nextInt(), "testApnId-" + random.nextInt(), "testVoipApnId-" + random.nextInt(), random.nextBoolean(), random.nextInt(), signedPreKey, random.nextInt(), random.nextInt(), "testUserAgent-" + random.nextInt() , 0, new Device.DeviceCapabilities(random.nextBoolean(), random.nextBoolean(), random.nextBoolean(), random.nextBoolean())); } private Account generateAccount(String number, UUID uuid) {