]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/utilities/system_utilities.m
mDNSResponder-1310.60.4.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / utilities / system_utilities.m
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 #import <SoftLinking/WeakLinking.h>
25 #endif // TARGET_OS_OSX
26
27 bool IsAppleInternalBuild(void)
28 {
29 return (os_variant_has_internal_diagnostics("com.apple.mDNSResponder") != false);
30 }
31
32 #if TARGET_OS_OSX
33 WEAK_LINK_FORCE_IMPORT(_UTHardwareColorGetCurrentEnclosureColor);
34
35 static util_enclosure_color_t
36 _uti_get_enclosure_color_str(char * const out_str, uint8_t len, uint8_t *out_size)
37 {
38 util_enclosure_color_t color_type = util_enclosure_color_none;
39 if (@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)) {
40 if(_UTHardwareColorGetCurrentEnclosureColor) {
41 UTHardwareColor enclosureColor;
42 if (_UTHardwareColorGetCurrentEnclosureColor(&enclosureColor)) {
43 switch (enclosureColor.type) {
44 case UTHardwareColorTypeRGB: {
45 int size = snprintf(out_str, len, "%u,%u,%u",
46 enclosureColor.rgb.r, enclosureColor.rgb.g, enclosureColor.rgb.b);
47 if (size > 0 && size < len) {
48 color_type = util_enclosure_color_rgb;
49 *out_size = size;
50 }
51 break;
52 }
53 case UTHardwareColorTypeIndexed: {
54 int size = snprintf(out_str, len, "%i", enclosureColor.index);
55 if (size > 0 && size < len) {
56 color_type = util_enclosure_color_index;
57 *out_size = size;
58 }
59 break;
60 }
61 default:
62 *out_size = 0;
63 break;
64 }
65 }
66 }
67 }
68 return color_type;
69 }
70
71 util_enclosure_color_t
72 util_get_enclosure_color_str(char * const out_str, uint8_t len, uint8_t *out_size)
73 {
74 util_enclosure_color_t color_type = _uti_get_enclosure_color_str(out_str, len, out_size);
75 if (color_type == util_enclosure_color_none) {
76 uint8_t red = 0;
77 uint8_t green = 0;
78 uint8_t blue = 0;
79
80 IOReturn rGetDeviceColor = IOPlatformGetDeviceColor(kIOPlatformDeviceEnclosureColorKey,
81 &red, &green, &blue);
82 if (kIOReturnSuccess == rGetDeviceColor)
83 {
84 int size = snprintf(out_str, len, "%u,%u,%u", red, green, blue);
85 if (size > 0 && size < len) {
86 color_type = util_enclosure_color_rgb;
87 *out_size = size;
88 }
89 }
90 }
91 return color_type;
92 }
93 #else // TARGET_OS_OSX
94 util_enclosure_color_t
95 util_get_enclosure_color_str(char * const __unused out_str, uint8_t __unused len, uint8_t * __unused out_size)
96 {
97 return util_enclosure_color_none;
98 }
99 #endif // TARGET_OS_OSX