2 * Copyright (c) 2020 Apple Inc. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #import "setup_assistant_helper.h"
19 #import <SoftLinking/SoftLinking.h>
23 #import <SetupAssistantFramework/SAUserSetupState.h>
24 #import <SystemConfiguration/SystemConfiguration.h>
26 SOFT_LINK_FRAMEWORK(PrivateFrameworks, SetupAssistantFramework)
27 SOFT_LINK_CLASS(SetupAssistantFramework, SAUserSetupState)
29 #endif // TARGET_OS_OSX
32 static uid_t s_last_uid = 0;
34 _update_console_user_id(void)
36 CFStringRef userName = SCDynamicStoreCopyConsoleUser(NULL, &s_last_uid, NULL);
41 #endif // TARGET_OS_OSX
44 assistant_helper_get_buddy_state(void)
47 buddy_state_t buddy_state = buddy_state_indeterminate;
48 _update_console_user_id();
49 SAUserSetupStateEnum state = [SAUserSetupState getSetupStateForUser:s_last_uid];
51 case SAUserSetupStateSetupDone:
52 buddy_state = buddy_state_done;
55 case SAUserSetupStateSetupUser:
56 case SAUserSetupStateSetupInProcess:
57 buddy_state = buddy_state_in_process;
60 case SAUserSetupStateIndeterminate:
62 buddy_state = buddy_state_indeterminate;
67 return buddy_state_done;
68 #endif // TARGET_OS_OSX
72 assistant_helper_notify_when_buddy_done(buddy_done_handler_t handler)
75 [SAUserSetupState notifyWhenUserIsSetup:s_last_uid withCompletionBlock:handler];
78 #endif // TARGET_OS_OSX