]>
Commit | Line | Data |
---|---|---|
19fa75a9 A |
1 | /* |
2 | * Copyright (c) 2019-2020 Apple Inc. All rights reserved. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * https://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #import "system_utilities.h" | |
18 | #import <os/variant_private.h> // os_variant_has_internal_diagnostics | |
19 | #import <TargetConditionals.h> | |
20 | ||
21 | #if TARGET_OS_OSX | |
22 | #import <UniformTypeIdentifiers/UniformTypeIdentifiersPriv.h> | |
23 | #import <IOKit/platform/IOPlatformSupportPrivate.h> | |
24 | #endif // TARGET_OS_OSX | |
25 | ||
26 | bool IsAppleInternalBuild(void) | |
27 | { | |
28 | return (os_variant_has_internal_diagnostics("com.apple.mDNSResponder") != false); | |
29 | } | |
30 | ||
31 | #if TARGET_OS_OSX | |
32 | util_enclosure_color_t | |
33 | util_get_enclosure_color_str(char * const out_str, uint8_t len, uint8_t *out_size) | |
34 | { | |
35 | util_enclosure_color_t color_type = util_enclosure_color_none; | |
36 | if (@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)) { | |
37 | UTHardwareColor enclosureColor; | |
38 | if (_UTHardwareColorGetCurrentEnclosureColor(&enclosureColor)) { | |
39 | switch (enclosureColor.type) { | |
40 | case UTHardwareColorTypeRGB: { | |
41 | int size = snprintf(out_str, len, "%u,%u,%u", | |
42 | enclosureColor.rgb.r, enclosureColor.rgb.g, enclosureColor.rgb.b); | |
43 | if (size < len) { | |
44 | color_type = util_enclosure_color_rgb; | |
45 | *out_size = size; | |
46 | } | |
47 | break; | |
48 | } | |
49 | case UTHardwareColorTypeIndexed: { | |
50 | int size = snprintf(out_str, len, "%i", enclosureColor.index); | |
51 | if (size < len) { | |
52 | color_type = util_enclosure_color_index; | |
53 | *out_size = size; | |
54 | } | |
55 | break; | |
56 | } | |
57 | default: | |
58 | *out_size = 0; | |
59 | break; | |
60 | } | |
61 | } | |
62 | } else { | |
63 | uint8_t red = 0; | |
64 | uint8_t green = 0; | |
65 | uint8_t blue = 0; | |
66 | ||
67 | IOReturn rGetDeviceColor = IOPlatformGetDeviceColor(kIOPlatformDeviceEnclosureColorKey, | |
68 | &red, &green, &blue); | |
69 | if (kIOReturnSuccess == rGetDeviceColor) | |
70 | { | |
71 | int size = snprintf(out_str, len, "%u,%u,%u", red, green, blue); | |
72 | if (size < len) { | |
73 | color_type = util_enclosure_color_rgb; | |
74 | *out_size = size; | |
75 | } | |
76 | } | |
77 | } | |
78 | return color_type; | |
79 | } | |
80 | #else // TARGET_OS_OSX | |
81 | util_enclosure_color_t | |
82 | util_get_enclosure_color_str(char * const __unused out_str, uint8_t __unused len, uint8_t * __unused out_size) | |
83 | { | |
84 | return util_enclosure_color_none; | |
85 | } | |
86 | #endif // TARGET_OS_OSX |