merge in jb-release history after reset to jb-dev
diff --git a/keystore-engine/eng_keystore.cpp b/keystore-engine/eng_keystore.cpp
index ad2b638..9a3e7f4 100644
--- a/keystore-engine/eng_keystore.cpp
+++ b/keystore-engine/eng_keystore.cpp
@@ -36,7 +36,7 @@
 #include <openssl/engine.h>
 #include <openssl/evp.h>
 
-//#define LOG_NDEBUG 0
+#define LOG_NDEBUG 0
 #define LOG_TAG "OpenSSL-keystore"
 #include <cutils/log.h>
 
@@ -210,14 +210,9 @@
     return 1;
 }
 
-static EVP_PKEY* keystore_loadkey(ENGINE* e, const char* key_id, UI_METHOD* ui_method,
-        void* callback_data) {
-#if LOG_NDEBUG
-    (void)ui_method;
-    (void)callback_data;
-#else
+static EVP_PKEY* keystore_loadkey(ENGINE* e, const char* key_id, UI_METHOD *ui_method,
+        void *callback_data) {
     ALOGV("keystore_loadkey(%p, \"%s\", %p, %p)", e, key_id, ui_method, callback_data);
-#endif
 
     Keystore_Reply reply;
     if (keystore_cmd(CommandCodes[GET_PUBKEY], &reply, 1, strlen(key_id), key_id) != NO_ERROR) {
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp
index 6f506dd..af8c937 100644
--- a/keystore/keystore.cpp
+++ b/keystore/keystore.cpp
@@ -439,7 +439,7 @@
 
 typedef struct {
     uint32_t uid;
-    const uint8_t* filename;
+    const uint8_t* keyName;
 
     struct listnode plist;
 } grant_t;
@@ -622,18 +622,20 @@
         if (grant == NULL) {
             grant = new grant_t;
             grant->uid = uid;
-            grant->filename = reinterpret_cast<const uint8_t*>(strdup(filename));
+            grant->keyName = reinterpret_cast<const uint8_t*>(strdup(filename));
             list_add_tail(&mGrants, &grant->plist);
         }
     }
 
-    bool removeGrant(const char* filename, const Value* uidValue) {
+    bool removeGrant(const Value* keyValue, const Value* uidValue) {
         uid_t uid;
         if (!convertToUid(uidValue, &uid)) {
             return false;
         }
 
-        grant_t *grant = getGrant(filename, uid);
+        ValueString keyString(keyValue);
+
+        grant_t *grant = getGrant(keyString.c_str(), uid);
         if (grant != NULL) {
             list_remove(&grant->plist);
             delete grant;
@@ -643,8 +645,9 @@
         return false;
     }
 
-    bool hasGrant(const char* filename, const uid_t uid) const {
-        return getGrant(filename, uid) != NULL;
+    bool hasGrant(const Value* keyValue, const uid_t uid) const {
+        ValueString keyString(keyValue);
+        return getGrant(keyString.c_str(), uid) != NULL;
     }
 
     ResponseCode importKey(const Value* key, const char* filename) {
@@ -745,15 +748,15 @@
                 && (strcmp(filename, "..") != 0));
     }
 
-    grant_t* getGrant(const char* filename, uid_t uid) const {
+    grant_t* getGrant(const char* keyName, uid_t uid) const {
         struct listnode *node;
         grant_t *grant;
 
         list_for_each(node, &mGrants) {
             grant = node_to_item(node, grant_t, plist);
             if (grant->uid == uid
-                    && !strcmp(reinterpret_cast<const char*>(grant->filename),
-                               filename)) {
+                    && !strcmp(reinterpret_cast<const char*>(grant->keyName),
+                               keyName)) {
                 return grant;
             }
         }
@@ -913,12 +916,12 @@
     }
 
     // They might be using a granted key.
-    encode_key(filename, keyName);
-    if (!keyStore->hasGrant(filename, uid)) {
+    if (!keyStore->hasGrant(keyName, uid)) {
         return responseCode;
     }
 
     // It is a granted key. Try to load it.
+    encode_key(filename, keyName);
     return keyStore->get(filename, keyBlob, type);
 }
 
@@ -1264,7 +1267,7 @@
         return (errno != ENOENT) ? SYSTEM_ERROR : KEY_NOT_FOUND;
     }
 
-    return keyStore->removeGrant(filename, granteeData) ? NO_ERROR : KEY_NOT_FOUND;
+    return keyStore->removeGrant(keyName, granteeData) ? NO_ERROR : KEY_NOT_FOUND;
 }
 
 /* Here are the permissions, actions, users, and the main function. */