1 /*
2 * Copyright (c) 2025 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_log_wrapper.h"
17 #include "os_account_state_subscriber.h"
18 #include "ios_account_state_reply_callback.h"
19 #include "ipc_skeleton.h"
20 #include "app_account_control_manager.h"
21
22 namespace OHOS {
23 namespace AccountSA {
24 namespace {
25 const uid_t ACCOUNT_UID = 3058;
26 }
OsAccountStateSubscriber()27 OsAccountStateSubscriber::OsAccountStateSubscriber()
28 {}
29
OnStateChanged(const OsAccountStateParcel & parcel)30 ErrCode OsAccountStateSubscriber::OnStateChanged(const OsAccountStateParcel &parcel)
31 {
32 ACCOUNT_LOGI("State: %{public}d, fromId: %{public}d, toId: %{public}d", parcel.state, parcel.fromId, parcel.toId);
33 if (parcel.state == OsAccountState::STOPPING) {
34 ACCOUNT_LOGI("Account stopping id=%{public}d", parcel.fromId);
35 AppAccountControlManager::GetInstance().OnUserStopping(parcel.fromId);
36 }
37 auto callback = iface_cast<IOsAccountStateReplyCallback>(parcel.callback);
38 if (callback == nullptr) {
39 ACCOUNT_LOGE("Callback is nullptr");
40 return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
41 }
42 callback->OnComplete();
43 return ERR_OK;
44 }
45
OnAccountsChanged(int32_t localId)46 ErrCode OsAccountStateSubscriber::OnAccountsChanged(int32_t localId)
47 {
48 return ERR_OK;
49 }
50
OnAccountsSwitch(int32_t newId,int32_t oldId)51 ErrCode OsAccountStateSubscriber::OnAccountsSwitch(int32_t newId, int32_t oldId)
52 {
53 return ERR_OK;
54 }
55
CallbackEnter(uint32_t code)56 ErrCode OsAccountStateSubscriber::CallbackEnter([[maybe_unused]] uint32_t code)
57 {
58 int32_t callingUid = IPCSkeleton::GetCallingUid();
59 if (callingUid != ACCOUNT_UID) {
60 ACCOUNT_LOGE("GetCallingUid failed, please check callingUid: %{public}d", callingUid);
61 return ERR_ACCOUNT_COMMON_PERMISSION_DENIED;
62 }
63 return ERR_OK;
64 }
65
CallbackExit(uint32_t code,int32_t result)66 ErrCode OsAccountStateSubscriber::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
67 {
68 return ERR_OK;
69 }
70 } // namespace AccountSA
71 } // namespace OHOS