diff options
| author | 2024-12-05 22:56:48 +0000 | |
|---|---|---|
| committer | 2024-12-11 00:17:59 +0000 | |
| commit | cad495eb9fa161facc934ef7ca1f0a37b24c90da (patch) | |
| tree | 702611065e0599069ed79d0d051c8dc5e2ab3ffa | |
| parent | 24630204c424fae7efd6a9e6e395ab271421fa1c (diff) | |
Allows message transactions to be used by any transaction owner
Today, reliable message transactions are limited by host endpoints. To extend its use for sessions, expand the host endpoint ID to an owner ID which can be defined by a new transaction type, guaranteeing uniqueness.
Bug: 381102453
Flag: android.chre.flags.offload_implementation
Test: Compile
Test: CHQTS reliable message test pass
Change-Id: I8dc68776e1391eaed33ca2d561041d4c3a9e5aeb
3 files changed, 50 insertions, 46 deletions
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubServiceTransaction.java b/services/core/java/com/android/server/location/contexthub/ContextHubServiceTransaction.java index 3aea6d533295..4e96b4442a33 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubServiceTransaction.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubServiceTransaction.java @@ -16,6 +16,7 @@ package com.android.server.location.contexthub; +import android.chre.flags.Flags; import android.hardware.location.ContextHubTransaction; import android.hardware.location.NanoAppState; @@ -46,7 +47,11 @@ abstract class ContextHubServiceTransaction { /** The number of times the transaction has been started (start function called). */ private int mNumCompletedStartCalls; - private final short mHostEndpointId; + /** + * A unique identifier for the entity which owns this transaction, scoped by the transaction + * type. + */ + private final int mOwnerId; private boolean mIsComplete = false; @@ -59,7 +64,7 @@ abstract class ContextHubServiceTransaction { mNextRetryTime = Long.MAX_VALUE; mTimeoutTime = Long.MAX_VALUE; mNumCompletedStartCalls = 0; - mHostEndpointId = Short.MAX_VALUE; + mOwnerId = Integer.MAX_VALUE; } ContextHubServiceTransaction(int id, int type, long nanoAppId, @@ -72,11 +77,11 @@ abstract class ContextHubServiceTransaction { mNextRetryTime = Long.MAX_VALUE; mTimeoutTime = Long.MAX_VALUE; mNumCompletedStartCalls = 0; - mHostEndpointId = Short.MAX_VALUE; + mOwnerId = Integer.MAX_VALUE; } - ContextHubServiceTransaction(int id, int type, String packageName, - int messageSequenceNumber, short hostEndpointId) { + ContextHubServiceTransaction( + int id, int type, String packageName, int messageSequenceNumber, int ownerId) { mTransactionId = id; mTransactionType = type; mNanoAppId = Long.MAX_VALUE; @@ -85,7 +90,7 @@ abstract class ContextHubServiceTransaction { mNextRetryTime = Long.MAX_VALUE; mTimeoutTime = Long.MAX_VALUE; mNumCompletedStartCalls = 0; - mHostEndpointId = hostEndpointId; + mOwnerId = ownerId; } /** @@ -147,8 +152,15 @@ abstract class ContextHubServiceTransaction { return mNumCompletedStartCalls; } - short getHostEndpointId() { - return mHostEndpointId; + /** + * @return A unique identifier for the entity owning this transaction. + */ + long getOwnerId() { + if (Flags.offloadImplementation()) { + return ((long) mTransactionType << 32) | (0x00000000FFFFFFFFL & mOwnerId); + } else { + return mOwnerId; + } } /** @@ -215,15 +227,16 @@ abstract class ContextHubServiceTransaction { out.append(", messageSequenceNumber = "); out.append(mMessageSequenceNumber); } - if (mTransactionType == ContextHubTransaction.TYPE_RELIABLE_MESSAGE) { + if (mTransactionType == ContextHubTransaction.TYPE_RELIABLE_MESSAGE + || mTransactionType == ContextHubTransaction.TYPE_HUB_MESSAGE_REQUIRES_RESPONSE) { 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(", ownerId = "); + out.append(getOwnerId()); } out.append(")"); diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java index ccfa61b400b6..214def4ec95a 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManager.java @@ -84,9 +84,9 @@ import java.util.concurrent.atomic.AtomicInteger; protected final Map<Integer, ContextHubServiceTransaction> mReliableMessageTransactionMap = new HashMap<>(); - /** A set of host endpoint IDs that have an active pending transaction. */ + /** A set of IDs of transaction owners that have an active pending transaction. */ @GuardedBy("mReliableMessageLock") - protected final Set<Short> mReliableMessageHostEndpointIdActiveSet = new HashSet<>(); + protected final Set<Long> mReliableMessageOwnerIdActiveSet = new HashSet<>(); protected final AtomicInteger mNextAvailableId = new AtomicInteger(); @@ -355,27 +355,32 @@ import java.util.concurrent.atomic.AtomicInteger; /** * Creates a transaction to send a reliable message. * - * @param hostEndpointId The ID of the host endpoint sending the message. - * @param contextHubId The ID of the hub to send the message to. - * @param message The message to send. + * @param ownerId The ID of the transaction owner. + * @param contextHubId The ID of the hub to send the message to. + * @param message The message to send. * @param transactionCallback The callback of the transactions. - * @param packageName The host package associated with this transaction. + * @param packageName The host package associated with this transaction. * @return The generated transaction. */ /* package */ ContextHubServiceTransaction createMessageTransaction( - short hostEndpointId, int contextHubId, NanoAppMessage message, - IContextHubTransactionCallback transactionCallback, String packageName) { - return new ContextHubServiceTransaction(mNextAvailableId.getAndIncrement(), - ContextHubTransaction.TYPE_RELIABLE_MESSAGE, packageName, - mNextAvailableMessageSequenceNumber.getAndIncrement(), hostEndpointId) { + short ownerId, + int contextHubId, + NanoAppMessage message, + IContextHubTransactionCallback transactionCallback, + String packageName) { + return new ContextHubServiceTransaction( + mNextAvailableId.getAndIncrement(), + ContextHubTransaction.TYPE_RELIABLE_MESSAGE, + packageName, + mNextAvailableMessageSequenceNumber.getAndIncrement(), + ownerId) { @Override /* package */ int onTransact() { try { message.setIsReliable(/* isReliable= */ true); message.setMessageSequenceNumber(getMessageSequenceNumber()); - return mContextHubProxy.sendMessageToContextHub(hostEndpointId, contextHubId, - message); + return mContextHubProxy.sendMessageToContextHub(ownerId, contextHubId, message); } catch (RemoteException e) { Log.e(TAG, "RemoteException while trying to send a reliable message", e); return ContextHubTransaction.RESULT_FAILED_UNKNOWN; @@ -766,10 +771,10 @@ import java.util.concurrent.atomic.AtomicInteger; mReliableMessageTransactionMap.entrySet().iterator(); while (iter.hasNext()) { ContextHubServiceTransaction transaction = iter.next().getValue(); - short hostEndpointId = transaction.getHostEndpointId(); + long ownerId = transaction.getOwnerId(); int numCompletedStartCalls = transaction.getNumCompletedStartCalls(); if (numCompletedStartCalls == 0 - && mReliableMessageHostEndpointIdActiveSet.contains(hostEndpointId)) { + && mReliableMessageOwnerIdActiveSet.contains(ownerId)) { continue; } @@ -871,7 +876,7 @@ import java.util.concurrent.atomic.AtomicInteger; } else { iter.remove(); } - mReliableMessageHostEndpointIdActiveSet.remove(transaction.getHostEndpointId()); + mReliableMessageOwnerIdActiveSet.remove(transaction.getOwnerId()); } /** @@ -906,7 +911,7 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.setTimeoutTime(now + RELIABLE_MESSAGE_TIMEOUT.toNanos()); } transaction.setNumCompletedStartCalls(numCompletedStartCalls + 1); - mReliableMessageHostEndpointIdActiveSet.add(transaction.getHostEndpointId()); + mReliableMessageOwnerIdActiveSet.add(transaction.getOwnerId()); } private int toStatsTransactionResult(@ContextHubTransaction.Result int result) { diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java index a67fa308a6ea..657375d2cbd7 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubTransactionManagerOld.java @@ -18,28 +18,14 @@ package com.android.server.location.contexthub; import android.chre.flags.Flags; import android.hardware.location.ContextHubTransaction; -import android.hardware.location.IContextHubTransactionCallback; -import android.hardware.location.NanoAppBinary; -import android.hardware.location.NanoAppMessage; import android.hardware.location.NanoAppState; -import android.os.RemoteException; import android.os.SystemClock; import android.util.Log; -import java.time.Duration; -import java.util.ArrayDeque; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; /** * Manages transactions at the Context Hub Service. @@ -326,10 +312,10 @@ import java.util.concurrent.atomic.AtomicInteger; mReliableMessageTransactionMap.entrySet().iterator(); while (iter.hasNext()) { ContextHubServiceTransaction transaction = iter.next().getValue(); - short hostEndpointId = transaction.getHostEndpointId(); + long ownerId = transaction.getOwnerId(); int numCompletedStartCalls = transaction.getNumCompletedStartCalls(); if (numCompletedStartCalls == 0 - && mReliableMessageHostEndpointIdActiveSet.contains(hostEndpointId)) { + && mReliableMessageOwnerIdActiveSet.contains(ownerId)) { continue; } @@ -394,7 +380,7 @@ import java.util.concurrent.atomic.AtomicInteger; } else { iter.remove(); } - mReliableMessageHostEndpointIdActiveSet.remove(transaction.getHostEndpointId()); + mReliableMessageOwnerIdActiveSet.remove(transaction.getOwnerId()); Log.d( TAG, @@ -436,7 +422,7 @@ import java.util.concurrent.atomic.AtomicInteger; transaction.setTimeoutTime(now + RELIABLE_MESSAGE_TIMEOUT.toNanos()); } transaction.setNumCompletedStartCalls(numCompletedStartCalls + 1); - mReliableMessageHostEndpointIdActiveSet.add(transaction.getHostEndpointId()); + mReliableMessageOwnerIdActiveSet.add(transaction.getOwnerId()); } @Override |