Bug 884131 - Messages to netd need sequence number on gonk-JB. r=dhylands

This commit is contained in:
Vincent Chang 2013-08-05 12:16:14 +08:00
parent 78655ea191
commit ccfb3b7e0a

View File

@ -55,6 +55,8 @@ const INTERFACE_DELIMIT = "\0";
importScripts("systemlibs.js");
const SDK_VERSION = libcutils.property_get("ro.build.version.sdk", "0");
function netdResponseType(code) {
return Math.floor(code/100)*100;
}
@ -307,25 +309,51 @@ let gPending = false;
let gReason = [];
/**
* Handle received data from netd.
* This helper function acts like String.split() fucntion.
* The function finds the first token in the javascript
* uint8 type array object, where tokens are delimited by
* the delimiter. The first token and the index pointer to
* the next token are returned in this function.
*/
function onNetdMessage(data) {
let result = "";
let reason = "";
function split(start, data, delimiter) {
// Sanity check.
if (start < 0 || data.length <= 0) {
return null;
}
// The return result is separated from the reason by a space character.
let i = 0;
let result = "";
let i = start;
while (i < data.length) {
let octet = data[i];
i += 1;
if (octet == 32) {
break;
if (octet === delimiter) {
return {token: result, index: i};
}
result += String.fromCharCode(octet);
}
return null;
}
let code = parseInt(result);
/**
* Handle received data from netd.
*/
function onNetdMessage(data) {
let result = split(0, data, 32);
if (!result) {
nextNetdCommand();
return;
}
let code = parseInt(result.token);
// Netd response contains the command sequence number
// in non-broadcast message for Android jb version.
// The format is ["code" "optional sequence number" "reason"]
if (!isBroadcastMessage(code) && SDK_VERSION >= 16) {
result = split(result.index, data, 32);
}
let i = result.index;
let reason = "";
for (; i < data.length; i++) {
let octet = data[i];
reason += String.fromCharCode(octet);
@ -383,7 +411,10 @@ function nextNetdCommand() {
[gCurrentCommand, gCurrentCallback] = gCommandQueue.shift();
debug("Sending '" + gCurrentCommand + "' command to netd.");
gPending = true;
return postNetdCommand(gCurrentCommand);
// Android JB version adds sequence number to netd command.
let command = (SDK_VERSION >= 16) ? "0 " + gCurrentCommand : gCurrentCommand;
return postNetdCommand(command);
}
function setInterfaceUp(params, callback) {