未验证 提交 f43fca76 编写于 作者: 朱天怡 提交者: Gitee

告警修复

Signed-off-by: N朱天怡 <zhutianyi2@huawei.com>
上级 5be5552b
......@@ -17,7 +17,7 @@
## 导入模块
```js
```ts
import backgroundTaskManager from '@ohos.backgroundTaskManager';
```
......@@ -47,7 +47,7 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
**示例**
```js
```ts
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let myReason = 'test requestSuspendDelay';
......@@ -79,11 +79,11 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;):
**示例**
```js
```ts
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {});
backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId, (err, res) => {
backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId, (err: BusinessError, res: number) => {
if(err) {
console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.code);
} else {
......@@ -115,7 +115,7 @@ getRemainingDelayTime(requestId: number): Promise&lt;number&gt;
**示例**
```js
```ts
let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {});
backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId).then((res:number) => {
console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
......@@ -141,7 +141,7 @@ cancelSuspendDelay(requestId: number): void
**示例**
```js
```ts
let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {});
backgroundTaskManager.cancelSuspendDelay(delayInfo.requestId);
```
......@@ -267,7 +267,7 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
**示例**
FA模型示例:
FA模型示例(需使用js代码开发)
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
......@@ -348,7 +348,7 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): vo
**示例**
FA模型示例:
FA模型示例(需使用js代码开发)
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
......
......@@ -9,7 +9,7 @@
## 导入模块
```js
```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
```
......@@ -53,22 +53,23 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
**示例**
```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let myReason = 'test requestSuspendDelay';
try {
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
let myReason = 'test requestSuspendDelay';
try {
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspension delay will time out.");
})
let id = delayInfo.requestId;
let time = delayInfo.actualDelayTime;
console.info("The requestId is: " + id);
console.info("The actualDelayTime is: " + time);
} catch (error) {
console.error(`requestSuspendDelay failed. code is ${error.code} message is ${error.message}`);
}
```
})
let id = delayInfo.requestId;
let time = delayInfo.actualDelayTime;
console.info("The requestId is: " + id);
console.info("The actualDelayTime is: " + time);
} catch (error) {
console.error(`requestSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
## backgroundTaskManager.getRemainingDelayTime
......@@ -102,22 +103,19 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;):
**示例**
```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let id = 1;
try {
backgroundTaskManager.getRemainingDelayTime(id, (error, res) => {
let id = 1;
backgroundTaskManager.getRemainingDelayTime(id, (error: BusinessError, res: number) => {
if(error) {
console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
} else {
console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
}
})
} catch (error) {
console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
}
```
})
```
## backgroundTaskManager.getRemainingDelayTime
......@@ -155,20 +153,17 @@ getRemainingDelayTime(requestId: number): Promise&lt;number&gt;
**示例**
```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let id = 1;
try {
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
let id = 1;
backgroundTaskManager.getRemainingDelayTime(id).then((res: number) => {
console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
}).catch( error => {
}).catch((error: BusinessError) => {
console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
})
} catch (error) {
console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
}
```
})
```
## backgroundTaskManager.cancelSuspendDelay
......@@ -202,12 +197,13 @@ cancelSuspendDelay(requestId: number): void
```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let id = 1;
try {
backgroundTaskManager.cancelSuspendDelay(id);
} catch (error) {
console.error(`cancelSuspendDelay failed. code is ${error.code} message is ${error.message}`);
console.error(`cancelSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......@@ -249,9 +245,10 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
```js
import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent from '@ohos.app.ability.wantAgent';
import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
import { BusinessError } from '@ohos.base';
function callback(error, data) {
function callback(error: BusinessError, data: void) {
if (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
} else {
......@@ -260,8 +257,8 @@ function callback(error, data) {
}
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
let wantAgentInfo = {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
......@@ -274,16 +271,16 @@ export default class EntryAbility extends UIAbility {
};
try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
try {
backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
} catch (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
});
} catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
}
};
......@@ -332,11 +329,12 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
```js
import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent from '@ohos.app.ability.wantAgent';
import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
let wantAgentInfo = {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
......@@ -349,20 +347,20 @@ export default class EntryAbility extends UIAbility {
};
try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
try {
backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => {
console.info("Operation startBackgroundRunning succeeded");
}).catch((error) => {
}).catch((error: BusinessError) => {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
});
} catch (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
});
} catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
}
};
......@@ -402,8 +400,9 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): vo
```js
import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
function callback(error, data) {
function callback(error: BusinessError, data: void) {
if (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
} else {
......@@ -412,11 +411,11 @@ function callback(error, data) {
}
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try {
backgroundTaskManager.stopBackgroundRunning(this.context, callback);
} catch (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
}
};
......@@ -461,17 +460,18 @@ stopBackgroundRunning(context: Context): Promise&lt;void&gt;
```js
import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
console.info("Operation stopBackgroundRunning succeeded");
}).catch((error) => {
}).catch((error: BusinessError) => {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
});
} catch (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
}
};
......@@ -510,8 +510,9 @@ applyEfficiencyResources(request: EfficiencyResourcesRequest): void
```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let request = {
let request: backgroundTaskManager.EfficiencyResourcesRequest = {
resourceTypes: backgroundTaskManager.ResourceType.CPU,
isApply: true,
timeOut: 0,
......@@ -523,7 +524,7 @@ try {
backgroundTaskManager.applyEfficiencyResources(request);
console.info("applyEfficiencyResources success. ");
} catch (error) {
console.error(`applyEfficiencyResources failed. code is ${error.code} message is ${error.message}`);
console.error(`applyEfficiencyResources failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......
......@@ -10,7 +10,7 @@
## 导入模块
```js
```ts
import workScheduler from '@ohos.resourceschedule.workScheduler';
```
......@@ -42,8 +42,8 @@ startWork(work: WorkInfo): void
**示例**
```js
let workInfo = {
```ts
let workInfo: workScheduler.WorkInfo = {
workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false,
......@@ -61,7 +61,7 @@ startWork(work: WorkInfo): void
workScheduler.startWork(workInfo);
console.info('workschedulerLog startWork success');
} catch (error) {
console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`);
console.error(`workschedulerLog startwork failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......@@ -93,8 +93,8 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
**示例**
```js
let workInfo = {
```ts
let workInfo: workScheduler.WorkInfo = {
workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false,
......@@ -112,7 +112,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
workScheduler.stopWork(workInfo, false);
console.info('workschedulerLog stopWork success');
} catch (error) {
console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`);
console.error(`workschedulerLog stopWork failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......@@ -144,20 +144,14 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
**示例**
```js
try{
workScheduler.getWorkStatus(50, (error, res) => {
```ts
workScheduler.getWorkStatus(50, (error: BusinessError, res: workScheduler.WorkInfo) => {
if (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
} else {
for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
console.info(`workschedulerLog getWorkStatus success, ${JSON.stringify(res)}`);
}
});
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.getWorkStatus
......@@ -193,18 +187,12 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
**示例**
```js
try{
workScheduler.getWorkStatus(50).then((res) => {
for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
}).catch((error) => {
```ts
workScheduler.getWorkStatus(50).then((res: workScheduler.WorkInfo) => {
console.info(`workschedulerLog getWorkStatus success, ${JSON.stringify(res)}`);
}).catch((error: BusinessError) => {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
})
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.obtainAllWorks
......@@ -239,18 +227,14 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
**示例**
```js
try{
workScheduler.obtainAllWorks((error, res) =>{
```ts
workScheduler.obtainAllWorks((error: BusinessError, res: Array<workScheduler.WorkInfo>) =>{
if (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
} else {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}
});
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.obtainAllWorks
......@@ -279,16 +263,12 @@ obtainAllWorks(): Promise\<Array\<WorkInfo>>
**示例**
```js
try{
workScheduler.obtainAllWorks().then((res) => {
```ts
workScheduler.obtainAllWorks().then((res: Array<workScheduler.WorkInfo>) => {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}).catch((error) => {
}).catch((error: BusinessError) => {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
})
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.stopAndClearWorks
......@@ -311,12 +291,12 @@ stopAndClearWorks(): void
**示例**
```js
```ts
try{
workScheduler.stopAndClearWorks();
console.info(`workschedulerLog stopAndClearWorks success`);
} catch (error) {
console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`);
console.error(`workschedulerLog stopAndClearWorks failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......@@ -354,18 +334,14 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
**示例**
```js
try{
workScheduler.isLastWorkTimeOut(500, (error, res) =>{
```ts
workScheduler.isLastWorkTimeOut(500, (error: BusinessError, res: boolean) =>{
if (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
} else {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
}
});
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
```
## workScheduler.isLastWorkTimeOut
......@@ -401,18 +377,14 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
**示例**
```js
try{
```ts
workScheduler.isLastWorkTimeOut(500)
.then(res => {
.then((res: boolean) => {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
})
.catch(error => {
.catch((error: BusinessError) => {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
});
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
```
## WorkInfo
......
......@@ -103,7 +103,7 @@
private context: Context = getContext(this);
startContinuousTask() {
let wantAgentInfo: wantAgent.wantAgentInfo = {
let wantAgentInfo: wantAgent.WantAgentInfo = {
// 点击通知后,将要执行的动作列表
wants: [
{
......@@ -353,7 +353,7 @@
import { BusinessError } from '@ohos.base';
```
4. 申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消。
4. 申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消,通过js代码实现
```js
function startContinuousTask() {
......
......@@ -121,7 +121,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
```ts
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
import workScheduler fron '@ohos.resourceschedule.workScheduler';
import workScheduler from '@ohos.resourceschedule.workScheduler';
```
3. 实现WorkSchedulerExtension生命周期接口。
......@@ -184,8 +184,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try {
workScheduler.startWork(this.workInfo);
console.info(`startWork success`);
} catch (error: BusinessError) {
console.error(`startWork failed. code is ${error.code} message is ${error.message}`);
} catch (error) {
console.error(`startWork failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......@@ -202,8 +202,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try {
workScheduler.stopWork(this.workInfo);
console.info(`stopWork success`);
} catch (error: BusinessError) {
console.error(`stopWork failed. code is ${error.code} message is ${error.message}`);
} catch (error) {
console.error(`stopWork failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册