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

Commit 75a95694 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Handles synchronous failures of transactions

Also removes onTimeout, and instaed use onTransactionResponse.

Bug: 67734082
Bug: 69862275
Test: Run CHQTS, verify that synchronous failures are reported.
Change-Id: I995d381e89a602293e3480a12e56665d3d500a9a
parent d27c9dab
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -53,19 +53,11 @@ import java.util.concurrent.TimeUnit;
    /* package */
    abstract int onTransact();

    /**
     * A function to invoke when a transaction times out.
     *
     * All instances of this class must implement this method by reporting the timeout to the
     * client.
     */
    /* package */
    abstract void onTimeout();

    /**
     * A function to invoke when the transaction completes.
     *
     * Only relevant for load, unload, enable, or disable transactions.
     * For transactions with expected contents (such as a query), the class instance should
     * implement the appropriate behavior (e.g. invoke onQueryResponse with an empty list).
     *
     * @param result the result of the transaction
     */
+12 −20
Original line number Diff line number Diff line
@@ -106,16 +106,11 @@ import java.util.concurrent.atomic.AtomicInteger;
                            contextHubId, hidlNanoAppBinary, this.getTransactionId());
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to load nanoapp with ID 0x" +
                            Long.toHexString(nanoAppBinary.getNanoAppId()));
                            Long.toHexString(nanoAppBinary.getNanoAppId()), e);
                    return Result.UNKNOWN_FAILURE;
                }
            }

            @Override
            /* package */ void onTimeout() {
                onTransactionComplete(ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);
            }

            @Override
            /* package */ void onTransactionComplete(int result) {
                try {
@@ -124,7 +119,7 @@ import java.util.concurrent.atomic.AtomicInteger;
                        mClientManager.onNanoAppLoaded(contextHubId, nanoAppBinary.getNanoAppId());
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while calling client onTransactionComplete");
                    Log.e(TAG, "RemoteException while calling client onTransactionComplete", e);
                }
            }
        };
@@ -149,16 +144,11 @@ import java.util.concurrent.atomic.AtomicInteger;
                            contextHubId, nanoAppId, this.getTransactionId());
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to unload nanoapp with ID 0x" +
                            Long.toHexString(nanoAppId));
                            Long.toHexString(nanoAppId), e);
                    return Result.UNKNOWN_FAILURE;
                }
            }

            @Override
            /* package */ void onTimeout() {
                onTransactionComplete(ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);
            }

            @Override
            /* package */ void onTransactionComplete(int result) {
                try {
@@ -167,7 +157,7 @@ import java.util.concurrent.atomic.AtomicInteger;
                        mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while calling client onTransactionComplete");
                    Log.e(TAG, "RemoteException while calling client onTransactionComplete", e);
                }
            }
        };
@@ -189,15 +179,14 @@ import java.util.concurrent.atomic.AtomicInteger;
                try {
                    return mContextHubProxy.queryApps(contextHubId);
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to query for nanoapps");
                    Log.e(TAG, "RemoteException while trying to query for nanoapps", e);
                    return Result.UNKNOWN_FAILURE;
                }
            }

            @Override
            /* package */ void onTimeout() {
                onQueryResponse(ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT,
                        Collections.emptyList());
            /* package */ void onTransactionComplete(int result) {
                onQueryResponse(result, Collections.emptyList());
            }

            @Override
@@ -205,7 +194,7 @@ import java.util.concurrent.atomic.AtomicInteger;
                try {
                    onCompleteCallback.onQueryResponse(result, nanoAppStateList);
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while calling client onQueryComplete");
                    Log.e(TAG, "RemoteException while calling client onQueryComplete", e);
                }
            }
        };
@@ -333,7 +322,8 @@ import java.util.concurrent.atomic.AtomicInteger;
                    synchronized (this) {
                        if (!transaction.isComplete()) {
                            Log.d(TAG, transaction + " timed out");
                            transaction.onTimeout();
                            transaction.onTransactionComplete(
                                    ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);

                            removeTransactionAndStartNext();
                        }
@@ -344,6 +334,8 @@ import java.util.concurrent.atomic.AtomicInteger;
                mTimeoutFuture = mTimeoutExecutor.schedule(onTimeoutFunc, timeoutSeconds,
                        TimeUnit.SECONDS);
            } else {
                transaction.onTransactionComplete(
                        ContextHubServiceUtil.toTransactionResult(result));
                mTransactionQueue.remove();
            }
        }