Skip to content

Commit

Permalink
[Android] Avoid using OffsetDateTime on APIs 25 and lower (#75196)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrozsival authored Sep 8, 2022
1 parent cc9d465 commit a3daf37
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/tasks/AndroidAppBuilder/Templates/MonoRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.OutputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -90,7 +91,7 @@ public static int initialize(String entryPointLibName, String[] args, Context co
unzipAssets(context, filesDir, "assets.zip");

Log.i("DOTNET", "MonoRunner initialize,, entryPointLibName=" + entryPointLibName);
int localDateTimeOffset = OffsetDateTime.now().getOffset().getTotalSeconds();
int localDateTimeOffset = getLocalDateTimeOffset();
return initRuntime(filesDir, cacheDir, testResultsDir, entryPointLibName, args, localDateTimeOffset);
}

Expand Down Expand Up @@ -152,6 +153,15 @@ static void unzipAssets(Context context, String toPath, String zipName) {
}
}

static int getLocalDateTimeOffset() {
if (android.os.Build.VERSION.SDK_INT >= 26) {
return OffsetDateTime.now().getOffset().getTotalSeconds();
} else {
int offsetInMillis = Calendar.getInstance().getTimeZone().getRawOffset();
return offsetInMillis / 1000;
}
}

static native int initRuntime(String libsDir, String cacheDir, String testResultsDir, String entryPointLibName, String[] args, int local_date_time_offset);

static native int setEnv(String key, String value);
Expand Down

0 comments on commit a3daf37

Please sign in to comment.