提交 2c001841 编写于 作者: X xinking129

fix code check

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 536b6e6e
...@@ -13,135 +13,136 @@ ...@@ -13,135 +13,136 @@
* limitations under the License. * limitations under the License.
*/ */
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 commonStateArr: number[] = [-1, -1, -1, -1] const ONE_SECOND = 1000;
const FIVE_HUNDRED_MILLISECOND = 500;
const VALID_STATE = 1;
const INVALID_STATE = -1;
const TAG = 'StateChangeTestTAG';
let commonStateArr: number[] = [-1, -1, -1, -1];
let commonEventData = { let commonEventData = {
parameters: { parameters: {
commonStateArr: commonStateArr commonStateArr: commonStateArr
} }
} };
let onForeGroundTAG = -1 let onForeGroundTAG = INVALID_STATE;
let TAG = 'StateChangeTestTAG' let applicationStateChangeCallbackFir = {
let ApplicationStateChangeCallbackFir = { onApplicationForeground() {
onApplicationForeground() { console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground');
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationForeground') commonEventData.parameters.commonStateArr[0] = VALID_STATE;
commonEventData.parameters.commonStateArr[0] = 1
setTimeout(() => {
console.info('Enter onApplicationForeground publish!')
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
})
}, 1000)
}, setTimeout(() => {
onApplicationBackground() { console.info('Enter onApplicationForeground publish!');
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationBackground') commonEvent.publish('processState', commonEventData, (err) => {
commonEventData.parameters.commonStateArr[1] = 1 console.info('====>processState publish err: ' + JSON.stringify(err));
});
}, ONE_SECOND);
},
onApplicationBackground() {
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
commonEventData.parameters.commonStateArr[1] = VALID_STATE;
if (globalThis.want.action == 'NeedBackGroundOff' || globalThis.want.action == 'MultiAppRegister' if (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister' ||
|| globalThis.want.action == 'DoubleRegisterOff') { globalThis.want.action === 'DoubleRegisterOff') {
console.info('entered needbackgroundoff!') console.info('entered needbackgroundoff!');
globalThis.applicationContext.off('applicationStateChange', ApplicationStateChangeCallbackFir) globalThis.applicationContext.off('applicationStateChange', 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] = VALID_STATE;
}, },
onApplicationBackground() { onApplicationBackground() {
console.log(TAG, 'ApplicationStateChangeCallbackSec onApplicationBackground') console.log(TAG, 'applicationStateChangeCallbackSec onApplicationBackground');
commonEventData.parameters.commonStateArr[3] = 1 commonEventData.parameters.commonStateArr[3] = VALID_STATE;
if (globalThis.want.action == 'doubleNeedBackGroundOff') { if (globalThis.want.action === 'doubleNeedBackGroundOff') {
setTimeout(() => { setTimeout(() => {
globalThis.applicationContext.off('applicationStateChange', ApplicationStateChangeCallbackSec) globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackSec);
}, 500) }, FIVE_HUNDRED_MILLISECOND);
} }
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) }, FIVE_HUNDRED_MILLISECOND);
}
} }
}
} }
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
onForeGroundTAG = -1 onForeGroundTAG = INVALID_STATE;
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
commonStateArr[i] = -1 commonStateArr[i] = INVALID_STATE;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext = this.context
globalThis.want = want
globalThis.applicationContext = this.context.getApplicationContext();
if (globalThis.want.action == 'RegisterOnOffOn') {
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackFir)
globalThis.applicationContext.off('applicationStateChange', ApplicationStateChangeCallbackFir)
}
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackFir)
if (globalThis.want.action == 'doubleRegister' || globalThis.want.action == 'doubleNeedBackGroundOff'
|| globalThis.want.action == 'DoubleRegisterOff') {
console.info("double in action is logic entered!")
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackSec)
}
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
onDestroy() { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext = this.context;
globalThis.want = want;
globalThis.applicationContext = this.context.getApplicationContext();
if (globalThis.want.action === 'RegisterOnOffOn') {
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackFir);
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackFir);
}
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackFir);
if (globalThis.want.action === 'doubleRegister' || globalThis.want.action === 'doubleNeedBackGroundOff'
|| globalThis.want.action === 'DoubleRegisterOff') {
console.info('double in action is logic entered!');
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec);
} }
}
onWindowStageCreate(windowStage: Window.WindowStage) { onDestroy() {
// Main window is created, set main page for this ability hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); }
windowStage.loadContent('pages/Index', (err, data) => { onWindowStageCreate(windowStage: Window.WindowStage) {
if (err.code) { // Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() { windowStage.loadContent('pages/Index', (err, data) => {
// Main window is destroyed, release UI related resources if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
} return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onForeground() { onWindowStageDestroy() {
// Ability has brought to foreground // Main window is destroyed, release UI related resources
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', 'Ability onWindowStageDestroy');
onForeGroundTAG += 1 }
if (onForeGroundTAG == 1 && (globalThis.want.action == 'NeedBackGroundOff' || globalThis.want.action == 'MultiAppRegister'
|| globalThis.want.action == 'DoubleRegisterOff')) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
})
}, 2000)
} onForeground() {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Abilityone onForeground');
onForeGroundTAG++;
if (onForeGroundTAG === VALID_STATE && (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister'
|| globalThis.want.action === 'DoubleRegisterOff')) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
})
}, 2000);
} }
}
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Abilityone onBackground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Abilityone onBackground');
} }
} }
...@@ -13,94 +13,96 @@ ...@@ -13,94 +13,96 @@
* limitations under the License. * limitations under the License.
*/ */
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';
const ONE_SECOND = 1000;
let TAG = 'getRunningProcess' const THREE_SECOND = 3000;
let commonStateArr const VALID_STATE = 1;
const INVALID_STATE = -1;
const TAG = 'getRunningProcess';
let commonStateArr;
let commonEventData = { let commonEventData = {
parameters: { parameters: {
commonStateArr: commonStateArr commonStateArr: commonStateArr
} }
} };
let ApplicationStateChangeCallbackFir = { let applicationStateChangeCallbackFir = {
onApplicationForeground() { onApplicationForeground() {
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationForeground') console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground');
}, },
onApplicationBackground() { onApplicationBackground() {
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationBackground') console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
setTimeout(() => { setTimeout(() => {
console.info('Enter onApplicationForeground publish!') console.info('Enter onApplicationForeground publish!');
commonEventData.parameters.commonStateArr = 1 commonEventData.parameters.commonStateArr = VALID_STATE;
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) }, ONE_SECOND);
} }
} };
let ForegroundTAG = -1 let foregroundTAG = INVALID_STATE;
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
ForegroundTAG = -1 foregroundTAG = INVALID_STATE;
commonEventData.parameters.commonStateArr = -1 commonEventData.parameters.commonStateArr = INVALID_STATE;
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) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext1 = this.context globalThis.abilityContext1 = this.context;
globalThis.want1 = want globalThis.want1 = want;
globalThis.applicationContext1 = this.context.getApplicationContext(); globalThis.applicationContext1 = this.context.getApplicationContext();
globalThis.applicationContext1.on('applicationStateChange', ApplicationStateChangeCallbackFir) globalThis.applicationContext1.on('applicationStateChange', applicationStateChangeCallbackFir);
}
} onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onDestroy() { onWindowStageCreate(windowStage: Window.WindowStage) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); // Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
} hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
onWindowStageCreate(windowStage: Window.WindowStage) { windowStage.loadContent('pages/Index', (err, data) => {
// Main window is created, set main page for this ability if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
windowStage.loadContent('pages/Index', (err, data) => { onWindowStageDestroy() {
if (err.code) { // Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
return; }
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() { onForeground() {
// Main window is destroyed, release UI related resources // Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); foregroundTAG++
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); if (foregroundTAG === VALID_STATE) {
} setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info('====>processState publish err: ' + JSON.stringify(err));
})
}, THREE_SECOND)
onForeground() {
// Ability has brought to foreground
ForegroundTAG++
if (ForegroundTAG == 1) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
})
}, 3000)
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
} }
} }
...@@ -13,61 +13,61 @@ ...@@ -13,61 +13,61 @@
* limitations under the License. * limitations under the License.
*/ */
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';
export default class EntryAbility1 extends Ability { export default class EntryAbility1 extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
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) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext2 = this.context globalThis.abilityContext2 = this.context;
globalThis.want2 = want globalThis.want2 = want;
globalThis.applicationContext2 = this.context.getApplicationContext(); globalThis.applicationContext2 = this.context.getApplicationContext();
} }
onDestroy() { onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
} }
onWindowStageCreate(windowStage: Window.WindowStage) { onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => { windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) { if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return; return;
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
} }
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed, release UI related resources // Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
} }
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
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);
} }
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
} }
} }
...@@ -13,76 +13,76 @@ ...@@ -13,76 +13,76 @@
* limitations under the License. * limitations under the License.
*/ */
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';
let TAG = 'StateChangeTestTAG' const TAG = 'StateChangeTestTAG';
let ApplicationStateChangeCallbackSec = { let applicationStateChangeCallbackSec = {
onApplicationForeground() { onApplicationForeground() {
console.info('==== ApplicationStateChange Foreground ===='); console.info('==== ApplicationStateChange Foreground ====');
console.log(TAG, 'App2 ApplicationStateChangeCallbackSec onApplicationForeground') console.log(TAG, 'App2 applicationStateChangeCallbackSec onApplicationForeground');
}, },
onApplicationBackground() { onApplicationBackground() {
console.info('==== ApplicationStateChange Background ===='); console.info('==== ApplicationStateChange Background ====');
console.log(TAG, 'App2 ApplicationStateChangeCallbackSec onApplicationBackground') console.log(TAG, 'App2 applicationStateChangeCallbackSec onApplicationBackground');
} }
} }
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
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) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
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);
}
} }
}
onDestroy() { onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
} }
onWindowStageCreate(windowStage: Window.WindowStage) { onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => { windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) { if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return; return;
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
} }
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed, release UI related resources // Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
} }
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
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) }, 3000);
} }
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
} }
} }
...@@ -13,19 +13,19 @@ ...@@ -13,19 +13,19 @@
* limitations under the License. * limitations under the License.
*/ */
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';
import AbilityConstant from '@ohos.app.ability.AbilityConstant' import AbilityConstant from '@ohos.app.ability.AbilityConstant';
let sequence = 0; let sequence = 0;
let TAG = 'GetRunningProcessInformation' let TAG = 'GetRunningProcessInformation';
let commonStateArr: number[] = [-1, -1, -1, -1] let commonStateArr: number[] = [-1, -1, -1, -1];
let commonEventData = { let commonEventData = {
parameters: { parameters: {
commonStateArr: commonStateArr commonStateArr: commonStateArr
} }
} };
globalThis.StartFloatingAbility = () => { globalThis.StartFloatingAbility = () => {
let want = { let want = {
"deviceId": "", "deviceId": "",
...@@ -36,8 +36,8 @@ globalThis.StartFloatingAbility = () => { ...@@ -36,8 +36,8 @@ globalThis.StartFloatingAbility = () => {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING, windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING,
}; };
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 = () => {
...@@ -47,8 +47,8 @@ globalThis.StartNormalAbility = () => { ...@@ -47,8 +47,8 @@ globalThis.StartNormalAbility = () => {
"abilityName": "EntryAbility" "abilityName": "EntryAbility"
}; };
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 = () => {
...@@ -58,15 +58,15 @@ globalThis.GetRunningProcessInfoCallback = () => { ...@@ -58,15 +58,15 @@ globalThis.GetRunningProcessInfoCallback = () => {
} }
else { else {
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) => {
console.log(TAG, 'Oncreate Promise State: ' + JSON.stringify(data[0].state)); console.log(TAG, 'Oncreate Promise State: ' + JSON.stringify(data[0].state));
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));
}); });
...@@ -74,20 +74,20 @@ globalThis.GetRunningProcessInfoPromise = () => { ...@@ -74,20 +74,20 @@ globalThis.GetRunningProcessInfoPromise = () => {
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) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.want = want globalThis.want = want;
globalThis.abilityContext = this.context globalThis.abilityContext = this.context;
globalThis.applicationContext = this.context.getApplicationContext(); globalThis.applicationContext = this.context.getApplicationContext();
} }
......
...@@ -13,73 +13,73 @@ ...@@ -13,73 +13,73 @@
* limitations under the License. * limitations under the License.
*/ */
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner' import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
var abilityDelegator = undefined let abilityDelegator = undefined;
var abilityDelegatorArguments = undefined let abilityDelegatorArguments = undefined;
function translateParamsToString(parameters) { function translateParamsToString(parameters) {
const keySet = new Set([ const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it', '-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout', '-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun' '-s dryRun'
]) ]);
let targetParams = ''; let targetParams = '';
for (const key in parameters) { for (const key in parameters) {
if (keySet.has(key)) { if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}` targetParams = `${targetParams} ${key} ${parameters[key]}`;
}
} }
return targetParams.trim() }
return targetParams.trim();
} }
async function onAbilityCreateCallback() { async function onAbilityCreateCallback() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
} }
async function addAbilityMonitorCallback(err: any) { async function addAbilityMonitorCallback(err: any) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
} }
export default class OpenHarmonyTestRunner implements TestRunner { export default class OpenHarmonyTestRunner implements TestRunner {
constructor() { constructor() {
} }
onPrepare() { onPrepare() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
} }
async onRun() { async onRun() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
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' let 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 let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters);
var debug = abilityDelegatorArguments.parameters['-D'] let debug = abilityDelegatorArguments.parameters['-D'];
if (debug == 'true') if (debug == 'true')
{ {
cmd += ' -D' cmd += ' -D';
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
});
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
} }
\ No newline at end of file
...@@ -13,53 +13,53 @@ ...@@ -13,53 +13,53 @@
* limitations under the License. * limitations under the License.
*/ */
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';
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
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) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
} }
onDestroy() { onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
} }
onWindowStageCreate(windowStage: Window.WindowStage) { onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => { windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) { if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return; return;
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
} }
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed, release UI related resources // Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
} }
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
} }
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册