1 |
efrain |
1 |
// Copyright 2019 Google
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
#include "Crashlytics/Shared/FIRCLSFABHost.h"
|
|
|
16 |
|
|
|
17 |
#if TARGET_OS_WATCH
|
|
|
18 |
#import <WatchKit/WatchKit.h>
|
|
|
19 |
#elif TARGET_OS_IPHONE
|
|
|
20 |
#import <UIKit/UIKit.h>
|
|
|
21 |
#endif
|
|
|
22 |
|
|
|
23 |
#include <sys/sysctl.h>
|
|
|
24 |
|
|
|
25 |
#define FIRCLS_HOST_SYSCTL_BUFFER_SIZE (128)
|
|
|
26 |
|
|
|
27 |
#pragma mark - OS Versions
|
|
|
28 |
|
|
|
29 |
#pragma mark Private
|
|
|
30 |
|
|
|
31 |
static NSString *FIRCLSHostSysctlEntry(const char *sysctlKey) {
|
|
|
32 |
char buffer[FIRCLS_HOST_SYSCTL_BUFFER_SIZE];
|
|
|
33 |
size_t bufferSize = FIRCLS_HOST_SYSCTL_BUFFER_SIZE;
|
|
|
34 |
if (sysctlbyname(sysctlKey, buffer, &bufferSize, NULL, 0) != 0) {
|
|
|
35 |
return nil;
|
|
|
36 |
}
|
|
|
37 |
return [NSString stringWithUTF8String:buffer];
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
#pragma mark Public
|
|
|
41 |
|
|
|
42 |
NSOperatingSystemVersion FIRCLSHostGetOSVersion(void) {
|
|
|
43 |
// works on macos(10.10), ios(8.0), watchos(2.0), tvos(9.0)
|
|
|
44 |
if ([NSProcessInfo.processInfo respondsToSelector:@selector(operatingSystemVersion)]) {
|
|
|
45 |
return [NSProcessInfo.processInfo operatingSystemVersion];
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
NSOperatingSystemVersion version = {0, 0, 0};
|
|
|
49 |
|
|
|
50 |
#if TARGET_OS_IPHONE
|
|
|
51 |
|
|
|
52 |
#if TARGET_OS_WATCH
|
|
|
53 |
NSString *versionString = [[WKInterfaceDevice currentDevice] systemVersion];
|
|
|
54 |
#else
|
|
|
55 |
NSString *versionString = [[UIDevice currentDevice] systemVersion];
|
|
|
56 |
#endif
|
|
|
57 |
|
|
|
58 |
NSArray *parts = [versionString componentsSeparatedByString:@"."];
|
|
|
59 |
|
|
|
60 |
if (parts.count > 0) {
|
|
|
61 |
version.majorVersion = [[parts objectAtIndex:0] integerValue];
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
if ([parts count] > 1) {
|
|
|
65 |
version.minorVersion = [[parts objectAtIndex:1] integerValue];
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
if ([parts count] > 2) {
|
|
|
69 |
version.patchVersion = [[parts objectAtIndex:2] integerValue];
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
#endif
|
|
|
73 |
|
|
|
74 |
return version;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
NSString *FIRCLSHostOSBuildVersion(void) {
|
|
|
78 |
return FIRCLSHostSysctlEntry("kern.osversion");
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
NSString *FIRCLSHostOSDisplayVersion(void) {
|
|
|
82 |
NSOperatingSystemVersion version = FIRCLSHostGetOSVersion();
|
|
|
83 |
return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion,
|
|
|
84 |
(long)version.minorVersion, (long)version.patchVersion];
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
#pragma mark - Host Models
|
|
|
88 |
|
|
|
89 |
#pragma mark Public
|
|
|
90 |
|
|
|
91 |
NSString *FIRCLSHostModelInfo(void) {
|
|
|
92 |
NSString *model = nil;
|
|
|
93 |
|
|
|
94 |
#if TARGET_OS_SIMULATOR
|
|
|
95 |
#if TARGET_OS_WATCH
|
|
|
96 |
model = @"watchOS Simulator";
|
|
|
97 |
#elif TARGET_OS_TV
|
|
|
98 |
model = @"tvOS Simulator";
|
|
|
99 |
#elif TARGET_OS_IPHONE
|
|
|
100 |
switch ([[UIDevice currentDevice] userInterfaceIdiom]) {
|
|
|
101 |
case UIUserInterfaceIdiomPhone:
|
|
|
102 |
model = @"iOS Simulator (iPhone)";
|
|
|
103 |
break;
|
|
|
104 |
case UIUserInterfaceIdiomPad:
|
|
|
105 |
model = @"iOS Simulator (iPad)";
|
|
|
106 |
break;
|
|
|
107 |
default:
|
|
|
108 |
model = @"iOS Simulator (Unknown)";
|
|
|
109 |
break;
|
|
|
110 |
}
|
|
|
111 |
#endif
|
|
|
112 |
#elif TARGET_OS_EMBEDDED
|
|
|
113 |
model = FIRCLSHostSysctlEntry("hw.machine");
|
|
|
114 |
#else
|
|
|
115 |
model = FIRCLSHostSysctlEntry("hw.model");
|
|
|
116 |
#endif
|
|
|
117 |
|
|
|
118 |
return model;
|
|
|
119 |
}
|