• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 { appManager } from '@kit.AbilityKit';
17import { hilog } from '@kit.PerformanceAnalysisKit';
18import { promptAction } from '@kit.ArkUI';
19
20const TAG: string = 'AppManager';
21const DOMAIN: number = 0xFF00;
22
23@Entry
24@Component
25struct AppManager {
26  private promptDuration: number = 2000;
27
28  build() {
29    Column() {
30      Row() {
31        Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) {
32          Text($r('app.string.AppManager'))
33            .fontSize(30)
34            .fontWeight(700)
35            .textAlign(TextAlign.Start)
36            .margin({
37              top: 8,
38              bottom: 8,
39              left: 12
40            })
41        }
42      }
43      .width('100%')
44      .height('7.18%')
45      .justifyContent(FlexAlign.Start)
46      .backgroundColor($r('app.color.backGrounding'))
47      .margin({
48        top: '7.18%',
49        bottom: '6.41%',
50        left: '3.33%'
51      })
52
53      List({ initialIndex: 0 }) {
54        ListItem() {
55          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
56            Text($r('app.string.isRunningInStabilityTestCallback'))
57              .textAlign(TextAlign.Start)
58              .fontWeight(500)
59              .margin({
60                top: 17,
61                bottom: 17,
62                left: 12
63              })
64              .fontSize(16)
65              .width('77.87%')
66              .height('39.29%')
67              .fontColor($r('app.color.text_color'))
68              .id('isRunningInStabilityTestCallback')
69          }
70          .onClick(() => {
71            try {
72              appManager.isRunningInStabilityTest((err, data) => {
73                hilog.info(DOMAIN, TAG,
74                  `The result of isRunningInStabilityTest(callback) is: ${JSON.stringify(data)}`);
75                promptAction.showToast({
76                  message: `isRunningInStabilityTest(callback) success, data: ${JSON.stringify(data)}`,
77                  duration: this.promptDuration
78                })
79              })
80            } catch (err) {
81              hilog.info(DOMAIN, TAG, `isRunningInStabilityTest(callback) fail, err: ${JSON.stringify(err)}`);
82            }
83          })
84        }
85        .height('8.45%')
86        .backgroundColor($r('app.color.start_window_background'))
87        .borderRadius(24)
88        .margin({ top: 12, right: 12, left: 12 })
89
90        ListItem() {
91          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
92            Text($r('app.string.isRunningInStabilityTestPromise'))
93              .textAlign(TextAlign.Start)
94              .fontWeight(500)
95              .margin({
96                top: 17,
97                bottom: 17,
98                left: 12
99              })
100              .fontSize(16)
101              .width('77.87%')
102              .height('39.29%')
103              .fontColor($r('app.color.text_color'))
104              .id('isRunningInStabilityTestPromise')
105          }
106          .onClick(() => {
107            try {
108              appManager.isRunningInStabilityTest().then((data) => {
109                hilog.info(DOMAIN, TAG,
110                  `The result of isRunningInStabilityTest(promise) is: ${JSON.stringify(data)}`);
111                promptAction.showToast({
112                  message: `isRunningInStabilityTest(promise) success, data: ${JSON.stringify(data)}`,
113                  duration: this.promptDuration
114                })
115              })
116            } catch (err) {
117              hilog.info(DOMAIN, TAG, `isRunningInStabilityTest(promise) fail, err: ${JSON.stringify(err)}`);
118            }
119          })
120        }
121        .height('8.45%')
122        .backgroundColor($r('app.color.start_window_background'))
123        .borderRadius(24)
124        .margin({ top: 12, right: 12, left: 12 })
125
126        ListItem() {
127          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
128            Text($r('app.string.isRamConstrainedDeviceCallback'))
129              .textAlign(TextAlign.Start)
130              .fontWeight(500)
131              .margin({
132                top: 17,
133                bottom: 17,
134                left: 12
135              })
136              .fontSize(16)
137              .width('77.87%')
138              .height('39.29%')
139              .fontColor($r('app.color.text_color'))
140              .id('isRamConstrainedDeviceCallback')
141          }
142          .onClick(() => {
143            try {
144              appManager.isRamConstrainedDevice((err, data) => {
145                hilog.info(DOMAIN, TAG,
146                  `The result of isRamConstrainedDevice(callback) is: ${JSON.stringify(data)}`);
147                promptAction.showToast({
148                  message: `isRamConstrainedDevice(callback) success, data: ${JSON.stringify(data)}`,
149                  duration: this.promptDuration
150                })
151              })
152            } catch (err) {
153              hilog.info(DOMAIN, TAG, `isRamConstrainedDevice(callback) fail, err: ${JSON.stringify(err)}`);
154            }
155          })
156        }
157        .height('8.45%')
158        .backgroundColor($r('app.color.start_window_background'))
159        .borderRadius(24)
160        .margin({ top: 12, right: 12, left: 12 })
161
162        ListItem() {
163          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
164            Text($r('app.string.isRamConstrainedDevicePromise'))
165              .textAlign(TextAlign.Start)
166              .fontWeight(500)
167              .margin({
168                top: 17,
169                bottom: 17,
170                left: 12
171              })
172              .fontSize(16)
173              .width('77.87%')
174              .height('39.29%')
175              .fontColor($r('app.color.text_color'))
176              .id('isRamConstrainedDevicePromise')
177          }
178          .onClick(() => {
179            try {
180              appManager.isRamConstrainedDevice().then((data) => {
181                hilog.info(DOMAIN, TAG,
182                  `The result of isRamConstrainedDevice(promise) is: ${JSON.stringify(data)}`);
183                promptAction.showToast({
184                  message: `isRamConstrainedDevice(promise) success, data: ${JSON.stringify(data)}`,
185                  duration: this.promptDuration
186                })
187              })
188            } catch (err) {
189              hilog.info(DOMAIN, TAG, `isRamConstrainedDevice(promise) fail, err: ${JSON.stringify(err)}`);
190            }
191          })
192        }
193        .height('8.45%')
194        .backgroundColor($r('app.color.start_window_background'))
195        .borderRadius(24)
196        .margin({ top: 12, right: 12, left: 12 })
197
198        ListItem() {
199          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
200            Text($r('app.string.getAppMemorySizeCallback'))
201              .textAlign(TextAlign.Start)
202              .fontWeight(500)
203              .margin({
204                top: 17,
205                bottom: 17,
206                left: 12
207              })
208              .fontSize(16)
209              .width('77.87%')
210              .height('39.29%')
211              .fontColor($r('app.color.text_color'))
212              .id('getAppMemorySizeCallback')
213          }
214          .onClick(() => {
215            try {
216              appManager.getAppMemorySize((err, data) => {
217                hilog.info(DOMAIN, TAG,
218                  `The result of getAppMemorySize(callback) is: ${JSON.stringify(data)}`);
219                promptAction.showToast({
220                  message: `getAppMemorySize(callback) success, data: ${JSON.stringify(data)}`,
221                  duration: this.promptDuration
222                })
223              })
224            } catch (err) {
225              hilog.info(DOMAIN, TAG, `getAppMemorySize(callback) fail, err: ${JSON.stringify(err)}`);
226            }
227          })
228        }
229        .height('8.45%')
230        .backgroundColor($r('app.color.start_window_background'))
231        .borderRadius(24)
232        .margin({ top: 12, right: 12, left: 12 })
233
234        ListItem() {
235          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
236            Text($r('app.string.getAppMemorySizePromise'))
237              .textAlign(TextAlign.Start)
238              .fontWeight(500)
239              .margin({
240                top: 17,
241                bottom: 17,
242                left: 12
243              })
244              .fontSize(16)
245              .width('77.87%')
246              .height('39.29%')
247              .fontColor($r('app.color.text_color'))
248              .id('getAppMemorySizePromise')
249          }
250          .onClick(() => {
251            try {
252              appManager.getAppMemorySize().then((data) => {
253                hilog.info(DOMAIN, TAG,
254                  `The result of getAppMemorySize(promise) is: ${JSON.stringify(data)}`);
255                promptAction.showToast({
256                  message: `getAppMemorySize(promise) success, data: ${JSON.stringify(data)}`,
257                  duration: this.promptDuration
258                })
259              })
260            } catch (err) {
261              hilog.info(DOMAIN, TAG, `getAppMemorySize(promise) fail, err: ${JSON.stringify(err)}`);
262            }
263          })
264        }
265        .height('8.45%')
266        .backgroundColor($r('app.color.start_window_background'))
267        .borderRadius(24)
268        .margin({ top: 12, right: 12, left: 12 })
269
270        ListItem() {
271          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
272            Text($r('app.string.getRunningProcessInformationCallback'))
273              .textAlign(TextAlign.Start)
274              .fontWeight(500)
275              .margin({
276                top: 17,
277                bottom: 17,
278                left: 12
279              })
280              .fontSize(16)
281              .width('100%')
282              .height('39.29%')
283              .fontColor($r('app.color.text_color'))
284              .id('getRunningProcessInformationCallback')
285          }
286          .onClick(() => {
287            try {
288              appManager.getRunningProcessInformation((err, data) => {
289                hilog.info(DOMAIN, TAG,
290                  `The result of getRunningProcessInformation(callback) is: ${JSON.stringify(data)}`);
291                promptAction.showToast({
292                  message: `getRunningProcessInformation(callback) success, data: ${JSON.stringify(data)}`,
293                  duration: this.promptDuration
294                })
295              })
296            } catch (err) {
297              hilog.info(DOMAIN, TAG, `getRunningProcessInformation(callback) fail, err: ${JSON.stringify(err)}`);
298            }
299          })
300        }
301        .height('8.45%')
302        .backgroundColor($r('app.color.start_window_background'))
303        .borderRadius(24)
304        .margin({ top: 12, right: 12, left: 12 })
305
306        ListItem() {
307          Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) {
308            Text($r('app.string.getRunningProcessInformationPromise'))
309              .textAlign(TextAlign.Start)
310              .fontWeight(500)
311              .margin({
312                top: 17,
313                bottom: 17,
314                left: 12
315              })
316              .fontSize(16)
317              .width('100%')
318              .height('39.29%')
319              .fontColor($r('app.color.text_color'))
320              .id('getRunningProcessInformationPromise')
321          }
322          .onClick(() => {
323            try {
324              appManager.getRunningProcessInformation().then((data) => {
325                hilog.info(DOMAIN, TAG,
326                  `The result of getRunningProcessInformation(promise) is: ${JSON.stringify(data)}`);
327                promptAction.showToast({
328                  message: `getRunningProcessInformation(promise) success, data: ${JSON.stringify(data)}`,
329                  duration: this.promptDuration
330                })
331              })
332            } catch (err) {
333              hilog.info(DOMAIN, TAG, `getRunningProcessInformation(promise) fail, err: ${JSON.stringify(err)}`);
334            }
335          })
336        }
337        .height('8.45%')
338        .backgroundColor($r('app.color.start_window_background'))
339        .borderRadius(24)
340        .margin({ top: 12, right: 12, left: 12 })
341      }
342      .height('86%')
343      .backgroundColor($r('app.color.backGrounding'))
344    }
345    .width('100%')
346    .height('100%')
347    .backgroundColor($r('app.color.backGrounding'))
348  }
349}