• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022  Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit BackgroundTasksKit
19 */
20
21import { AsyncCallback, Callback } from './@ohos.base';
22
23/**
24 * Provides methods for managing bundle usage statistics,
25 * including the methods for querying bundle usage information and state data.
26 * <p>You can use the methods defined in this class to query
27 * the usage history and states of bundles in a specified period.
28 * The system stores the query result in a {@link BundleStateInfo} or {@link BundleActiveState} instance and
29 * then returns it to you.
30 *
31 * @namespace bundleState
32 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
33 * @since 7
34 * @deprecated since 9
35 * @useinstead ohos.resourceschedule.usageStatistics
36 */
37declare namespace bundleState {
38  /**
39   * @interface BundleStateInfo
40   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
41   * @since 7
42   * @deprecated since 9
43   * @useinstead ohos.resourceschedule.usageStatistics.BundleStatsInfo
44   */
45  interface BundleStateInfo {
46    /**
47     * The identifier of BundleStateInfo.
48     * @type { number }
49     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
50     * @since 7
51     * @deprecated since 9
52     */
53    id: number;
54    /**
55     * The total duration, in milliseconds.
56     * @type { ?number }
57     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
58     * @since 7
59     * @deprecated since 9
60     */
61    abilityInFgTotalTime?: number;
62    /**
63     * The last time when the application was accessed, in milliseconds.
64     * @type { ?number }
65     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
66     * @since 7
67     * @deprecated since 9
68     */
69    abilityPrevAccessTime?: number;
70    /**
71     * The last time when the application was visible in the foreground, in milliseconds.
72     * @type { ?number }
73     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
74     * @since 7
75     * @deprecated since 9
76     */
77    abilityPrevSeenTime?: number;
78    /**
79     * The total duration, in milliseconds.
80     * @type { ?number }
81     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
82     * @since 7
83     * @deprecated since 9
84     */
85    abilitySeenTotalTime?: number;
86    /**
87     * The bundle name of the application.
88     * @type { ?string }
89     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
90     * @since 7
91     * @deprecated since 9
92     */
93    bundleName?: string;
94    /**
95     * The total duration, in milliseconds.
96     * @type { ?number }
97     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
98     * @since 7
99     * @deprecated since 9
100     */
101    fgAbilityAccessTotalTime?: number;
102    /**
103     * The last time when the foreground application was accessed, in milliseconds.
104     * @type { ?number }
105     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
106     * @since 7
107     * @deprecated since 9
108     */
109    fgAbilityPrevAccessTime?: number;
110    /**
111     * The time of the first bundle usage record in this {@code BundleActiveInfo} object,
112     * in milliseconds.
113     * @type { ?number }
114     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
115     * @since 7
116     * @deprecated since 9
117     */
118    infosBeginTime?: number;
119    /**
120     * The time of the last bundle usage record in this {@code BundleActiveInfo} object,
121     * in milliseconds.
122     * @type { ?number }
123     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
124     * @since 7
125     * @deprecated since 9
126     */
127    infosEndTime?: number;
128
129    /**
130     * Merges a specified {@link BundleActiveInfo} object with this {@link BundleActiveInfo} object.
131     * The bundle name of both objects must be the same.
132     *
133     * @param { BundleStateInfo } toMerge Indicates the {@link BundleActiveInfo} object to merge.
134     * If the bundle names of the two {@link BundleActiveInfo} objects are different.
135     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
136     * @since 7
137     * @deprecated since 9
138     */
139    merge(toMerge: BundleStateInfo): void;
140  }
141
142  /**
143   * @typedef BundleActiveState
144   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
145   * @since 7
146   * @deprecated since 9
147   * @useinstead ohos.resourceschedule.usageStatistics.BundleEvents
148   */
149  interface BundleActiveState {
150    /**
151     * The usage priority group of the application.
152     * @type { ?number }
153     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
154     * @since 7
155     * @deprecated since 9
156     */
157    appUsagePriorityGroup?: number;
158    /**
159     * The bundle name.
160     * @type { ?string }
161     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
162     * @since 7
163     * @deprecated since 9
164     */
165    bundleName?: string;
166    /**
167     * The shortcut ID.
168     * @type { ?string }
169     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
170     * @since 7
171     * @deprecated since 9
172     */
173    indexOfLink?: string;
174    /**
175     * The class name.
176     * @type { ?string }
177     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
178     * @since 7
179     * @deprecated since 9
180     */
181    nameOfClass?: string;
182    /**
183     * The time when this state occurred, in milliseconds.
184     * @type { ?number }
185     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
186     * @since 7
187     * @deprecated since 9
188     */
189    stateOccurredTime?: number;
190    /**
191     * The state type.
192     * @type { ?number }
193     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
194     * @since 7
195     * @deprecated since 9
196     */
197    stateType?: number;
198  }
199
200  /**
201   * Checks whether the application with a specified bundle name is in the idle state.
202   *
203   * @param { string } bundleName Indicates the bundle name of the application to query.
204   * @param { AsyncCallback<boolean> } callback - the callback of isIdleState.
205   * <p> boolean value is true mean the application is idle in a particular period; false mean otherwise.
206   * The time range of the particular period is defined by the system, which may be hours or days.</p>
207   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
208   * @since 7
209   * @deprecated since 9
210   * @useinstead ohos.resourceschedule.usageStatistics.isIdleState
211   */
212  function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void;
213
214  /**
215   * Checks whether the application with a specified bundle name is in the idle state.
216   *
217   * @param { string } bundleName Indicates the bundle name of the application to query.
218   * @returns { Promise<boolean> } the promise returned by isIdleState.
219   * <p> boolean value is true mean the application is idle in a particular period; false mean otherwise.
220   * The time range of the particular period is defined by the system, which may be hours or days.</p>
221   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
222   * @since 7
223   * @deprecated since 9
224   * @useinstead ohos.resourceschedule.usageStatistics.isIdleState
225   */
226  function isIdleState(bundleName: string): Promise<boolean>;
227
228  /**
229   * Queries the usage priority group of the calling application.
230   * <p>The priority defined in a priority group restricts the resource usage of an application,
231   * for example, restricting the running of background tasks. </p>
232   *
233   * @param { AsyncCallback<number> } callback - the callback of queryAppUsagePriorityGroup.
234   * <p> Returns the app group of the calling application.</p>
235   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
236   * @since 7
237   * @deprecated since 9
238   * @useinstead ohos.resourceschedule.usageStatistics.queryAppGroup
239   */
240  function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void;
241
242  /**
243   * Queries the usage priority group of the calling application.
244   * <p>The priority defined in a priority group restricts the resource usage of an application,
245   * for example, restricting the running of background tasks. </p>
246   *
247   * @returns { Promise<number> } the promise returned by queryAppUsagePriorityGroup.
248   * <p> Returns the app group of the calling application.</p>
249   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
250   * @since 7
251   * @deprecated since 9
252   * @useinstead ohos.resourceschedule.usageStatistics.queryAppGroup
253   */
254  function queryAppUsagePriorityGroup(): Promise<number>;
255
256  /**
257   * @typedef BundleActiveInfoResponse
258   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
259   * @since 7
260   * @deprecated since 9
261   * @useinstead ohos.resourceschedule.usageStatistics.BundleStatsMap
262   */
263  interface BundleActiveInfoResponse {
264    [key: string]: BundleStateInfo;
265  }
266
267  /**
268   * Queries usage information about each bundle within a specified period.
269   * <p>This method queries usage information at the {@link #BY_OPTIMIZED} interval by default.</p>
270   *
271   * @permission ohos.permission.BUNDLE_ACTIVE_INFO
272   * @param { number } begin Indicates the start time of the query period, in milliseconds.
273   * @param { number } end Indicates the end time of the query period, in milliseconds.
274   * @param { AsyncCallback<BundleActiveInfoResponse> } callback - the callback of queryBundleStateInfos.
275   * <p> the {@link BundleActiveInfoResponse} objects containing the usage information about each bundle.</p>
276   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
277   * @systemapi Hide this for inner system use.
278   * @since 7
279   * @deprecated since 9
280   * @useinstead ohos.resourceschedule.usageStatistics.queryBundleStatsInfos
281   */
282  function queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback<BundleActiveInfoResponse>): void;
283
284  /**
285   * Queries usage information about each bundle within a specified period.
286   * <p>This method queries usage information at the {@link #BY_OPTIMIZED} interval by default.</p>
287   *
288   * @permission ohos.permission.BUNDLE_ACTIVE_INFO
289   * @param { number } begin Indicates the start time of the query period, in milliseconds.
290   * @param { number } end Indicates the end time of the query period, in milliseconds.
291   * @returns { Promise<BundleActiveInfoResponse> } the promise returned by queryBundleStatsInfos.
292   * <p> the {@link BundleActiveInfoResponse} objects containing the usage information about each bundle.</p>
293   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
294   * @systemapi Hide this for inner system use.
295   * @since 7
296   * @deprecated since 9
297   * @useinstead ohos.resourceschedule.usageStatistics.queryBundleStatsInfos
298   */
299  function queryBundleStateInfos(begin: number, end: number): Promise<BundleActiveInfoResponse>;
300
301  /**
302   * Declares interval type.
303   *
304   * @enum { number }
305   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
306   * @since 7
307   * @deprecated since 9
308   * @useinstead ohos.resourceschedule.usageStatistics.IntervalType
309   */
310  export enum IntervalType {
311    /**
312     * Indicates the interval type that will determine the optimal interval based on the start and end time.
313     *
314     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
315     * @since 7
316     * @deprecated since 9
317     */
318    BY_OPTIMIZED = 0,
319
320    /**
321     * Indicates the daily interval.
322     *
323     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
324     * @since 7
325     * @deprecated since 9
326     */
327    BY_DAILY = 1,
328
329    /**
330     * Indicates the weekly interval.
331     *
332     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
333     * @since 7
334     * @deprecated since 9
335     */
336    BY_WEEKLY = 2,
337
338    /**
339     * Indicates the monthly interval.
340     *
341     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
342     * @since 7
343     * @deprecated since 9
344     */
345    BY_MONTHLY = 3,
346
347    /**
348     * Indicates the annually interval.
349     *
350     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
351     * @since 7
352     * @deprecated since 9
353     */
354    BY_ANNUALLY = 4
355  }
356
357  /**
358   * Queries usage information about each bundle within a specified period at a specified interval.
359   *
360   * @permission ohos.permission.BUNDLE_ACTIVE_INFO
361   * @param { IntervalType } byInterval Indicates the interval at which the usage statistics are queried.
362   * <p>The value can be {@link #BY_OPTIMIZED}, {@link #BY_DAILY},
363   * {@link #BY_WEEKLY}, {@link #BY_MONTHLY}, or {@link #BY_ANNUALLY}.</p>
364   * @param { number } begin Indicates the start time of the query period, in milliseconds.
365   * @param { number } end Indicates the end time of the query period, in milliseconds.
366   * @param { AsyncCallback<Array<BundleStateInfo>> } callback - the callback of usage information about each bundle.
367   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
368   * @systemapi Hide this for inner system use.
369   * @since 7
370   * @deprecated since 9
371   * @useinstead ohos.resourceschedule.usageStatistics.queryBundleStatsInfoByInterval
372   */
373  function queryBundleStateInfoByInterval(
374    byInterval: IntervalType,
375    begin: number,
376    end: number,
377    callback: AsyncCallback<Array<BundleStateInfo>>
378  ): void;
379
380  /**
381   * Queries usage information about each bundle within a specified period at a specified interval.
382   *
383   * @permission ohos.permission.BUNDLE_ACTIVE_INFO
384   * @param { IntervalType } byInterval Indicates the interval at which the usage statistics are queried.
385   * <p>The value can be {@link #BY_OPTIMIZED}, {@link #BY_DAILY},
386   * {@link #BY_WEEKLY}, {@link #BY_MONTHLY}, or {@link #BY_ANNUALLY}.</p>
387   * @param { number } begin Indicates the start time of the query period, in milliseconds.
388   * @param { number } end Indicates the end time of the query period, in milliseconds.
389   * @returns { Promise<Array<BundleStateInfo>> } the usage information about each bundle.
390   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
391   * @systemapi Hide this for inner system use.
392   * @since 7
393   * @deprecated since 9
394   * @useinstead ohos.resourceschedule.usageStatistics.queryBundleStatsInfoByInterval
395   */
396  function queryBundleStateInfoByInterval(
397    byInterval: IntervalType,
398    begin: number,
399    end: number
400  ): Promise<Array<BundleStateInfo>>;
401
402  /**
403   * Queries state data of all bundles within a specified period identified by the start and end time.
404   *
405   * @permission ohos.permission.BUNDLE_ACTIVE_INFO
406   * @param { number } begin Indicates the start time of the query period, in milliseconds.
407   * @param { number } end Indicates the end time of the query period, in milliseconds.
408   * @param { AsyncCallback<Array<BundleActiveState>> } callback - the state data of all bundles.
409   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
410   * @systemapi Hide this for inner system use.
411   * @since 7
412   * @deprecated since 9
413   * @useinstead ohos.resourceschedule.usageStatistics.queryBundleEvents
414   */
415  function queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void;
416
417  /**
418   * Queries state data of all bundles within a specified period identified by the start and end time.
419   *
420   * @permission ohos.permission.BUNDLE_ACTIVE_INFO
421   * @param { number } begin Indicates the start time of the query period, in milliseconds.
422   * @param { number } end Indicates the end time of the query period, in milliseconds.
423   * @returns { Promise<Array<BundleActiveState>> } the state data of all bundles.
424   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
425   * @systemapi Hide this for inner system use.
426   * @since 7
427   * @deprecated since 9
428   * @useinstead ohos.resourceschedule.usageStatistics.queryBundleEvents
429   */
430  function queryBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>>;
431
432  /**
433   * Queries state data of the current bundle within a specified period.
434   *
435   * @param { number } begin Indicates the start time of the query period, in milliseconds.
436   * @param { number } end Indicates the end time of the query period, in milliseconds.
437   * @param { AsyncCallback<Array<BundleActiveState>> } callback - the state data of the current bundle.
438   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
439   * @since 7
440   * @deprecated since 9
441   * @useinstead ohos.resourceschedule.usageStatistics.queryCurrentBundleEvents
442   */
443  function queryCurrentBundleActiveStates(
444    begin: number,
445    end: number,
446    callback: AsyncCallback<Array<BundleActiveState>>
447  ): void;
448
449  /**
450   * Queries state data of the current bundle within a specified period.
451   *
452   * @param { number } begin Indicates the start time of the query period, in milliseconds.
453   * @param { number } end Indicates the end time of the query period, in milliseconds.
454   * @returns { Promise<Array<BundleActiveState>> } the state data of the current bundle.
455   * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
456   * @since 7
457   * @deprecated since 9
458   * @useinstead ohos.resourceschedule.usageStatistics.queryCurrentBundleEvents
459   */
460  function queryCurrentBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>>;
461}
462
463export default bundleState;
464