[Huawei Developers] riteshchanchal:
Contact Shield is a basic contact diagnosis service developed based on the Bluetooth low energy (BLE) technology. Global public health institutions can authorize developers to develop COVID-19 contact diagnosis apps using Contact Shield APIs. These apps can interact with other devices while protecting user privacy to check whether a user has been in contact with a person tested positive for COVID-19. If so, the user will be notified and instructed to take relevant measures, effectively controlling the spread of the virus.

Working Principles​

1. The mobile phone of B broadcasts the DSC (Dynamic Sharing Code). The phone can generate a DSC collection based on the periodic key on each day, select a DSC based on the current time, and broadcast the DSC to surrounding devices through BLE.

2. The mobile phone of A receives the DSC broadcast by B. After scanning the DSC broadcast by the mobile phone of B, the mobile phone of A records the current timestamp and received signal strength indicator (RSSI), and stores the data in a local database.

3. If B is diagnosed as a COVID-19 patient, the app obtains authorization from B and uploads the periodic key within the virus incubation period (14 days by default) to the app server or the server specified by a public health institution. In this case, the periodic key of B is called the shared key.

4. The app of A periodically downloads the compressed package of periodic keys of the diagnosed user from the server and calls Contact Shield to perform contact diagnosis. Contact Shield deduces the DSC collection broadcast by the diagnosed person based on the periodic keys provided by the app.

5. During contact diagnosis, Contact Shield uses the DSC collection generated in 4 to match a record in the DSC data table of the last 14 days stored in the local database. After the matching is complete, Contact Shield generates a diagnosis report and notifies A of the contact diagnosis result through the app.

Based on the diagnosis report, A knows whether he or she has been in close contact with the diagnosed user and the potential contact risk level.

When the Contact Shield invokes the interface, the error code -1 is returned. There are many possible causes in this scenario. This section describes the troubleshooting procedure for this error code.

\Note: If the error code -1 is displayed, view the error log and search for the keyword HmsNearbyKit_sdk_ContactApiImpl. Generally, the log contains an error code with the actual error cause.

1. Developer have not applied for the Contact Shield permission (Error code 6004).

Cause 1：

Unlike other HMS SDKs, the Contact Shield SDK requires developers to send related information through emails to grant permissions.

For details about how to apply for the contact guard API permission, see:

https://developer.huawei.com/consum...equest-access-0000001058448610?ha_source=hms1

Cause 2：

The agconnect-services.json file in the local project does not match.

Check whether the agconnect-services.json file added to the local project is the same as the required agconnect-services.json file.

You can download the new agconnect-services.json file from the AGC official website and commission the project again.

For details about how to download the agconnect-services.json file, see：https://developer.huawei.com/consum...-integratesdk-0000001058897058?ha_source=hms1

2. The generated APK signature file (.keystore or .jks file) is different from the SHA-256 information configured on the AGC. (Error code 6003).​

The APK signature file must be the same as the signature configured on the AGC.

The configuration procedure is as follows:

https://developer.huawei.com/consum...ld-config-agc-0000001057648627?ha_source=hms1

3. When the API is invoked for the first time, the mobile phone is not connected to the network.​

When the contact guard API is invoked for the first time, if the mobile phone is not connected to the network, the error code -1 is returned.

In this scenario, ensure that the network connection is normal and invoke the Contact Shield API again.

​

4. After the startContactShield() interface is invoked, the pop-up message is manually canceled.​

After the startContactShield() interface is invoked, the following dialog box is displayed.

User must select Allow to invoke the Contact Shield API.

Note: The error code in the latest Contact Shield has been updated to 8015.

5. User do not have the location permission of the HMS Core APK.​

When the startContactShield() interface is invoked, in addition to the pop-up for point 4, the dialog box shown in the following figure is displayed if you do not have the location permission.

User must select “ALLOW ALL THE TIME”to invoke the Contact Shield API.

Note: The error code in the latest Contact Shield has been updated to 8103.

To view the permission, choose Settings > Apps > Apps > Search HMS Core > Permissions > location.

6. When the putSharedKeyFiles() interface is invoked, the file format provided by the developer is incorrect.​

When the putSharedKeyFiles interface of the Contact Shield is invoked, the transferred file in List<File> files is incorrect.

The format and generation method of this file are the same as those in Google's Exposure Notifications.

For more details, you can go to:

l Our official website

l Our Development Documentation page, to find the documents you need

l Reddit to join our developer discussion

l GitHub to download demos and sample codes

l Stack Overflow to solve any integration problems

Original Source