• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     newWant.SetAction(SETTINGS_ACTION);
36     newWant.SetParam(SETTINGS_PARAM_BUNDLE_NAME, bundleName);
37     ErrCode errCode = AbilityManagerClient::GetInstance()->StartAbility(newWant);
38     if (errCode != ERR_OK) {
39         APP_LOGE("AppDetailAbility bundleName: %{public}s start ability failed, errCode: %{public}d",
40             want.GetBundle().c_str(), errCode);
41     }
42     errCode = TerminateAbility();
43     if (errCode != ERR_OK) {
44         APP_LOGE("AppDetailAbility bundleName: %{public}s terminate ability failed, errCode: %{public}d",
45             want.GetBundle().c_str(), errCode);
46         return;
47     }
48     APP_LOGD("AppDetailAbility::OnStart end.");
49 }
50 
51 REGISTER_AA(AppDetailAbility)
52 }  // namespace AppExecFwk
53 }  // namespace OHOS