summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2011-11-09 18:02:20 -0800
committerStephen Hines <srhines@google.com>2011-11-10 15:44:25 -0800
commitd2f561d183f6f2aab19cd8552d83b32cbc7fa5be (patch)
tree2409c2237cfce6c70b5d08f5d322280a15db2606
parent46bb0a1cf687e77f7f7338cf74d5ae4897fda9b0 (diff)
downloadframeworks_base-d2f561d183f6f2aab19cd8552d83b32cbc7fa5be.zip
frameworks_base-d2f561d183f6f2aab19cd8552d83b32cbc7fa5be.tar.gz
frameworks_base-d2f561d183f6f2aab19cd8552d83b32cbc7fa5be.tar.bz2
Fix setTimeZone() and use it properly in RSTest/rstime.
BUG=5470134 The original implementation for rsi_ScriptSetTimeZone() never actually did anything with the bytes received. This change allows it to safely update the timezone. RSTest is also updated to call setTimeZone(), so that users in different timezones can accurately get test results. Change-Id: I6cb1b3a0c3a417749ba39e0fe09cc9c7ab65c2e7
-rw-r--r--libs/rs/rsScript.cpp19
-rw-r--r--libs/rs/rsScript.h1
-rw-r--r--tests/RenderScriptTests/tests/src/com/android/rs/test/UT_rstime.java1
-rw-r--r--tests/RenderScriptTests/tests/src/com/android/rs/test/rstime.rs2
4 files changed, 19 insertions, 4 deletions
diff --git a/libs/rs/rsScript.cpp b/libs/rs/rsScript.cpp
index 93513fe..16446dd 100644
--- a/libs/rs/rsScript.cpp
+++ b/libs/rs/rsScript.cpp
@@ -15,6 +15,7 @@
*/
#include "rsContext.h"
+#include <time.h>
using namespace android;
using namespace android::renderscript;
@@ -89,8 +90,22 @@ void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint3
}
void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
- Script *s = static_cast<Script *>(vs);
- s->mEnviroment.mTimeZone = timeZone;
+ // We unfortunately need to make a new copy of the string, since it is
+ // not NULL-terminated. We then use setenv(), which properly handles
+ // freeing/duplicating the actual string for the environment.
+ char *tz = (char *) malloc(length + 1);
+ if (!tz) {
+ LOGE("Couldn't allocate memory for timezone buffer");
+ return;
+ }
+ strncpy(tz, timeZone, length);
+ tz[length] = '\0';
+ if (setenv("TZ", tz, 1) == 0) {
+ tzset();
+ } else {
+ LOGE("Error setting timezone");
+ }
+ free(tz);
}
void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index d645421..abb55b8 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -59,7 +59,6 @@ public:
struct Enviroment_t {
int64_t mStartTimeMillis;
int64_t mLastDtTime;
- const char* mTimeZone;
ObjectBaseRef<ProgramVertex> mVertex;
ObjectBaseRef<ProgramFragment> mFragment;
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_rstime.java b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_rstime.java
index f302e1a..21e657c 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_rstime.java
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/UT_rstime.java
@@ -32,6 +32,7 @@ public class UT_rstime extends UnitTest {
RenderScript pRS = RenderScript.create(mCtx);
ScriptC_rstime s = new ScriptC_rstime(pRS, mRes, R.raw.rstime);
pRS.setMessageHandler(mRsMessage);
+ s.setTimeZone("America/Los_Angeles");
s.invoke_test_rstime(0, 0);
pRS.finish();
waitForMessage();
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/rstime.rs b/tests/RenderScriptTests/tests/src/com/android/rs/test/rstime.rs
index 5e3e078..7be955d 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/rstime.rs
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/rstime.rs
@@ -19,7 +19,7 @@ static bool basic_test(uint32_t index) {
rsDebug("tm.tm_yday", tm.tm_yday);
rsDebug("tm.tm_isdst", tm.tm_isdst);
- // Test a specific time (only valid for PST localtime)
+ // Test a specific time (since we set America/Los_Angeles localtime)
curTime = 1294438893;
rsLocaltime(&tm, &curTime);