• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 { BusinessError, AsyncCallback } from '@ohos.base';
16import Want from '@ohos.app.ability.Want';
17import ExtensionContext from 'application.ExtensionContext';
18import hilog from '@ohos.hilog';
19
20const TAG: string = 'commonEventManager';
21
22type ResolveCallback<T> = (data: T) => void;
23type RejectCallback = (err: Error) => void;
24
25loadLibrary("ani_commoneventmanager.z");
26export class StaticSubscriberExtensionContext extends ExtensionContext {
27    nativeStaticSubscriberExtensionContext: long = 0;
28    native nativeStartAbilitySync(want: Want): void;
29
30    startAbility(want: Want, callback: AsyncCallback<void, void>): void {
31        let task = taskpool.execute(this.nativeStartAbilitySync, want);
32        task.then((e: NullishType)=>{
33          callback(null, undefined);
34      }, (error: Object): void => {
35          let err: BusinessError = error as BusinessError;
36          callback(err, undefined);
37      });
38    }
39
40    startAbility(want: Want): Promise<void> {
41      let pPromise = new Promise<void>((resolve: ResolveCallback<void>, reject: RejectCallback): void => {
42      let task = taskpool.execute(this.nativeStartAbilitySync, want);
43      task.then((e: NullishType): void => {
44          resolve(undefined);
45      }, (error: Error): void => {
46          hilog.error(0xD001202, TAG, 'nativeStartAbilitySync Promise error');
47          reject(error);
48      });
49  });
50      return pPromise;
51  }
52}