• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import SPLogger from './SPLogger';
16const TAG = 'AbilityUtils';
17/**
18 * 启动ability  since API8
19 * @param bundleName
20 * @param abilityName
21 */
22export function commonStartAbility(
23  bundleName: string,
24  abilityName: string,
25  parameters?: { [key: string]: unknown }
26): void {
27  SPLogger.INFO(
28    TAG,
29    'Operation bundleName:' +
30      bundleName +
31      'Operation abilityName:' +
32      abilityName
33  );
34  let str = {
35    bundleName: bundleName,
36    abilityName: abilityName,
37    parameters: parameters,
38  };
39  console.info(abilityName + ' Operation after. Cause:');
40  globalThis.abilityContext.startAbility(str, (err, data) => {
41    if (err) {
42      SPLogger.ERROR(
43        TAG,
44        abilityName + ' Operation failed. Cause:' + JSON.stringify(err)
45      );
46      return;
47    }
48    SPLogger.INFO(
49      TAG,
50      abilityName + ' Operation successful. Data: ' + JSON.stringify(data)
51    );
52  });
53}
54