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 "cb_start_ability.h" 17#include "os_account_manager.h" 18#include "ability_manager_client.h" 19#include "int_wrapper.h" 20#include "string_wrapper.h" 21#include "telephony_errors.h" 22#include "telephony_log_wrapper.h" 23#include "want.h" 24 25namespace OHOS { 26namespace Telephony { 27const std::string BUNDLE_NAME_BEGIN = "com.hua"; 28const std::string BUNDLE_NAME_END = "wei.hmos.cellbroadcast"; 29constexpr const char *ABILITY_NAME = "AlertService"; 30constexpr const char *MODULE_NAME = "entry"; 31static constexpr int32_t USER_ID = 100; 32 33CbStartAbility::~CbStartAbility() {} 34 35CbStartAbility::CbStartAbility() {} 36 37void CbStartAbility::StartAbility(AAFwk::Want &want) 38{ 39 std::vector<int> activatedOsAccountIds; 40 AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds); 41 TELEPHONY_LOGI("start cellbroadcast ability"); 42 want.SetElementName("", BUNDLE_NAME_BEGIN + BUNDLE_NAME_END, ABILITY_NAME, MODULE_NAME); 43 if (!activatedOsAccountIds.empty()) { 44 TELEPHONY_LOGI("the foreground OS account local ID: %{public}d", activatedOsAccountIds[0]); 45 ErrCode code = AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility(want, nullptr, 46 activatedOsAccountIds[0]); 47 TELEPHONY_LOGI("start ability code:%{public}d", code); 48 } else { 49 TELEPHONY_LOGI("the activatedOsAccountId is empty, input default userid: 100"); 50 ErrCode code = AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility(want, nullptr, USER_ID); 51 TELEPHONY_LOGI("start ability code:%{public}d", code); 52 } 53} 54} // namespace Telephony 55} // namespace OHOS 56