1115cd2caSopenharmony_ci/*
2115cd2caSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3115cd2caSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4115cd2caSopenharmony_ci * you may not use this file except in compliance with the License.
5115cd2caSopenharmony_ci * You may obtain a copy of the License at
6115cd2caSopenharmony_ci *
7115cd2caSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8115cd2caSopenharmony_ci *
9115cd2caSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10115cd2caSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11115cd2caSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12115cd2caSopenharmony_ci * See the License for the specific language governing permissions and
13115cd2caSopenharmony_ci * limitations under the License.
14115cd2caSopenharmony_ci */
15115cd2caSopenharmony_ci
16115cd2caSopenharmony_ci#include "account_change_event.h"
17115cd2caSopenharmony_ci
18115cd2caSopenharmony_ci#include "account_sync.h"
19115cd2caSopenharmony_ci#include "common.h"
20115cd2caSopenharmony_ci#include "contacts_string_utils.h"
21115cd2caSopenharmony_ci#include "hilog_wrapper.h"
22115cd2caSopenharmony_ci
23115cd2caSopenharmony_cinamespace OHOS {
24115cd2caSopenharmony_cinamespace Contacts {
25115cd2caSopenharmony_ciAccountChangeEvent::AccountChangeEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
26115cd2caSopenharmony_ci{
27115cd2caSopenharmony_ci}
28115cd2caSopenharmony_ci
29115cd2caSopenharmony_ciAccountChangeEvent::~AccountChangeEvent()
30115cd2caSopenharmony_ci{
31115cd2caSopenharmony_ci}
32115cd2caSopenharmony_ci
33115cd2caSopenharmony_civoid AccountChangeEvent::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
34115cd2caSopenharmony_ci{
35115cd2caSopenharmony_ci    std::shared_ptr<AccountSync> accountSync = AccountSync::GetInstance();
36115cd2caSopenharmony_ci    std::vector<OHOS::AccountSA::OhosAccountInfo> sysAccounts;
37115cd2caSopenharmony_ci    std::vector<std::string> accountObjVec = ContactsStringUtils::SplitStr(data.GetData(), SPLIT_SYMBOL_VERTICAL);
38115cd2caSopenharmony_ci    for (size_t i = 0; i < accountObjVec.size(); i++) {
39115cd2caSopenharmony_ci        std::vector<std::string> accountObj = ContactsStringUtils::SplitStr(accountObjVec[i], SPLIT_SYMBOL_COMMA);
40115cd2caSopenharmony_ci        OHOS::AccountSA::OhosAccountInfo var;
41115cd2caSopenharmony_ci        var.name_ = accountObj[0];
42115cd2caSopenharmony_ci        var.uid_ = accountObj[1];
43115cd2caSopenharmony_ci        sysAccounts.push_back(var);
44115cd2caSopenharmony_ci    }
45115cd2caSopenharmony_ci    accountSync->SyncUpdateAccount(sysAccounts, true);
46115cd2caSopenharmony_ci    HILOG_INFO("AccountChangeEvent OnReceiveEvent update profile successful");
47115cd2caSopenharmony_ci    accountSync->SyncUpdateAccount(sysAccounts, false);
48115cd2caSopenharmony_ci    HILOG_INFO("AccountChangeEvent OnReceiveEvent update local successful");
49115cd2caSopenharmony_ci}
50115cd2caSopenharmony_ci} // namespace Contacts
51115cd2caSopenharmony_ci} // namespace OHOS