Merge "Fix Rcs1To1Thread creation"
diff --git a/src/java/com/android/internal/telephony/ims/RcsMessageStoreController.java b/src/java/com/android/internal/telephony/ims/RcsMessageStoreController.java
index 269e3a9..ffe4bac 100644
--- a/src/java/com/android/internal/telephony/ims/RcsMessageStoreController.java
+++ b/src/java/com/android/internal/telephony/ims/RcsMessageStoreController.java
@@ -57,7 +57,6 @@
import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_ALIAS_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_ID_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_URI;
-import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_URI_PART;
import static android.provider.Telephony.RcsColumns.RcsParticipantEventColumns.NEW_ALIAS_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsThreadColumns.RCS_THREAD_ID_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsThreadEventColumns.DESTINATION_PARTICIPANT_ID_COLUMN;
@@ -99,7 +98,6 @@
import android.telephony.ims.RcsMessageSnippet;
import android.telephony.ims.RcsMessageStore;
import android.telephony.ims.RcsOutgoingMessageCreationParams;
-import android.telephony.ims.RcsParticipant;
import android.telephony.ims.RcsParticipantQueryParams;
import android.telephony.ims.RcsParticipantQueryResult;
import android.telephony.ims.RcsQueryContinuationToken;
@@ -244,35 +242,7 @@
@Override
public int createRcs1To1Thread(int recipientId) throws RemoteException {
- // Look up if a similar thread exists. Fail the call if it does
- RcsParticipant participant = mParticipantQueryHelper.getParticipantFromId(recipientId);
- if (participant == null) {
- throw new RemoteException(
- "RcsParticipant with id: " + recipientId + " does not exist.");
- }
-
- RcsThreadQueryParams queryParameters = new RcsThreadQueryParams.Builder()
- .setThreadType(RcsThreadQueryParams.THREAD_TYPE_1_TO_1).setParticipant(
- participant).build();
- RcsThreadQueryResult queryResult = getRcsThreads(queryParameters);
- if (queryResult.getThreads().size() > 0) {
- throw new RemoteException(
- "Rcs1To1Thread with recipient " + recipientId + " already exists.");
- }
-
- int rcs1To1ThreadId = mThreadQueryHelper.create1To1Thread();
- // add the recipient
- Uri recipientUri = RCS_1_TO_1_THREAD_URI.buildUpon().appendPath(
- Integer.toString(rcs1To1ThreadId)).appendPath(
- RCS_PARTICIPANT_URI_PART).appendPath(Integer.toString(recipientId)).build();
- Uri insertionResult = mContentResolver.insert(recipientUri, null);
-
- if (insertionResult.equals(recipientUri)) {
- // insertion successful, return the created thread
- return rcs1To1ThreadId;
- }
-
- throw new RemoteException("Creating Rcs1To1Thread failed");
+ return mThreadQueryHelper.create1To1Thread(recipientId);
}
@Override
diff --git a/src/java/com/android/internal/telephony/ims/RcsParticipantQueryHelper.java b/src/java/com/android/internal/telephony/ims/RcsParticipantQueryHelper.java
index 92fc459..29be536 100644
--- a/src/java/com/android/internal/telephony/ims/RcsParticipantQueryHelper.java
+++ b/src/java/com/android/internal/telephony/ims/RcsParticipantQueryHelper.java
@@ -43,8 +43,8 @@
RcsParticipant participant = null;
try (Cursor cursor = mContentResolver.query(
Uri.withAppendedPath(RCS_PARTICIPANT_URI, Integer.toString(participantId)),
- null, null, null)) {
- if (cursor == null && !cursor.moveToNext()) {
+ new String[]{RCS_PARTICIPANT_ID_COLUMN}, null, null)) {
+ if (cursor == null || !cursor.moveToNext()) {
throw new RemoteException("Could not find participant with id: " + participantId);
}
diff --git a/src/java/com/android/internal/telephony/ims/RcsThreadQueryHelper.java b/src/java/com/android/internal/telephony/ims/RcsThreadQueryHelper.java
index 3df1c2c..596ee22 100644
--- a/src/java/com/android/internal/telephony/ims/RcsThreadQueryHelper.java
+++ b/src/java/com/android/internal/telephony/ims/RcsThreadQueryHelper.java
@@ -19,6 +19,7 @@
import static android.provider.Telephony.RcsColumns.RcsGroupThreadColumns.GROUP_ICON_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsGroupThreadColumns.GROUP_NAME_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsGroupThreadColumns.RCS_GROUP_THREAD_URI;
+import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_ID_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.RCS_PARTICIPANT_URI_PART;
import static android.provider.Telephony.RcsColumns.RcsThreadColumns.RCS_THREAD_ID_COLUMN;
import static android.provider.Telephony.RcsColumns.RcsThreadColumns.RCS_THREAD_URI;
@@ -89,16 +90,16 @@
return new RcsThreadQueryResult(continuationToken, rcsThreadIdList);
}
- int create1To1Thread() throws RemoteException {
- ContentValues contentValues = new ContentValues(0);
- Uri insertionUri = mContentResolver.insert(RCS_THREAD_URI, contentValues);
+ int create1To1Thread(int participantId) throws RemoteException {
+ ContentValues contentValues = new ContentValues(1);
+ contentValues.put(RCS_PARTICIPANT_ID_COLUMN, participantId);
+ Uri insertionUri = mContentResolver.insert(RCS_1_TO_1_THREAD_URI, contentValues);
if (insertionUri == null) {
throw new RemoteException("Rcs1To1Thread creation failed");
}
- String threadIdAsString = insertionUri.getPathSegments().get(
- THREAD_ID_INDEX_IN_INSERTION_URI);
+ String threadIdAsString = insertionUri.getLastPathSegment();
int threadId = Integer.parseInt(threadIdAsString);
if (threadId <= 0) {