提交 3f5ae173 编写于 作者: X xinking129

modify format

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 44c09795
...@@ -25,22 +25,26 @@ let commonEventData = { ...@@ -25,22 +25,26 @@ let commonEventData = {
}; };
let onForeGroundTAG = -1; let onForeGroundTAG = -1;
let TAG = 'StateChangeTestTAG'; let TAG = 'StateChangeTestTAG';
let delayTime_500 = 500;
let delayTime_1000 = 1000;
let delayTime_2000 = 2000;
let undefineTag = -1;
let defineTag = 1;
let applicationStateChangeCallbackFir = { let applicationStateChangeCallbackFir = {
onApplicationForeground() { onApplicationForeground() {
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground'); console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground');
commonEventData.parameters.commonStateArr[0] = 1; commonEventData.parameters.commonStateArr[0] = defineTag;
setTimeout(() => { setTimeout(() => {
console.info('Enter onApplicationForeground publish!') console.info('Enter onApplicationForeground publish!');
commonEvent.publish('processState', commonEventData, (err) => { commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err)); console.info('====>processState publish err: ' + JSON.stringify(err));
}) });
}, 1000); }, delayTime_1000);
}, },
onApplicationBackground() { onApplicationBackground() {
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground'); console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
commonEventData.parameters.commonStateArr[1] = 1; commonEventData.parameters.commonStateArr[1] = defineTag;
if (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister') { if (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister') {
console.info('entered needbackgroundoff!'); console.info('entered needbackgroundoff!');
...@@ -52,30 +56,30 @@ let applicationStateChangeCallbackFir = { ...@@ -52,30 +56,30 @@ let applicationStateChangeCallbackFir = {
let applicationStateChangeCallbackSec = { let applicationStateChangeCallbackSec = {
onApplicationForeground() { onApplicationForeground() {
console.log(TAG, 'applicationStateChangeCallbackSec onApplicationForeground'); console.log(TAG, 'applicationStateChangeCallbackSec onApplicationForeground');
commonEventData.parameters.commonStateArr[2] = 1; commonEventData.parameters.commonStateArr[2] = defineTag;
}, },
onApplicationBackground() { onApplicationBackground() {
console.log(TAG, 'applicationStateChangeCallbackSec onApplicationBackground'); console.log(TAG, 'applicationStateChangeCallbackSec onApplicationBackground');
commonEventData.parameters.commonStateArr[3] = 1; commonEventData.parameters.commonStateArr[3] = defineTag;
if (globalThis.want.action === 'doubleNeedBackGroundOff') { if (globalThis.want.action === 'doubleNeedBackGroundOff') {
setTimeout(() => { setTimeout(() => {
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackSec); globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackSec);
}, 500); }, delayTime_500);
} }
else if (globalThis.want.action === 'DoubleRegisterOff') { else if (globalThis.want.action === 'DoubleRegisterOff') {
setTimeout(() => { setTimeout(() => {
console.info('entered DoubleRegisterOff'); console.info('entered DoubleRegisterOff');
globalThis.applicationContext.off('applicationStateChange'); globalThis.applicationContext.off('applicationStateChange');
}, 500); }, delayTime_500);
} }
} }
} };
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
onForeGroundTAG = -1; onForeGroundTAG = undefineTag;
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
commonStateArr[i] = -1 commonStateArr[i] = undefineTag;
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
...@@ -89,9 +93,9 @@ export default class EntryAbility extends Ability { ...@@ -89,9 +93,9 @@ export default class EntryAbility extends Ability {
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackFir); globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackFir);
} }
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackFir); globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackFir);
if (globalThis.want.action === 'doubleRegister' || globalThis.want.action === 'doubleNeedBackGroundOff'|| if (globalThis.want.action === 'doubleRegister' || globalThis.want.action === 'doubleNeedBackGroundOff'||
globalThis.want.action === 'DoubleRegisterOff') { globalThis.want.action === 'DoubleRegisterOff') {
console.info("double in action is logic entered!"); console.info('double in action is logic entered!');
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec); globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec);
} }
...@@ -129,13 +133,13 @@ export default class EntryAbility extends Ability { ...@@ -129,13 +133,13 @@ export default class EntryAbility extends Ability {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Abilityone onForeground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Abilityone onForeground');
onForeGroundTAG += 1; onForeGroundTAG += 1;
if (onForeGroundTAG === 1 && (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister'|| if (onForeGroundTAG === 1 && (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister'||
globalThis.want.action === 'DoubleRegisterOff')) { globalThis.want.action === 'DoubleRegisterOff')) {
setTimeout(() => { setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => { commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err)); console.info('====>processState publish err: ' + JSON.stringify(err));
}) });
}, 2000); }, delayTime_2000);
} }
} }
......
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
*/ */
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'; import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window'; import type Window from '@ohos.window';
import commonEvent from '@ohos.commonEvent'; import commonEvent from '@ohos.commonEvent';
let TAG = 'getRunningProcess'; let TAG = 'getRunningProcess';
let commonStateArr; let commonStateArr;
let delayTime_3000 = 3000;
let delayTime_1000 = 1000;
let commonEventData = { let commonEventData = {
parameters: { parameters: {
commonStateArr: commonStateArr commonStateArr: commonStateArr
...@@ -36,15 +38,15 @@ let applicationStateChangeCallbackFir = { ...@@ -36,15 +38,15 @@ let applicationStateChangeCallbackFir = {
commonEventData.parameters.commonStateArr = 1; commonEventData.parameters.commonStateArr = 1;
commonEvent.publish('processState', commonEventData, (err) => { commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err)); console.info('====>processState publish err: ' + JSON.stringify(err));
}) });
}, 1000); }, delayTime_1000);
} }
} };
let ForegroundTAG = -1; let foregroundTAG = -1;
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
ForegroundTAG = -1; foregroundTAG = -1;
commonEventData.parameters.commonStateArr = -1; commonEventData.parameters.commonStateArr = -1;
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
...@@ -86,13 +88,13 @@ export default class EntryAbility extends Ability { ...@@ -86,13 +88,13 @@ export default class EntryAbility extends Ability {
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
ForegroundTAG++ foregroundTAG++;
if (ForegroundTAG === 1) { if (foregroundTAG === 1) {
setTimeout(() => { setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => { commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err)); console.info('====>processState publish err: ' + JSON.stringify(err));
}) });
}, 3000); }, delayTime_3000);
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
......
...@@ -61,7 +61,7 @@ export default class EntryAbility1 extends Ability { ...@@ -61,7 +61,7 @@ export default class EntryAbility1 extends Ability {
setTimeout(() => { setTimeout(() => {
globalThis.abilityContext2.terminateSelf((err) => { globalThis.abilityContext2.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err)); console.log('terminateSelf result:' + JSON.stringify(err));
}) });
}, 3000); }, 3000);
} }
......
...@@ -17,6 +17,7 @@ import Ability from '@ohos.app.ability.UIAbility'; ...@@ -17,6 +17,7 @@ import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window'; import Window from '@ohos.window';
let TAG = 'StateChangeTestTAG'; let TAG = 'StateChangeTestTAG';
let delayTime_3000 = 3000;
let applicationStateChangeCallbackSec = { let applicationStateChangeCallbackSec = {
onApplicationForeground() { onApplicationForeground() {
console.info('==== ApplicationStateChange Foreground ===='); console.info('==== ApplicationStateChange Foreground ====');
...@@ -37,7 +38,7 @@ export default class EntryAbility extends Ability { ...@@ -37,7 +38,7 @@ export default class EntryAbility extends Ability {
globalThis.abilityContext = this.context; globalThis.abilityContext = this.context;
globalThis.want = want; globalThis.want = want;
if (want.action == 'MultiAppRegister' || want.action == 'DoubleRegisterOff') { if (want.action === 'MultiAppRegister' || want.action === 'DoubleRegisterOff') {
globalThis.applicationContext = this.context.getApplicationContext(); globalThis.applicationContext = this.context.getApplicationContext();
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec); globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec);
} }
...@@ -77,8 +78,8 @@ export default class EntryAbility extends Ability { ...@@ -77,8 +78,8 @@ export default class EntryAbility extends Ability {
setTimeout(() => { setTimeout(() => {
globalThis.abilityContext.terminateSelf((err) => { globalThis.abilityContext.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err)); console.log('terminateSelf result:' + JSON.stringify(err));
}) });
}, 3000) }, delayTime_3000);
} }
onBackground() { onBackground() {
......
...@@ -37,8 +37,8 @@ globalThis.StartFloatingAbility = () => { ...@@ -37,8 +37,8 @@ globalThis.StartFloatingAbility = () => {
}; };
globalThis.abilityContext.startAbility(want, options, (error) => { globalThis.abilityContext.startAbility(want, options, (error) => {
console.log(TAG, 'start floating ability error.code = ' + error.code); console.log(TAG, 'start floating ability error.code = ' + error.code);
}) });
} };
globalThis.StartNormalAbility = () => { globalThis.StartNormalAbility = () => {
let want = { let want = {
...@@ -48,8 +48,8 @@ globalThis.StartNormalAbility = () => { ...@@ -48,8 +48,8 @@ globalThis.StartNormalAbility = () => {
}; };
globalThis.abilityContext.startAbility(want, (error) => { globalThis.abilityContext.startAbility(want, (error) => {
console.log(TAG, 'start normal ability error.code = ' + error.code); console.log(TAG, 'start normal ability error.code = ' + error.code);
}) });
} };
globalThis.GetRunningProcessInfoCallback = () => { globalThis.GetRunningProcessInfoCallback = () => {
globalThis.applicationContext.getRunningProcessInformation((err, data) => { globalThis.applicationContext.getRunningProcessInformation((err, data) => {
...@@ -60,8 +60,8 @@ globalThis.GetRunningProcessInfoCallback = () => { ...@@ -60,8 +60,8 @@ globalThis.GetRunningProcessInfoCallback = () => {
console.log(TAG, 'Oncreate Callback State: ' + JSON.stringify(data[0].state)); console.log(TAG, 'Oncreate Callback State: ' + JSON.stringify(data[0].state));
commonStateArr[sequence++] = data[0].state; commonStateArr[sequence++] = data[0].state;
} }
}) });
} };
globalThis.GetRunningProcessInfoPromise = () => { globalThis.GetRunningProcessInfoPromise = () => {
globalThis.applicationContext.getRunningProcessInformation().then((data) => { globalThis.applicationContext.getRunningProcessInformation().then((data) => {
...@@ -69,18 +69,18 @@ globalThis.GetRunningProcessInfoPromise = () => { ...@@ -69,18 +69,18 @@ globalThis.GetRunningProcessInfoPromise = () => {
commonStateArr[sequence++] = data[0].state; commonStateArr[sequence++] = data[0].state;
}).catch((err) => { }).catch((err) => {
console.log(TAG, 'getRunningProcessInformation err: ' + JSON.stringify(err)); console.log(TAG, 'getRunningProcessInformation err: ' + JSON.stringify(err));
}) });
} };
globalThis.PublishStateArray = () => { globalThis.PublishStateArray = () => {
commonEvent.publish('processState', commonEventData, (err) => { commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err)); console.info('====>processState publish err: ' + JSON.stringify(err));
}) });
} };
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
sequence = 0 sequence = 0;
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
......
...@@ -58,15 +58,15 @@ export default class OpenHarmonyTestRunner implements TestRunner { ...@@ -58,15 +58,15 @@ export default class OpenHarmonyTestRunner implements TestRunner {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility';
let lMonitor = { let lMonitor = {
abilityName: testAbilityName, abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback, onAbilityCreate: onAbilityCreateCallback,
}; };
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters['-D'] var debug = abilityDelegatorArguments.parameters['-D'];
if (debug == 'true') { if (debug == 'true') {
cmd += ' -D' cmd += ' -D'
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册