Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Avoid using OffsetDateTime on APIs 25 and lower #75196

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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