1 /*
2  * Copyright (c) 2022-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 "callback_death_recipients.h"
17 
18 #include "access_token.h"
19 #include "callback_manager.h"
20 #ifdef TOKEN_SYNC_ENABLE
21 #include "token_modify_notifier.h"
22 #endif // TOKEN_SYNC_ENABLE
23 
24 namespace OHOS {
25 namespace Security {
26 namespace AccessToken {
27 namespace {
28 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
29     LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "CallbackDeathRecipients"
30 };
31 }
32 
OnRemoteDied(const wptr<IRemoteObject> & remote)33 void PermStateCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
34 {
35     ACCESSTOKEN_LOG_INFO(LABEL, "Enter");
36     if (remote == nullptr) {
37         ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object is nullptr");
38         return;
39     }
40 
41     sptr<IRemoteObject> object = remote.promote();
42     if (object == nullptr) {
43         ACCESSTOKEN_LOG_ERROR(LABEL, "Object is nullptr");
44         return;
45     }
46     CallbackManager::GetInstance().RemoveCallback(object);
47     ACCESSTOKEN_LOG_INFO(LABEL, "End");
48 }
49 
50 #ifdef TOKEN_SYNC_ENABLE
OnRemoteDied(const wptr<IRemoteObject> & remote)51 void TokenSyncCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
52 {
53     ACCESSTOKEN_LOG_INFO(LABEL, "Call OnRemoteDied.");
54     if (remote == nullptr) {
55         ACCESSTOKEN_LOG_ERROR(LABEL, "Remote object is nullptr.");
56         return;
57     }
58     TokenModifyNotifier::GetInstance().UnRegisterTokenSyncCallback();
59     ACCESSTOKEN_LOG_INFO(LABEL, "Call UnRegisterTokenSyncCallback end.");
60 }
61 #endif // TOKEN_SYNC_ENABLE
62 } // namespace AccessToken
63 } // namespace Security
64 } // namespace OHOS
65