1e41f4b71Sopenharmony_ci# Adaptation Guide for the Application Sandbox
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Verification Process
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci![](figures/verification-process.png)
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci1. Verify your application functions. If all the functions are normal, no adaptation is required.
8e41f4b71Sopenharmony_ci2. If any function is found to be abnormal, analyze the code to identify the exception. Then adapt the file access model by following the instructions provided in [Adaptation Process](#adaptation-process).
9e41f4b71Sopenharmony_ci3. After the adaptation is complete, verify the functions again. If all the functions are normal, the adaptation process is complete. If any function is found to be abnormal, repeat the operations described in Step 2.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Adaptation Process
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci![](figures/adaptation-process.png)
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci1. Check whether the identified exception is caused by an incorrect access path of the application source code. You can check the correctness of an access path against [Sandbox File Access Specifications](#sandbox-file-access-specifications).
16e41f4b71Sopenharmony_ci2. If the application source code accesses an incorrect path, change the path access policy. Specifically, use the **Context** API rather than the absolute path to access the **/data** directory. For details about the **Context** API, see the following documents:
17e41f4b71Sopenharmony_ci   https://gitee.com/openharmony/docs/blob/master/en/application-dev/application-models/application-context-stage.md
18e41f4b71Sopenharmony_ci3. If the exception is caused by a third-party module invoked by the application and the application source code does not use an absolute path to access files, proceed as follows:
19e41f4b71Sopenharmony_ci   - Request the third-party module to access the file path through the **Context** API instead of using the absolute path.
20e41f4b71Sopenharmony_ci   - If the third-party module is a common module used by both appspawn incubated processes and native processes, abstract the third-party module as a service and access the service in IPC mode.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci## Sandbox File Access Specifications
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**Access Paths in the Application Root Directory**
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| Path               | Description                                      |
27e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------ |
28e41f4b71Sopenharmony_ci| bin                   | Binary file directory.                      |
29e41f4b71Sopenharmony_ci| config                | Configuration directory.                                  |
30e41f4b71Sopenharmony_ci| data                  | Application data directory.                              |
31e41f4b71Sopenharmony_ci| dev                   | Device node directory.                                  |
32e41f4b71Sopenharmony_ci| etc                   | Soft link of **/system/etc**.                       |
33e41f4b71Sopenharmony_ci| init                  | Soft link of **/system/bin/init**.                  |
34e41f4b71Sopenharmony_ci| lib                   | Soft link of **/system/lib**.                       |
35e41f4b71Sopenharmony_ci| mnt                   | Mount directory.                                  |
36e41f4b71Sopenharmony_ci| proc                  | Directory of the proc file system.                          |
37e41f4b71Sopenharmony_ci| sys                   | Directory of the sys file system.                           |
38e41f4b71Sopenharmony_ci| sys_prod              | This directory varies according to devices. Some devices do not have this directory.|
39e41f4b71Sopenharmony_ci| system/app            | System directory resources.                              |
40e41f4b71Sopenharmony_ci| system/fonts          | System fonts.                              |
41e41f4b71Sopenharmony_ci| system/lib            | System libraries.                                    |
42e41f4b71Sopenharmony_ci| system/data           | System directory resources.                              |
43e41f4b71Sopenharmony_ci| system/usr            | System directory resources.                              |
44e41f4b71Sopenharmony_ci| system/profile        | System directory resources.                              |
45e41f4b71Sopenharmony_ci| system/bin            | System programs.                                  |
46e41f4b71Sopenharmony_ci| system/etc            | System configuration.                                  |
47e41f4b71Sopenharmony_ci| vendor/lib/chipsetsdk | Chip component directory. Currently, only chipsetsdk is mounted.        |
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Access Paths in the Application Data Directory**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci| Path                            | Description                                                        |
52e41f4b71Sopenharmony_ci| ---------------------------------- | ------------------------------------------------------------ |
53e41f4b71Sopenharmony_ci| /data                              | Application data directory.                                                |
54e41f4b71Sopenharmony_ci| /data/storage                      | Application data.                                                    |
55e41f4b71Sopenharmony_ci| /data/bundles                      | Installation directory of all applications. Only applications with the BASIC or higher ability privilege level (APL) can access this directory.|
56e41f4b71Sopenharmony_ci| /data/storage/el1                  | Data directory of applications with encryption level 1.                                     |
57e41f4b71Sopenharmony_ci| /data/storage/el2                  | Data directory of applications with encryption level 2.                                     |
58e41f4b71Sopenharmony_ci| /data/storage/el1/base             | Data directory of applications with encryption level 1.                                     |
59e41f4b71Sopenharmony_ci| /data/storage/el1/bundles          | Installation package directory of applications with encryption level 1.                               |
60e41f4b71Sopenharmony_ci| /data/storage/el1/database         | Database directory of applications with encryption level 1.                               |
61e41f4b71Sopenharmony_ci| /data/storage/el2/base             | Data directory of applications with encryption level 2.                                     |
62e41f4b71Sopenharmony_ci| /data/storage/el2/database         | Database directory of applications with encryption level 2.                               |
63e41f4b71Sopenharmony_ci| /data/storage/el2/auth_groups      | Distributed data directory of applications with encryption level 2 but without an account.                     |
64e41f4b71Sopenharmony_ci| /data/storage/el2/distributedfiles | Distributed data directory of applications with encryption level 2 and an account.                     |
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ciWhen the application sandbox is enabled, your application cannot access the physical paths in the application data directory in the application namespace. It must use the **Context** API for the access.
67e41f4b71Sopenharmony_ciFor a specific application, its physical data directory and sandbox data directory store the same set of data, which is associated using bind mounts. Any change to one directory affects the data in the other directory. Applications can access data in namespaces only through sandbox paths. The following table lists the mapping between physical paths and sandbox paths in the application data directory.
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci**Mapping Between Physical Paths and Sandbox Paths in the Application Data Directory**
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci| Physical Path                                                    | Sandbox Path                          | Description                                   |
72e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ---------------------------------- | --------------------------------------- |
73e41f4b71Sopenharmony_ci| /data/app/el1/bundle/public/\<PackageName>\                  | /data/storage/el1/bundle           | Application installation package directory.                         |
74e41f4b71Sopenharmony_ci| /data/app/el1/\<USERID\>/base/\<PACKAGENAME\>                | /data/storage/el1/base             | Encrypted data directory of applications with encryption level 1.                |
75e41f4b71Sopenharmony_ci| /data/app/el2/\<USERID\>/base/\<PACKAGENAME\>                | /data/storage/el2/base             | Encrypted data directory of applications with encryption level 2.                |
76e41f4b71Sopenharmony_ci| /data/app/el1/\<USERID\>/database/\<PACKAGENAME\>            | /data/storage/el1/database         | Encrypted database directory of applications with encryption level 1.              |
77e41f4b71Sopenharmony_ci| /data/app/el2/\<USERID\>/database/\<PACKAGENAME\>            | /data/storage/el2/database         | Encrypted database directory of applications with encryption level 2.              |
78e41f4b71Sopenharmony_ci| /mnt/hmdfs/\<USERID\>/account/merge_view/data/\<PACKAGENAME\> | /data/storage/el2/distributedfiles | Distributed data directory of applications with encryption level 2 and an account.|
79e41f4b71Sopenharmony_ci| /mnt/hmdfs/\<USERID\>/non_account/merge_view/data/           | /data/storage/el2/auth_groups      | Distributed data directory of applications with encryption level 2 but without an account.|
80e41f4b71Sopenharmony_ci| /mnt/hmdfs/                                                  | /mnt/hmdfs/                        | Distributed file system directory.                     |
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci> **NOTE**
83e41f4b71Sopenharmony_ci>
84e41f4b71Sopenharmony_ci>  \<USERID\> indicates the current user ID.
85e41f4b71Sopenharmony_ci> \<PACKAGENAME\> indicates the name of the current application package.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ciFor more information about the mapping between physical paths and sandbox paths, see the following:
88e41f4b71Sopenharmony_cihttps://gitee.com/OpenHarmony/startup_appspawn/blob/master/appdata-sandbox64.json
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci## Case: No Audio in the Contacts.hap Dialing Scenario
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciAs shown in the figure below, the access path is a hardcoded absolute path, **/data/app/el1**. The access to such paths is not allowed in the application sandbox, causing the access failure.
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci![](figures/example1.png)
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ciThe preceding code snippet uses the **fileIO** interface to open a fixed path to obtain a **fdNumber**, which will be used for subsequent file access. Since the **fdNumber** can no longer be obtained using a fixed path, you can use other methods to obtain the **fdNumber**.
97e41f4b71Sopenharmony_ciIn OpenHarmony, you can use **resourceManager** to obtain a **fdNumber**.
98e41f4b71Sopenharmony_ciThe new code is as follows:
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci![](figures/example2.png)
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci## Workaround
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ciIf an application exception persists after the preceding adaptation process, you can disable the application sandbox.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci1. Open the source code of the OpenHarmony startup_appspawn repository, and find the application sandbox configuration file based on the build type.
107e41f4b71Sopenharmony_ci   For a 32-bit system, modify the file **https://gitee.com/OpenHarmony/startup_appspawn/blob/master/appdata-sandbox.json**.
108e41f4b71Sopenharmony_ci   For a 64-bit system, modify the file **https://gitee.com/OpenHarmony/startup_appspawn/blob/master/appdata-sandbox.json**.
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci2. Find the camera configuration in the .json file, and copy it to create your own application configuration record. In this new record, change the bundle name to your actual application name, and retain the other settings. The value **OFF** indicates that the application sandbox is disabled.
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci   ![](figures/example3.png)
113