README_zh.md
1# **用户程序框架子系统**
2
3## 简介
4
5用户程序框架子系统是OpenHarmony为开发者提供的一套开发OpenHarmony应用程序的框架。
6
7**包含以下模块:**
8
9- **AppKit:**是用户程序框架提供给开发者的开发包,开发者基于该开发包可以开发出基于Ability组件的应用。
10
11- **AppManagerService:**应用管理服务,用于管理应用运行关系、调度应用进程生命周期及状态的系统服务。
12
13- **BundleManagerService:**是负责管理安装包的系统服务,常见的比如包安装、更新,卸载和包信息查询等,运行在Foundation进程。
14
15应用程序框架子系统架构如下图所示:
16
17
18
19
20
21## 目录
22
23```
24foundation/appexecfwk/standard
25├── kits
26│ └── appkit # Appkit实现的核心代码
27├── common
28│ └── log # 日志组件目录
29├── interfaces
30│ └── innerkits # 内部接口存放目录
31├── services
32│ ├── appmgr # 用户程序管理服务框架代码
33│ └── bundlemgr # 包管理服务框架代码
34├── test # 测试目录
35└── tools # bm命令存放目录
36```
37
38### 使用说明
39
40#### 根据给定的bundle名称获取ApplicationInfo
41
42* getApplicationInfo参数描述
43
44 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
45 | ----------- | -------- | ------ | ---- | ------------------------------------------------------- |
46 | bundleName | 只读 | string | 是 | 应用名 |
47 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 |
48 | userId | 只读 | number | 是 | 用户ID |
49
50* 返回值
51
52 Promise<ApplicationInfo>:返回值为Promise对象,Promise中包含应用信息。
53
54* 示例
55
56```
57bundle.getApplicationInfo('com.example.myapplicationInstall', 8, 0).then((data) => {
58 console.info("name: for begin");
59 console.info("name:" + data.name);
60 console.info("bundleName:" + data.bundleName);
61 console.info("description:" + data.description);
62 console.info("descriptionId:" + data.descriptionId);
63 console.info("iconPath:" + data.iconPath);
64 console.info("iconId:" + data.iconId);
65 console.info("label:" + data.label);
66 console.info("labelId:" + data.labelId);
67 console.info("deviceId:" + data.deviceId);
68 console.info("signatureKey:" + data.signatureKey);
69 console.info("process:" + data.process);
70 console.info("isSystemApp:" + data.isSystemApp);
71 console.info("isLauncherApp:" + data.isLauncherApp);
72 console.info("supportedModes:" + data.supportedModes);
73
74 console.info('getApplicationInfo permissions length [' + data.permissions.length + ']');
75 for (var j = 0; j < data.permissions.length; j++) {
76 console.info("permissions[" + j + "]:" + data.permissions[j]);
77 }
78 console.info('getApplicationInfo moduleSourceDirs length [' + data.moduleSourceDirs.length + ']');
79 for (var j = 0; j < data.moduleSourceDirs.length; j++) {
80 console.info("moduleSourceDirs[" + j + "]:" + data.moduleSourceDirs[j]);
81 }
82 console.info('getApplicationInfo moduleInfos length [' + data.moduleInfos.length + ']');
83 for (var j = 0; j < data.moduleInfos.length; j++) {
84 console.info("moduleInfos[" + j + "]moduleName:" + data.moduleInfos[j].moduleName);
85 console.info("moduleInfos[" + j + "]moduleSourceDir:" + data.moduleInfos[j].moduleSourceDir);
86 }
87 console.info("entryDir:" + data.entryDir);
88 console.info("codePath:" + data.codePath);
89 console.info("dataDir:" + data.dataDir);
90 console.info("dataBaseDir:" + data.dataBaseDir);
91 console.info("cacheDir:" + data.cacheDir);
92})
93```
94根据给定的bundle名称获取ApplicationInfo(callback方式)
95
96* getApplicationInfo参数描述
97
98 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
99 | ----------- | -------- | ------------------------------ | ---- | ------------------------------------------------------- |
100 | bundleName | 只读 | string | 是 | 应用名 |
101 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 |
102 | userId | 只读 | number | 是 | 用户ID |
103 | callback | 只读 | AsyncCallback<ApplicationInfo> | 是 | 回调方法 |
104
105* 返回值
106
107 void
108
109* 示例
110
111```
112bundle.getApplicationInfo('com.example.myapplicationInstall', 8, 0, OnReceiveEvent);
113
114function OnReceiveEvent(err, data) {
115 console.info("name: for begin");
116 console.info("name:" + data.name);
117 console.info("bundleName:" + data.bundleName);
118 console.info("description:" + data.description);
119 console.info("descriptionId:" + data.descriptionId);
120 console.info("iconPath:" + data.iconPath);
121 console.info("iconId:" + data.iconId);
122 console.info("label:" + data.label);
123 console.info("labelId:" + data.labelId);
124 console.info("deviceId:" + data.deviceId);
125 console.info("signatureKey:" + data.signatureKey);
126 console.info("process:" + data.process);
127 console.info("isSystemApp:" + data.isSystemApp);
128 console.info("isLauncherApp:" + data.isLauncherApp);
129 console.info("supportedModes:" + data.supportedModes);
130
131 console.info('getApplicationInfo permissions length [' + data.permissions.length + ']');
132 for (var j = 0; j < data.permissions.length; j++) {
133 console.info("permissions[" + j + "]:" + data.permissions[j]);
134 }
135 console.info('getApplicationInfo moduleSourceDirs length [' + data.moduleSourceDirs.length + ']');
136 for (var j = 0; j < data.moduleSourceDirs.length; j++) {
137 console.info("moduleSourceDirs[" + j + "]:" + data.moduleSourceDirs[j]);
138 }
139 console.info('getApplicationInfo moduleInfos length [' + data.moduleInfos.length + ']');
140 for (var j = 0; j < data.moduleInfos.length; j++) {
141 console.info("moduleInfos[" + j + "]moduleName:" + data.moduleInfos[j].moduleName);
142 console.info("moduleInfos[" + j + "]moduleSourceDir:" + data.moduleInfos[j].moduleSourceDir);
143 }
144 console.info("entryDir:" + data.entryDir);
145 console.info("codePath:" + data.codePath);
146 console.info("dataDir:" + data.dataDir);
147 console.info("dataBaseDir:" + data.dataBaseDir);
148 console.info("cacheDir:" + data.cacheDir);
149}
150```
151
152#### 获取系统中所有可用的包信息
153
154* getAllBundleInfo参数描述
155
156 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
157 | ---------- | -------- | ---------- | ---- | ----------------------------------------------------------- |
158 | bundleFlag | 只读 | BundleFlag | 是 | 0:返回默认BundleInfo<br>1:返回包含abilityInfo的BundleInfo |
159
160* 返回值
161
162 Promise<Array<BundleInfo>>:返回值为Promise对象,Promise中包含包信息列表。
163
164* 示例
165
166```
167bundle.getAllBundleInfo(0).then((data) => {
168 for (var i = 0; i < data.length; i++) {
169 console.info("index[" + i + "].name: for begin");
170 console.info("index[" + i + "].name:" + data[i].name);
171 console.info("index[" + i + "].label:" + data[i].label);
172 console.info("index[" + i + "].description:" + data[i].description);
173 console.info("index[" + i + "].vendor:" + data[i].vendor);
174 console.info("index[" + i + "].versionCode:" + data[i].versionCode);
175 console.info("index[" + i + "].versionName:" + data[i].versionName);
176 console.info("index[" + i + "].jointUserId:" + data[i].jointUserId);
177 console.info("index[" + i + "].minSdkVersion:" + data[i].minSdkVersion);
178 console.info("index[" + i + "].maxSdkVersion:" + data[i].maxSdkVersion);
179 console.info("index[" + i + "].mainEntry:" + data[i].mainEntry);
180 console.info("index[" + i + "].cpuAbi:" + data[i].cpuAbi);
181 console.info("index[" + i + "].appId:" + data[i].appId);
182 console.info("index[" + i + "].compatibleVersion:" + data[i].compatibleVersion);
183 console.info("index[" + i + "].targetVersion:" + data[i].targetVersion);
184 console.info("index[" + i + "].releaseType:" + data[i].releaseType);
185 console.info("index[" + i + "].uid:" + data[i].uid);
186 console.info("index[" + i + "].gid:" + data[i].gid);
187 console.info("index[" + i + "].seInfo:" + data[i].seInfo);
188 console.info("index[" + i + "].entryModuleName:" + data[i].entryModuleName);
189 console.info("index[" + i + "].isKeepAlive:" + data[i].isKeepAlive);
190 console.info("index[" + i + "].isNativeApp:" + data[i].isNativeApp);
191 console.info("index[" + i + "].installTime:" + data[i].installTime);
192 console.info("index[" + i + "].updateTime:" + data[i].updateTime);
193 console.info("index[" + i + "].appInfo.name:" + data[i].applicationInfo.name);
194 console.info("index[" + i + "].appInfo.bundleName:" + data[i].applicationInfo.bundleName);
195 console.info('getAllBundleInfo reqPermissions length [' + data[i].reqPermissions.length + ']');
196 for (var j = 0; j < data[i].reqPermissions.length; j++) {
197 console.info("index[" + i + "]reqPermissions[" + j + "]:" + data[i].reqPermissions[j]);
198 }
199 console.info('getAllBundleInfo defPermissions length [' + data[i].defPermissions.length + ']');
200 for (var j = 0; j < data[i].defPermissions.length; j++) {
201 console.info("index[" + i + "]defPermissions[" + j + "]:" + data[i].defPermissions[j]);
202 }
203
204 console.info('getAllBundleInfo hapModuleNames length [' + data[i].hapModuleNames.length + ']');
205 for (var j = 0; j < data[i].hapModuleNames.length; j++) {
206 console.info("index[" + i + "]hapModuleNames[" + j + "]:" + data[i].hapModuleNames[j]);
207 }
208 console.info('getAllBundleInfo moduleNames length [' + data[i].moduleNames.length + ']');
209 for (var j = 0; j < data[i].moduleNames.length; j++) {
210 console.info("index[" + i + "]moduleNames[" + j + "]:" + data[i].moduleNames[j]);
211 }
212 console.info('getAllBundleInfo modulePublicDirs length [' + data[i].modulePublicDirs.length + ']');
213 for (var j = 0; j < data[i].modulePublicDirs.length; j++) {
214 console.info("index[" + i + "]modulePublicDirs[" + j + "]:" + data[i].modulePublicDirs[j]);
215 }
216 console.info('getAllBundleInfo moduleDirs length [' + data[i].moduleDirs.length + ']');
217 for (var j = 0; j < data[i].moduleDirs.length; j++) {
218 console.info("index[" + i + "]moduleDirs[" + j + "]:" + data[i].moduleDirs[j]);
219 }
220 console.info('getAllBundleInfo moduleResPaths length [' + data[i].moduleResPaths.length + ']');
221 for (var j = 0; j < data[i].moduleResPaths.length; j++) {
222 console.info("index[" + i + "]moduleResPaths[" + j + "]:" + data[i].moduleResPaths[j]);
223 }
224 console.info('getAllBundleInfo abilityInfo length [' + data[i].abilityInfos.length + ']');
225 for (var j = 0; j < data[i].abilityInfos.length; j++) {
226 console.info("index[" + i + "]abilityInfos[" + j + "]name:" + data[i].abilityInfos[j].name);
227 console.info("index[" + i + "]abilityInfos[" + j + "]package:" + data[i].abilityInfos[j].package);
228 }
229 }
230})
231```
232
233获取系统中所有可用的包信息(callback形式)
234
235* getAllBundleInfo参数描述
236
237 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
238 | ---------- | -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
239 | bundleFlag | 只读 | BundleFlag | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo |
240 | callback | 只读 | AsyncCallback<Array<BundleInfo>> | 是 | 回调方法 |
241
242* 返回值
243
244 void
245
246* 示例
247
248```
249bundle.getAllBundleInfo(0, OnReceiveEvent);
250
251function OnReceiveEvent(err, data) {
252 console.info('xxx getAllBundleInfo data length [' + data.length + ']');
253 for (var i = 0; i < data.length; i++) {
254 console.info("index[" + i + "].name: for begin");
255 console.info("index[" + i + "].name:" + data[i].name);
256 console.info("index[" + i + "].label:" + data[i].label);
257 console.info("index[" + i + "].description:" + data[i].description);
258 console.info("index[" + i + "].vendor:" + data[i].vendor);
259 console.info("index[" + i + "].versionCode:" + data[i].versionCode);
260 console.info("index[" + i + "].versionName:" + data[i].versionName);
261 console.info("index[" + i + "].jointUserId:" + data[i].jointUserId);
262 console.info("index[" + i + "].minSdkVersion:" + data[i].minSdkVersion);
263 console.info("index[" + i + "].maxSdkVersion:" + data[i].maxSdkVersion);
264 console.info("index[" + i + "].mainEntry:" + data[i].mainEntry);
265 console.info("index[" + i + "].cpuAbi:" + data[i].cpuAbi);
266 console.info("index[" + i + "].appId:" + data[i].appId);
267 console.info("index[" + i + "].compatibleVersion:" + data[i].compatibleVersion);
268 console.info("index[" + i + "].targetVersion:" + data[i].targetVersion);
269 console.info("index[" + i + "].releaseType:" + data[i].releaseType);
270 console.info("index[" + i + "].uid:" + data[i].uid);
271 console.info("index[" + i + "].gid:" + data[i].gid);
272 console.info("index[" + i + "].seInfo:" + data[i].seInfo);
273 console.info("index[" + i + "].entryModuleName:" + data[i].entryModuleName);
274 console.info("index[" + i + "].isKeepAlive:" + data[i].isKeepAlive);
275 console.info("index[" + i + "].isNativeApp:" + data[i].isNativeApp);
276 console.info("index[" + i + "].installTime:" + data[i].installTime);
277 console.info("index[" + i + "].updateTime:" + data[i].updateTime);
278 console.info("index[" + i + "].appInfo.name:" + data[i].applicationInfo.name);
279 console.info("index[" + i + "].appInfo.bundleName:" + data[i].applicationInfo.bundleName);
280 console.info('getAllBundleInfo reqPermissions length [' + data[i].reqPermissions.length + ']');
281 for (var j = 0; j < data[i].reqPermissions.length; j++) {
282 console.info("index[" + i + "]reqPermissions[" + j + "]:" + data[i].reqPermissions[j]);
283 }
284 console.info('getAllBundleInfo defPermissions length [' + data[i].defPermissions.length + ']');
285 for (var j = 0; j < data[i].defPermissions.length; j++) {
286 console.info("index[" + i + "]defPermissions[" + j + "]:" + data[i].defPermissions[j]);
287 }
288
289 console.info('getAllBundleInfo hapModuleNames length [' + data[i].hapModuleNames.length + ']');
290 for (var j = 0; j < data[i].hapModuleNames.length; j++) {
291 console.info("index[" + i + "]hapModuleNames[" + j + "]:" + data[i].hapModuleNames[j]);
292 }
293 console.info('getAllBundleInfo moduleNames length [' + data[i].moduleNames.length + ']');
294 for (var j = 0; j < data[i].moduleNames.length; j++) {
295 console.info("index[" + i + "]moduleNames[" + j + "]:" + data[i].moduleNames[j]);
296 }
297 console.info('getAllBundleInfo modulePublicDirs length [' + data[i].modulePublicDirs.length + ']');
298 for (var j = 0; j < data[i].modulePublicDirs.length; j++) {
299 console.info("index[" + i + "]modulePublicDirs[" + j + "]:" + data[i].modulePublicDirs[j]);
300 }
301 console.info('getAllBundleInfo moduleDirs length [' + data[i].moduleDirs.length + ']');
302 for (var j = 0; j < data[i].moduleDirs.length; j++) {
303 console.info("index[" + i + "]moduleDirs[" + j + "]:" + data[i].moduleDirs[j]);
304 }
305 console.info('getAllBundleInfo moduleResPaths length [' + data[i].moduleResPaths.length + ']');
306 for (var j = 0; j < data[i].moduleResPaths.length; j++) {
307 console.info("index[" + i + "]moduleResPaths[" + j + "]:" + data[i].moduleResPaths[j]);
308 }
309 console.info('getAllBundleInfo abilityInfo length [' + data[i].abilityInfos.length + ']');
310 for (var j = 0; j < data[i].abilityInfos.length; j++) {
311 console.info("index[" + i + "]abilityInfos[" + j + "]name:" + data[i].abilityInfos[j].name);
312 console.info("index[" + i + "]abilityInfos[" + j + "]package:" + data[i].abilityInfos[j].package);
313 }
314 }
315}
316```
317
318#### 根据bundle名称获取BundleInfo
319
320* getBundleInfo参数描述
321
322 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
323 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ |
324 | bundleName | 只读 | string | 是 | 包名 |
325 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo |
326
327* 返回值
328
329 Promise<BundleInfo>:返回值为Promise对象,Promise中包含包信息。
330
331* 示例
332
333```
334bundle.getBundleInfo('com.example.myapplicationInstall', 1).then((data) => {
335 console.info("name:" + data.name);
336 console.info("label:" + data.label);
337 console.info("description:" + data.description);
338 console.info("vendor:" + data.vendor);
339 console.info("versionCode:" + data.versionCode);
340 console.info("versionName:" + data.versionName);
341 console.info("jointUserId:" + data.jointUserId);
342 console.info("minSdkVersion:" + data.minSdkVersion);
343 console.info("maxSdkVersion:" + data.maxSdkVersion);
344 console.info("mainEntry:" + data.mainEntry);
345 console.info("cpuAbi:" + data.cpuAbi);
346 console.info("appId:" + data.appId);
347 console.info("compatibleVersion:" + data.compatibleVersion);
348 console.info("targetVersion:" + data.targetVersion);
349 console.info("releaseType:" + data.releaseType);
350 console.info("uid:" + data.uid);
351 console.info("gid:" + data.gid);
352 console.info("seInfo:" + data.seInfo);
353 console.info("entryModuleName:" + data.entryModuleName);
354 console.info("isKeepAlive:" + data.isKeepAlive);
355 console.info("isNativeApp:" + data.isNativeApp);
356 console.info("installTime:" + data.installTime);
357 console.info("updateTime:" + data.updateTime);
358 console.info("appInfo.name:" + data.applicationInfo.name);
359 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName);
360 console.info('getBundleInfo reqPermissions length [' + data.reqPermissions.length + ']');
361 for (var j = 0; j < data.reqPermissions.length; j++) {
362 console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]);
363 }
364 console.info('getBundleInfo defPermissions length [' + data.defPermissions.length + ']');
365 for (var j = 0; j < data.defPermissions.length; j++) {
366 console.info("defPermissions[" + j + "]:" + data.defPermissions[j]);
367 }
368
369 console.info('getBundleInfo hapModuleNames length [' + data.hapModuleNames.length + ']');
370 for (var j = 0; j < data.hapModuleNames.length; j++) {
371 console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]);
372 }
373 console.info('getBundleInfo moduleNames length [' + data.moduleNames.length + ']');
374 for (var j = 0; j < data.moduleNames.length; j++) {
375 console.info("moduleNames[" + j + "]:" + data.moduleNames[j]);
376 }
377 console.info('getBundleInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']');
378 for (var j = 0; j < data.modulePublicDirs.length; j++) {
379 console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]);
380 }
381 console.info('getBundleInfo moduleDirs length [' + data.moduleDirs.length + ']');
382 for (var j = 0; j < data.moduleDirs.length; j++) {
383 console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]);
384 }
385 console.info('getBundleInfo moduleResPaths length [' + data.moduleResPaths.length + ']');
386 for (var j = 0; j < data.moduleResPaths.length; j++) {
387 console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]);
388 }
389 console.info('getBundleInfo abilityInfo length [' + data.abilityInfos.length + ']');
390 for (var j = 0; j < data.abilityInfos.length; j++) {
391 console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name);
392 console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package);
393 }
394})
395```
396
397根据bundle名称获取BundleInfo(callback形式)
398
399* getBundleInfo参数描述
400
401 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
402 | ----------- | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
403 | bundleName | 只读 | string | 是 | 包名 |
404 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo |
405 | callback | 只读 | AsyncCallback<BundleInfo> | 是 | 回调方法 |
406
407* 返回值
408
409 void
410
411* 示例
412
413```
414bundle.getBundleInfo('com.example.myapplicationInstall', 1, OnReceiveEvent);
415
416function OnReceiveEvent(err, data) {
417 console.info("name:" + data.name);
418 console.info("label:" + data.label);
419 console.info("description:" + data.description);
420 console.info("vendor:" + data.vendor);
421 console.info("versionCode:" + data.versionCode);
422 console.info("versionName:" + data.versionName);
423 console.info("jointUserId:" + data.jointUserId);
424 console.info("minSdkVersion:" + data.minSdkVersion);
425 console.info("maxSdkVersion:" + data.maxSdkVersion);
426 console.info("mainEntry:" + data.mainEntry);
427 console.info("cpuAbi:" + data.cpuAbi);
428 console.info("appId:" + data.appId);
429 console.info("compatibleVersion:" + data.compatibleVersion);
430 console.info("targetVersion:" + data.targetVersion);
431 console.info("releaseType:" + data.releaseType);
432 console.info("uid:" + data.uid);
433 console.info("gid:" + data.gid);
434 console.info("seInfo:" + data.seInfo);
435 console.info("entryModuleName:" + data.entryModuleName);
436 console.info("isKeepAlive:" + data.isKeepAlive);
437 console.info("isNativeApp:" + data.isNativeApp);
438 console.info("installTime:" + data.installTime);
439 console.info("updateTime:" + data.updateTime);
440 console.info("appInfo.name:" + data.applicationInfo.name);
441 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName);
442 console.info('getBundleInfo reqPermissions length [' + data.reqPermissions.length + ']');
443 for (var j = 0; j < data.reqPermissions.length; j++) {
444 console.info("reqPermissions[" + j + "]:" + data.reqPermissions[j]);
445 }
446 console.info('getBundleInfo defPermissions length [' + data.defPermissions.length + ']');
447 for (var j = 0; j < data.defPermissions.length; j++) {
448 console.info("defPermissions[" + j + "]:" + data.defPermissions[j]);
449 }
450
451 console.info('getBundleInfo hapModuleNames length [' + data.hapModuleNames.length + ']');
452 for (var j = 0; j < data.hapModuleNames.length; j++) {
453 console.info("hapModuleNames[" + j + "]:" + data.hapModuleNames[j]);
454 }
455 console.info('getBundleInfo moduleNames length [' + data.moduleNames.length + ']');
456 for (var j = 0; j < data.moduleNames.length; j++) {
457 console.info("moduleNames[" + j + "]:" + data.moduleNames[j]);
458 }
459 console.info('getBundleInfo modulePublicDirs length [' + data.modulePublicDirs.length + ']');
460 for (var j = 0; j < data.modulePublicDirs.length; j++) {
461 console.info("modulePublicDirs[" + j + "]:" + data.modulePublicDirs[j]);
462 }
463 console.info('getBundleInfo moduleDirs length [' + data.moduleDirs.length + ']');
464 for (var j = 0; j < data.moduleDirs.length; j++) {
465 console.info("moduleDirs[" + j + "]:" + data.moduleDirs[j]);
466 }
467 console.info('getBundleInfo moduleResPaths length [' + data.moduleResPaths.length + ']');
468 for (var j = 0; j < data.moduleResPaths.length; j++) {
469 console.info("moduleResPaths[" + j + "]:" + data.moduleResPaths[j]);
470 }
471 console.info('getBundleInfo abilityInfo length [' + data.abilityInfos.length + ']');
472 for (var j = 0; j < data.abilityInfos.length; j++) {
473 console.info("abilityInfos[" + j + "]name:" + data.abilityInfos[j].name);
474 console.info("abilityInfos[" + j + "]package:" + data.abilityInfos[j].package);
475 }
476}
477```
478
479#### 获取指定用户下所有已安装的应用信息
480
481* getAllApplicationInfo参数描述
482
483 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
484 | ----------- | -------- | ------ | ---- | ------------------------------------------------------- |
485 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 |
486 | userId | 只读 | number | 是 | 用户ID |
487
488* 返回值
489
490 Promise<Array<ApplicationInfo>>:返回值为Promise对象,Promise中包含应用信息列表。
491
492* 示例
493
494```
495bundle.getAllApplicationInfo(8, 0).then((data) => {
496 console.info('xxx getAllApplicationInfo data length [' + data.length + ']');
497 for (var i = 0; i < data.length; i++) {
498 console.info("index[" + i + "].name: for begin");
499 console.info("index[" + i + "].name:" + data[i].name);
500 console.info("index[" + i + "].bundleName:" + data[i].bundleName);
501 console.info("index[" + i + "].description:" + data[i].description);
502 console.info("index[" + i + "].descriptionId:" + data[i].descriptionId);
503 console.info("index[" + i + "].iconPath:" + data[i].iconPath);
504 console.info("index[" + i + "].iconId:" + data[i].iconId);
505 console.info("index[" + i + "].label:" + data[i].label);
506 console.info("index[" + i + "].labelId:" + data[i].labelId);
507 console.info("index[" + i + "].deviceId:" + data[i].deviceId);
508 console.info("index[" + i + "].signatureKey:" + data[i].signatureKey);
509 console.info("index[" + i + "].process:" + data[i].process);
510 console.info("index[" + i + "].isSystemApp:" + data[i].isSystemApp);
511 console.info("index[" + i + "].isLauncherApp:" + data[i].isLauncherApp);
512 console.info("index[" + i + "].supportedModes:" + data[i].supportedModes);
513
514 console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']');
515 for (var j = 0; j < data[i].permissions.length; j++) {
516 console.info("index[" + i + "]permissions[" + j + "]:" + data[i].permissions[j]);
517 }
518 console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']');
519 for (var j = 0; j < data[i].moduleSourceDirs.length; j++) {
520 console.info("index[" + i + "]moduleSourceDirs[" + j + "]:" + data[i].moduleSourceDirs[j]);
521 }
522 console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']');
523 for (var j = 0; j < data[i].moduleInfos.length; j++) {
524 console.info("index[" + i + "]moduleInfos[" + j + "]moduleName:" + data[i].moduleInfos[j].moduleName);
525 console.info("index[" + i + "]moduleInfos[" + j + "]moduleSourceDir:" + data[i].moduleInfos[j].moduleSourceDir);
526 }
527 console.info("index[" + i + "].entryDir:" + data[i].entryDir);
528 console.info("index[" + i + "].codePath:" + data[i].codePath);
529 console.info("index[" + i + "].dataDir:" + data[i].dataDir);
530 console.info("index[" + i + "].dataBaseDir:" + data[i].dataBaseDir);
531 console.info("index[" + i + "].cacheDir:" + data[i].cacheDir);
532 }
533})
534```
535
536获取指定用户下所有已安装的应用信息(callback形式)
537
538* getAllApplicationInfo参数描述
539
540 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
541 | ----------- | -------- | ------------------------------------- | ---- | ------------------------------------------------------- |
542 | bundleFlags | 只读 | number | 是 | 0:返回默认app信息<<br/>8:返回包含permissions的app信息 |
543 | userId | 只读 | number | 是 | 用户ID |
544 | callback | 只读 | AsyncCallback<Array<ApplicationInfo>> | 是 | 回调方法 |
545
546* 返回值
547
548 void
549
550* 示例
551
552```
553bundle.getAllApplicationInfo(8, 0, OnReceiveEvent);
554
555function OnReceiveEvent(err, data) {
556 console.info('xxx getAllApplicationInfo data length [' + data.length + ']');
557 for (var i = 0; i < data.length; i++) {
558 console.info("index[" + i + "].name: for begin");
559 console.info("index[" + i + "].name:" + data[i].name);
560 console.info("index[" + i + "].bundleName:" + data[i].bundleName);
561 console.info("index[" + i + "].description:" + data[i].description);
562 console.info("index[" + i + "].descriptionId:" + data[i].descriptionId);
563 console.info("index[" + i + "].iconPath:" + data[i].iconPath);
564 console.info("index[" + i + "].iconId:" + data[i].iconId);
565 console.info("index[" + i + "].label:" + data[i].label);
566 console.info("index[" + i + "].labelId:" + data[i].labelId);
567 console.info("index[" + i + "].deviceId:" + data[i].deviceId);
568 console.info("index[" + i + "].signatureKey:" + data[i].signatureKey);
569 console.info("index[" + i + "].process:" + data[i].process);
570 console.info("index[" + i + "].isSystemApp:" + data[i].isSystemApp);
571 console.info("index[" + i + "].isLauncherApp:" + data[i].isLauncherApp);
572 console.info("index[" + i + "].supportedModes:" + data[i].supportedModes);
573
574 console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']');
575 for (var j = 0; j < data[i].permissions.length; j++) {
576 console.info("index[" + i + "]permissions[" + j + "]:" + data[i].permissions[j]);
577 }
578 console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']');
579 for (var j = 0; j < data[i].moduleSourceDirs.length; j++) {
580 console.info("index[" + i + "]moduleSourceDirs[" + j + "]:" + data[i].moduleSourceDirs[j]);
581 }
582 console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']');
583 for (var j = 0; j < data[i].moduleInfos.length; j++) {
584 console.info("index[" + i + "]moduleInfos[" + j + "]moduleName:" + data[i].moduleInfos[j].moduleName);
585 console.info("index[" + i + "]moduleInfos[" + j + "]moduleSourceDir:" + data[i].moduleInfos[j].moduleSourceDir);
586 }
587 console.info("index[" + i + "].entryDir:" + data[i].entryDir);
588 console.info("index[" + i + "].codePath:" + data[i].codePath);
589 console.info("index[" + i + "].dataDir:" + data[i].dataDir);
590 console.info("index[" + i + "].dataBaseDir:" + data[i].dataBaseDir);
591 console.info("index[" + i + "].cacheDir:" + data[i].cacheDir);
592 }
593}
594```
595
596
597#### 通过Want获取对应的Ability信息
598
599* queryAbilityInfo参数描述
600
601 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
602 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ |
603 | want | 只读 | Want | 是 | 指定Want信息 |
604 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo |
605 | userId | 只读 | number | 是 | 用户ID |
606
607* Want类型说明
608
609 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
610 | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
611 | elementName | 只读 | ElementName | 是 | 表示运行指定Ability的ElementName。 |
612 | uri | 只读 | string | 否 | 表示Uri描述。 |
613 | flags | 只读 | int | 否 | Ability的flag,表示处理Want的方式。 |
614 | type | 只读 | string | 否 | Want中的type属性是指由Want的URI所指示的资源的MIME类型。 |
615 | action | 只读 | string | 否 | 表示动作,通常使用系统预置Action,应用也可以自定义Action。 |
616 | want_param | 只读 | {[key: string]: any} | 否 | want_param是一种支持自定义的数据结构,开发者可以通过want_param传递某些请求所需的额外信息。 |
617 | entities | 只读 | Array<string> | 否 | 表示类别,通常使用系统预置Entity,应用也可以自定义Entity。 |
618
619* ElementName类型说明
620
621 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
622 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ |
623 | deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 |
624 | bundleName | 只读 | string | 是 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
625 | abilityName | 只读 | string | 是 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
626
627* 返回值
628
629 Promise<AbilityInfo>:返回值为Promise对象,Promise中包含Ability信息。
630
631* 示例
632
633```
634bundle.queryAbilityByWant({
635 want: {
636 action: "action.system.home",
637 entities: ["entity.system.home"],
638 elementName: {
639 deviceId: "0",
640 bundleName: "com.example.myapplicationInstall",
641 abilityName: "com.example.myapplication.MainAbility",
642 },
643 }
644}, 1, 0,
645}).then((data) => {
646 console.info("name:" + data.name);
647 console.info("label:" + data.label);
648 console.info("description:" + data.description);
649 console.info("iconPath:" + data.iconPath);
650 console.info("visible:" + data.visible);
651 console.info("kind:" + data.kind);
652 console.info("uri:" + data.uri);
653 console.info("process:" + data.process);
654 console.info("package:" + data.package);
655 console.info("bundleName:" + data.bundleName);
656 console.info("moduleName:" + data.moduleName);
657 console.info("applicationName:" + data.applicationName);
658 console.info("deviceId:" + data.deviceId);
659 console.info("codePath:" + data.codePath);
660 console.info("resourcePath:" + data.resourcePath);
661 console.info("libPath:" + data.libPath);
662
663 console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']');
664 for (var j = 0; j < data.permissions.length; j++) {
665 console.info("permissions[" + j + "]:" + data.permissions[j]);
666 }
667 console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']');
668 for (var j = 0; j < data.deviceTypes.length; j++) {
669 console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]);
670 }
671 console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']');
672 for (var j = 0; j < data.deviceCapabilities.length; j++) {
673 console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]);
674 }
675 console.info("appInfo.name:" + data.applicationInfo.name);
676 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName);
677 // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA
678 console.info("type:" + data.type);
679 // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT,
680 console.info("orientation:" + data.orientation);
681 // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD
682 console.info("launchMode:" + data.launchMode);
683
684 // the enum of AbilityType
685 console.info("AbilityType:" + bundle.AbilityType.UNKNOWN);
686 console.info("AbilityType:" + bundle.AbilityType.PAGE);
687 console.info("AbilityType:" + bundle.AbilityType.SERVICE);
688 console.info("AbilityType:" + bundle.AbilityType.DATA);
689 if (data.type == bundle.AbilityType.PAGE) {
690 console.info("this AbilityType is PAGE");
691 }
692 // the enum of DisplayOrientation
693 console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED);
694 console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE);
695 console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT);
696 console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT);
697 if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) {
698 console.info("this DisplayOrientation is UNSPECIFIED");
699 }
700 // the enum of LaunchMode
701 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON);
702 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP);
703 console.info("LaunchMode:" + bundle.LaunchMode.STANDARD);
704 if (data.launchMode == bundle.LaunchMode.STANDARD) {
705 console.info("this LaunchMode is STANDARD");
706 }
707
708})
709```
710
711通过Want获取对应的Ability信息(callback形式)
712
713* queryAbilityInfo参数描述
714
715 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
716 | ----------- | -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
717 | want | 只读 | Want | 是 | 指定Want信息 |
718 | bundleFlags | 只读 | number | 是 | 0:返回默认BundleInfo<br/>1:返回包含abilityInfo的BundleInfo |
719 | userId | 只读 | number | 是 | 用户ID |
720 | callback | 只读 | AsyncCallback<Array<AbilityInfo>> | 是 | 回调方法 |
721
722* Want类型说明
723
724 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
725 | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
726 | elementName | 只读 | ElementName | 是 | 表示运行指定Ability的ElementName。 |
727 | uri | 只读 | string | 否 | 表示Uri描述。 |
728 | flags | 只读 | int | 否 | Ability的flag,表示处理Want的方式。 |
729 | type | 只读 | string | 否 | Want中的type属性是指由Want的URI所指示的资源的MIME类型。 |
730 | action | 只读 | string | 否 | 表示动作,通常使用系统预置Action,应用也可以自定义Action。 |
731 | want_param | 只读 | {[key: string]: any} | 否 | want_param是一种支持自定义的数据结构,开发者可以通过want_param传递某些请求所需的额外信息。 |
732 | entities | 只读 | Array<string> | 否 | 表示类别,通常使用系统预置Entity,应用也可以自定义Entity。 |
733
734* ElementName类型说明
735
736 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
737 | ----------- | -------- | ------ | ---- | ------------------------------------------------------------ |
738 | deviceId | 只读 | string | 否 | 表示运行指定Ability的设备ID。 |
739 | bundleName | 只读 | string | 是 | 表示包描述。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
740 | abilityName | 只读 | string | 是 | 表示待启动的Ability名称。如果在Want中同时指定了BundleName和AbilityName,则Want可以直接匹配到指定的Ability。 |
741
742* 返回值
743
744 void
745
746* 示例
747
748```
749bundle.queryAbilityByWant(
750 {
751 want: {
752 action: "action.system.home",
753 entities: ["entity.system.home"],
754 elementName: {
755 deviceId: "0",
756 bundleName: "com.example.myapplicationInstall",
757 abilityName: "com.example.myapplication.MainAbility",
758 },
759 }
760 }, 1, 0,
761 }, OnReceiveEvent);
762
763function OnReceiveEvent(err, data) {
764 console.info("name:" + data.name);
765 console.info("label:" + data.label);
766 console.info("description:" + data.description);
767 console.info("iconPath:" + data.iconPath);
768 console.info("visible:" + data.visible);
769 console.info("kind:" + data.kind);
770 console.info("uri:" + data.uri);
771 console.info("process:" + data.process);
772 console.info("package:" + data.package);
773 console.info("bundleName:" + data.bundleName);
774 console.info("moduleName:" + data.moduleName);
775 console.info("applicationName:" + data.applicationName);
776 console.info("deviceId:" + data.deviceId);
777 console.info("codePath:" + data.codePath);
778 console.info("resourcePath:" + data.resourcePath);
779 console.info("libPath:" + data.libPath);
780
781 console.info('queryAbilityInfo permissions length [' + data.permissions.length + ']');
782 for (var j = 0; j < data.permissions.length; j++) {
783 console.info("permissions[" + j + "]:" + data.permissions[j]);
784 }
785 console.info('queryAbilityInfo deviceTypes length [' + data.deviceTypes.length + ']');
786 for (var j = 0; j < data.deviceTypes.length; j++) {
787 console.info("deviceTypes[" + j + "]:" + data.deviceTypes[j]);
788 }
789 console.info('queryAbilityInfo deviceCapabilities length [' + data.deviceCapabilities.length + ']');
790 for (var j = 0; j < data.deviceCapabilities.length; j++) {
791 console.info("deviceCapabilities[" + j + "]:" + data.deviceCapabilities[j]);
792 }
793 console.info("appInfo.name:" + data.applicationInfo.name);
794 console.info("appInfo.bundleName:" + data.applicationInfo.bundleName);
795 // ability type: 0:UNKNOWN, 1:PAGE, 2:SERVICE, 3:DATA
796 console.info("type:" + data.type);
797 // orientation: 0:UNSPECIFIED, 1:LANDSCAPE, 2:PORTRAIT, 3:FOLLOWRECENT,
798 console.info("orientation:" + data.orientation);
799 // launchMode: 0:SINGLETON, 1:SINGLETOP, 2:STANDARD
800 console.info("launchMode:" + data.launchMode);
801
802 // the enum of AbilityType
803 console.info("AbilityType:" + bundle.AbilityType.UNKNOWN);
804 console.info("AbilityType:" + bundle.AbilityType.PAGE);
805 console.info("AbilityType:" + bundle.AbilityType.SERVICE);
806 console.info("AbilityType:" + bundle.AbilityType.DATA);
807 if (data.type == bundle.AbilityType.PAGE) {
808 console.info("this AbilityType is PAGE");
809 }
810 // the enum of DisplayOrientation
811 console.info("DisplayOrientation:" + bundle.DisplayOrientation.UNSPECIFIED);
812 console.info("DisplayOrientation:" + bundle.DisplayOrientation.LANDSCAPE);
813 console.info("DisplayOrientation:" + bundle.DisplayOrientation.PORTRAIT);
814 console.info("DisplayOrientation:" + bundle.DisplayOrientation.FOLLOWRECENT);
815 if (data.orientation == bundle.DisplayOrientation.UNSPECIFIED) {
816 console.info("this DisplayOrientation is UNSPECIFIED");
817 }
818 // the enum of LaunchMode
819 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETON);
820 console.info("LaunchMode:" + bundle.LaunchMode.SINGLETOP);
821 console.info("LaunchMode:" + bundle.LaunchMode.STANDARD);
822 if (data.launchMode == bundle.LaunchMode.STANDARD) {
823 console.info("this LaunchMode is STANDARD");
824 }
825}
826```
827
828#### 安装hap包
829
830* install参数描述
831
832 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
833 | --------------- | -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
834 | bundleFilePaths | 只读 | Array<string> | 是 | 安装用包路径 |
835 | param | 只读 | InstallParam | 是 | userId:用户ID<br/>installFlag:安装标识。<br/> NORMAL:安装/卸载<br/> REPLACE_EXISTING:更新<br/>isKeepData:卸载时是否保留运行时数据 |
836 | callback | 只读 | AsyncCallback<InstallStatus> | 是 | 回调方法 |
837
838* 返回值
839
840 void
841
842* InstallStatus类型说明
843
844 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
845 | ------------- | -------- | --------------- | ---- | -------- |
846 | InstallStatus | 只读 | IStatusReceiver | 是 | 安装结果 |
847
848* 示例
849
850```
851bundle.getBundleInstaller().then((data) => {
852 data.install(['/data/test.hap'], {
853 param: {
854 userId: 0,
855 isKeepData: false
856 }
857 }, OnReceiveinstallEvent);
858
859 function OnReceiveinstallEvent(err, data) {
860 console.info("name: for begin");
861 console.info("install result code:" + data.status);
862 console.info("install result msg:" + data.statusMessage);
863 }
864})
865```
866
867
868#### 卸载hap包
869
870* uninstall参数描述
871
872 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
873 | ---------- | -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
874 | bundleName | 只读 | string | 是 | 卸载用包名 |
875 | param | 只读 | InstallParam | 是 | userId:用户ID<br/>installFlag:安装标识。<br/> NORMAL:安装/卸载<br/> REPLACE_EXISTING:更新<br/>isKeepData:卸载时是否保留运行时数据 |
876 | callback | 只读 | AsyncCallback<InstallStatus> | 是 | 回调方法 |
877
878* 返回值
879
880 void
881
882* InstallStatus类型说明
883
884 | 名称 | 读写属性 | 类型 | 必填 | 描述 |
885 | ------------- | -------- | --------------- | ---- | -------- |
886 | InstallStatus | 只读 | IStatusReceiver | 是 | 卸载结果 |
887
888* 示例
889
890```
891bundle.getBundleInstaller().then((data) => {
892 data.uninstall('com.example.myapplication', {
893 param: {
894 userId: 0,
895 isKeepData: false
896 }
897 }, OnReceiveinstallEvent);
898
899 function OnReceiveinstallEvent(err, data) {
900 console.info("name: for begin");
901 console.info("uninstall result code:" + data.status);
902 console.info("uninstall result msg:" + data.statusMessage);
903 }
904})
905```
906
907
908### bm命令如下
909
910**bm命令帮助**
911
912| 命令 | 描述 |
913| ------- | ---------- |
914| bm help | bm帮助命令 |
915
916**安装应用**
917
918| 命令 | 描述 |
919| ----------------------------------- | -------------------------- |
920| bm install -p <bundle-file-path> | 通过指定路径安装一个应用包 |
921| bm install -r -p <bundle-file-path> | 覆盖安装一个应用包 |
922
923```
924示例如下:
925bm install -p /data/app/ohosapp.hap
926```
927
928**卸载应用**
929
930| 命令 | 描述 |
931| ----------------------------- | ------------------------ |
932| bm uninstall -n <bundle-name> | 通过指定包名卸载一个应用 |
933
934```
935示例如下:
936bm uninstall -n com.ohos.app
937```
938
939**查看应用安装信息**
940
941| 命令 | 描述 |
942| ---------- | -------------------------- |
943| bm dump -a | 列出系统已经安装的所有应用 |
944
945## 相关仓
946
947用户程序框架子系统
948
949**appexecfwk_standard**
950
951aafwk_standard
952
953startup_appspawn
954