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 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 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 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 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 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 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 93 94### Checking Whether an API Is Available 95 96You can use either the ArkTS or native API to determine whether an API is available. 97 98- ArkTS API 99 100 - Method 1: Use the **canIUse()** API to check whether a SysCap is supported. 101 102 ```ts 103 if (canIUse("SystemCapability.ArkUI.ArkUI.Full")) { 104 console.log("This device supports SystemCapability.ArkUI.ArkUI.Full."); 105 } else { 106 console.log("This device does not support SystemCapability.ArkUI.ArkUI.Full."); 107 } 108 ``` 109 110 - 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. 111 112 ```ts 113 import geolocationManager from '@ohos.geoLocationManager'; 114 115 try { 116 geolocationManager.getCurrentLocation((location) => { 117 console.log('current location: ' + JSON.stringify(location)); 118 }); 119 } catch(err) { 120 console.log('This device does not support location information.' + err); 121 } 122 ``` 123- Native API 124 125 ```c 126 #include <stdio.h> 127 #include <stdlib.h> 128 #include "syscap_ndk.h" 129 130 char syscap[] = "SystemCapability.ArkUI.ArkUI.Full"; 131 bool result = canIUse(syscap); 132 if (result) { 133 printf("SysCap: %s is supported!\n", syscap); 134 } else { 135 printf("SysCap: %s is not supported!\n", syscap); 136 } 137 ``` 138 139You can also find out the SysCap to which an API belongs by referring to the API reference document. 140 141### Checking the Differences Between Devices with a Specific SysCap 142 143The 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. 144 145```ts 146import userAuth from '@ohos.userIAM.userAuth'; 147 148const authParam : userAuth.AuthParam = { 149 challenge: new Uint8Array(), 150 authType: [userAuth.UserAuthType.PIN], 151 authTrustLevel: userAuth.AuthTrustLevel.ATL1, 152}; 153const widgetParam :userAuth.WidgetParam = { 154 title: 'Enter password', 155}; 156try { 157 let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); 158 userAuthInstance.start(); 159 console.log('Device authentication succeeded.'); 160} catch (error) { 161 console.error('auth catch error: ' + JSON.stringify(error)); 162} 163``` 164 165### How Do SysCap Differences Arise Between Devices 166 167The device SysCaps in product solutions vary according to the component combination defined by the product solution vendor. The following figure shows the overall process. 168 169 170 1711. A set of OpenHarmony source code consists of optional and mandatory components. Different components represent different SysCaps. 172 1732. In a normalized released SDK, APIs are mapped to SysCap sets. 174 1753. Product solution vendors can assemble components based on hardware capabilities and product requirements. 176 1774. 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. 178 1795. 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. 180 1816. 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. 182 1837. 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. 184 1858. 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. 186