@@ -19,8 +19,6 @@ internal class ProcessInfo
19
19
/// </summary>
20
20
internal DateTimeOffset ? BootTime { get ; }
21
21
22
- private readonly SentryOptions _options ;
23
- private readonly Func < DateTimeOffset > _findPreciseStartupTime ;
24
22
private volatile Task _preciseAppStartupTask = Task . CompletedTask ;
25
23
26
24
// For testability
@@ -34,12 +32,9 @@ internal ProcessInfo(
34
32
SentryOptions options ,
35
33
Func < DateTimeOffset > ? findPreciseStartupTime = null )
36
34
{
37
- _options = options ;
38
- _findPreciseStartupTime = findPreciseStartupTime ?? GetStartupTime ;
39
35
if ( options . DetectStartupTime == StartupTimeDetectionMode . None )
40
36
{
41
- _options . LogDebug ( "Not detecting startup time due to option: {0}" ,
42
- _options . DetectStartupTime ) ;
37
+ options . LogDebug ( "Not detecting startup time due to option: {0}" , options . DetectStartupTime ) ;
43
38
return ;
44
39
}
45
40
@@ -64,7 +59,7 @@ internal ProcessInfo(
64
59
// ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
65
60
// https://github.com/getsentry/sentry-unity/issues/233
66
61
67
- _options . LogError (
62
+ options . LogError (
68
63
"Failed to find BootTime: Now {0}, GetTimestamp {1}, Frequency {2}, TicksPerSecond: {3}" ,
69
64
e ,
70
65
now ,
@@ -75,33 +70,41 @@ internal ProcessInfo(
75
70
76
71
// An opt-out to the more precise approach (mainly due to IL2CPP):
77
72
// https://issuetracker.unity3d.com/issues/il2cpp-player-crashes-when-calling-process-dot-getcurrentprocess-dot-starttime
78
- if ( _options . DetectStartupTime == StartupTimeDetectionMode . Best )
73
+ if ( options . DetectStartupTime == StartupTimeDetectionMode . Best )
79
74
{
75
+ #if ANDROID
76
+ options . LogWarning ( "StartupTimeDetectionMode.Best is not available on android. Using 'Fast' mode." ) ;
77
+ return ;
78
+ #else
80
79
// StartupTime is set to UtcNow in this constructor.
81
80
// That's computationally cheap but not very precise.
82
81
// This method will give a better precision to the StartupTime at a cost
83
82
// of calling Process.GetCurrentProcess, on a thread pool thread.
83
+ var preciseStartupTimeFunc = findPreciseStartupTime ?? GetStartupTime ;
84
84
PreciseAppStartupTask = Task . Run ( ( ) =>
85
85
{
86
86
try
87
87
{
88
- StartupTime = _findPreciseStartupTime ( ) ;
88
+ StartupTime = preciseStartupTimeFunc ( ) ;
89
89
}
90
90
catch ( Exception e )
91
91
{
92
- _options . LogError ( "Failure getting precise App startup time." , e ) ;
92
+ options . LogError ( "Failure getting precise App startup time." , e ) ;
93
93
//Ignore any exception and stay with the less-precise DateTime.UtcNow value.
94
94
}
95
95
} ) . ContinueWith ( _ =>
96
96
// Let the actual task get collected
97
97
PreciseAppStartupTask = Task . CompletedTask ) ;
98
+ #endif
98
99
}
99
100
}
100
101
102
+ #if ! ANDROID
101
103
private static DateTimeOffset GetStartupTime ( )
102
104
{
103
105
using var proc = Process . GetCurrentProcess ( ) ;
104
106
return proc . StartTime . ToUniversalTime ( ) ;
105
107
}
108
+ #endif
106
109
}
107
110
}
0 commit comments