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][libraries] TimeZoneInfo Android imp #54845

Merged
merged 82 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
1014cc6
Initial Android implementation
Jun 24, 2021
d161105
Split implementations for Android specific GetTimeZoneIds
Jun 25, 2021
cfa0b33
Differentiate Unix and Android TimeZoneInfo by PopulateAllSystemTimeZ…
Jun 25, 2021
caa39a6
Utilize Android paths for timezone data
Jun 28, 2021
ee51c67
Clean up mono style to match runtime style
Jun 28, 2021
ce91611
Pulled in parsing implementation from mono and broke out GetLocalTime…
Jun 29, 2021
4ed8616
TimeZoneInfo.Android builds properly now. Found PopulateAllSystemTim…
Jun 29, 2021
555d0b5
Found TryGetTimeZoneFromLocalMachine to map to FindSystemTimeZoneById…
Jun 29, 2021
d59fb1a
Fixed typo on type
Jun 29, 2021
84dcbb7
Added cacheddata param
Jun 30, 2021
cb9efd4
Initial implementation of PopulateAllSystemTimeZonesCore and TryGetTi…
Jun 30, 2021
b68e290
Clean up missing variables and wrong function calls
Jun 30, 2021
65615ca
Fix cachedData parameter overload
Jun 30, 2021
514fa44
Add JNI GetDefaultTimeZone
Jun 30, 2021
6c3e567
Remove excess of imports in pal_datetime
Jun 30, 2021
3787086
Clean up PopulateAllSystemTimeZonesCore comments
Jun 30, 2021
912ab4d
Remove ParseTZBuffer middleman
Jun 30, 2021
d67920e
Add id check and runtime style to _GetTimeZone
Jun 30, 2021
b602bf7
cleanup pal_datetime imports
Jun 30, 2021
caa9229
Remove ZoneTab related code
Jun 30, 2021
a7aee33
Remove Version related code
Jun 30, 2021
fb72a04
Remove PopulateAllSystemTimeZonesCore middleman
Jun 30, 2021
c3f1e18
Add return for non Android
Jul 1, 2021
c314363
Avoid using static constructor for paths
Jul 1, 2021
0890a23
Remove redundant using
Jul 1, 2021
80c28e8
Fix GetTimeZoneIds return
Jul 1, 2021
858ef84
Condition TargetsAndroid around function
Jul 1, 2021
e062265
Clean up functions
Jul 1, 2021
3956ff7
Remove GetTimeZoneDirectory Android implementation
Jul 1, 2021
18c4955
Remove interface
Jul 1, 2021
37c0a0c
Cleanup style
Jul 1, 2021
98ee19d
Remove zoneTabOffset
Jul 1, 2021
fc8ce4a
Temporarily add GetTimeZoneDirectory
Jul 2, 2021
c4397b7
Refactoring code
Jul 2, 2021
7188c6b
Address some feedback
Jul 2, 2021
3198101
Move interop to its own file
Jul 2, 2021
1a495cc
Rename variable
Jul 2, 2021
6e40f61
Refactor to modify access from internal to private
Jul 6, 2021
4c82a11
Remove static Paths, pass tzFilePath as parameter instead of holding
Jul 6, 2021
3cc1da1
Add ordinal comparison for performance gain
Jul 6, 2021
4df973a
Add Softcode Local
Jul 6, 2021
b4d5ba6
Softcode tzdata file path
Jul 6, 2021
2bb25ce
Refactor Unix specific code
Jul 6, 2021
efa339e
Lazy allocation of Android TimeZone Data
Jul 6, 2021
54e3218
Fix up imports
Jul 7, 2021
144f4dd
Apply coding style
Jul 7, 2021
0790650
More clean up
Jul 7, 2021
5f4fae7
Rename property
Jul 8, 2021
d1070d1
Update TimeZone data header and entry structs
Jul 8, 2021
e20c6cb
Refactor header correctness check
Jul 8, 2021
4b31684
Fix resource string message
Jul 8, 2021
2616ca0
Revert to original header check
Jul 8, 2021
ecf6f70
Cleanup comments
Jul 8, 2021
3b424dc
Expect Ansi strings
Jul 9, 2021
ed3355e
Fix casing
Jul 9, 2021
2bfb9e4
Stackalloc tzdata buffer
Jul 9, 2021
5edd7ea
Remove redundant exception message
Jul 9, 2021
966aee5
Remove nullable from fields
Jul 9, 2021
290caa2
Add missing namechange
Jul 9, 2021
fc551d2
Pass stream through ReadHeader and only open file once
Jul 9, 2021
6fb3133
Rename files
Jul 9, 2021
6ccad5d
Avoid unnecessary allocation
Jul 9, 2021
0987ee7
Assert buffer size over creating resource exception
Jul 9, 2021
69d5a84
Merge remote-tracking branch 'upstream/main' into port_android_timezo…
Jul 12, 2021
8d88a6d
Use compare exchange atomic method
Jul 13, 2021
4433be6
Reduce redundant calls
Jul 13, 2021
8330c2a
Cleanup output variables
Jul 13, 2021
b8bcce4
Remove comments
Jul 13, 2021
37b80ca
Use sizeof over Marshal
Jul 13, 2021
8891709
Address feedback
Jul 13, 2021
15d4455
Address Feedback
Jul 14, 2021
6501d7e
Address more feedback
Jul 16, 2021
a63f8f9
Separate buffer loading into independent method
Jul 16, 2021
16289d2
Properly set where to write into the buffer
Jul 16, 2021
d5ffcef
Update comments
Jul 16, 2021
311ecaa
Remove AndroidTzDataHeader and fix typos
Jul 16, 2021
a07da96
Add const keyword, move field declaration, use length comparison
Jul 19, 2021
a47ade2
Change data entry id to string
Jul 19, 2021
cc06d96
Parse id account for null terminating character
Jul 19, 2021
00b0abe
Remove AndroidTzDataEntry struct and use out parameters
Jul 19, 2021
5290490
Remove unsafe keywords
Jul 19, 2021
95f30f6
Close file handle in GetTimeZoneData
Jul 19, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetDefaultTimeZone", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern string? GetDefaultTimeZone();
}
}
27 changes: 22 additions & 5 deletions src/libraries/Native/Unix/System.Native/pal_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include "pal_config.h"

