summaryrefslogtreecommitdiff
path: root/mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp')
-rw-r--r--mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp102
1 files changed, 52 insertions, 50 deletions
diff --git a/mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp b/mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp
index e47653d..4180907 100644
--- a/mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp
+++ b/mobicore/rootpa/Code/Android/app/jni/CommonPAWrapper/JniHelpers.cpp
@@ -3,29 +3,29 @@ Copyright © Trustonic Limited 2013
All rights reserved.
-Redistribution and use in source and binary forms, with or without modification,
+Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice, this
+ 1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- 3. Neither the name of the Trustonic Limited nor the names of its contributors
- may be used to endorse or promote products derived from this software
+ 3. Neither the name of the Trustonic Limited nor the names of its contributors
+ may be used to endorse or promote products derived from this software
without specific prior written permission.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@@ -34,7 +34,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
#include "JniHelpers.h"
#include "rootpaErrors.h"
-JniHelpers::JniHelpers(JNIEnv* envP):broken_(false),
+JniHelpers::JniHelpers(JNIEnv* envP):broken_(false),
envP_(envP),
keysP_(NULL),
valuesP_(NULL),
@@ -45,7 +45,7 @@ JniHelpers::JniHelpers(JNIEnv* envP):broken_(false),
stringConstructur_(NULL),
intConstructor_(NULL),
listAdd_(NULL)
-{}
+{}
JniHelpers::~JniHelpers()
{
@@ -53,20 +53,20 @@ JniHelpers::~JniHelpers()
{
envP_->DeleteLocalRef(listCls_);
}
-
+
if(intCls_!=NULL)
{
envP_->DeleteLocalRef(intCls_);
- }
-
+ }
+
if(stringCls_!=NULL)
{
envP_->DeleteLocalRef(stringCls_);
- }
+ }
}
-JniHelpers::JniHelpers(JNIEnv* envP,jobject* keysP, jobject* valuesP, jbyteArray* productIdP):broken_(false),
+JniHelpers::JniHelpers(JNIEnv* envP,jobject* keysP, jobject* valuesP, jbyteArray* productIdP):broken_(false),
envP_(envP),
keysP_(keysP),
valuesP_(valuesP),
@@ -81,15 +81,15 @@ JniHelpers::JniHelpers(JNIEnv* envP,jobject* keysP, jobject* valuesP, jbyteArray
listCls_=envP_->FindClass("java/util/List");
if(NULL == listCls_)
{
- LOGE("JniHelpers::JniHelpers no listCls_");
+ LOGE("JniHelpers::JniHelpers no listCls_");
broken_=true;
return;
}
- listAdd_=envP_->GetMethodID(listCls_, "add", "(Ljava/lang/Object;)Z");
+ listAdd_=envP_->GetMethodID(listCls_, "add", "(Ljava/lang/Object;)Z");
if(NULL == listAdd_)
{
- LOGE("JniHelpers::JniHelpers no listAdd_");
+ LOGE("JniHelpers::JniHelpers no listAdd_");
broken_=true;
return;
}
@@ -102,18 +102,18 @@ JniHelpers::JniHelpers(JNIEnv* envP,jobject* keysP, jobject* valuesP, jbyteArray
return;
}
- intConstructor_=envP_->GetMethodID(intCls_, "<init>", "(I)V");
+ intConstructor_=envP_->GetMethodID(intCls_, "<init>", "(I)V");
if(NULL == intConstructor_)
{
- LOGE("JniHelpers::JniHelpers no intConstructor_");
+ LOGE("JniHelpers::JniHelpers no intConstructor_");
broken_=true;
return;
}
-
+
stringCls_=envP_->FindClass("java/lang/String");
if(NULL == stringCls_)
{
- LOGE("JniHelpers::JniHelpers no stringCls_");
+ LOGE("JniHelpers::JniHelpers no stringCls_");
broken_=true;
return;
}
@@ -121,7 +121,7 @@ JniHelpers::JniHelpers(JNIEnv* envP,jobject* keysP, jobject* valuesP, jbyteArray
stringConstructur_=envP_->GetMethodID(stringCls_, "<init>", "([B)V");
if(NULL == stringConstructur_)
{
- LOGE("JniHelpers::JniHelpers no stringConstructur_");
+ LOGE("JniHelpers::JniHelpers no stringConstructur_");
broken_=true;
return;
}
@@ -138,11 +138,11 @@ int JniHelpers::setVersion(char* fieldName, int version)
broken_=true;
return ROOTPA_ERROR_INTERNAL;
}
-
+
jobject newStringObject = envP_->NewObject(stringCls_, stringConstructur_, fName);
if(NULL == newStringObject)
{
- LOGE("JniHelpers::setVersion no newStringObject");
+ LOGE("JniHelpers::setVersion no newStringObject");
broken_=true;
envP_->DeleteLocalRef(fName);
return ROOTPA_ERROR_INTERNAL;
@@ -151,31 +151,31 @@ int JniHelpers::setVersion(char* fieldName, int version)
if(envP_->CallBooleanMethod(*keysP_, listAdd_, newStringObject)==JNI_FALSE)
{
- LOGE("JniHelpers::setVersion can not add key");
+ LOGE("JniHelpers::setVersion can not add key");
broken_=true;
envP_->DeleteLocalRef(newStringObject);
- return ROOTPA_ERROR_INTERNAL;
+ return ROOTPA_ERROR_INTERNAL;
}
envP_->DeleteLocalRef(newStringObject);
jobject newIntObject = envP_->NewObject(intCls_, intConstructor_, version);
if(NULL == newIntObject)
{
- LOGE("JniHelpers::setVersion no newIntObject");
+ LOGE("JniHelpers::setVersion no newIntObject");
broken_=true;
return ROOTPA_ERROR_INTERNAL;
- }
-
+ }
+
if(envP_->CallBooleanMethod(*valuesP_, listAdd_, newIntObject)==JNI_FALSE)
{
- LOGE("JniHelpers::setVersion can not add value");
+ LOGE("JniHelpers::setVersion can not add value");
broken_=true;
envP_->DeleteLocalRef(newIntObject);
- return ROOTPA_ERROR_INTERNAL;
+ return ROOTPA_ERROR_INTERNAL;
}
envP_->DeleteLocalRef(newIntObject);
-
- return ROOTPA_OK;
+
+ return ROOTPA_OK;
}
int JniHelpers::setProductId(char* productId)
@@ -210,20 +210,20 @@ int JniHelpers::setIntToArray(jintArray* targetArrayP, int index, int source)
return ROOTPA_OK;
}
-jbyteArray JniHelpers::byteArrayToJByteArray(uint8_t* dataP, uint32_t length)
+jbyteArray JniHelpers::byteArrayToJByteArray(uint8_t* dataP, uint32_t length)
{
jbyteArray jbArray = NULL;
- if (envP_->EnsureLocalCapacity(1) == JNI_OK)
+ if (envP_->EnsureLocalCapacity(1) == JNI_OK)
{
-
- if ((length > 0) && (dataP != NULL))
+
+ if ((length > 0) && (dataP != NULL))
{
jbArray = envP_->NewByteArray(length);
- if (jbArray != NULL)
+ if (jbArray != NULL)
{
envP_->SetByteArrayRegion(jbArray, 0, length, (jbyte*) dataP);
}
- }
+ }
}
return jbArray;
@@ -235,7 +235,7 @@ jbyteArray JniHelpers::byteArrayToJByteArray(uint8_t* dataP, uint32_t length)
* @param outLength* (OUT PARAMETER) length of the returned uint8_t* byte array
* @return uint8_t* byte array. Needs to be freed with delete[] afterwards.
*/
-uint8_t* JniHelpers::jByteArrayToCByteArray(jbyteArray jBytes, uint32_t* outLength)
+uint8_t* JniHelpers::jByteArrayToCByteArray(jbyteArray jBytes, uint32_t* outLength)
{
*outLength=0;
uint8_t* cBytes = NULL;
@@ -244,16 +244,18 @@ uint8_t* JniHelpers::jByteArrayToCByteArray(jbyteArray jBytes, uint32_t* outLeng
*outLength = envP_->GetArrayLength(jBytes);
cBytes = new uint8_t[*outLength];
jbyte* p_jcResult = envP_->GetByteArrayElements(jBytes, JNI_FALSE);
- for (unsigned int i = 0; i < *outLength; i++)
+ for (unsigned int i = 0; i < *outLength; i++)
{
cBytes[i] = (uint8_t) p_jcResult[i] & (0x00ff);
}
envP_->ReleaseByteArrayElements(jBytes, p_jcResult, JNI_FALSE);
}
- else
+ else
{
LOGE("jByteArrayToCByteArray: Input is NULL or something else is broken. Cannot return byte array");
}
return cBytes;
}
+
+