2 // KeychainSyncAccountNotification.m
6 #import "KeychainSyncAccountNotification.h"
7 #import <Accounts/ACLogging.h>
8 #import <Accounts/Accounts.h>
9 #import <Accounts/Accounts_Private.h>
11 #import <AppleAccount/ACAccount+AppleAccount.h>
13 #import <AOSAccounts/ACAccount+iCloudAccount.h>
15 #import <AccountsDaemon/ACDAccountStore.h>
16 #import <AccountsDaemon/ACDClientAuthorizationManager.h>
17 #import <AccountsDaemon/ACDClientAuthorization.h>
18 #import <Security/SOSCloudCircle.h>
20 @implementation KeychainSyncAccountNotification
23 - (bool)accountIsPrimary:(ACAccount *)account
26 return [account aa_isPrimaryAccount];
28 return [account icaIsPrimaryAccount];
32 - (BOOL)account:(ACAccount *)account willChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
34 if ((changeType == kACAccountChangeTypeDeleted) && [oldAccount.accountType.identifier isEqualToString:ACAccountTypeIdentifierAppleAccount]) {
35 if(oldAccount.identifier != NULL && oldAccount.username !=NULL){
37 if ([self accountIsPrimary:oldAccount]) {
39 CFErrorRef removalError = NULL;
41 ACLogDebug(@"Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
43 if (!SOSCCLoggedOutOfAccount(&removalError)) {
44 ACLogError(@"Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
47 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
51 ACLogDebug(@"Already logged out of account");
59 - (void)account:(ACAccount *)account didChangeWithType:(ACAccountChangeType)changeType inStore:(ACDAccountStore *)store oldAccount:(ACAccount *)oldAccount {
60 if (changeType == kACAccountChangeTypeDeleted) {
61 if (oldAccount.identifier != NULL && oldAccount.username != NULL){
63 if ([self accountIsPrimary:oldAccount]) {
64 CFErrorRef removalError = NULL;
65 ACLogDebug(@"Performing SOS circle credential removal for account %@: %@", oldAccount.identifier, oldAccount.username);
66 if (!SOSCCLoggedOutOfAccount(&removalError)) {
67 ACLogError(@"Account %@ could not leave the SOS circle: %@", oldAccount.identifier, removalError);
70 ACLogDebug(@"NOT performing SOS circle credential removal for secondary account %@: %@", account.identifier, account.username);
73 ACLogDebug(@"Already logged out of account");