Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8dad5ae3 authored by Leland Miller's avatar Leland Miller Committed by android-build-merger
Browse files

Merge "Fix Rcs1To1Thread creation"

am: f6d45e0c

Change-Id: I191241f7735060a0cf77be1d4509cc3940410885
parents 86d0cd6a f6d45e0c
Loading
Loading
Loading
Loading
+1 −31
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import static android.provider.Telephony.RcsColumns.RcsParticipantColumns.CANONI
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.RcsMessageQueryResult;
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 @@ public class RcsMessageStoreController extends IRcs.Stub {

    @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
+2 −2
Original line number Diff line number Diff line
@@ -43,8 +43,8 @@ class RcsParticipantQueryHelper {
        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);
            }

+6 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static android.provider.Telephony.RcsColumns.Rcs1To1ThreadColumns.RCS_1_T
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 @@ class RcsThreadQueryHelper {
        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) {