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

Commit 424945e0 authored by Sahin Caliskan's avatar Sahin Caliskan
Browse files

Implement RcsThread querying (base)

This change does a first pass to introduce RcsThread querying. We can
now insert threads and query them back.

Test: Added unit test

Bug: 109759350
Change-Id: Ib116cd533a19ce4d099864a095f585ac47cdc9f6
parent 6a3d45c4
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@ import android.os.Parcel;
 * @hide - TODO(sahinc) make this public
 */
public class Rcs1To1Thread extends RcsThread {
    public Rcs1To1Thread(int threadId) {
        super(threadId);
    }

    public static final Creator<Rcs1To1Thread> CREATOR = new Creator<Rcs1To1Thread>() {
        @Override
        public Rcs1To1Thread createFromParcel(Parcel in) {
@@ -36,6 +40,7 @@ public class Rcs1To1Thread extends RcsThread {
    };

    protected Rcs1To1Thread(Parcel in) {
        super(in);
    }

    @Override
@@ -45,5 +50,7 @@ public class Rcs1To1Thread extends RcsThread {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(RCS_1_TO_1_TYPE);
        super.writeToParcel(dest, flags);
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class RcsGroupThread extends RcsThread {
    };

    protected RcsGroupThread(Parcel in) {
        super(in);
    }

    @Override
@@ -45,5 +46,7 @@ public class RcsGroupThread extends RcsThread {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(RCS_GROUP_TYPE);
        super.writeToParcel(dest, flags);
    }
}
+76 −7
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.telephony.ims;

import android.annotation.Nullable;
import android.annotation.WorkerThread;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.Rlog;
@@ -27,26 +29,93 @@ import android.telephony.ims.aidl.IRcs;
 * @hide - TODO make this public
 */
public class RcsMessageStore {
    private static final String TAG = "RcsMessageStore";
    private static final boolean VDBG = false;
    static final String TAG = "RcsMessageStore";

    /**
     * Delete the RcsThread identified by the given threadId.
     * Returns the first chunk of existing {@link RcsThread}s in the common storage.
     * @param queryParameters Parameters to specify to return a subset of all RcsThreads.
     *                        Passing a value of null will return all threads.
     */
    @WorkerThread
    public RcsThreadQueryResult getRcsThreads(@Nullable RcsThreadQueryParameters queryParameters) {
        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                return iRcs.getRcsThreads(queryParameters);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsMessageStore: Exception happened during getRcsThreads", re);
        }

        return null;
    }

    /**
     * Returns the next chunk of {@link RcsThread}s in the common storage.
     * @param continuationToken A token to continue the query to get the next chunk. This is
     *                          obtained through {@link RcsThreadQueryResult#nextChunkToken}.
     */
    @WorkerThread
    public RcsThreadQueryResult getRcsThreads(RcsThreadQueryContinuationToken continuationToken) {
        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                return iRcs.getRcsThreadsWithToken(continuationToken);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsMessageStore: Exception happened during getRcsThreads", re);
        }

        return null;
    }

    /**
     * Creates a new 1 to 1 thread with the given participant and persists it in the storage.
     */
    @WorkerThread
    public Rcs1To1Thread createRcs1To1Thread(RcsParticipant recipient) {
        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                return iRcs.createRcs1To1Thread(recipient);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsMessageStore: Exception happened during createRcs1To1Thread", re);
        }

        return null;
    }

    /**
     * Delete the {@link RcsThread} identified by the given threadId.
     * @param threadId threadId of the thread to be deleted.
     */
    @WorkerThread
    public void deleteThread(int threadId) {
        if (VDBG) logd("deleteThread: threadId: " + threadId);
        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                iRcs.deleteThread(threadId);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsMessageStore: Exception happened during deleteThread", re);
        }
    }

    /**
     * Creates a new participant and persists it in the storage.
     * @param canonicalAddress The defining address (e.g. phone number) of the participant.
     */
    public RcsParticipant createRcsParticipant(String canonicalAddress) {
        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
                return iRcs.createRcsParticipant(canonicalAddress);
            }
        } catch (RemoteException re) {
            Rlog.e(TAG, "RcsMessageStore: Exception happened during createRcsParticipant", re);
        }

    private static void logd(String msg) {
        Rlog.d(TAG, msg);
        return null;
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -23,6 +23,16 @@ import android.os.Parcelable;
 * @hide - TODO(sahinc) make this public
 */
public class RcsParticipant implements Parcelable {
    /**
     * Returns the row id of this participant.
     *
     * TODO(sahinc) implement
     * @hide
     */
    public int getId() {
        return 12345;
    }

    public static final Creator<RcsParticipant> CREATOR = new Creator<RcsParticipant>() {
        @Override
        public RcsParticipant createFromParcel(Parcel in) {
+47 −0
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package android.telephony.ims;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

/**
 * RcsThread represents a single RCS conversation thread. It holds messages that were sent and
@@ -24,5 +26,50 @@ import android.os.Parcelable;
 * @hide - TODO(sahinc) make this public
 */
public abstract class RcsThread implements Parcelable {
    // Since this is an abstract class that gets parcelled, the sub-classes need to write these
    // magic values into the parcel so that we know which type to unparcel into.
    protected static final int RCS_1_TO_1_TYPE = 998;
    protected static final int RCS_GROUP_TYPE = 999;

    protected int mThreadId;

    protected RcsThread(int threadId) {
        mThreadId = threadId;
    }

    protected RcsThread(Parcel in) {
        mThreadId = in.readInt();
    }

    public static final Creator<RcsThread> CREATOR = new Creator<RcsThread>() {
        @Override
        public RcsThread createFromParcel(Parcel in) {
            int type = in.readInt();

            switch (type) {
                case RCS_1_TO_1_TYPE:
                    return new Rcs1To1Thread(in);
                case RCS_GROUP_TYPE:
                    return new RcsGroupThread(in);
                default:
                    Log.e(RcsMessageStore.TAG, "Cannot unparcel RcsThread, wrong type: " + type);
            }
            return null;
        }

        @Override
        public RcsThread[] newArray(int size) {
            return new RcsThread[0];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mThreadId);
    }
}
Loading