summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Greg Kaiser <gkaiser@google.com> 2016-09-28 00:11:46 +0000
committer android-build-merger <android-build-merger@google.com> 2016-09-28 00:11:46 +0000
commit5abcc9a8884712c25ba05f15c3adea458e33e481 (patch)
tree3bf697a3e38f90dd5d9bade7e84d534558eeb54d
parent7991626e0f33de49e5d40e9bc43ee4407ae33401 (diff)
parenteaed84e40ab02dedef0574addcacfe54a190b06a (diff)
ContextHubService: Hack around 32-bit app ID am: 1983f9b05b am: 40c0435026
am: eaed84e40a Change-Id: I2eb38c4cf7e27bfb75db2f41b529840ac9fd1f44
-rw-r--r--core/java/android/hardware/location/ContextHubService.java51
1 files changed, 35 insertions, 16 deletions
diff --git a/core/java/android/hardware/location/ContextHubService.java b/core/java/android/hardware/location/ContextHubService.java
index 19c82a5a83ef..35df015aaeb6 100644
--- a/core/java/android/hardware/location/ContextHubService.java
+++ b/core/java/android/hardware/location/ContextHubService.java
@@ -18,6 +18,8 @@ package android.hardware.location;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.HashMap;
@@ -146,6 +148,36 @@ public class ContextHubService extends IContextHubService.Stub {
return mContextHubInfo[contextHubHandle];
}
+ // TODO(b/30808791): Remove this when NanoApp's API is correctly treating
+ // app IDs as 64-bits.
+ private static long parseAppId(NanoApp app) {
+ // NOTE: If this shifting seems odd (since it's actually "ONAN"), note
+ // that it matches how this is defined in context_hub.h.
+ final int HEADER_MAGIC =
+ (((int)'N' << 0) |
+ ((int)'A' << 8) |
+ ((int)'N' << 16) |
+ ((int)'O' << 24));
+ final int HEADER_MAGIC_OFFSET = 4;
+ final int HEADER_APP_ID_OFFSET = 8;
+
+ ByteBuffer header = ByteBuffer.wrap(app.getAppBinary())
+ .order(ByteOrder.LITTLE_ENDIAN);
+
+ try {
+ if (header.getInt(HEADER_MAGIC_OFFSET) == HEADER_MAGIC) {
+ // This is a legitimate nanoapp header. Let's grab the app ID.
+ return header.getLong(HEADER_APP_ID_OFFSET);
+ }
+ } catch (IndexOutOfBoundsException e) {
+ // The header is undersized. We'll fall through to our code
+ // path below, which handles being unable to parse the header.
+ }
+ // We failed to parse the header. Even through it's probably wrong,
+ // let's give NanoApp's idea of our ID. This is at least consistent.
+ return app.getAppId();
+ }
+
@Override
public int loadNanoApp(int contextHubHandle, NanoApp app) throws RemoteException {
checkPermissions();
@@ -165,27 +197,14 @@ public class ContextHubService extends IContextHubService.Stub {
msgHeader[HEADER_FIELD_MSG_TYPE] = MSG_LOAD_NANO_APP;
long appId = app.getAppId();
- // TODO(b/30808791): Remove this hack when the NanoApp API is fixed.
- // Due to a bug in the NanoApp API, only the least significant four
- // bytes of the app ID can be stored. The most significant five
- // bytes of a normal app ID are the "vendor", and thus the most
- // significant of the bytes we have is the least significant byte
- // of the vendor. In the case that byte is the ASCII value for
- // lower-case 'L', we assume the vendor is supposed to be "Googl"
- // and fill in the four most significant bytes accordingly.
+ // TODO(b/30808791): Remove this hack when the NanoApp API is fixed,
+ // and getAppId() returns a 'long' instead of an 'int'.
if ((appId >> 32) != 0) {
// We're unlikely to notice this warning, but at least
// we can avoid running our hack logic.
Log.w(TAG, "Code has not been updated since API fix.");
} else {
- // Note: Lower-case 'L', not the number 1.
- if (((appId >> 24) & 0xFF) == (long)'l') {
- // Assume we're a Google nanoapp.
- appId |= ((long)'G') << 56;
- appId |= ((long)'o') << 48;
- appId |= ((long)'o') << 40;
- appId |= ((long)'g') << 32;
- }
+ appId = parseAppId(app);
}
msgHeader[HEADER_FIELD_LOAD_APP_ID_LO] = (int)(appId & 0xFFFFFFFF);