From 7b378ab80349aed05acc83128caba135cf3926a6 Mon Sep 17 00:00:00 2001 From: Leland Miller Date: Thu, 24 Jan 2019 16:09:10 -0800 Subject: [PATCH] Add getOrCreateCanonicalAddressId This is used exclusively for RCS message storage to retrieve canonical address IDs for participants. Test: CtsRcsTestCases Change-Id: Idd935b8d7787db9597b643551714f134d63b33c0 --- .../java/android/provider/Telephony.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/telephony/java/android/provider/Telephony.java b/telephony/java/android/provider/Telephony.java index ac34cea30f559..51c8f65a6c9d0 100644 --- a/telephony/java/android/provider/Telephony.java +++ b/telephony/java/android/provider/Telephony.java @@ -2653,6 +2653,41 @@ public final class Telephony { Uri RCS_EVENT_QUERY_URI = Uri.withAppendedPath(CONTENT_AND_AUTHORITY, RCS_EVENT_QUERY_URI_PATH); } + + /** + * Allows RCS specific canonical address handling. + */ + interface RcsCanonicalAddressHelper { + /** + * Returns the canonical address ID for a canonical address, if now row exists, this + * will add a row and return its ID. This helper works against the same table used by + * the SMS and MMS threads, but is accessible only by the phone process for use by RCS + * message storage. + * + * @throws IllegalArgumentException if unable to retrieve or create the canonical + * address entry. + */ + static long getOrCreateCanonicalAddressId( + ContentResolver contentResolver, String canonicalAddress) { + + Uri.Builder uriBuilder = CONTENT_AND_AUTHORITY.buildUpon(); + uriBuilder.appendPath("canonical-address"); + uriBuilder.appendQueryParameter("address", canonicalAddress); + Uri uri = uriBuilder.build(); + + try (Cursor cursor = contentResolver.query(uri, null, null, null)) { + if (cursor != null && cursor.moveToFirst()) { + return cursor.getLong(cursor.getColumnIndex(CanonicalAddressesColumns._ID)); + } else { + Rlog.e(TAG, "getOrCreateCanonicalAddressId returned no rows"); + } + } + + Rlog.e(TAG, "getOrCreateCanonicalAddressId failed"); + throw new IllegalArgumentException( + "Unable to find or allocate a canonical address ID"); + } + } } /**