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

Commit 721a2fc3 authored by Matthew Sedam's avatar Matthew Sedam
Browse files

Add reliable message retry fields to ContextHubServiceTransaction

Bug: 331795143
Flag: android.chre.flags.reliable_message_retry_support_service
Test: Presubmits
Change-Id: I9a08c256324aa673c0e0d1d8b241dd2afe395221
parent 337b0586
Loading
Loading
Loading
Loading
+75 −36
Original line number Diff line number Diff line
@@ -27,53 +27,65 @@ import java.util.concurrent.TimeUnit;
 *
 * @hide
 */
/* package */ abstract class ContextHubServiceTransaction {
abstract class ContextHubServiceTransaction {
    private final int mTransactionId;

    @ContextHubTransaction.Type
    private final int mTransactionType;

    /** The ID of the nanoapp this transaction is targeted for, null if not applicable. */
    private final Long mNanoAppId;

    /**
     * The host package associated with this transaction.
     */
    private final String mPackage;

    /**
     * The message sequence number associated with this transaction, null if not applicable.
     */
    private final Integer mMessageSequenceNumber;

    /**
     * true if the transaction has already completed, false otherwise
     */
    private long mNextRetryTime;

    private long mTimeoutTime;

    /** The number of times the transaction has been started (start function called). */
    private int mNumCompletedStartCalls;

    private final short mHostEndpointId;

    private boolean mIsComplete = false;

    /* package */ ContextHubServiceTransaction(int id, int type, String packageName) {
    ContextHubServiceTransaction(int id, int type, String packageName) {
        mTransactionId = id;
        mTransactionType = type;
        mNanoAppId = null;
        mPackage = packageName;
        mMessageSequenceNumber = null;
        mNextRetryTime = Long.MAX_VALUE;
        mTimeoutTime = Long.MAX_VALUE;
        mNumCompletedStartCalls = 0;
        mHostEndpointId = Short.MAX_VALUE;
    }

    /* package */ ContextHubServiceTransaction(int id, int type, long nanoAppId,
    ContextHubServiceTransaction(int id, int type, long nanoAppId,
            String packageName) {
        mTransactionId = id;
        mTransactionType = type;
        mNanoAppId = nanoAppId;
        mPackage = packageName;
        mMessageSequenceNumber = null;
        mNextRetryTime = Long.MAX_VALUE;
        mTimeoutTime = Long.MAX_VALUE;
        mNumCompletedStartCalls = 0;
        mHostEndpointId = Short.MAX_VALUE;
    }

    /* package */ ContextHubServiceTransaction(int id, int type, String packageName,
            int messageSequenceNumber) {
    ContextHubServiceTransaction(int id, int type, String packageName,
            int messageSequenceNumber, short hostEndpointId) {
        mTransactionId = id;
        mTransactionType = type;
        mNanoAppId = null;
        mPackage = packageName;
        mMessageSequenceNumber = messageSequenceNumber;
        mNextRetryTime = Long.MAX_VALUE;
        mTimeoutTime = Long.MAX_VALUE;
        mNumCompletedStartCalls = 0;
        mHostEndpointId = hostEndpointId;
    }

    /**
@@ -95,7 +107,7 @@ import java.util.concurrent.TimeUnit;
     *
     * @param result the result of the transaction
     */
    /* package */ void onTransactionComplete(@ContextHubTransaction.Result int result) {
    void onTransactionComplete(@ContextHubTransaction.Result int result) {
    }

    /**
@@ -106,44 +118,51 @@ import java.util.concurrent.TimeUnit;
     * @param result           the result of the query
     * @param nanoAppStateList the list of nanoapps given by the query response
     */
    /* package */ void onQueryResponse(
    void onQueryResponse(
            @ContextHubTransaction.Result int result, List<NanoAppState> nanoAppStateList) {
    }

    /**
     * @return the ID of this transaction
     */
    /* package */ int getTransactionId() {
    int getTransactionId() {
        return mTransactionId;
    }

    /**
     * @return the type of this transaction
     * @see ContextHubTransaction.Type
     */
    @ContextHubTransaction.Type
    /* package */ int getTransactionType() {
    int getTransactionType() {
        return mTransactionType;
    }

    /**
     * @return the message sequence number of this transaction
     */
    Integer getMessageSequenceNumber() {
        return mMessageSequenceNumber;
    }

    long getNextRetryTime() {
        return mNextRetryTime;
    }

    long getTimeoutTime() {
        return mTimeoutTime;
    }

    int getNumCompletedStartCalls() {
        return mNumCompletedStartCalls;
    }

    short getHostEndpointId() {
        return mHostEndpointId;
    }

    /**
     * Gets the timeout period as defined in IContexthub.hal
     *
     * @return the timeout of this transaction in the specified time unit
     */
    /* package */ long getTimeout(TimeUnit unit) {
    long getTimeout(TimeUnit unit) {
        switch (mTransactionType) {
            case ContextHubTransaction.TYPE_LOAD_NANOAPP:
                return unit.convert(30L, TimeUnit.SECONDS);
            case ContextHubTransaction.TYPE_RELIABLE_MESSAGE:
                return unit.convert(1000L, TimeUnit.MILLISECONDS);
                return unit.convert(ContextHubTransactionManager.RELIABLE_MESSAGE_TIMEOUT_NS,
                        TimeUnit.NANOSECONDS);
            case ContextHubTransaction.TYPE_UNLOAD_NANOAPP:
            case ContextHubTransaction.TYPE_ENABLE_NANOAPP:
            case ContextHubTransaction.TYPE_DISABLE_NANOAPP:
@@ -159,14 +178,23 @@ import java.util.concurrent.TimeUnit;
     *
     * Should only be called as a result of a response from a Context Hub callback
     */
    /* package */ void setComplete() {
    void setComplete() {
        mIsComplete = true;
    }

    /**
     * @return true if the transaction has already completed, false otherwise
     */
    /* package */ boolean isComplete() {
    void setNextRetryTime(long nextRetryTime) {
        mNextRetryTime = nextRetryTime;
    }

    void setTimeoutTime(long timeoutTime) {
        mTimeoutTime = timeoutTime;
    }

    void setNumCompletedStartCalls(int numCompletedStartCalls) {
        mNumCompletedStartCalls = numCompletedStartCalls;
    }

    boolean isComplete() {
        return mIsComplete;
    }

@@ -187,7 +215,18 @@ import java.util.concurrent.TimeUnit;
            out.append(", messageSequenceNumber = ");
            out.append(mMessageSequenceNumber);
        }
        if (mTransactionType == ContextHubTransaction.TYPE_RELIABLE_MESSAGE) {
            out.append(", nextRetryTime = ");
            out.append(mNextRetryTime);
            out.append(", timeoutTime = ");
            out.append(mTimeoutTime);
            out.append(", numCompletedStartCalls = ");
            out.append(mNumCompletedStartCalls);
            out.append(", hostEndpointId = ");
            out.append(mHostEndpointId);
        }
        out.append(")");

        return out.toString();
    }
}