diff options
| -rw-r--r-- | services/core/java/com/android/server/location/ContextHubService.java | 23 | ||||
| -rw-r--r-- | services/core/java/com/android/server/location/NanoAppStateManager.java | 62 |
2 files changed, 42 insertions, 43 deletions
diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java index 6673a8909bd6..f70ca86eafcd 100644 --- a/services/core/java/com/android/server/location/ContextHubService.java +++ b/services/core/java/com/android/server/location/ContextHubService.java @@ -202,11 +202,11 @@ public class ContextHubService extends IContextHubService.Stub { return new IContextHubClientCallback.Stub() { @Override public void onMessageFromNanoApp(NanoAppMessage message) { - int nanoAppInstanceId = mNanoAppStateManager.getNanoAppInstanceId( + int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle( contextHubId, message.getNanoAppId()); onMessageReceiptOldApi( - message.getMessageType(), contextHubId, nanoAppInstanceId, + message.getMessageType(), contextHubId, nanoAppHandle, message.getMessageBody()); } @@ -403,17 +403,17 @@ public class ContextHubService extends IContextHubService.Stub { } @Override - public int unloadNanoApp(int nanoAppInstanceHandle) throws RemoteException { + public int unloadNanoApp(int nanoAppHandle) throws RemoteException { checkPermissions(); if (mContextHubProxy == null) { return -1; } NanoAppInstanceInfo info = - mNanoAppStateManager.getNanoAppInstanceInfo(nanoAppInstanceHandle); + mNanoAppStateManager.getNanoAppInstanceInfo(nanoAppHandle); if (info == null) { - Log.e(TAG, "Cannot find app with handle " + nanoAppInstanceHandle); - return -1; //means failed + Log.e(TAG, "Cannot find nanoapp with handle " + nanoAppHandle); + return -1; } int contextHubId = info.getContexthubId(); @@ -434,11 +434,10 @@ public class ContextHubService extends IContextHubService.Stub { } @Override - public NanoAppInstanceInfo getNanoAppInstanceInfo( - int nanoAppInstanceHandle) throws RemoteException { + public NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) throws RemoteException { checkPermissions(); - return mNanoAppStateManager.getNanoAppInstanceInfo(nanoAppInstanceHandle); + return mNanoAppStateManager.getNanoAppInstanceInfo(nanoAppHandle); } @Override @@ -524,7 +523,7 @@ public class ContextHubService extends IContextHubService.Stub { success = (client.sendMessageToNanoApp(message) == ContextHubTransaction.TRANSACTION_SUCCESS); } else { - Log.e(TAG, "Failed to send nanoapp message - nanoapp with instance ID " + Log.e(TAG, "Failed to send nanoapp message - nanoapp with handle " + nanoAppHandle + " does not exist."); } } @@ -556,9 +555,9 @@ public class ContextHubService extends IContextHubService.Stub { byte[] data = new byte[5]; data[0] = (byte) result; - int instanceId = mNanoAppStateManager.getNanoAppInstanceId( + int nanoAppHandle = mNanoAppStateManager.getNanoAppHandle( contextHubId, nanoAppBinary.getNanoAppId()); - ByteBuffer.wrap(data, 1, 4).order(ByteOrder.nativeOrder()).putInt(instanceId); + ByteBuffer.wrap(data, 1, 4).order(ByteOrder.nativeOrder()).putInt(nanoAppHandle); onMessageReceiptOldApi(MSG_LOAD_NANO_APP, contextHubId, OS_APP_INSTANCE, data); } diff --git a/services/core/java/com/android/server/location/NanoAppStateManager.java b/services/core/java/com/android/server/location/NanoAppStateManager.java index de040d2f7471..81c47849c3ad 100644 --- a/services/core/java/com/android/server/location/NanoAppStateManager.java +++ b/services/core/java/com/android/server/location/NanoAppStateManager.java @@ -48,24 +48,24 @@ import java.util.List; private static final boolean ENABLE_LOG_DEBUG = true; /* - * Service cache maintaining of instance ID to nanoapp infos. + * Service cache maintaining of handle to nanoapp infos. */ private final HashMap<Integer, NanoAppInstanceInfo> mNanoAppHash = new HashMap<>(); /* - * The next instance ID to use. + * The next nanoapp handle to use. */ - private int mNextInstanceId = 0; + private int mNextHandle = 0; /** - * @param instanceId the instance ID of the nanoapp - * @return the NanoAppInstanceInfo for the given nanoapp, null if the nanoapp does not exist in - * the cache + * @param nanoAppHandle the nanoapp handle + * @return the NanoAppInstanceInfo for the given nanoapp, or null if the nanoapp does not exist + * in the cache */ @Nullable /* package */ - synchronized NanoAppInstanceInfo getNanoAppInstanceInfo(int instanceId) { - return mNanoAppHash.get(instanceId); + synchronized NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) { + return mNanoAppHash.get(nanoAppHandle); } /** @@ -79,10 +79,10 @@ import java.util.List; /** * @param contextHubId the ID of the hub to search for the instance * @param nanoAppId the unique 64-bit ID of the nanoapp - * @return the instance ID of the nanoapp, -1 if the nanoapp is not in the cache + * @return the nanoapp handle, -1 if the nanoapp is not in the cache */ /* package */ - synchronized int getNanoAppInstanceId(int contextHubId, long nanoAppId) { + synchronized int getNanoAppHandle(int contextHubId, long nanoAppId) { for (NanoAppInstanceInfo info : mNanoAppHash.values()) { if (info.getContexthubId() == contextHubId && info.getAppId() == nanoAppId) { return info.getHandle(); @@ -95,7 +95,7 @@ import java.util.List; /** * Adds a nanoapp instance to the cache. * - * If the cache already contained the nanoapp, the entry is removed and a new instance ID is + * If the cache already contained the nanoapp, the entry is removed and a new nanoapp handle is * generated. * * @param contextHubId the ID of the hub the nanoapp is loaded in @@ -110,20 +110,20 @@ import java.util.List; return; } - int instanceId = mNextInstanceId; + int nanoAppHandle = mNextHandle; for (int i = 0; i <= Integer.MAX_VALUE; i++) { - if (!mNanoAppHash.containsKey(instanceId)) { - mNanoAppHash.put(instanceId, new NanoAppInstanceInfo( - instanceId, nanoAppId, nanoAppVersion, contextHubId)); - mNextInstanceId = (instanceId == Integer.MAX_VALUE) ? 0 : instanceId + 1; + if (!mNanoAppHash.containsKey(nanoAppHandle)) { + mNanoAppHash.put(nanoAppHandle, new NanoAppInstanceInfo( + nanoAppHandle, nanoAppId, nanoAppVersion, contextHubId)); + mNextHandle = (nanoAppHandle == Integer.MAX_VALUE) ? 0 : nanoAppHandle + 1; break; } - instanceId = (instanceId == Integer.MAX_VALUE) ? 0 : instanceId + 1; + nanoAppHandle = (nanoAppHandle == Integer.MAX_VALUE) ? 0 : nanoAppHandle + 1; } if (ENABLE_LOG_DEBUG) { - Log.v(TAG, "Added app instance " + instanceId + " to hub " + contextHubId - + ": ID=0x" + Long.toHexString(nanoAppId) + Log.v(TAG, "Added app instance with handle " + nanoAppHandle + " to hub " + + contextHubId + ": ID=0x" + Long.toHexString(nanoAppId) + ", version=0x" + Integer.toHexString(nanoAppVersion)); } } @@ -135,8 +135,8 @@ import java.util.List; */ /* package */ synchronized void removeNanoAppInstance(int contextHubId, long nanoAppId) { - int instanceId = getNanoAppInstanceId(contextHubId, nanoAppId); - mNanoAppHash.remove(instanceId); + int nanoAppHandle = getNanoAppHandle(contextHubId, nanoAppId); + mNanoAppHash.remove(nanoAppHandle); } /** @@ -153,11 +153,11 @@ import java.util.List; nanoAppIdSet.add(appInfo.appId); } - for (int instanceId : mNanoAppHash.keySet()) { - NanoAppInstanceInfo info = mNanoAppHash.get(instanceId); + for (int nanoAppHandle : mNanoAppHash.keySet()) { + NanoAppInstanceInfo info = mNanoAppHash.get(nanoAppHandle); if (info.getContexthubId() == contextHubId && !nanoAppIdSet.contains(info.getAppId())) { - mNanoAppHash.remove(instanceId); + mNanoAppHash.remove(nanoAppHandle); } } } @@ -171,17 +171,17 @@ import java.util.List; * @param nanoAppVersion the version of the nanoapp */ private void handleQueryAppEntry(int contextHubId, long nanoAppId, int nanoAppVersion) { - int instanceId = getNanoAppInstanceId(contextHubId, nanoAppId); - if (instanceId == -1) { + int nanoAppHandle = getNanoAppHandle(contextHubId, nanoAppId); + if (nanoAppHandle == -1) { addNanoAppInstance(contextHubId, nanoAppId, nanoAppVersion); } else { - NanoAppInstanceInfo info = mNanoAppHash.get(instanceId); + NanoAppInstanceInfo info = mNanoAppHash.get(nanoAppHandle); if (info.getAppVersion() != nanoAppVersion) { - mNanoAppHash.put(instanceId, new NanoAppInstanceInfo( - instanceId, nanoAppId, nanoAppVersion, contextHubId)); + mNanoAppHash.put(nanoAppHandle, new NanoAppInstanceInfo( + nanoAppHandle, nanoAppId, nanoAppVersion, contextHubId)); if (ENABLE_LOG_DEBUG) { - Log.v(TAG, "Updated app instance " + instanceId + " at hub " + contextHubId - + ": ID=0x" + Long.toHexString(nanoAppId) + Log.v(TAG, "Updated app instance with handle " + nanoAppHandle + " at hub " + + contextHubId + ": ID=0x" + Long.toHexString(nanoAppId) + ", version=0x" + Integer.toHexString(nanoAppVersion)); } } |