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

Commit 7ec9e684 authored by Sahin Caliskan's avatar Sahin Caliskan Committed by Gerrit Code Review
Browse files

Merge "Implement RcsThread querying (base)"

parents 3ada5146 424945e0
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,10 @@ import android.os.Parcel;
 * @hide - TODO(sahinc) make this public
 * @hide - TODO(sahinc) make this public
 */
 */
public class Rcs1To1Thread extends RcsThread {
public class Rcs1To1Thread extends RcsThread {
    public Rcs1To1Thread(int threadId) {
        super(threadId);
    }

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


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


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


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


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


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


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


package android.telephony.ims;
package android.telephony.ims;


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


    /**
    /**
     * 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.
     * @param threadId threadId of the thread to be deleted.
     */
     */
    @WorkerThread
    public void deleteThread(int threadId) {
    public void deleteThread(int threadId) {
        if (VDBG) logd("deleteThread: threadId: " + threadId);
        try {
        try {
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService("ircs"));
            if (iRcs != null) {
            if (iRcs != null) {
                iRcs.deleteThread(threadId);
                iRcs.deleteThread(threadId);
            }
            }
        } catch (RemoteException re) {
        } 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) {
        return null;
        Rlog.d(TAG, msg);
    }
    }
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,16 @@ import android.os.Parcelable;
 * @hide - TODO(sahinc) make this public
 * @hide - TODO(sahinc) make this public
 */
 */
public class RcsParticipant implements Parcelable {
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>() {
    public static final Creator<RcsParticipant> CREATOR = new Creator<RcsParticipant>() {
        @Override
        @Override
        public RcsParticipant createFromParcel(Parcel in) {
        public RcsParticipant createFromParcel(Parcel in) {
+47 −0
Original line number Original line Diff line number Diff line
@@ -16,7 +16,9 @@


package android.telephony.ims;
package android.telephony.ims;


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


/**
/**
 * RcsThread represents a single RCS conversation thread. It holds messages that were sent and
 * 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
 * @hide - TODO(sahinc) make this public
 */
 */
public abstract class RcsThread implements Parcelable {
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