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 7ca5f5a03..2b0be43cd 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java @@ -252,11 +252,21 @@ public class Device { } public boolean isGroupsV2Supported() { - if (this.getGcmId() != null) { - return this.capabilities != null && (this.capabilities.isGv2() || this.capabilities.isGv2_2()); + final boolean groupsV2Supported; + + if (this.capabilities != null) { + if (this.getGcmId() != null) { + groupsV2Supported = this.capabilities.isGv2() || this.capabilities.isGv2_2() || this.capabilities.isGv2_3(); + } else if (this.apnId != null || this.voipApnId != null) { + groupsV2Supported = this.capabilities.isGv2_2() || this.capabilities.isGv2_3(); + } else { + groupsV2Supported = this.capabilities.isGv2_3(); + } } else { - return this.capabilities != null && this.capabilities.isGv2_2(); + groupsV2Supported = false; } + + return groupsV2Supported; } @Override @@ -279,6 +289,9 @@ public class Device { @JsonProperty("gv2-2") private boolean gv2_2; + @JsonProperty("gv2-3") + private boolean gv2_3; + @JsonProperty private boolean storage; @@ -287,9 +300,10 @@ public class Device { public DeviceCapabilities() {} - public DeviceCapabilities(boolean gv2, final boolean gv2_2, boolean storage, boolean transfer) { + public DeviceCapabilities(boolean gv2, final boolean gv2_2, final boolean gv2_3, boolean storage, boolean transfer) { this.gv2 = gv2; this.gv2_2 = gv2_2; + this.gv2_3 = gv2_3; this.storage = storage; this.transfer = transfer; } @@ -302,6 +316,10 @@ public class Device { return gv2_2; } + public boolean isGv2_3() { + return gv2_3; + } + public boolean isStorage() { return storage; } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java index c71d0201e..db22e240f 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java @@ -12,23 +12,40 @@ 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); + public void testIsGroupsV2Supported(final String gcmId, final String apnId, final boolean gv2Capability, final boolean gv2_2Capability, final boolean gv2_3Capability, final boolean expectGv2Supported) { + final Device.DeviceCapabilities capabilities = new Device.DeviceCapabilities(gv2Capability, gv2_2Capability, gv2_3Capability, false, false); + final Device device = new Device(1, "test", "auth-token", "salt", "signaling-key", gcmId, apnId, null, 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 } + // gcmId apnId gv2 gv2-2 gv2-3 capable + new Object[] { "gcm-id", null, false, false, false, false }, + new Object[] { "gcm-id", null, true, false, false, true }, + new Object[] { "gcm-id", null, false, true, false, true }, + new Object[] { "gcm-id", null, true, true, false, true }, + new Object[] { "gcm-id", null, false, false, true, true }, + new Object[] { "gcm-id", null, true, false, true, true }, + new Object[] { "gcm-id", null, false, true, true, true }, + new Object[] { "gcm-id", null, true, true, true, true }, + new Object[] { null, "apn-id", false, false, false, false }, + new Object[] { null, "apn-id", true, false, false, false }, + new Object[] { null, "apn-id", false, true, false, true }, + new Object[] { null, "apn-id", true, true, false, true }, + new Object[] { null, "apn-id", false, false, true, true }, + new Object[] { null, "apn-id", true, false, true, true }, + new Object[] { null, "apn-id", false, true, true, true }, + new Object[] { null, "apn-id", true, true, true, true }, + new Object[] { null, null, false, false, false, false }, + new Object[] { null, null, true, false, false, false }, + new Object[] { null, null, false, true, false, false }, + new Object[] { null, null, true, true, false, false }, + new Object[] { null, null, false, false, true, true }, + new Object[] { null, null, true, false, true, true }, + new Object[] { null, null, false, true, true, true }, + new Object[] { null, null, true, true, true, true } }; } } 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 0b657c956..46c1be94c 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, false, true, false); + Device.DeviceCapabilities deviceCapabilities = new Device.DeviceCapabilities(false, 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 df58dad3e..6ee696532 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, false, 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, 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, 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))); + 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, 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, 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, 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/AccountsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/AccountsTest.java index 0f57a1536..dce659f0b 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 @@ -286,7 +286,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(), 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(), random.nextBoolean())); } private Account generateAccount(String number, UUID uuid) {