diff --git a/frameworks/ets/ets/@ohos.app.ability.abilityManager.ets b/frameworks/ets/ets/@ohos.app.ability.abilityManager.ets index 646d8c5652321e72341baa6a270f5e1328a91f85..5d99a8c6839a1cc1a5c404e2668639d9c6732ebc 100644 --- a/frameworks/ets/ets/@ohos.app.ability.abilityManager.ets +++ b/frameworks/ets/ets/@ohos.app.ability.abilityManager.ets @@ -206,11 +206,11 @@ export default namespace abilityManager { }); } - export function on(type: 'abilityForegroundState', observer: AbilityForegroundStateObserver): void { + export function onAbilityForegroundState(observer: AbilityForegroundStateObserver): void { abilityManager.nativeOn('abilityForegroundState', observer); } - export function off(type: 'abilityForegroundState', observer?: AbilityForegroundStateObserver): void { + export function offAbilityForegroundState(observer?: AbilityForegroundStateObserver): void { abilityManager.nativeOff('abilityForegroundState', observer); } diff --git a/frameworks/ets/ets/@ohos.app.ability.appManager.ets b/frameworks/ets/ets/@ohos.app.ability.appManager.ets index 8e2a1b28dae9373cd7cc684f476fb1ae0941a8fa..53ffaaae09384339460f0ad7ce3da7dbab8ae4ae 100644 --- a/frameworks/ets/ets/@ohos.app.ability.appManager.ets +++ b/frameworks/ets/ets/@ohos.app.ability.appManager.ets @@ -220,25 +220,25 @@ export function getRunningProcessInfoByBundleName(bundleName: string, userId: in export native function nativeOn(type: string, observer: ApplicationStateObserver, bundleNameList?: Array) : int; export native function nativeOn(type: string, observer: ApplicationStateObserver) : int; -export function on(type: 'applicationState', observer: ApplicationStateObserver): int { +export function onApplicationState(observer: ApplicationStateObserver): int { return appManager.nativeOn('applicationState', observer); } -export function on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array): int { +export function onApplicationState(observer: ApplicationStateObserver, bundleNameList: Array): int { return appManager.nativeOn('applicationState', observer, bundleNameList); } export native function nativeOff(type:string, observerId: int, callback: AsyncCallbackWrapper) : void; export native function nativeOffApplicationStateCheck(observerId: int): void; -export function off(type: 'applicationState', observerId: int, callback: AsyncCallback): void { +export function offApplicationState(observerId: int, callback: AsyncCallback): void { nativeOffApplicationStateCheck(observerId); let myCall = new AsyncCallbackWrapper(callback); taskpool.execute((): void => { - appManager.nativeOff(type, observerId, myCall); + appManager.nativeOff('applicationState', observerId, myCall); }); } -export function off(type: 'applicationState', observerId: int): Promise { +export function offApplicationState(observerId: int): Promise { nativeOffApplicationStateCheck(observerId); let p:Promise = new Promise((resolve: (data:undefined)=>void, reject:(err: BusinessError | null)=>void):void => { let myCall = new AsyncCallbackWrapper((err: BusinessError | null)=>{ @@ -249,7 +249,7 @@ export function off(type: 'applicationState', observerId: int): Promise { } }); taskpool.execute((): void => { - appManager.nativeOff(type, observerId, myCall); + appManager.nativeOff('applicationState', observerId, myCall); }); }); return p; @@ -365,22 +365,22 @@ export function killProcessesByBundleName(bundleName: string, clearPageStack: bo } export native function nativeOnAbilityFirstFrameState(type: string, observer: AbilityFirstFrameStateObserver, bundleName?: string) : void; -export function on(type: 'abilityFirstFrameState', observer: AbilityFirstFrameStateObserver, bundleName?: string) : void { +export function onAbilityFirstFrameState(observer: AbilityFirstFrameStateObserver, bundleName?: string) : void { appManager.nativeOnAbilityFirstFrameState('abilityFirstFrameState', observer, bundleName); } export native function nativeOffAbilityFirstFrameState(type: string, observer?: AbilityFirstFrameStateObserver) : void; -export function off(type: 'abilityFirstFrameState', observer?: AbilityFirstFrameStateObserver) : void { +export function offAbilityFirstFrameState(observer?: AbilityFirstFrameStateObserver) : void { appManager.nativeOffAbilityFirstFrameState('abilityFirstFrameState', observer); } export native function nativeOnAppForeGroundState(type: string, observer: AppForegroundStateObserver) : void; -export function on(type: 'appForegroundState', observer: AppForegroundStateObserver) : void { +export function onAppForegroundState(observer: AppForegroundStateObserver) : void { appManager.nativeOnAppForeGroundState('appForegroundState', observer); } export native function nativeOffAppForeGroundState(type: string, observer?: AppForegroundStateObserver) : void; -export function off(type: 'appForegroundState', observer?: AppForegroundStateObserver) : void { +export function offAppForegroundState(observer?: AppForegroundStateObserver) : void { appManager.nativeOffAppForeGroundState('appForegroundState', observer); } diff --git a/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets b/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets index 40e7ec55260ae192b340a9f2a814e45ab7e863fd..f7a1ff4e4a8885a190ba8c77ce3d18a731d10698 100644 --- a/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets +++ b/frameworks/ets/ets/@ohos.app.ability.autoStartupManager.ets @@ -27,11 +27,11 @@ export default namespace autoStartupManager { export native function nativeCancelApplicationAutoStartup(info: AutoStartupInfo, callback: AsyncCallbackWrapper): void; export native function nativeQueryAllAutoStartupApplications(callback: AsyncCallbackWrapper>): void; - export function on(type: 'systemAutoStartup', callback: AutoStartupCallback): void { + export function onSystemAutoStartup(callback: AutoStartupCallback): void { autoStartupManager.nativeOnApplicationAutoStartupStateChangeSync('systemAutoStartup', callback); } - export function off(type: 'systemAutoStartup', callback?: AutoStartupCallback): void { + export function offSystemAutoStartup(callback?: AutoStartupCallback): void { autoStartupManager.nativeOffApplicationAutoStartupStateChangeSync('systemAutoStartup', callback); } diff --git a/frameworks/ets/ets/@ohos.app.ability.missionManager.ets b/frameworks/ets/ets/@ohos.app.ability.missionManager.ets index 99f6e481cf8e2e928e97bbe0d79efe468ac56670..0973ea4282c88838b2fa77b5bc1e1bd09d98ea26 100644 --- a/frameworks/ets/ets/@ohos.app.ability.missionManager.ets +++ b/frameworks/ets/ets/@ohos.app.ability.missionManager.ets @@ -336,18 +336,18 @@ export function getMissionInfos(deviceId: string, numMax: int, callback: AsyncCa return p; } - export function on(type: 'mission', listener: MissionListener): long { + export function onMission(listener: MissionListener): long { return missionManager.nativeOn('mission', listener); } - export function off(type: 'mission', listenerId: long, callback: AsyncCallback): void { + export function offMission(listenerId: long, callback: AsyncCallback): void { let myCall = new AsyncCallbackWrapper(callback); taskpool.execute((): void => { - missionManager.nativeOff(type, listenerId, myCall); + missionManager.nativeOff('mission', listenerId, myCall); }); } - export function off(type: 'mission', listenerId: long): Promise { + export function offMission(listenerId: long): Promise { let p: Promise = new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError | null) => void): void => { let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { @@ -358,7 +358,7 @@ export function getMissionInfos(deviceId: string, numMax: int, callback: AsyncCa } }); taskpool.execute((): void => { - missionManager.nativeOff(type, listenerId, myCall); + missionManager.nativeOff('mission', listenerId, myCall); }); }); return p; diff --git a/frameworks/ets/ets/application/ApplicationContext.ets b/frameworks/ets/ets/application/ApplicationContext.ets index 2b671931462a47951f44cc5ca3ca7ac855b3bc55..1aaf6c3588e27c933cb47932d4b94ae5bad0715b 100644 --- a/frameworks/ets/ets/application/ApplicationContext.ets +++ b/frameworks/ets/ets/application/ApplicationContext.ets @@ -237,22 +237,25 @@ export default class ApplicationContext extends Context { return p; } - on(type: 'environment', callback: EnvironmentCallback): int { + onEnvironment(callback: EnvironmentCallback): int { return this.nativeOnEnvironmentSync(callback); } - off(type: string, callbackId: int, callback: AsyncCallback): void { + offEnvironment(callbackId: int, callback: AsyncCallback): void { let myCall = new AsyncCallbackWrapper(callback); taskpool.execute((): void => { - if (type == 'environment') { - this.nativeOffEnvironmentSync(callbackId, myCall); - } else if (type == 'abilityLifecycle') { - this.nativeOffLifecycleCallbackSync(type, callbackId, myCall); - } + this.nativeOffEnvironmentSync(callbackId, myCall); }); } - off(type: string, callbackId: int): Promise { + offAbilityLifecycle(callbackId: int, callback: AsyncCallback): void { + let myCall = new AsyncCallbackWrapper(callback); + taskpool.execute((): void => { + this.nativeOffLifecycleCallbackSync('abilityLifecycle', callbackId, myCall); + }); + } + + offEnvironment(callbackId: int): Promise { let p = new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { @@ -263,21 +266,34 @@ export default class ApplicationContext extends Context { } }); taskpool.execute((): void => { - if (type == 'environment') { - this.nativeOffEnvironmentSync(callbackId, myCall); - } else if (type == 'abilityLifecycle') { - this.nativeOffLifecycleCallbackSync(type, callbackId, myCall); + this.nativeOffEnvironmentSync(callbackId, myCall); + }); + }); + return p; + } + + offAbilityLifecycle(callbackId: int): Promise { + let p = + new Promise((resolve: (data: undefined) => void, reject: (err: BusinessError) => void): void => { + let myCall = new AsyncCallbackWrapper((err: BusinessError | null) => { + if (err == null || err.code == 0) { + resolve(undefined); + } else { + reject(err); } }); + taskpool.execute((): void => { + this.nativeOffLifecycleCallbackSync('abilityLifecycle', callbackId, myCall); + }); }); return p; } - on(type: 'applicationStateChange', callback: ApplicationStateChangeCallback): void { + onApplicationStateChange(callback: ApplicationStateChangeCallback): void { this.nativeOnApplicationStateChangeSync(callback); } - off(type: 'applicationStateChange', callback?: ApplicationStateChangeCallback): void { + offApplicationStateChange(callback?: ApplicationStateChangeCallback): void { this.nativeOffApplicationStateChangeSync(callback); } @@ -304,16 +320,16 @@ export default class ApplicationContext extends Context { return ApplicationContext.nativeTransferDynamic(input).unwrap(); } - on(type: 'abilityLifecycle', callback: AbilityLifecycleCallback): int { - return this.nativeOnLifecycleCallbackSync(type, callback); + onAbilityLifecycle(callback: AbilityLifecycleCallback): int { + return this.nativeOnLifecycleCallbackSync('abilityLifecycle', callback); } public native nativeOnInteropLifecycleCallbackSync(type: string, callback: InteropAbilityLifecycleCallback): void; public native nativeOffInteropLifecycleCallbackSync(type: string, callback?: InteropAbilityLifecycleCallback): void; - on(type: 'interopAbilityLifecycle', callback: InteropAbilityLifecycleCallback): void { - this.nativeOnInteropLifecycleCallbackSync(type, callback); + onInteropAbilityLifecycle(callback: InteropAbilityLifecycleCallback): void { + this.nativeOnInteropLifecycleCallbackSync('interopAbilityLifecycle', callback); } - off(type: 'interopAbilityLifecycle', callback?: InteropAbilityLifecycleCallback): void { - this.nativeOffInteropLifecycleCallbackSync(type, callback); + offInteropAbilityLifecycle(callback?: InteropAbilityLifecycleCallback): void { + this.nativeOffInteropLifecycleCallbackSync('interopAbilityLifecycle', callback); } } diff --git a/frameworks/ets/ets/application/Caller.ets b/frameworks/ets/ets/application/Caller.ets index d529b527891ad5a6414927fea4c2a54ffa044fb8..ecced75068b0027004f25cbd8dcece6b576e5501 100644 --- a/frameworks/ets/ets/application/Caller.ets +++ b/frameworks/ets/ets/application/Caller.ets @@ -238,14 +238,11 @@ export class CallerImpl implements Caller { } this.onRelease(callback); } - off(type: string, callback: OnReleaseCallback): void { + offRelease(callback: OnReleaseCallback): void { hilog.info(domainID, TAG, 'off called'); - if (type != 'release') { - throw buildInvalidParamError('Parameter error: Failed to get type, must be string type release.'); - } // do nothing } - off(type: string): void { + offRelease(): void { hilog.info(domainID, TAG, 'off called'); // do nothing }