1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "account_change_event.h" 17 18 #include "account_sync.h" 19 #include "common.h" 20 #include "contacts_string_utils.h" 21 #include "hilog_wrapper.h" 22 23 namespace OHOS { 24 namespace Contacts { AccountChangeEvent(const OHOS::EventFwk::CommonEventSubscribeInfo & sp)25AccountChangeEvent::AccountChangeEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) 26 { 27 } 28 ~AccountChangeEvent()29AccountChangeEvent::~AccountChangeEvent() 30 { 31 } 32 OnReceiveEvent(const OHOS::EventFwk::CommonEventData & data)33void AccountChangeEvent::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) 34 { 35 std::shared_ptr<AccountSync> accountSync = AccountSync::GetInstance(); 36 std::vector<OHOS::AccountSA::OhosAccountInfo> sysAccounts; 37 std::vector<std::string> accountObjVec = ContactsStringUtils::SplitStr(data.GetData(), SPLIT_SYMBOL_VERTICAL); 38 for (size_t i = 0; i < accountObjVec.size(); i++) { 39 std::vector<std::string> accountObj = ContactsStringUtils::SplitStr(accountObjVec[i], SPLIT_SYMBOL_COMMA); 40 OHOS::AccountSA::OhosAccountInfo var; 41 var.name_ = accountObj[0]; 42 var.uid_ = accountObj[1]; 43 sysAccounts.push_back(var); 44 } 45 accountSync->SyncUpdateAccount(sysAccounts, true); 46 HILOG_INFO("AccountChangeEvent OnReceiveEvent update profile successful"); 47 accountSync->SyncUpdateAccount(sysAccounts, false); 48 HILOG_INFO("AccountChangeEvent OnReceiveEvent update local successful"); 49 } 50 } // namespace Contacts 51 } // namespace OHOS