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