diff options
author | Calvin Pan <calvinpan@google.com> | 2021-11-08 12:41:11 +0800 |
---|---|---|
committer | Brad Ebinger <breadley@google.com> | 2022-03-07 12:54:40 -0800 |
commit | bdd893747aa376fcba3fc24a5c5d0292272e9aca (patch) | |
tree | 97fbc872c5ac7fc577e32cb7c52f58485b5a788f /src/java/com/android/ims | |
parent | 35a6054b0055e0f2c13aa4d370e139976656dbf4 (diff) | |
download | ims-bdd893747aa376fcba3fc24a5c5d0292272e9aca.tar.gz |
Fixing empty tuple capability always expired
EAB stores capabilities in two different tables (common, presence), and
stores the expiration time in the Presence table, because a contact may
have multiple tuples, and each tuple may have its own expiration time.
But if the server sends capabilities with empty tuples, EAB will not
store any data in the Presence table. It causes the EAB to treat it as
an expired capability and request a new capability every time.
[Fix] If there is no tuple ability, store the current timestamp and null
presence attributes in the presence table.
Bug: 203676348
Test: atest EabControllerTest
Merged-In: Id54a71b71d353f3d2fa5c3246ab534ad581fe245
Change-Id: Id54a71b71d353f3d2fa5c3246ab534ad581fe245
Diffstat (limited to 'src/java/com/android/ims')
-rw-r--r-- | src/java/com/android/ims/rcs/uce/eab/EabControllerImpl.java | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/src/java/com/android/ims/rcs/uce/eab/EabControllerImpl.java b/src/java/com/android/ims/rcs/uce/eab/EabControllerImpl.java index f069c07f..346f00d1 100644 --- a/src/java/com/android/ims/rcs/uce/eab/EabControllerImpl.java +++ b/src/java/com/android/ims/rcs/uce/eab/EabControllerImpl.java @@ -323,8 +323,10 @@ public class EabControllerImpl implements EabController { if (mechanism == CAPABILITY_MECHANISM_PRESENCE) { PresenceBuilder builder = new PresenceBuilder( contactUri, SOURCE_TYPE_CACHED, result); - builder.addCapabilityTuple(createPresenceTuple(contactUri, cursor)); - + RcsContactPresenceTuple tuple = createPresenceTuple(contactUri, cursor); + if (tuple != null) { + builder.addCapabilityTuple(tuple); + } String entityUri = getStringValue(cursor, EabProvider.EabCommonColumns.ENTITY_URI); if (!TextUtils.isEmpty(entityUri)) { builder.setEntityUri(Uri.parse(entityUri)); @@ -390,29 +392,34 @@ public class EabControllerImpl implements EabController { serviceCapabilities = serviceCapabilitiesBuilder.build(); // Create RcsContactPresenceTuple - RcsContactPresenceTuple.Builder rcsContactPresenceTupleBuilder = - new RcsContactPresenceTuple.Builder(status, serviceId, version); - if (description != null) { - rcsContactPresenceTupleBuilder.setServiceDescription(description); - } - if (contactUri != null) { - rcsContactPresenceTupleBuilder.setContactUri(contactUri); - } - if (serviceCapabilities != null) { - rcsContactPresenceTupleBuilder.setServiceCapabilities(serviceCapabilities); - } - if (timeStamp != null) { - try { - Instant instant = Instant.ofEpochSecond(Long.parseLong(timeStamp)); - rcsContactPresenceTupleBuilder.setTime(instant); - } catch (NumberFormatException ex) { - Log.w(TAG, "Create presence tuple: NumberFormatException"); - } catch (DateTimeParseException e) { - Log.w(TAG, "Create presence tuple: parse timestamp failed"); + boolean isTupleEmpty = TextUtils.isEmpty(status) && TextUtils.isEmpty(serviceId) + && TextUtils.isEmpty(version); + if (!isTupleEmpty) { + RcsContactPresenceTuple.Builder rcsContactPresenceTupleBuilder = + new RcsContactPresenceTuple.Builder(status, serviceId, version); + if (description != null) { + rcsContactPresenceTupleBuilder.setServiceDescription(description); } + if (contactUri != null) { + rcsContactPresenceTupleBuilder.setContactUri(contactUri); + } + if (serviceCapabilities != null) { + rcsContactPresenceTupleBuilder.setServiceCapabilities(serviceCapabilities); + } + if (timeStamp != null) { + try { + Instant instant = Instant.ofEpochSecond(Long.parseLong(timeStamp)); + rcsContactPresenceTupleBuilder.setTime(instant); + } catch (NumberFormatException ex) { + Log.w(TAG, "Create presence tuple: NumberFormatException"); + } catch (DateTimeParseException e) { + Log.w(TAG, "Create presence tuple: parse timestamp failed"); + } + } + return rcsContactPresenceTupleBuilder.build(); + } else { + return null; } - - return rcsContactPresenceTupleBuilder.build(); } private boolean isCapabilityExpired(Cursor cursor) { @@ -570,8 +577,28 @@ public class EabControllerImpl implements EabController { int commonId = Integer.parseInt(result.getLastPathSegment()); Log.d(TAG, "Insert into common table. Id: " + commonId); + if (capability.getCapabilityTuples().size() == 0) { + insertEmptyTuple(commonId); + } else { + insertAllTuples(commonId, capability); + } + } + + private void insertEmptyTuple(int commonId) { + Log.d(TAG, "Insert empty tuple into presence table."); + ContentValues contentValues = new ContentValues(); + contentValues.put(EabProvider.PresenceTupleColumns.EAB_COMMON_ID, commonId); + // Using current timestamp instead of network timestamp since there is not use cases for + // network timestamp and the network timestamp may cause capability expire immediately. + contentValues.put(EabProvider.PresenceTupleColumns.REQUEST_TIMESTAMP, + mExpirationTimeFactory.getExpirationTime()); + mContext.getContentResolver().insert(EabProvider.PRESENCE_URI, contentValues); + } + + private void insertAllTuples(int commonId, RcsContactUceCapability capability) { ContentValues[] presenceContent = new ContentValues[capability.getCapabilityTuples().size()]; + for (int i = 0; i < presenceContent.length; i++) { RcsContactPresenceTuple tuple = capability.getCapabilityTuples().get(i); @@ -592,7 +619,7 @@ public class EabControllerImpl implements EabController { } } - contentValues = new ContentValues(); + ContentValues contentValues = new ContentValues(); contentValues.put(EabProvider.PresenceTupleColumns.EAB_COMMON_ID, commonId); contentValues.put(EabProvider.PresenceTupleColumns.BASIC_STATUS, tuple.getStatus()); contentValues.put(EabProvider.PresenceTupleColumns.SERVICE_ID, tuple.getServiceId()); |