• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SystemCapability
2
3## Overview
4
5### System Capabilities and APIs
6
7SystemCapability (SysCap) refers to a standalone feature in the operating system, for example, Bluetooth, Wi-Fi, NFC, or camera. Each SysCap corresponds to a set of APIs, whose availability depends on the support of the target device. Such a set of APIs can be provided in DevEco Studio for association.
8
9![image-20220326064841782](figures/image-20220326064841782.png)
10
11For details about the SysCap sets in OpenHarmony, see [SysCap List](syscap-list.md).
12
13### Supported SysCap Set, Associated SysCap Set, and Required SysCap Set
14
15The supported SysCap set, associated SysCap set, and required SysCap set are collections of SysCaps.
16The supported SysCap set covers the device capabilities, and the required SysCap set covers the application capabilities. If the SysCap set required by application A is a subset of the SysCap set supported by device N, application A can be distributed to device N for installation and running. Otherwise, application A cannot be distributed.
17The associated SysCap set covers the system capabilities of associated APIs that DevEco Studio offers during application development.
18
19![image-20220326064913834](figures/image-20220326064913834.png)
20
21### Devices and Supported SysCap Sets
22
23Each device provides a SysCap set that matches its hardware capability.
24The SDK classifies devices into general devices and custom devices. The general devices' supported SysCap set is defined by OpenHarmony, and the custom devices' is defined by device vendors.
25
26![image-20220326064955505](figures/image-20220326064955505.png)
27
28### Mapping Between Devices and SDK Capabilities
29
30The SDK provides a full set of APIs for DevEco Studio. DevEco Studio identifies the supported SysCap set based on the devices selected for the project, filters the APIs contained in the SysCap set, and provides the supported APIs for association (to autocomplete input).
31
32![image-20220326065043006](figures/image-20220326065043006.png)
33
34## How to Develop
35
36### Obtaining the PCID
37
38The Product Compatibility ID (PCID) contains the SysCap information supported by the current device. For the moment, you can obtain the PCID of a device from the device vendor. In the future, you'll be able to obtain the PCIDs of all devices from the authentication center, which is in development.
39
40### Importing the PCID
41
42DevEco Studio allows Product Compatibility ID (PCID) imports for projects. After the imported PCID file is decoded, the SysCap is output and written into the **syscap.json** file.
43
44Right-click the project directory and choose **Import Product Compatibility ID** from the shortcut menu to upload the PCID file and import it to the **syscap.json** file.
45
46![20220329-103626](figures/20220329-103626.gif)
47
48### Configuring the Associated SysCap Set and Required SysCap Set
49
50DevEco Studio automatically configures the associated SysCap set and required SysCap set based on the settings supported by the created project. You can modify these SysCap sets when necessary.
51You can add APIs to the associated SysCap set in DevEco Studio by adding system capabilities. However, note that these APIs may not be supported on the device. Therefore, check whether these APIs are supported before using them.
52Exercise caution when modifying the required SysCap set. Incorrect modifications may result in the application being unable to be distributed to the target device.
53
54```json
55// syscap.json
56{
57	"devices": {
58		"general": [            // General devices. Each general device supports a SysCap set. Multiple general devices can be configured.
59			"default",
60			"car"
61		],
62		"custom": [             // Custom devices.
63			{
64				"Custom device": [
65					"SystemCapability.Communication.SoftBus.Core"
66				]
67			}
68		]
69	},
70	"development": {             // The SysCap set in addedSysCaps and the SysCap set supported by each device configured in devices form the associated SysCap set.
71		"addedSysCaps": [
72			"SystemCapability.Location.Location.Lite"
73		]
74	},
75	"production": {              // Used to generate the RPCID. Exercise caution when adding this parameter. Under incorrect settings, applications may fail to be distributed to target devices.
76		"addedSysCaps": [],      // Intersection of SysCap sets supported by devices configured in devices. It is the required SysCap set with addedSysCaps set and removedSysCaps set.
77		"removedSysCaps": []     // When the required SysCap set is a capability subset of a device, the application can be distributed to the device.
78	}
79}
80```
81
82### Single-Device Application Development
83
84By default, the associated SysCap set and required SysCap set of the application are the same as the supported SysCap set of the device. Exercise caution when modifying the required SysCap set.
85
86![image-20220326065124911](figures/image-20220326065124911.png)
87
88### Cross-Device Application Development
89
90By default, the associated SysCap set of an application is the union of multiple devices' supported SysCap sets, while the required SysCap set is the intersection of the devices' supported SysCap sets.
91
92![image-20220326065201867](figures/image-20220326065201867.png)
93
94### Checking Whether an API Is Available
95
96- Method 1: Use the **canIUse()** API to check whether a SysCap is supported.
97
98   ```ts
99   if (canIUse("SystemCapability.ArkUI.ArkUI.Full")) {
100   	   console.log("This device supports SystemCapability.ArkUI.ArkUI.Full.");
101   } else {
102	   console.log("This device does not support SystemCapability.ArkUI.ArkUI.Full.");
103   }
104   ```
105
106- Method 2: Import a module using the **import** API. If the current device does not support the module, the import result is **undefined**. Before using an API, you must make sure the API is available.
107
108   ```ts
109   import geolocation from '@ohos.geolocation';
110
111   if (geolocation) {
112	   geolocation.getCurrentLocation((location) => {
113		   console.log(location.latitude, location.longitude);
114	   });
115   } else {
116	   console.log('This device does not support location information.');
117   }
118   ```
119You can also find out the SysCap to which an API belongs by referring to the API reference document.
120
121### Checking the Differences Between Devices with a Specific SysCap
122
123The performance of a SysCap may vary by device type. For example, a tablet is superior to a smart wearable device in terms of the camera capability.
124
125```ts
126import userAuth from '@ohos.userIAM.userAuth';
127
128const authenticator = userAuth.getAuthenticator();
129const result = authenticator.checkAbility('FACE_ONLY', 'S1');
130
131if (result == authenticator.CheckAvailabilityResult.AUTH_NOT_SUPPORT) {
132	console.log('This device does not support facial recognition.');
133}
134// If an unsupported API is forcibly called, an error message is returned, but no syntax error occurs.
135authenticator.execute('FACE_ONLY', 'S1', (err, result) => {
136	if (err) {
137		console.log(err.message);
138		return;
139	}
140})
141```
142
143### How Do SysCap Differences Arise Between Devices
144
145The device SysCaps in product solutions vary according to the component combination defined by the product solution vendor. The following figure shows the overall process.
146
147![image-20220326072448840](figures/image-20220326072448840.png)
148
1491. A set of OpenHarmony source code consists of optional and mandatory components. Different components represent different SysCaps.
150
1512. In a normalized released SDK, APIs are mapped to SysCap sets.
152
1533. Product solution vendors can assemble components based on hardware capabilities and product requirements.
154
1554. The components configured for a product can be OpenHarmony components or proprietary components developed by a third party. Since there is mapping between components and SysCap, the SysCap set of the product can be obtained after all components are assembled.
156
1575. The SysCap set is encoded to generate the PCID. You can import the PCID to DevEco Studio and decode it into SysCaps. During development, compatibility processing is performed to mitigate the SysCap differences of devices.
158
1596. System parameters deployed on devices contain the SysCap set. The system provides native interfaces and application interfaces for components and applications to check whether a specific SysCap is available.
160
1617. During application development, the SysCap set required by the application is encoded into the Required Product Compatibility ID (RPCID) and written into the application installation package. During application installation, the package manager decodes the RPCID to obtain the SysCap set required by the application and compares it with the SysCap set supported by the device. If the SysCap set required by the application is met, the application can be installed on the device.
162
1638. When an application is running on a device, the **canIUse** API can be used to query whether the device is compatible with a specific SysCap.
164