Add a second-generation GV2 capability and ignore the old capability for iOS devices.
This commit is contained in:
parent
5756be7d36
commit
5986145282
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -85,13 +85,13 @@ public class MessageControllerTest {
|
|||
@Before
|
||||
public void setup() throws Exception {
|
||||
Set<Device> singleDeviceList = new HashSet<Device>() {{
|
||||
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<Device> multiDeviceList = new HashSet<Device>() {{
|
||||
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());
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue