1 /*
2 * Copyright (c) 2022-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 #include "app_detail_ability.h"
16
17 #include "ability_loader.h"
18 #include "ability_manager_client.h"
19 #include "app_log_wrapper.h"
20 #include "element_name.h"
21 #include "session_info.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 constexpr const char* SETTINGS_ACTION = "action.settings.app.info";
27 constexpr const char* SETTINGS_PARAM_BUNDLE_NAME = "settingsParamBundleName";
28 }
29
OnStart(const Want & want,sptr<AAFwk::SessionInfo> sessionInfo)30 void AppDetailAbility::OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
31 {
32 std::string bundleName = want.GetBundle();
33 APP_LOGD("AppDetailAbility::OnStart, bundleName: %{public}s", bundleName.c_str());
34 Want newWant;
35 if (sessionInfo != nullptr) {
36 sessionToken_ = sessionInfo->sessionToken;
37 }
38 newWant.SetAction(SETTINGS_ACTION);
39 newWant.SetParam(SETTINGS_PARAM_BUNDLE_NAME, bundleName);
40 ErrCode errCode = AbilityManagerClient::GetInstance()->StartAbility(newWant);
41 if (errCode != ERR_OK) {
42 APP_LOGE("AppDetailAbility bundleName: %{public}s start ability failed, errCode: %{public}d",
43 want.GetBundle().c_str(), errCode);
44 }
45 errCode = TerminateAbility();
46 if (errCode != ERR_OK) {
47 APP_LOGE("AppDetailAbility bundleName: %{public}s terminate ability failed, errCode: %{public}d",
48 want.GetBundle().c_str(), errCode);
49 return;
50 }
51 APP_LOGD("AppDetailAbility::OnStart end");
52 }
53
54 REGISTER_AA(AppDetailAbility)
55 } // namespace AppExecFwk
56 } // namespace OHOS