blob: 4421ac4230456d178dd6dfff9b02bfeb4eef749e [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[email protected]e2ac70002008-12-09 14:58:132// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]0378bf42011-01-01 18:20:145#ifndef BASE_MAC_MAC_UTIL_H_
6#define BASE_MAC_MAC_UTIL_H_
[email protected]e2ac70002008-12-09 14:58:137
Avi Drissman5197d3bca2020-07-23 03:11:328#include <AvailabilityMacros.h>
Meredith Lanea43420c2020-07-22 23:40:419#import <CoreGraphics/CoreGraphics.h>
Avi Drissman5197d3bca2020-07-23 03:11:3210#include <stdint.h>
11
12#include <string>
Avi Drissman922a94f22023-08-28 23:43:4113#include <string_view>
Avi Drissmanfc29fbd2024-01-22 21:37:2514#include <vector>
Meredith Lanea43420c2020-07-22 23:40:4115
[email protected]0bea7252011-08-05 15:34:0016#include "base/base_export.h"
[email protected]455687952010-12-17 18:42:2317
[email protected]a3ef4832013-02-02 05:12:3318namespace base {
[email protected]455687952010-12-17 18:42:2319class FilePath;
Avi Drissmanefca4122022-01-05 23:59:3620}
[email protected]e2ac70002008-12-09 14:58:1321
Avi Drissmanefca4122022-01-05 23:59:3622namespace base::mac {
[email protected]e2ac70002008-12-09 14:58:1323
[email protected]265cf96b2009-09-03 21:51:1024// Returns an sRGB color space. The return value is a static value; do not
25// release it!
[email protected]0bea7252011-08-05 15:34:0026BASE_EXPORT CGColorSpaceRef GetSRGBColorSpace();
[email protected]265cf96b2009-09-03 21:51:1027
Mike Jacksona481f3f2021-01-13 04:00:1928// Adds the specified application to the set of Login Items with specified
29// "hide" flag. This has the same effect as adding/removing the application in
30// SystemPreferences->Accounts->LoginItems or marking Application in the Dock
31// as "Options->Open on Login".
32// Does nothing if the application is already set up as Login Item with
33// specified hide flag.
34BASE_EXPORT void AddToLoginItems(const FilePath& app_bundle_file_path,
35 bool hide_on_startup);
36
Avi Drissmanfee70e5f2022-11-02 20:50:1137// Removes the specified application from the list of Login Items.
Mike Jacksona481f3f2021-01-13 04:00:1938BASE_EXPORT void RemoveFromLoginItems(const FilePath& app_bundle_file_path);
39
[email protected]91484af2010-08-27 17:55:5440// Returns true if the current process was automatically launched as a
[email protected]751d4102011-08-10 17:18:4541// 'Login Item' or via Lion's Resume. Used to suppress opening windows.
42BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
43
44// Returns true if the current process was automatically launched as a
[email protected]769ddfe2014-06-13 23:13:2045// 'Login Item' or via Resume, and the 'Reopen windows when logging back in'
46// checkbox was selected by the user. This indicates that the previous
47// session should be restored.
48BASE_EXPORT bool WasLaunchedAsLoginItemRestoreState();
49
50// Returns true if the current process was automatically launched as a
[email protected]91484af2010-08-27 17:55:5451// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
[email protected]0bea7252011-08-05 15:34:0052BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
[email protected]91484af2010-08-27 17:55:5453
[email protected]ccfab592013-01-15 06:24:3254// Remove the quarantine xattr from the given file. Returns false if there was
55// an error, or true otherwise.
56BASE_EXPORT bool RemoveQuarantineAttribute(const FilePath& file_path);
57
Avi Drissmanfc29fbd2024-01-22 21:37:2558// Sets the tags on a given file or folder.
59BASE_EXPORT void SetFileTags(const FilePath& file_path,
60 const std::vector<std::string>& file_tags);
61
Avi Drissman922a94f22023-08-28 23:43:4162// The following two functions return the version of the macOS currently
63// running. MacOSVersion() returns the full trio of version numbers, packed into
64// one int (e.g. macOS 12.6.5 returns 12'06'05), and MacOSMajorVersion() returns
65// only the major version number (e.g. macOS 12.6.5 returns 12). Use for runtime
66// OS version checking. Prefer to use @available in Objective-C files. Note that
67// this does not include any Rapid Security Response (RSR) suffixes (the "(a)"
68// at the end of version numbers.)
69BASE_EXPORT __attribute__((const)) int MacOSVersion();
70inline __attribute__((const)) int MacOSMajorVersion() {
71 return MacOSVersion() / 1'00'00;
72}
markfd1cb64d2016-07-08 19:58:5973
Avi Drissman07833802020-07-25 18:29:2374enum class CPUType {
75 kIntel,
76 kTranslatedIntel, // Rosetta
77 kArm,
78};
79
80// Returns the type of CPU this is being executed on.
81BASE_EXPORT CPUType GetCPUType();
82
Nicolas Ouellet-Payeurf5b3aa32019-06-11 00:50:2483// Returns an OS name + version string. e.g.:
84//
85// "macOS Version 10.14.3 (Build 18D109)"
86//
87// Parts of this string change based on OS locale, so it's only useful for
88// displaying to the user.
89BASE_EXPORT std::string GetOSDisplayName();
90
Tim Song3aa67792019-12-10 22:43:1391// Returns the serial number of the macOS device.
92BASE_EXPORT std::string GetPlatformSerialNumber();
93
Avi Drissman35b115d2022-11-01 19:28:5094// System Settings (née System Preferences) pane or subpanes to open via
95// `OpenSystemSettingsPane()`, below. The naming is based on the naming in the
96// System Settings app in the latest macOS release, macOS 13 Ventura.
97enum class SystemSettingsPane {
98 // Accessibility > Captions
99 kAccessibility_Captions,
100
101 // Date & Time
102 kDateTime,
103
104 // Network > Proxies
105 kNetwork_Proxies,
106
Marijn Kruisselbrink957a66c2024-02-22 21:26:45107 // Notifications; optionally pass a bundle identifier as `id_param` to
108 // directly open the notification settings page for the given app.
109 kNotifications,
110
Avi Drissman35b115d2022-11-01 19:28:50111 // Printers & Scanners
112 kPrintersScanners,
113
Muyao Xu6166dba72024-08-14 18:46:32114 // Privacy & Security
115 kPrivacySecurity,
116
Avi Drissman35b115d2022-11-01 19:28:50117 // Privacy & Security > Accessibility
118 kPrivacySecurity_Accessibility,
119
120 // Privacy & Security > Bluetooth
Avi Drissman35b115d2022-11-01 19:28:50121 kPrivacySecurity_Bluetooth,
122
123 // Privacy & Security > Camera
Avi Drissman35b115d2022-11-01 19:28:50124 kPrivacySecurity_Camera,
125
126 // Privacy & Security > Extensions > Sharing
127 kPrivacySecurity_Extensions_Sharing,
128
129 // Privacy & Security > Location Services
130 kPrivacySecurity_LocationServices,
131
132 // Privacy & Security > Microphone
Avi Drissman35b115d2022-11-01 19:28:50133 kPrivacySecurity_Microphone,
134
135 // Privacy & Security > Screen Recording
Avi Drissman35b115d2022-11-01 19:28:50136 kPrivacySecurity_ScreenRecording,
Charles Meng4a9eff0e2023-08-17 22:45:31137
138 // Trackpad
139 kTrackpad,
Avi Drissman35b115d2022-11-01 19:28:50140};
141
142// Opens the specified System Settings pane. If the specified subpane does not
143// exist on the release of macOS that is running, the parent pane will open
Marijn Kruisselbrink957a66c2024-02-22 21:26:45144// instead. For some panes, `id_param` can be used to specify a subpane. See the
145// various SystemSettingsPane values for details.
146BASE_EXPORT void OpenSystemSettingsPane(SystemSettingsPane pane,
147 const std::string& id_param = "");
Avi Drissman35b115d2022-11-01 19:28:50148
Avi Drissman922a94f22023-08-28 23:43:41149// ------- For testing --------
150
151// An implementation detail of `MacOSVersion()` above, exposed for testing.
152BASE_EXPORT int ParseOSProductVersionForTesting(
153 const std::string_view& version);
154
Avi Drissmanefca4122022-01-05 23:59:36155} // namespace base::mac
[email protected]455687952010-12-17 18:42:23156
[email protected]0378bf42011-01-01 18:20:14157#endif // BASE_MAC_MAC_UTIL_H_