Merge "ContextHubService: Hack around 32-bit app ID" into nyc-mr1-dev
This commit is contained in:
@@ -18,6 +18,8 @@ package android.hardware.location;
|
|||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@@ -146,6 +148,36 @@ public class ContextHubService extends IContextHubService.Stub {
|
|||||||
return mContextHubInfo[contextHubHandle];
|
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
|
@Override
|
||||||
public int loadNanoApp(int contextHubHandle, NanoApp app) throws RemoteException {
|
public int loadNanoApp(int contextHubHandle, NanoApp app) throws RemoteException {
|
||||||
checkPermissions();
|
checkPermissions();
|
||||||
@@ -162,27 +194,14 @@ public class ContextHubService extends IContextHubService.Stub {
|
|||||||
msgHeader[HEADER_FIELD_MSG_TYPE] = MSG_LOAD_NANO_APP;
|
msgHeader[HEADER_FIELD_MSG_TYPE] = MSG_LOAD_NANO_APP;
|
||||||
|
|
||||||
long appId = app.getAppId();
|
long appId = app.getAppId();
|
||||||
// TODO(b/30808791): Remove this hack when the NanoApp API is fixed.
|
// 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
|
// and getAppId() returns a 'long' instead of an 'int'.
|
||||||
// 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.
|
|
||||||
if ((appId >> 32) != 0) {
|
if ((appId >> 32) != 0) {
|
||||||
// We're unlikely to notice this warning, but at least
|
// We're unlikely to notice this warning, but at least
|
||||||
// we can avoid running our hack logic.
|
// we can avoid running our hack logic.
|
||||||
Log.w(TAG, "Code has not been updated since API fix.");
|
Log.w(TAG, "Code has not been updated since API fix.");
|
||||||
} else {
|
} else {
|
||||||
// Note: Lower-case 'L', not the number 1.
|
appId = parseAppId(app);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
msgHeader[HEADER_FIELD_LOAD_APP_ID_LO] = (int)(appId & 0xFFFFFFFF);
|
msgHeader[HEADER_FIELD_LOAD_APP_ID_LO] = (int)(appId & 0xFFFFFFFF);
|
||||||
|
|||||||
Reference in New Issue
Block a user