Loading services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java +162 −65 Original line number Diff line number Diff line Loading @@ -584,6 +584,34 @@ import java.util.concurrent.atomic.AtomicInteger; */ /* package */ void onTransactionResponse(int transactionId, boolean success) { if (Flags.simplifyServiceTransactionLock()) { synchronized (mTransactionLock) { TransactionAcceptConditions conditions = transaction -> { if (transaction.getTransactionId() != transactionId) { Log.w( TAG, "Unexpected transaction: expected " + transactionId + ", received " + transaction.getTransactionId()); return false; } return true; }; ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions); if (transaction == null) { Log.w(TAG, "Received unexpected transaction response"); return; } transaction.onTransactionComplete( success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_AT_HUB); transaction.setComplete(); } } else { TransactionAcceptConditions conditions = transaction -> { if (transaction.getTransactionId() != transactionId) { Loading Loading @@ -611,6 +639,7 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.setComplete(); } } } /** * Handles a message delivery response from a Context Hub. Loading @@ -620,6 +649,28 @@ import java.util.concurrent.atomic.AtomicInteger; */ /* package */ void onMessageDeliveryResponse(int messageSequenceNumber, boolean success) { if (Flags.simplifyServiceTransactionLock()) { ContextHubServiceTransaction transaction = null; synchronized (mReliableMessageLock) { transaction = mReliableMessageTransactionMap.get(messageSequenceNumber); if (transaction == null) { Log.w( TAG, "Could not find reliable message transaction with " + "message sequence number = " + messageSequenceNumber); return; } removeMessageTransaction(transaction); completeMessageTransaction( transaction, success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_AT_HUB); } } else { ContextHubServiceTransaction transaction = null; synchronized (mReliableMessageLock) { transaction = mReliableMessageTransactionMap.get(messageSequenceNumber); Loading @@ -640,6 +691,8 @@ import java.util.concurrent.atomic.AtomicInteger; success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_AT_HUB); } mExecutor.execute(() -> processMessageTransactions()); } Loading @@ -650,6 +703,22 @@ import java.util.concurrent.atomic.AtomicInteger; */ /* package */ void onQueryResponse(List<NanoAppState> nanoAppStateList) { if (Flags.simplifyServiceTransactionLock()) { synchronized (mTransactionLock) { TransactionAcceptConditions conditions = transaction -> transaction.getTransactionType() == ContextHubTransaction.TYPE_QUERY_NANOAPPS; ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions); if (transaction == null) { Log.w(TAG, "Received unexpected query response"); return; } transaction.onQueryResponse(ContextHubTransaction.RESULT_SUCCESS, nanoAppStateList); transaction.setComplete(); } } else { TransactionAcceptConditions conditions = transaction -> transaction.getTransactionType() Loading @@ -665,6 +734,7 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.setComplete(); } } } /** Handles a hub reset event by stopping a pending transaction and starting the next. */ /* package */ Loading Loading @@ -729,9 +799,13 @@ import java.util.concurrent.atomic.AtomicInteger; cancelTimeoutFuture(); ContextHubServiceTransaction transaction = mTransactionQueue.remove(); if (Flags.simplifyServiceTransactionLock()) { transaction.setComplete(); } else { synchronized (transaction) { transaction.setComplete(); } } if (!mTransactionQueue.isEmpty()) { startNextTransaction(); Loading Loading @@ -766,6 +840,17 @@ import java.util.concurrent.atomic.AtomicInteger; if (result == ContextHubTransaction.RESULT_SUCCESS) { Runnable onTimeoutFunc = () -> { if (Flags.simplifyServiceTransactionLock()) { synchronized (mTransactionLock) { if (!transaction.isComplete()) { Log.d(TAG, transaction + " timed out"); transaction.onTransactionComplete( ContextHubTransaction.RESULT_FAILED_TIMEOUT); transaction.setComplete(); removeTransactionAndStartNext(); } } } else { synchronized (transaction) { if (!transaction.isComplete()) { Log.d(TAG, transaction + " timed out"); Loading @@ -778,6 +863,7 @@ import java.util.concurrent.atomic.AtomicInteger; synchronized (mTransactionLock) { removeTransactionAndStartNext(); } } }; long timeoutMs = transaction.getTimeout(TimeUnit.MILLISECONDS); Loading @@ -787,12 +873,18 @@ import java.util.concurrent.atomic.AtomicInteger; } catch (Exception e) { Log.e(TAG, "Error when schedule a timer", e); } } else { if (Flags.simplifyServiceTransactionLock()) { transaction.onTransactionComplete( ContextHubServiceUtil.toTransactionResult(result)); transaction.setComplete(); } else { synchronized (transaction) { transaction.onTransactionComplete( ContextHubServiceUtil.toTransactionResult(result)); transaction.setComplete(); } } mTransactionQueue.remove(); } Loading Loading @@ -874,12 +966,18 @@ import java.util.concurrent.atomic.AtomicInteger; * @param transaction The transaction to complete. * @param result The result code. */ @GuardedBy("mReliableMessageLock") private void completeMessageTransaction( ContextHubServiceTransaction transaction, @ContextHubTransaction.Result int result) { if (Flags.simplifyServiceTransactionLock()) { transaction.onTransactionComplete(result); transaction.setComplete(); } else { synchronized (transaction) { transaction.onTransactionComplete(result); transaction.setComplete(); } } Log.d( TAG, Loading @@ -897,7 +995,6 @@ import java.util.concurrent.atomic.AtomicInteger; * @param result The result code. * @param iter The iterator for the reliable message map - used to remove the message directly. */ @GuardedBy("mReliableMessageLock") private void removeAndCompleteMessageTransaction( ContextHubServiceTransaction transaction, @ContextHubTransaction.Result int result, Loading Loading
services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java +162 −65 Original line number Diff line number Diff line Loading @@ -584,6 +584,34 @@ import java.util.concurrent.atomic.AtomicInteger; */ /* package */ void onTransactionResponse(int transactionId, boolean success) { if (Flags.simplifyServiceTransactionLock()) { synchronized (mTransactionLock) { TransactionAcceptConditions conditions = transaction -> { if (transaction.getTransactionId() != transactionId) { Log.w( TAG, "Unexpected transaction: expected " + transactionId + ", received " + transaction.getTransactionId()); return false; } return true; }; ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions); if (transaction == null) { Log.w(TAG, "Received unexpected transaction response"); return; } transaction.onTransactionComplete( success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_AT_HUB); transaction.setComplete(); } } else { TransactionAcceptConditions conditions = transaction -> { if (transaction.getTransactionId() != transactionId) { Loading Loading @@ -611,6 +639,7 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.setComplete(); } } } /** * Handles a message delivery response from a Context Hub. Loading @@ -620,6 +649,28 @@ import java.util.concurrent.atomic.AtomicInteger; */ /* package */ void onMessageDeliveryResponse(int messageSequenceNumber, boolean success) { if (Flags.simplifyServiceTransactionLock()) { ContextHubServiceTransaction transaction = null; synchronized (mReliableMessageLock) { transaction = mReliableMessageTransactionMap.get(messageSequenceNumber); if (transaction == null) { Log.w( TAG, "Could not find reliable message transaction with " + "message sequence number = " + messageSequenceNumber); return; } removeMessageTransaction(transaction); completeMessageTransaction( transaction, success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_AT_HUB); } } else { ContextHubServiceTransaction transaction = null; synchronized (mReliableMessageLock) { transaction = mReliableMessageTransactionMap.get(messageSequenceNumber); Loading @@ -640,6 +691,8 @@ import java.util.concurrent.atomic.AtomicInteger; success ? ContextHubTransaction.RESULT_SUCCESS : ContextHubTransaction.RESULT_FAILED_AT_HUB); } mExecutor.execute(() -> processMessageTransactions()); } Loading @@ -650,6 +703,22 @@ import java.util.concurrent.atomic.AtomicInteger; */ /* package */ void onQueryResponse(List<NanoAppState> nanoAppStateList) { if (Flags.simplifyServiceTransactionLock()) { synchronized (mTransactionLock) { TransactionAcceptConditions conditions = transaction -> transaction.getTransactionType() == ContextHubTransaction.TYPE_QUERY_NANOAPPS; ContextHubServiceTransaction transaction = getTransactionAndHandleNext(conditions); if (transaction == null) { Log.w(TAG, "Received unexpected query response"); return; } transaction.onQueryResponse(ContextHubTransaction.RESULT_SUCCESS, nanoAppStateList); transaction.setComplete(); } } else { TransactionAcceptConditions conditions = transaction -> transaction.getTransactionType() Loading @@ -665,6 +734,7 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.setComplete(); } } } /** Handles a hub reset event by stopping a pending transaction and starting the next. */ /* package */ Loading Loading @@ -729,9 +799,13 @@ import java.util.concurrent.atomic.AtomicInteger; cancelTimeoutFuture(); ContextHubServiceTransaction transaction = mTransactionQueue.remove(); if (Flags.simplifyServiceTransactionLock()) { transaction.setComplete(); } else { synchronized (transaction) { transaction.setComplete(); } } if (!mTransactionQueue.isEmpty()) { startNextTransaction(); Loading Loading @@ -766,6 +840,17 @@ import java.util.concurrent.atomic.AtomicInteger; if (result == ContextHubTransaction.RESULT_SUCCESS) { Runnable onTimeoutFunc = () -> { if (Flags.simplifyServiceTransactionLock()) { synchronized (mTransactionLock) { if (!transaction.isComplete()) { Log.d(TAG, transaction + " timed out"); transaction.onTransactionComplete( ContextHubTransaction.RESULT_FAILED_TIMEOUT); transaction.setComplete(); removeTransactionAndStartNext(); } } } else { synchronized (transaction) { if (!transaction.isComplete()) { Log.d(TAG, transaction + " timed out"); Loading @@ -778,6 +863,7 @@ import java.util.concurrent.atomic.AtomicInteger; synchronized (mTransactionLock) { removeTransactionAndStartNext(); } } }; long timeoutMs = transaction.getTimeout(TimeUnit.MILLISECONDS); Loading @@ -787,12 +873,18 @@ import java.util.concurrent.atomic.AtomicInteger; } catch (Exception e) { Log.e(TAG, "Error when schedule a timer", e); } } else { if (Flags.simplifyServiceTransactionLock()) { transaction.onTransactionComplete( ContextHubServiceUtil.toTransactionResult(result)); transaction.setComplete(); } else { synchronized (transaction) { transaction.onTransactionComplete( ContextHubServiceUtil.toTransactionResult(result)); transaction.setComplete(); } } mTransactionQueue.remove(); } Loading Loading @@ -874,12 +966,18 @@ import java.util.concurrent.atomic.AtomicInteger; * @param transaction The transaction to complete. * @param result The result code. */ @GuardedBy("mReliableMessageLock") private void completeMessageTransaction( ContextHubServiceTransaction transaction, @ContextHubTransaction.Result int result) { if (Flags.simplifyServiceTransactionLock()) { transaction.onTransactionComplete(result); transaction.setComplete(); } else { synchronized (transaction) { transaction.onTransactionComplete(result); transaction.setComplete(); } } Log.d( TAG, Loading @@ -897,7 +995,6 @@ import java.util.concurrent.atomic.AtomicInteger; * @param result The result code. * @param iter The iterator for the reliable message map - used to remove the message directly. */ @GuardedBy("mReliableMessageLock") private void removeAndCompleteMessageTransaction( ContextHubServiceTransaction transaction, @ContextHubTransaction.Result int result, Loading