#include <stdlib.h>
#include "pal_datetime.h"
#include <stdint.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#include "pal_datetime.h"
#if defined(TARGET_ANDROID)
#include <sys/system_properties.h>
#endif
#include <time.h>

static const int64_t TICKS_PER_SECOND = 10000000; /* 10^7 */
#if HAVE_CLOCK_REALTIME
Expand Down Expand Up @@ -39,3 +41,18 @@ int64_t SystemNative_GetSystemTimeAsTicks()
// in failure we return 00:00 01 January 1970 UTC (Unix epoch)
return 0;
}

#if defined(TARGET_ANDROID)
char* SystemNative_GetDefaultTimeZone()
{
char defaulttimezone[PROP_VALUE_MAX];
if (__system_property_get("persist.sys.timezone", defaulttimezone))
{
return strdup(defaulttimezone);
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
return NULL;
}
}
#endif
5 changes: 5 additions & 0 deletions src/libraries/Native/Unix/System.Native/pal_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
#pragma once

#include "pal_compiler.h"
#include "pal_types.h"

PALEXPORT int64_t SystemNative_GetSystemTimeAsTicks(void);

#if defined(TARGET_ANDROID)
PALEXPORT char* SystemNative_GetDefaultTimeZone(void);
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3796,4 +3796,13 @@
<data name="Arg_MemberInfoNotFound" xml:space="preserve">
<value>A MemberInfo that matches '{0}' could not be found.</value>
</data>
<data name="InvalidOperation_BadTZHeader" xml:space="preserve">
<value>Bad magic in '{0}': Header starts with '{1}' instead of 'tzdata'</value>
</data>
<data name="InvalidOperation_ReadTZError" xml:space="preserve">
<value>Unable to fully read from file '{0}' at offset {1} length {2}; read {3} bytes expected {4}.</value>
</data>
<data name="InvalidOperation_BadIndexLength" xml:space="preserve">
<value>Length in index file less than AndroidTzDataHeader</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,9 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetCwd.cs">
<Link>Common\Interop\Unix\System.Native\Interop.GetCwd.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetDefaultTimeZone.Android.cs" Condition="'$(TargetsAndroid)' == 'true'">
<Link>Common\Interop\Unix\System.Native\Interop.GetDefaultTimeZone.Android.cs</Link>
</Compile>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetEGid.cs">
<Link>Common\Interop\Unix\System.Native\Interop.GetHostName.cs</Link>
</Compile>
Expand Down Expand Up @@ -2126,6 +2129,8 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelMonitor.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\TimerQueue.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.Android.cs" Condition="'$(TargetsAndroid)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.NonAndroid.cs" Condition="'$(TargetsAndroid)' != 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetEUid.cs">
Expand Down
Loading