Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09060056 authored by Stephen Hines's avatar Stephen Hines Committed by Android (Google) Code Review
Browse files

Merge "Fix setTimeZone() and use it properly in RSTest/rstime."

parents 06d04f22 d2f561d1
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -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,
+0 −1
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ public:
    struct Enviroment_t {
        int64_t mStartTimeMillis;
        int64_t mLastDtTime;
        const char* mTimeZone;

        ObjectBaseRef<ProgramVertex> mVertex;
        ObjectBaseRef<ProgramFragment> mFragment;
+1 −0
Original line number Diff line number Diff line
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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);