1 /*
2 * Copyright (c) 2024 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 "driver_os_account_subscriber.h"
17 #include "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace ExternalDeviceManager {
DriverOsAccountSwitched(const OsAccountSubscribeInfo & subscribeInfo,sptr<DrvBundleStateCallback> callback)21 DriverOsAccountSwitched::DriverOsAccountSwitched(const OsAccountSubscribeInfo &subscribeInfo,
22 sptr<DrvBundleStateCallback> callback)
23 : OsAccountSubscriber(subscribeInfo)
24 {
25 bundleStateCallback_ = callback;
26 }
27
OnAccountsChanged(const int & id)28 void DriverOsAccountSwitched::OnAccountsChanged(const int &id)
29 {
30 EDM_LOGI(MODULE_PKG_MGR, "DriverOsAccountSwitched::OnAccountsChanged, id=%{public}d", id);
31 }
32
OnAccountsSwitch(const int & newId,const int & oldId)33 void DriverOsAccountSwitched::OnAccountsSwitch(const int &newId, const int &oldId)
34 {
35 EDM_LOGI(MODULE_PKG_MGR, "OnAccountsSwitched, newId=%{public}d, oldId=%{public}d", newId, oldId);
36 if (bundleStateCallback_ == nullptr) {
37 EDM_LOGE(MODULE_PKG_MGR, "OnAccountsSwitched bundleStateCallback_ is null");
38 return;
39 }
40 bundleStateCallback_->ResetInitOnce();
41 bundleStateCallback_->GetAllDriverInfosAsync(true);
42 }
43
DriverOsAccountSwitching(const OsAccountSubscribeInfo & subscribeInfo,sptr<DrvBundleStateCallback> callback)44 DriverOsAccountSwitching::DriverOsAccountSwitching(const OsAccountSubscribeInfo &subscribeInfo,
45 sptr<DrvBundleStateCallback> callback)
46 : OsAccountSubscriber(subscribeInfo)
47 {
48 bundleStateCallback_ = callback;
49 }
50
OnAccountsChanged(const int & id)51 void DriverOsAccountSwitching::OnAccountsChanged(const int &id)
52 {
53 EDM_LOGI(MODULE_PKG_MGR, "DriverOsAccountSwitching::OnAccountsChanged, id=%{public}d", id);
54 }
55
OnAccountsSwitch(const int & newId,const int & oldId)56 void DriverOsAccountSwitching::OnAccountsSwitch(const int &newId, const int &oldId)
57 {
58 EDM_LOGI(MODULE_PKG_MGR, "OnAccountsSwitching, newId=%{public}d, oldId=%{public}d", newId, oldId);
59 if (bundleStateCallback_ == nullptr) {
60 EDM_LOGE(MODULE_PKG_MGR, "OnAccountsSwitching bundleStateCallback_ is null");
61 return;
62 }
63 bundleStateCallback_->ResetMatchedBundles(oldId);
64 }
65 }
66 }