2 // KeychainSyncAccountNotification.m
6 #import "KeychainSyncAccountNotification.h"
7 #import <Accounts/Accounts.h>
8 #import <Accounts/Accounts_Private.h>
10 #import <AppleAccount/ACAccount+AppleAccount.h>
12 #import <AOSAccounts/ACAccount+iCloudAccount.h>
14 #import <AccountsDaemon/ACDAccountStore.h>
15 #import <Security/SecureObjectSync/SOSCloudCircle.h>
17 #import "utilities/debugging.h"
19 @implementation KeychainSyncAccountNotification
21 - (bool)accountIsPrimary:(ACAccount *)account
24 return [account aa_isPrimaryAccount];
26 return [account icaIsPrimaryAccount];
30 - (BOOL)account:(ACAccount *)account willChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
31 NSString* oldAccountIdentifier = oldAccount.identifier;
32 NSString* accountIdentifier = account.identifier;
34 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
35 if(oldAccountIdentifier != NULL && oldAccount.username !=NULL) {
36 if ([self accountIsPrimary:oldAccount]) {
37 CFErrorRef removalError = NULL;
39 secinfo("accounts", "Performing SOS circle credential removal for account %@: %@", oldAccountIdentifier, oldAccount.username);
41 if (!SOSCCLoggedOutOfAccount(&removalError)) {
42 secerror("Account %@ could not leave the SOS circle: %@", oldAccountIdentifier, removalError);
45 secinfo("accounts", "NOT performing SOS circle credential removal for secondary account %@: %@", accountIdentifier, account.username);
48 secinfo("accounts", "Already logged out of account");