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