• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Atomic Service Space Management (for System Applications Only)
2
3Space management for atomic services is necessary from two aspects. On the one hand, users are unaware of the installation of atomic services and do not proactively uninstall them. On the other hand, atomic services have the [installation-free](../reference/apis/js-apis-freeInstall.md) feature, but they are not actually free of installation. This topic describes how to manage the space usage of atomic services for better system space usage.
4
5## Managing Quota for Atomic Service Data Directories
6
7Set a storage quota for the data sandbox directory of an atomic service. This quota can be obtained through the system parameter **persist.sys.bms.aging.policy.atomicservice.datasize.threshold**. The default value is 50 MB. When the quota is used up, writing data will return an error message.
8
9You can run the [param get/set](../../device-dev/subsystems/subsys-boot-init-plugin.md) command to view and set system parameters.
10
11## Proactively Destroying Atomic Services
12
13To proactively destroy an atomic service, call the [uninstall](../reference/apis/js-apis-installer.md#bundleinstalleruninstall) API.
14
15**Example**
16
17```ts
18import installer from '@ohos.bundle.installer';
19import { BusinessError } from '@ohos.base';
20
21let bundleName = 'com.ohos.demo';
22let installParam: installer.InstallParam = {
23    userId: 100
24};
25
26try {
27    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
28        data.uninstall(bundleName, installParam, (err: BusinessError) => {
29            if (err) {
30                console.error('uninstall failed:' + err.message);
31            } else {
32                console.info('uninstall successfully.');
33            }
34        });
35    }).catch((error: BusinessError) => {
36        console.error('getBundleInstaller failed. Cause: ' + error.message);
37    });
38} catch (error) {
39    let message = (error as BusinessError).message;
40    console.error('getBundleInstaller failed. Cause: ' + message);
41}
42```
43
44## Automatically Destroying Atomic Services
45
46### Automatic Destruction Time
47
48Automatic destruction of atomic services can be triggered in any of the following conditions:
49
50- When a timer is set and the given interval has elapsed. The timer interval can be obtained through the system parameter **persist.sys.bms.aging.policy.timer.interval**, which is 8 hours by default. The remaining battery level must be greater than or equal to the value of **persist.sys.bms.aging.policy.battery.threshold**, which is 10% by default.
51- When an atomic service is installed.
52- When the clearance flag of an atomic service is modified.
53
54### Destruction Conditions
55
56#### Prerequisites
57
58- [isHapModuleRemovable](../reference/apis/js-apis-freeInstall.md#ishapmoduleremovable) is set to **true**.
59- The atomic service is not running.
60
61#### Condition for Starting Destruction
62
63The space occupied by all atomic services (including their installation and data directories) is greater than the value of **persist.sys.bms.aging.policy.data.size.threshold**, which is 500 MB by default.
64
65#### Condition for Ending Destruction
66
67The space occupied by all atomic services (including the installation and data directories) is less than 80% of the value of **persist.sys.bms.aging.policy.data.size.threshold**.
68
69### Automatic Destruction Sequence
70
71- Atomic services that can be destroyed are classified into different time slots based on the last used time, for example, [0, 10), [10, 20), [20, 30), [30, ~). The time slot unit can be obtained from the system parameter **persist.sys.bms.aging.policy.recently.used.threshold**, which is 1 day by default.
72- For any two atomic services that can be destroyed, if they are in the same time slot, the atomic service that is less used is destroyed first; if they are in different time slots, the atomic service that is not used for a longer time is destroyed first.
73
74### Automatic Destruction by Level
75
76- When the condition for starting automatic destruction is met, the cache directories of the atomic services are destroyed first based on the destruction sequence. If the condition for ending destruction is met, the destruction is ended.
77- If the condition for ending destruction is not met, the other directories of the atomic service are destroyed based on the destruction sequence.
78