1 /* 2 * Copyright (c) 2023 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 "ability_debug_deal.h" 17 18 #include "ability_record.h" 19 #include "hilog_wrapper.h" 20 21 namespace OHOS { 22 namespace AAFwk { RegisterAbilityDebugResponse()23void AbilityDebugDeal::RegisterAbilityDebugResponse() 24 { 25 abilityDebugResponse_ = new (std::nothrow) AbilityDebugResponse(weak_from_this()); 26 if (abilityDebugResponse_ == nullptr) { 27 HILOG_ERROR("Ability debug response is nullptr."); 28 return; 29 } 30 31 DelayedSingleton<AppScheduler>::GetInstance()->RegisterAbilityDebugResponse(abilityDebugResponse_); 32 } 33 OnAbilitysDebugStarted(const std::vector<sptr<IRemoteObject>> & tokens)34void AbilityDebugDeal::OnAbilitysDebugStarted(const std::vector<sptr<IRemoteObject>> &tokens) 35 { 36 HILOG_DEBUG("Called."); 37 for (auto &token : tokens) { 38 auto abilityRecord = Token::GetAbilityRecordByToken(token); 39 if (abilityRecord == nullptr) { 40 HILOG_ERROR("Ability record is nullptr."); 41 continue; 42 } 43 abilityRecord->SetAttachDebug(true); 44 } 45 } 46 OnAbilitysDebugStoped(const std::vector<sptr<IRemoteObject>> & tokens)47void AbilityDebugDeal::OnAbilitysDebugStoped(const std::vector<sptr<IRemoteObject>> &tokens) 48 { 49 HILOG_DEBUG("Called."); 50 for (auto &token : tokens) { 51 auto abilityRecord = Token::GetAbilityRecordByToken(token); 52 if (abilityRecord == nullptr) { 53 HILOG_ERROR("Ability record is nullptr."); 54 continue; 55 } 56 abilityRecord->SetAttachDebug(false); 57 } 58 } 59 OnAbilitysDebugStarted(const std::vector<sptr<IRemoteObject>> & tokens)60void AbilityDebugResponse::OnAbilitysDebugStarted(const std::vector<sptr<IRemoteObject>> &tokens) 61 { 62 if (tokens.empty()) { 63 HILOG_WARN("Tokens is empty."); 64 return; 65 } 66 67 auto deal = abilityDebugDeal_.lock(); 68 if (deal == nullptr) { 69 HILOG_ERROR("Ability debug deal object is nullptr."); 70 return; 71 } 72 deal->OnAbilitysDebugStarted(tokens); 73 } 74 OnAbilitysDebugStoped(const std::vector<sptr<IRemoteObject>> & tokens)75void AbilityDebugResponse::OnAbilitysDebugStoped(const std::vector<sptr<IRemoteObject>> &tokens) 76 { 77 if (tokens.empty()) { 78 HILOG_WARN("Tokens is empty."); 79 return; 80 } 81 82 auto deal = abilityDebugDeal_.lock(); 83 if (deal == nullptr) { 84 HILOG_ERROR("Ability debug deal object is nullptr."); 85 return; 86 } 87 deal->OnAbilitysDebugStoped(tokens); 88 } 89 } // namespace AAFwk 90 } // namespace OHOS 91