syscap.md 8.2 KB
Newer Older
W
wusongqing 已提交
1
# SysCap
E
ester.zhou 已提交
2 3 4 5 6

## Overview

### System Capabilities and APIs

E
ester.zhou 已提交
7
SysCap is short for System Capability. It refers to a standalone feature in the operating system, for example, Bluetooth, Wi-Fi, NFC, or camera. Each system capability corresponds to a set of bound APIs, whose availability depends on the support of the target device. Such a set of APIs can be provided in the IDE for association.
E
ester.zhou 已提交
8 9 10 11 12

![image-20220326064841782](figures/image-20220326064841782.png)



E
ester.zhou 已提交
13
### Supported Capability Set, Associated Capability Set, and Required Capability Set
E
ester.zhou 已提交
14

E
ester.zhou 已提交
15
The supported capability set, associated capability set, and required capability set are collections of system capabilities.
E
ester.zhou 已提交
16
The supported capability set covers the device capabilities, and the required capability set covers the application capabilities. If the capability set required by application A is a subset of the capability set supported by device N, application A can be distributed to device N for installation and running. Otherwise, application A cannot be distributed.
E
ester.zhou 已提交
17
The associated capability set covers the system capabilities of associated APIs that the IDE offers during application development.
E
ester.zhou 已提交
18 19 20 21 22 23 24

![image-20220326064913834](figures/image-20220326064913834.png)



### Devices and Supported Capability Sets

E
ester.zhou 已提交
25
Each device provides a capability set that matches its hardware capability.
E
ester.zhou 已提交
26 27 28 29 30 31 32 33
The SDK classifies devices into general devices and custom devices. The general devices' supported capability set is defined by OpenHarmony, and the custom devices' is defined by device vendors.

![image-20220326064955505](figures/image-20220326064955505.png)



### Mapping Between Devices and SDK Capabilities

E
ester.zhou 已提交
34
The SDK provides a full set of APIs for the IDE. The IDE identifies the supported capability set based on the devices supported by the project, filters the APIs contained in the capability set, and provides the supported APIs for association (to autocomplete input).
E
ester.zhou 已提交
35 36 37 38 39 40 41 42 43

![image-20220326065043006](figures/image-20220326065043006.png)



## How to Develop

### Importing the PCID

E
ester.zhou 已提交
44
DevEco 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.
E
ester.zhou 已提交
45 46 47 48 49 50 51

Right-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.

![20220329-103626](figures/20220329-103626.gif)



E
ester.zhou 已提交
52
### Configuring the Associated Capability Set and Required Capability Set
E
ester.zhou 已提交
53

E
ester.zhou 已提交
54 55
The IDE automatically configures the associated capability set and required capability set based on the settings supported by the created project. You can modify the capability sets when necessary.
You can add APIs to the associated capability set in the IDE 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.
E
ester.zhou 已提交
56 57 58 59 60 61
Exercise caution when modifying the required capability set. Incorrect modifications may cause the application to unable to be distributed to the target device.

```
/* syscap.json */
{
	devices: {
E
ester.zhou 已提交
62 63
		general: [            /* General devices. Each general device supports a SysCap set. Multiple general devices can be configured. */
			"default",
E
ester.zhou 已提交
64 65 66
			"car,
			...
		],
E
ester.zhou 已提交
67
		custom: [             /* Custom devices. */
E
ester.zhou 已提交
68 69 70 71 72 73 74 75 76
			{
				"Custom device": [
					"SystemCapability.Communication.SoftBus.Core",
					...
				]
			},
			...
		]
	},
E
ester.zhou 已提交
77
	development: {             /* The SysCap set in addedSysCaps and the SysCap set supported by each device configured in devices form the associated capability set. */
E
ester.zhou 已提交
78 79 80 81 82
		addedSysCaps: [
			"SystemCapability.Location.Location.Lite",
			...
		]
	},
E
ester.zhou 已提交
83
	production: {              /* Used to generate the RPCID. Exercise caution when adding this parameter. Under incorrect settings, applications may fail to be distributed to target devices. */
E
ester.zhou 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
		addedSysCaps: [],      // Intersection of SysCap sets supported by devices configured in devices. It is the required capability set with addedSysCaps set and removedSysCaps set.
		removedSysCaps: []     // When the required capability set is a capability subset of a device, the application can be distributed to the device.
	}
}
```



