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

Commit 382a2fd0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Handles synchronous failures of transactions"

parents c5533865 75a95694
Loading
Loading
Loading
Loading
+2 −10
Original line number Original line Diff line number Diff line
@@ -53,19 +53,11 @@ import java.util.concurrent.TimeUnit;
    /* package */
    /* package */
    abstract int onTransact();
    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.
     * 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
     * @param result the result of the transaction
     */
     */
+12 −20
Original line number Original line Diff line number Diff line
@@ -106,16 +106,11 @@ import java.util.concurrent.atomic.AtomicInteger;
                            contextHubId, hidlNanoAppBinary, this.getTransactionId());
                            contextHubId, hidlNanoAppBinary, this.getTransactionId());
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to load nanoapp with ID 0x" +
                    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;
                    return Result.UNKNOWN_FAILURE;
                }
                }
            }
            }


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

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


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

            @Override
            @Override
            /* package */ void onTransactionComplete(int result) {
            /* package */ void onTransactionComplete(int result) {
                try {
                try {
@@ -167,7 +157,7 @@ import java.util.concurrent.atomic.AtomicInteger;
                        mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId);
                        mClientManager.onNanoAppUnloaded(contextHubId, nanoAppId);
                    }
                    }
                } catch (RemoteException e) {
                } 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 {
                try {
                    return mContextHubProxy.queryApps(contextHubId);
                    return mContextHubProxy.queryApps(contextHubId);
                } catch (RemoteException e) {
                } 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;
                    return Result.UNKNOWN_FAILURE;
                }
                }
            }
            }


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


            @Override
            @Override
@@ -205,7 +194,7 @@ import java.util.concurrent.atomic.AtomicInteger;
                try {
                try {
                    onCompleteCallback.onQueryResponse(result, nanoAppStateList);
                    onCompleteCallback.onQueryResponse(result, nanoAppStateList);
                } catch (RemoteException e) {
                } 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) {
                    synchronized (this) {
                        if (!transaction.isComplete()) {
                        if (!transaction.isComplete()) {
                            Log.d(TAG, transaction + " timed out");
                            Log.d(TAG, transaction + " timed out");
                            transaction.onTimeout();
                            transaction.onTransactionComplete(
                                    ContextHubTransaction.TRANSACTION_FAILED_TIMEOUT);


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