1 /* 2 * Copyright (c) 2020 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_list.h" 17 18 #include <cstring> 19 20 #include "ability_record.h" 21 22 namespace OHOS { Add(AbilityRecord * abilityRecord)23void AbilityList::Add(AbilityRecord *abilityRecord) 24 { 25 if (abilityRecord == nullptr) { 26 return; 27 } 28 29 if (Get(abilityRecord->GetToken()) == nullptr) { 30 abilityList_.PushBack(abilityRecord); 31 } 32 } 33 Get(uint16_t token) const34AbilityRecord *AbilityList::Get(uint16_t token) const 35 { 36 for (auto node = abilityList_.Begin(); node != abilityList_.End(); node = node->next_) { 37 AbilityRecord *record = node->value_; 38 if (record == nullptr) { 39 continue; 40 } 41 if (record->GetToken() == token) { 42 return record; 43 } 44 } 45 46 return nullptr; 47 } 48 Get(const char * bundleName) const49AbilityRecord *AbilityList::Get(const char *bundleName) const 50 { 51 if (bundleName == nullptr) { 52 return nullptr; 53 } 54 55 for (auto node = abilityList_.Begin(); node != abilityList_.End(); node = node->next_) { 56 AbilityRecord *record = node->value_; 57 if (record == nullptr || record->GetAppName() == nullptr) { 58 continue; 59 } 60 if (strcmp(bundleName, record->GetAppName()) == 0) { 61 return record; 62 } 63 } 64 65 return nullptr; 66 } 67 Erase(uint16_t token)68void AbilityList::Erase(uint16_t token) 69 { 70 for (auto node = abilityList_.Begin(); node != abilityList_.End(); node = node->next_) { 71 AbilityRecord *record = node->value_; 72 if (record == nullptr) { 73 continue; 74 } 75 if (record->GetToken() == token) { 76 abilityList_.Remove(node); 77 return; 78 } 79 } 80 } 81 } // namespace OHOS 82