### Single-Device Application Development

By default, the association capability set and required system capability set of the application are the same as the supported system capability set of the device. Exercise caution when modifying the required capability set.

![image-20220326065124911](figures/image-20220326065124911.png)



### Cross-Device Application Development

E
ester.zhou 已提交
102
By default, the associated capability set of the application is the union of multiple devices' supported capability sets. The capability sets must be the intersection.
E
ester.zhou 已提交
103 104 105 106 107 108 109

![image-20220326065201867](figures/image-20220326065201867.png)



### Checking Whether an API Is Available

E
ester.zhou 已提交
110
Use **canIUse** if you want to check whether a project supports a specific SysCap.
E
ester.zhou 已提交
111 112 113

```
if (canIUse("SystemCapability.ArkUI.ArkUI.Full")) {
E
ester.zhou 已提交
114
	console.log("This application supports SystemCapability.ArkUI.ArkUI.Full.");
E
ester.zhou 已提交
115
} else {
E
ester.zhou 已提交
116
	Console.log("This application does not support SystemCapability.ArkUI.ArkUI.Full".);
E
ester.zhou 已提交
117 118 119
}
```

E
ester.zhou 已提交
120
You can 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.
E
ester.zhou 已提交
121 122 123 124 125 126 127 128 129

```
import geolocation from '@ohos.geolocation';

if (geolocation) {
	geolocation.getCurrentLocation((location) => {
		console.log(location.latitude, location.longitude);
	});
} else {
E
ester.zhou 已提交
130
	Console.log('This device does not support location information.');
E
ester.zhou 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
}
```



### Checking the Differences Between Devices with the Same Capability

The performance of a system capability may vary by device type. For example, a tablet is superior to a smart wearable device in terms of the camera capability.

```
import userAuth from '@ohos.userIAM.userAuth';

const authenticator = userAuth.getAuthenticator();
const result = authenticator.checkAbility('FACE_ONLY', 'S1');

if (result == authenticator.CheckAvailabilityResult.AUTH_NOT_SUPPORT) {
E
ester.zhou 已提交
147
	Console.log('This device does not support facial recognition.');
E
ester.zhou 已提交
148 149 150 151 152 153 154 155 156 157 158
}
// If an unsupported API is forcibly called, an error message is returned, but no syntax error occurs.
authenticator.execute('FACE_ONLY', 'S1', (err, result) => {
	if (err) {
		console.log(err.message);
		return;
	}
})
```


E
ester.zhou 已提交
159
### How Do SysCap Differences Arise Between Devices
E
ester.zhou 已提交
160

E
ester.zhou 已提交
161
The SysCap of devices varies according to the component combination defined by the product solution vendor. The following figure shows the overall process.
E
ester.zhou 已提交
162 163 164 165 166

![image-20220326072448840](figures/image-20220326072448840.png)

1. A set of OpenHarmony source code consists of optional and mandatory components. Different components have different system capabilities. In other words, different components represent different SysCaps.

E
ester.zhou 已提交
167
2. In a normalized released SDK, APIs are mapped to SysCap sets.
E
ester.zhou 已提交
168 169 170

3. Product solution vendors can assemble components based on hardware capabilities and product requirements.

E
ester.zhou 已提交
171
4. 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.
E
ester.zhou 已提交
172

E
ester.zhou 已提交
173
5. The SysCap set is encoded to generate the PCID. You can import the PCID to the IDE and decode it into SysCap. During development, compatibility processing is performed to mitigate the SysCap differences of devices.
E
ester.zhou 已提交
174

E
ester.zhou 已提交
175
6. 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 SysCap set is available.
E
ester.zhou 已提交
176

E
ester.zhou 已提交
177
7. During application development, the SysCap 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 required by the application and compares it with the SysCap of the device. If the SysCap required by the application is met, the application can be installed.
E
ester.zhou 已提交
178

E
ester.zhou 已提交
179
8. When an application is running, the **canIUse** API can be used to query whether the SysCap is compatible with the device.