diff --git a/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-use-guide.md b/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-use-guide.md index 686cfa481f5b56496d233050009352819c9fbbbd..b32f8b9e080743a37105288b6b65678398476c3d 100644 --- a/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-use-guide.md +++ b/zh-cn/application-dev/device-usage-statistics/device-usage-statistics-use-guide.md @@ -21,9 +21,12 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics'; | function queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void | 通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。 | | function queryAppGroup(callback: AsyncCallback<number>): void | 查询当前应用的使用优先级群组。callback形式。 | | function queryAppGroup(): Promise<number>; | 查询当前应用的使用优先级群组。promise形式。 | +|function queryAppGroupSync(): number; | 查询当前应用的使用优先级群组。同步接口。| | function queryAppGroup(bundleName : string, callback: AsyncCallback<number>): void | 查询指定应用的使用优先级群组。callback形式。 | | function queryAppGroup(bundleName : string): Promise<number>; | 查询当前调用者应用或者指定应用的使用优先级群组。promise形式。 | +|function queryAppGroupSync(bundleName: string): number; | 查询当前调用者应用或者指定应用的使用优先级群组。同步接口。| | function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void | 判断指定Bundle Name的应用当前是否是空闲状态。 | +|function isIdleStateSync(bundleName: string): boolean; | 判断指定Bundle Name的应用当前是否是空闲状态,同步接口。 | | function queryModuleUsageRecords(callback: AsyncCallback<HapModuleInfo>): void | 查询FA使用记录,返回不超过1000条FA使用记录。 | | function queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<HapModuleInfo>): void | 根据maxNum,查询FA使用记录,返回不超过maxNum条FA使用记录。 maxNum不超过1000| | function queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void | 通过指定起始和结束时间查询所有应用的通知次数。 | @@ -225,6 +228,14 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics'; } catch (error) { console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message); } + + //同步方式 + try{ + var priorityGroup = usageStatistics.queryAppGroupSync(); + } catch (error) { + console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message); + } + ``` 7. 判断指定Bundle Name的应用当前是否是空闲状态,需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。 @@ -255,6 +266,13 @@ import usageStatistics from '@ohos.resourceschedule.usageStatistics'; } catch(error) { console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message); } + + //同步方式 + try{ + var isIdleState = usageStatistics.isIdleStateSync("com.ohos.camera"); + } catch(error) { + console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message); + } ``` 8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,若不传入maxNum参数,则默认maxNum为1000, 需要配置ohos.permission.BUNDLE_ACTIVE_INFO权限。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md b/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md index 5df2df5940b14be2b0455eba303b23dc6aff50cd..98c1588316898f7417357db1f7bd8fdfb9c8c064 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md +++ b/zh-cn/application-dev/reference/apis/js-apis-resourceschedule-deviceUsageStatistics.md @@ -124,6 +124,50 @@ isIdleState(bundleName: string): Promise<boolean> console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message); } ``` +## usageStatistics.isIdleStateSync10+ + +isIdleStateSync(bundleName: string): boolean + +判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态。 + +**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO + +**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + +**系统API**:此接口为系统接口。 + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ---------------------------- | ---- | ---------------------------------------- | +| bundleName | string | 是 | 应用的bundleName。 | + +**返回值**: + +| 类型 | 说明 | +| ---------------------- | ---------------------------------------- | +| boolean | 如果指定的bundleName有效,返回true则表示空闲状态,false则非空闲。 | + +**错误码**: + +以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)。 + +| 错误码ID | 错误信息 | +| ---------- | ---------------------------- | +| 10000001 | Memory operation failed. | +| 10000002 | Parcel operation failed. | +| 10000003 | System service operation failed. | +| 10000004 | IPC failed. | +| 10000006 | Failed to get the application information. | + +**示例**: + ```js + try{ + var isIdleState = usageStatistics.isIdleStateSync("com.ohos.camera"); + } catch(error) { + console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message); + } + ``` ## usageStatistics.queryAppGroup @@ -215,6 +259,92 @@ queryAppGroup(callback: AsyncCallback<number>): void } ``` +## usageStatistics.queryAppGroupSync10+ + +queryAppGroupSync(): number; + +查询当前应用的优先级分组。 + +**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + +**系统API**:此接口为系统接口。 + +**返回值**: + +| 类型 | 说明 | +| --------------- | --------------------------- | +| number | 返回当前应用优先级分组结果。 | + +**错误码**: + +以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)。 + +| 错误码ID | 错误信息 | +| ---------- | ---------------------------- | +| 10000001 | Memory operation failed. | +| 10000002 | Parcel operation failed. | +| 10000003 | System service operation failed. | +| 10000004 | IPC failed. | +| 10000005 | Application is not installed. | +| 10000006 | Failed to get the application information. | +| 10100002 | Failed to get the application group information. | + +**示例**: + +```javascript + try{ + var priorityGroup = usageStatistics.queryAppGroupSync(); + } catch (error) { + console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message); + } +``` + +## usageStatistics.queryAppGroupSync10+ + +queryAppGroupSync(bundleName: string): number + +查询指定bundleName应用的优先级分组。 + +**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + +**系统API**:此接口为系统接口。 + +**参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ---------------------------- | ---- | ---------------------------------------- | +| bundleName | string | 是 | 应用的bundleName。 | + +**返回值**: + +| 类型 | 说明 | +| --------------- | --------------------------- | +| number | 返回指定bundleName应用优先级分组结果。 | + +**错误码**: + +以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)。 + +| 错误码ID | 错误信息 | +| ---------- | ---------------------------- | +| 10000001 | Memory operation failed. | +| 10000002 | Parcel operation failed. | +| 10000003 | System service operation failed. | +| 10000004 | IPC failed. | +| 10000005 | Application is not installed. | +| 10000006 | Failed to get the application information. | +| 10100002 | Failed to get the application group information. | + +**示例**: + +```javascript + try{ + var priorityGroup = usageStatistics.queryAppGroupSync("com.ohos.camera"); + } catch (error) { + console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message); + } +``` + ## usageStatistics.queryBundleStatsInfos queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void