summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/Android.mk11
-rw-r--r--core/jni/AndroidRuntime.cpp8
-rw-r--r--core/jni/android_os_SELinux.cpp57
-rw-r--r--core/jni/android_text_format_Time.cpp192
4 files changed, 94 insertions, 174 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 3ca085b..9b95be1 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -11,10 +11,6 @@ else
LOCAL_CFLAGS += -DPACKED=""
endif
-ifeq ($(WITH_JIT),true)
- LOCAL_CFLAGS += -DWITH_JIT
-endif
-
ifneq ($(USE_CUSTOM_RUNTIME_HEAP_MAX),)
LOCAL_CFLAGS += -DCUSTOM_RUNTIME_HEAP_MAX=$(USE_CUSTOM_RUNTIME_HEAP_MAX)
endif
@@ -200,6 +196,7 @@ LOCAL_SHARED_LIBRARIES := \
libETC1 \
libhardware \
libhardware_legacy \
+ libselinux \
libsonivox \
libcrypto \
libssl \
@@ -213,12 +210,6 @@ LOCAL_SHARED_LIBRARIES := \
libharfbuzz \
libz
-ifeq ($(HAVE_SELINUX),true)
-LOCAL_C_INCLUDES += external/libselinux/include
-LOCAL_SHARED_LIBRARIES += libselinux
-LOCAL_CFLAGS += -DHAVE_SELINUX
-endif # HAVE_SELINUX
-
ifeq ($(USE_OPENGL_RENDERER),true)
LOCAL_SHARED_LIBRARIES += libhwui
endif
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 9820e60..94324f8 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -465,9 +465,7 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
kEMDefault,
kEMIntPortable,
kEMIntFast,
-#if defined(WITH_JIT)
kEMJitCompiler,
-#endif
} executionMode = kEMDefault;
@@ -487,10 +485,8 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
executionMode = kEMIntPortable;
} else if (strcmp(propBuf, "int:fast") == 0) {
executionMode = kEMIntFast;
-#if defined(WITH_JIT)
} else if (strcmp(propBuf, "int:jit") == 0) {
executionMode = kEMJitCompiler;
-#endif
}
property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, "");
@@ -660,7 +656,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
mOptions.add(opt);
}
-#if defined(WITH_JIT)
/* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
property_get("dalvik.vm.jit.op", propBuf, "");
@@ -680,7 +675,6 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
opt.optionString = jitMethodBuf;
mOptions.add(opt);
}
-#endif
if (executionMode == kEMIntPortable) {
opt.optionString = "-Xint:portable";
@@ -688,11 +682,9 @@ int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv)
} else if (executionMode == kEMIntFast) {
opt.optionString = "-Xint:fast";
mOptions.add(opt);
-#if defined(WITH_JIT)
} else if (executionMode == kEMJitCompiler) {
opt.optionString = "-Xint:jit";
mOptions.add(opt);
-#endif
}
if (checkDexSum) {
diff --git a/core/jni/android_os_SELinux.cpp b/core/jni/android_os_SELinux.cpp
index e813c38..b12fdfc 100644
--- a/core/jni/android_os_SELinux.cpp
+++ b/core/jni/android_os_SELinux.cpp
@@ -20,10 +20,8 @@
#include "JNIHelp.h"
#include "jni.h"
#include "android_runtime/AndroidRuntime.h"
-#ifdef HAVE_SELINUX
#include "selinux/selinux.h"
#include "selinux/android.h"
-#endif
#include <errno.h>
namespace android {
@@ -56,11 +54,7 @@ namespace android {
* Exceptions: none
*/
static jboolean isSELinuxEnforced(JNIEnv *env, jobject clazz) {
-#ifdef HAVE_SELINUX
return (security_getenforce() == 1) ? true : false;
-#else
- return false;
-#endif
}
/*
@@ -71,16 +65,12 @@ namespace android {
* Exceptions: none
*/
static jboolean setSELinuxEnforce(JNIEnv *env, jobject clazz, jboolean value) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return false;
int enforce = (value) ? 1 : 0;
return (security_setenforce(enforce) != -1) ? true : false;
-#else
- return false;
-#endif
}
/*
@@ -92,7 +82,6 @@ namespace android {
* Exceptions: NullPointerException if fileDescriptor object is NULL
*/
static jstring getPeerCon(JNIEnv *env, jobject clazz, jobject fileDescriptor) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return NULL;
@@ -123,9 +112,6 @@ namespace android {
freecon(context);
return securityString;
-#else
- return NULL;
-#endif
}
/*
@@ -138,7 +124,6 @@ namespace android {
* Exception: none
*/
static jboolean setFSCreateCon(JNIEnv *env, jobject clazz, jstring context) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return false;
@@ -163,9 +148,6 @@ namespace android {
env->ReleaseStringUTFChars(context, constant_securityContext);
return (ret == 0) ? true : false;
-#else
- return false;
-#endif
}
/*
@@ -178,7 +160,6 @@ namespace android {
* Exception: NullPointerException is thrown if either path or context strign are NULL
*/
static jboolean setFileCon(JNIEnv *env, jobject clazz, jstring path, jstring con) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return false;
@@ -208,9 +189,6 @@ namespace android {
env->ReleaseStringUTFChars(path, objectPath);
env->ReleaseStringUTFChars(con, constant_con);
return (ret == 0) ? true : false;
-#else
- return false;
-#endif
}
/*
@@ -224,7 +202,6 @@ namespace android {
* Exceptions: NullPointerException if the path object is null
*/
static jstring getFileCon(JNIEnv *env, jobject clazz, jstring path) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return NULL;
@@ -252,9 +229,6 @@ namespace android {
env->ReleaseStringUTFChars(path, objectPath);
return securityString;
-#else
- return NULL;
-#endif
}
/*
@@ -266,7 +240,6 @@ namespace android {
* Exceptions: none
*/
static jstring getCon(JNIEnv *env, jobject clazz) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return NULL;
@@ -285,9 +258,6 @@ namespace android {
freecon(context);
return securityString;
-#else
- return NULL;
-#endif
}
/*
@@ -300,7 +270,6 @@ namespace android {
* Exceptions: none
*/
static jstring getPidCon(JNIEnv *env, jobject clazz, jint pid) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return NULL;
@@ -321,9 +290,6 @@ namespace android {
freecon(context);
return securityString;
-#else
- return NULL;
-#endif
}
/*
@@ -335,7 +301,6 @@ namespace android {
* Exceptions: None
*/
static jobjectArray getBooleanNames(JNIEnv *env, JNIEnv clazz) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return NULL;
@@ -359,9 +324,6 @@ namespace android {
free(list);
return stringArray;
-#else
- return NULL;
-#endif
}
/*
@@ -373,7 +335,6 @@ namespace android {
* Exceptions: None
*/
static jboolean getBooleanValue(JNIEnv *env, jobject clazz, jstring name) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return false;
@@ -386,9 +347,6 @@ namespace android {
ret = security_get_boolean_active(boolean_name);
env->ReleaseStringUTFChars(name, boolean_name);
return (ret == 1) ? true : false;
-#else
- return false;
-#endif
}
/*
@@ -401,7 +359,6 @@ namespace android {
* Exceptions: None
*/
static jboolean setBooleanValue(JNIEnv *env, jobject clazz, jstring name, jboolean value) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return false;
@@ -420,9 +377,6 @@ namespace android {
return false;
return true;
-#else
- return false;
-#endif
}
/*
@@ -436,7 +390,6 @@ namespace android {
* Exceptions: None
*/
static jboolean checkSELinuxAccess(JNIEnv *env, jobject clazz, jstring scon, jstring tcon, jstring tclass, jstring perm) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return true;
@@ -468,10 +421,6 @@ namespace android {
bail:
return (accessGranted == 0) ? true : false;
-
-#else
- return true;
-#endif
}
/*
@@ -482,7 +431,6 @@ namespace android {
* Exceptions: none
*/
static jboolean native_restorecon(JNIEnv *env, jobject clazz, jstring pathname) {
-#ifdef HAVE_SELINUX
if (isSELinuxDisabled)
return true;
@@ -490,9 +438,6 @@ namespace android {
int ret = selinux_android_restorecon(file);
env->ReleaseStringUTFChars(pathname, file);
return (ret == 0);
-#else
- return true;
-#endif
}
/*
@@ -526,14 +471,12 @@ namespace android {
}
int register_android_os_SELinux(JNIEnv *env) {
-#ifdef HAVE_SELINUX
union selinux_callback cb;
cb.func_log = log_callback;
selinux_set_callback(SELINUX_CB_LOG, cb);
isSELinuxDisabled = (is_selinux_enabled() != 1) ? true : false;
-#endif
return AndroidRuntime::registerNativeMethods(
env, "android/os/SELinux",
method_table, NELEM(method_table));
diff --git a/core/jni/android_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp
index 0a59ae7..aa2c5f39 100644
--- a/core/jni/android_text_format_Time.cpp
+++ b/core/jni/android_text_format_Time.cpp
@@ -23,6 +23,7 @@
#include "jni.h"
#include "utils/misc.h"
#include "android_runtime/AndroidRuntime.h"
+#include "ScopedStringChars.h"
#include "TimeUtils.h"
#include <nativehelper/JNIHelp.h>
#include <cutils/tztime.h>
@@ -71,11 +72,10 @@ static inline bool java2time(JNIEnv* env, Time* t, jobject o)
t->t.tm_gmtoff = env->GetLongField(o, g_gmtoffField);
bool allDay = env->GetBooleanField(o, g_allDayField);
if (allDay &&
- ((t->t.tm_sec !=0) || (t->t.tm_min != 0) || (t->t.tm_hour != 0))) {
- char msg[100];
- sprintf(msg, "allDay is true but sec, min, hour are not 0.");
- jniThrowException(env, "java/lang/IllegalArgumentException", msg);
- return false;
+ ((t->t.tm_sec !=0) || (t->t.tm_min != 0) || (t->t.tm_hour != 0))) {
+ jniThrowException(env, "java/lang/IllegalArgumentException",
+ "allDay is true but sec, min, hour are not 0.");
+ return false;
}
return true;
}
@@ -313,7 +313,7 @@ static jstring android_text_format_Time_format(JNIEnv* env, jobject This,
static jstring android_text_format_Time_toString(JNIEnv* env, jobject This)
{
Time t;
- if (!java2time(env, &t, This)) return env->NewStringUTF("");;
+ if (!java2time(env, &t, This)) return env->NewStringUTF("");
ACQUIRE_TIMEZONE(This, t)
String8 r = t.toString();
@@ -365,32 +365,30 @@ static void android_text_format_Time_set(JNIEnv* env, jobject This, jlong millis
// ============================================================================
// Just do this here because it's not worth recreating the strings
-static int get_char(JNIEnv* env, const jchar *s, int spos, int mul,
- bool *thrown)
+static int get_char(JNIEnv* env, const ScopedStringChars& s, int spos, int mul,
+ bool* thrown)
{
jchar c = s[spos];
if (c >= '0' && c <= '9') {
return (c - '0') * mul;
} else {
if (!*thrown) {
- char msg[100];
- sprintf(msg, "Parse error at pos=%d", spos);
- jniThrowException(env, "android/util/TimeFormatException", msg);
+ jniThrowExceptionFmt(env, "android/util/TimeFormatException",
+ "Parse error at pos=%d", spos);
*thrown = true;
}
return 0;
}
}
-static bool check_char(JNIEnv* env, const jchar *s, int spos, jchar expected)
+static bool check_char(JNIEnv* env, const ScopedStringChars& s, int spos, jchar expected)
{
jchar c = s[spos];
if (c != expected) {
- char msg[100];
- sprintf(msg, "Unexpected character 0x%02x at pos=%d. Expected %c.", c, spos,
- expected);
- jniThrowException(env, "android/util/TimeFormatException", msg);
- return false;
+ jniThrowExceptionFmt(env, "android/util/TimeFormatException",
+ "Unexpected character 0x%02x at pos=%d. Expected %c.",
+ c, spos, expected);
+ return false;
}
return true;
}
@@ -399,20 +397,19 @@ static bool check_char(JNIEnv* env, const jchar *s, int spos, jchar expected)
static jboolean android_text_format_Time_parse(JNIEnv* env, jobject This, jstring strObj)
{
jsize len = env->GetStringLength(strObj);
- const jchar *s = env->GetStringChars(strObj, NULL);
+ if (len < 8) {
+ jniThrowException(env, "android/util/TimeFormatException",
+ "String too short -- expected at least 8 characters.");
+ return false;
+ }
- bool thrown = false;
- int n;
jboolean inUtc = false;
- if (len < 8) {
- char msg[100];
- sprintf(msg, "String too short -- expected at least 8 characters.");
- jniThrowException(env, "android/util/TimeFormatException", msg);
- return false;
- }
+ ScopedStringChars s(env, strObj);
// year
+ int n;
+ bool thrown = false;
n = get_char(env, s, 0, 1000, &thrown);
n += get_char(env, s, 1, 100, &thrown);
n += get_char(env, s, 2, 10, &thrown);
@@ -459,7 +456,7 @@ static jboolean android_text_format_Time_parse(JNIEnv* env, jobject This, jstrin
if (len > 15) {
// Z
if (!check_char(env, s, 15, 'Z')) return false;
- inUtc = true;
+ inUtc = true;
}
} else {
env->SetBooleanField(This, g_allDayField, JNI_TRUE);
@@ -472,8 +469,7 @@ static jboolean android_text_format_Time_parse(JNIEnv* env, jobject This, jstrin
env->SetIntField(This, g_ydayField, 0);
env->SetIntField(This, g_isdstField, -1);
env->SetLongField(This, g_gmtoffField, 0);
-
- env->ReleaseStringChars(strObj, s);
+
return inUtc;
}
@@ -482,19 +478,19 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env,
jstring strObj)
{
jsize len = env->GetStringLength(strObj);
- const jchar *s = env->GetStringChars(strObj, NULL);
-
- bool thrown = false;
- int n;
- jboolean inUtc = false;
-
if (len < 10) {
jniThrowException(env, "android/util/TimeFormatException",
- "Time input is too short; must be at least 10 characters");
+ "String too short --- expected at least 10 characters.");
return false;
}
+ jboolean inUtc = false;
+
+ ScopedStringChars s(env, strObj);
+
// year
+ int n;
+ bool thrown = false;
n = get_char(env, s, 0, 1000, &thrown);
n += get_char(env, s, 1, 100, &thrown);
n += get_char(env, s, 2, 10, &thrown);
@@ -525,28 +521,28 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env,
// T
if (!check_char(env, s, 10, 'T')) return false;
- env->SetBooleanField(This, g_allDayField, JNI_FALSE);
+ env->SetBooleanField(This, g_allDayField, JNI_FALSE);
// hour
n = get_char(env, s, 11, 10, &thrown);
n += get_char(env, s, 12, 1, &thrown);
if (thrown) return false;
- int hour = n;
+ int hour = n;
// env->SetIntField(This, g_hourField, n);
-
- // :
- if (!check_char(env, s, 13, ':')) return false;
- // minute
+ // :
+ if (!check_char(env, s, 13, ':')) return false;
+
+ // minute
n = get_char(env, s, 14, 10, &thrown);
n += get_char(env, s, 15, 1, &thrown);
if (thrown) return false;
- int minute = n;
+ int minute = n;
// env->SetIntField(This, g_minField, n);
- // :
- if (!check_char(env, s, 16, ':')) return false;
+ // :
+ if (!check_char(env, s, 16, ':')) return false;
- // second
+ // second
n = get_char(env, s, 17, 10, &thrown);
n += get_char(env, s, 18, 1, &thrown);
if (thrown) return false;
@@ -566,64 +562,63 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env,
if (len > tz_index) {
char c = s[tz_index];
- // NOTE: the offset is meant to be subtracted to get from local time
- // to UTC. we therefore use 1 for '-' and -1 for '+'.
- switch (c) {
- case 'Z':
- // Zulu time -- UTC
- offset = 0;
- break;
- case '-':
+ // NOTE: the offset is meant to be subtracted to get from local time
+ // to UTC. we therefore use 1 for '-' and -1 for '+'.
+ switch (c) {
+ case 'Z':
+ // Zulu time -- UTC
+ offset = 0;
+ break;
+ case '-':
offset = 1;
- break;
- case '+':
+ break;
+ case '+':
offset = -1;
- break;
- default:
- char msg[100];
- sprintf(msg, "Unexpected character 0x%02x at position %d. Expected + or -",
- c, tz_index);
- jniThrowException(env, "android/util/TimeFormatException", msg);
- return false;
- }
+ break;
+ default:
+ jniThrowExceptionFmt(env, "android/util/TimeFormatException",
+ "Unexpected character 0x%02x at position %d. Expected + or -",
+ c, tz_index);
+ return false;
+ }
inUtc = true;
- if (offset != 0) {
- if (len < tz_index + 6) {
- char msg[100];
- sprintf(msg, "Unexpected length; should be %d characters", tz_index + 6);
- jniThrowException(env, "android/util/TimeFormatException", msg);
- return false;
- }
-
- // hour
- n = get_char(env, s, tz_index + 1, 10, &thrown);
- n += get_char(env, s, tz_index + 2, 1, &thrown);
- if (thrown) return false;
- n *= offset;
- hour += n;
-
- // :
- if (!check_char(env, s, tz_index + 3, ':')) return false;
-
- // minute
- n = get_char(env, s, tz_index + 4, 10, &thrown);
- n += get_char(env, s, tz_index + 5, 1, &thrown);
- if (thrown) return false;
- n *= offset;
- minute += n;
- }
- }
- env->SetIntField(This, g_hourField, hour);
+ if (offset != 0) {
+ if (len < tz_index + 6) {
+ jniThrowExceptionFmt(env, "android/util/TimeFormatException",
+ "Unexpected length; should be %d characters",
+ tz_index + 6);
+ return false;
+ }
+
+ // hour
+ n = get_char(env, s, tz_index + 1, 10, &thrown);
+ n += get_char(env, s, tz_index + 2, 1, &thrown);
+ if (thrown) return false;
+ n *= offset;
+ hour += n;
+
+ // :
+ if (!check_char(env, s, tz_index + 3, ':')) return false;
+
+ // minute
+ n = get_char(env, s, tz_index + 4, 10, &thrown);
+ n += get_char(env, s, tz_index + 5, 1, &thrown);
+ if (thrown) return false;
+ n *= offset;
+ minute += n;
+ }
+ }
+ env->SetIntField(This, g_hourField, hour);
env->SetIntField(This, g_minField, minute);
- if (offset != 0) {
- // we need to normalize after applying the hour and minute offsets
- android_text_format_Time_normalize(env, This, false /* use isdst */);
- // The timezone is set to UTC in the calling Java code.
- }
+ if (offset != 0) {
+ // we need to normalize after applying the hour and minute offsets
+ android_text_format_Time_normalize(env, This, false /* use isdst */);
+ // The timezone is set to UTC in the calling Java code.
+ }
} else {
- env->SetBooleanField(This, g_allDayField, JNI_TRUE);
+ env->SetBooleanField(This, g_allDayField, JNI_TRUE);
env->SetIntField(This, g_hourField, 0);
env->SetIntField(This, g_minField, 0);
env->SetIntField(This, g_secField, 0);
@@ -633,8 +628,7 @@ static jboolean android_text_format_Time_parse3339(JNIEnv* env,
env->SetIntField(This, g_ydayField, 0);
env->SetIntField(This, g_isdstField, -1);
env->SetLongField(This, g_gmtoffField, 0);
-
- env->ReleaseStringChars(strObj, s);
+
return inUtc;
}