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