• 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
16import { AsyncCallback } from './basic';
17
18/**
19 * Provides methods for managing bundle usage statistics,
20 * including the methods for querying bundle usage information and state data.
21 *
22 * <p>You can use the methods defined in this class to query
23 * the usage history and states of bundles in a specified period.
24 * The system stores the query result in a {@link BundleStateInfo} or {@link BundleActiveState} instance and
25 * then returns it to you.
26 *
27 * @since 7
28 */
29declare namespace bundleState {
30
31    /**
32     * @since 7
33     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
34     */
35    interface BundleStateInfo {
36        /**
37         * the identifier of BundleStateInfo.
38         */
39        id: number;
40        /**
41         * the total duration, in milliseconds.
42         */
43        abilityInFgTotalTime?: number;
44        /**
45         * the last time when the application was accessed, in milliseconds.
46         */
47        abilityPrevAccessTime?: number;
48        /**
49         * the last time when the application was visible in the foreground, in milliseconds.
50         */
51        abilityPrevSeenTime?: number;
52        /**
53         * the total duration, in milliseconds.
54         */
55        abilitySeenTotalTime?: number;
56        /**
57         * the bundle name of the application.
58         */
59        bundleName?: string;
60        /**
61         * the total duration, in milliseconds.
62         */
63        fgAbilityAccessTotalTime?: number;
64        /**
65         * the last time when the foreground application was accessed, in milliseconds.
66         */
67        fgAbilityPrevAccessTime?: number;
68        /**
69         * the time of the first bundle usage record in this {@code BundleActiveInfo} object,
70         * in milliseconds.
71         */
72        infosBeginTime?: number;
73        /**
74         * the time of the last bundle usage record in this {@code BundleActiveInfo} object,
75         * in milliseconds.
76         */
77        infosEndTime?: number;
78
79        /**
80         * Merges a specified {@link BundleActiveInfo} object with this {@link BundleActiveInfo} object.
81         * The bundle name of both objects must be the same.
82         *
83         * @since 7
84         * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
85         * @param toMerge Indicates the {@link BundleActiveInfo} object to merge.
86         * if the bundle names of the two {@link BundleActiveInfo} objects are different.
87         */
88        merge(toMerge: BundleStateInfo): void;
89    }
90
91    /**
92     * @since 7
93     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
94     */
95     interface BundleActiveState {
96        /**
97         * the usage priority group of the application.
98         */
99        appUsagePriorityGroup?: number;
100        /**
101         * the bundle name.
102         */
103        bundleName?: string;
104        /**
105         * the shortcut ID.
106         */
107        indexOfLink?: string;
108        /**
109         * the class name.
110         */
111        nameOfClass?: string;
112        /**
113         * the time when this state occurred, in milliseconds.
114         */
115        stateOccurredTime?: number;
116        /**
117         * the state type.
118         */
119        stateType?: number;
120    }
121
122    /**
123     * Checks whether the application with a specified bundle name is in the idle state.
124     *
125     * @since 7
126     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
127     * @param bundleName Indicates the bundle name of the application to query.
128     * @return Returns {@code true} if the application is idle in a particular period;
129     * returns {@code false} otherwise. The time range of the particular period is defined by the system,
130     * which may be hours or days.
131     */
132    function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void;
133    function isIdleState(bundleName: string): Promise<boolean>;
134
135    /**
136     * Queries the usage priority group of the calling application.
137     *
138     * <p>The priority defined in a priority group restricts the resource usage of an application,
139     * for example, restricting the running of background tasks. </p>
140     *
141     * @since 7
142     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
143     * @return Returns the usage priority group of the calling application.
144     */
145    function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void;
146    function queryAppUsagePriorityGroup(): Promise<number>;
147
148    /**
149     * @since 7
150     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
151     */
152     interface BundleActiveInfoResponse {
153        [key: string]: BundleStateInfo;
154    }
155
156    /**
157     * Queries usage information about each bundle within a specified period.
158     *
159     * <p>This method queries usage information at the {@link #BY_OPTIMIZED} interval by default.</p>
160     *
161     * @since 7
162     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
163     * @permission ohos.permission.BUNDLE_ACTIVE_INFO
164     * @systemapi Hide this for inner system use.
165     * @param begin Indicates the start time of the query period, in milliseconds.
166     * @param end Indicates the end time of the query period, in milliseconds.
167     * @return Returns the {@link BundleActiveInfoResponse} objects containing the usage information about each bundle.
168     */
169    function queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback<BundleActiveInfoResponse>): void;
170    function queryBundleStateInfos(begin: number, end: number): Promise<BundleActiveInfoResponse>;
171
172    /**
173     * Declares interval type.
174     *
175     * @since 7
176     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
177     */
178    export enum IntervalType {
179        /**
180         * Indicates the interval type that will determine the optimal interval based on the start and end time.
181         */
182        BY_OPTIMIZED = 0,
183
184        /**
185         * Indicates the daily interval.
186         */
187        BY_DAILY = 1,
188
189        /**
190         * Indicates the weekly interval.
191         */
192        BY_WEEKLY = 2,
193
194        /**
195         * Indicates the monthly interval.
196         */
197        BY_MONTHLY = 3,
198
199        /**
200         * Indicates the annually interval.
201         */
202        BY_ANNUALLY = 4
203    }
204
205    /**
206     * Queries usage information about each bundle within a specified period at a specified interval.
207     *
208     * @since 7
209     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
210     * @permission ohos.permission.BUNDLE_ACTIVE_INFO
211     * @systemapi Hide this for inner system use.
212     * @param byInterval Indicates the interval at which the usage statistics are queried.
213     * The value can be {@link #BY_OPTIMIZED}, {@link #BY_DAILY},
214     * {@link #BY_WEEKLY}, {@link #BY_MONTHLY}, or {@link #BY_ANNUALLY}.
215     * @param begin Indicates the start time of the query period, in milliseconds.
216     * @param end Indicates the end time of the query period, in milliseconds.
217     * @return Returns the list of {@link BundleStateInfo} objects containing the usage information about each bundle.
218     */
219    function queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStateInfo>>): void;
220    function queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStateInfo>>;
221
222    /**
223     * Queries state data of all bundles within a specified period identified by the start and end time.
224     *
225     * @since 7
226     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
227     * @permission ohos.permission.BUNDLE_ACTIVE_INFO
228     * @systemapi Hide this for inner system use.
229     * @param begin Indicates the start time of the query period, in milliseconds.
230     * @param end Indicates the end time of the query period, in milliseconds.
231     * @return Returns the list of {@link BundleActiveState} objects containing the state data of all bundles.
232     */
233    function queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void;
234    function queryBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>>;
235
236    /**
237     * Queries state data of the current bundle within a specified period.
238     *
239     * @since 7
240     * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App
241     * @param begin Indicates the start time of the query period, in milliseconds.
242     * @param end Indicates the end time of the query period, in milliseconds.
243     * @return Returns the {@link BundleActiveState} object Array containing the state data of the current bundle.
244     */
245    function queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void;
246    function queryCurrentBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>>;
247}
248
249export default bundleState;