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

Commit a3d9f76b authored by Leland Miller's avatar Leland Miller
Browse files

Use injected instance of RcsControllerCall

Instead of static methods, create an instance of RcsControllerCall that
holds a reference to the Context and inject it where it is used.

This will be used in a follow up commit that will require the calling
package name be passed when calling IRcs methods.

This change will allow passing a calling package name to an
RcsServiceCall or an RcsServiceCallWithNoReturn, so uses of the call
method might look something like:

```
mRcsControllerCall.call((iRcs, callingPackage) ->
        iRcs.getFileTransferContentUri(mId, callingPackage));
```

Alternatives to storing the context here would have been:

1. To store the context everywhere the RcsControllerCall is injected and
   get the calling package name at each RcsControllerCall call

2. To store the calling package name everywhere that the
   RcsControllerCall instance is injected

Compared to solution 1, the implemented solution avoids repeating the
logic of retrieving the calling package.

Compared to solution 2, the implemented solution does not introduce any
complexity. In addition, the individual classes do not care about the
calling package name outside of the need to pass it to an IRcs method.
In the future, the implemented solution may also provide a useful point
to provide logic involving calls and the context (or other injected
dependencies). Though this future concern is not alone enough to justify
the solution, since the solution adds no additional complexity against
other solutions, it seems like a nice benefit.

Note, to avoid polluting this commit, a follow-up issue (b/128029441)
has been created to adjust the name of RcsControllerCall to reflect that
an instance of RcsControllerCall does not represent a single call to
RcsController.

Bug: 123699565
Test: Existing tests pass
Change-Id: Ib0f55f14397e5eb1e5a55864094c0be0c4e37c06
parent 35d29333
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -555,7 +555,7 @@ final class SystemServiceRegistry {
                new CachedServiceFetcher<RcsManager>() {
                    @Override
                    public RcsManager createService(ContextImpl ctx) {
                        return new RcsManager();
                        return new RcsManager(ctx.getOuterContext());
                    }
                });

+6 −5
Original line number Diff line number Diff line
@@ -33,8 +33,8 @@ public class Rcs1To1Thread extends RcsThread {
     *
     * @hide
     */
    public Rcs1To1Thread(int threadId) {
        super(threadId);
    public Rcs1To1Thread(RcsControllerCall rcsControllerCall, int threadId) {
        super(rcsControllerCall, threadId);
        mThreadId = threadId;
    }

@@ -56,7 +56,7 @@ public class Rcs1To1Thread extends RcsThread {
     */
    @WorkerThread
    public long getFallbackThreadId() throws RcsMessageStoreException {
        return RcsControllerCall.call(iRcs -> iRcs.get1To1ThreadFallbackThreadId(mThreadId));
        return mRcsControllerCall.call(iRcs -> iRcs.get1To1ThreadFallbackThreadId(mThreadId));
    }

    /**
@@ -69,7 +69,7 @@ public class Rcs1To1Thread extends RcsThread {
     */
    @WorkerThread
    public void setFallbackThreadId(long fallbackThreadId) throws RcsMessageStoreException {
        RcsControllerCall.callWithNoReturn(
        mRcsControllerCall.callWithNoReturn(
                iRcs -> iRcs.set1To1ThreadFallbackThreadId(mThreadId, fallbackThreadId));
    }

@@ -81,6 +81,7 @@ public class Rcs1To1Thread extends RcsThread {
    @WorkerThread
    public RcsParticipant getRecipient() throws RcsMessageStoreException {
        return new RcsParticipant(
                RcsControllerCall.call(iRcs -> iRcs.get1To1ThreadOtherParticipantId(mThreadId)));
                mRcsControllerCall,
                mRcsControllerCall.call(iRcs -> iRcs.get1To1ThreadOtherParticipantId(mThreadId)));
    }
}
+11 −11
Original line number Diff line number Diff line
@@ -27,7 +27,13 @@ import android.telephony.ims.aidl.IRcs;
 * @hide - not meant for public use
 */
class RcsControllerCall {
    static <R> R call(RcsServiceCall<R> serviceCall) throws RcsMessageStoreException {
    private final Context mContext;

    RcsControllerCall(Context context) {
        mContext = context;
    }

    <R> R call(RcsServiceCall<R> serviceCall) throws RcsMessageStoreException {
        IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_RCS_SERVICE));
        if (iRcs == null) {
            throw new RcsMessageStoreException("Could not connect to RCS storage service");
@@ -40,18 +46,12 @@ class RcsControllerCall {
        }
    }

    static void callWithNoReturn(RcsServiceCallWithNoReturn serviceCall)
    void callWithNoReturn(RcsServiceCallWithNoReturn serviceCall)
            throws RcsMessageStoreException {
        IRcs iRcs = IRcs.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_RCS_SERVICE));
        if (iRcs == null) {
            throw new RcsMessageStoreException("Could not connect to RCS storage service");
        }

        try {
        call(iRcs -> {
            serviceCall.methodOnIRcs(iRcs);
        } catch (RemoteException exception) {
            throw new RcsMessageStoreException(exception.getMessage());
        }
            return null;
        });
    }

    interface RcsServiceCall<R> {
+1 −1
Original line number Diff line number Diff line
@@ -40,5 +40,5 @@ public abstract class RcsEvent {
     *
     * @hide
     */
    abstract void persist() throws RcsMessageStoreException;
    abstract void persist(RcsControllerCall rcsControllerCall) throws RcsMessageStoreException;
}
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ public abstract class RcsEventDescriptor implements Parcelable {
     * descriptor.
     */
    @VisibleForTesting(visibility = PROTECTED)
    public abstract RcsEvent createRcsEvent();
    public abstract RcsEvent createRcsEvent(RcsControllerCall rcsControllerCall);

    RcsEventDescriptor(Parcel in) {
        mTimestamp = in.readLong();
Loading