huawei_contactshield 5.0.4+300
huawei_contactshield: ^5.0.4+300 copied to clipboard

Flutter Android

To help confront the global pandemic of coronavirus disease 2019 (COVID-19), Huawei provides HMS Core Contact Shield for developers to develop epidemic prevention and control apps.

Huawei Contact Shield Kit Flutter Plugin #


Contents #


1. Introduction #

Huawei Contact Shield is a basic contact tracing service developed based on the Bluetooth low energy (BLE) technology. Global public health institutions can authorize developers to develop COVID-19 contact tracing 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.

To protect user privacy, Huawei has taken many measures. For details, please refer to Privacy Statement.

HMS Core Contact Shield is compatible with industry-recognized protocols to make contact tracing more accurate. If you have any questions or suggestions, please send an email to nearybyservice@huawei.com.

Restrictions:

  • HMS Core Contact Shield depends on the BLE technology. Therefore, HMS Core Contact Shield cannot run on a mobile phone that does not support the BLE technology.
  • The available storage space must be greater than 100 MB.

This plugin enables communication between HUAWEI Contact Shield Kit SDK and Flutter platform. It exposes all functionality provided by HUAWEI Contact Shield Kit SDK.


2. Installation Guide #

Before you get started, you must register as a HUAWEI Developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.

Creating a Project in AppGallery Connect #

Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:

Step 1. Sign in to AppGallery Connect and select My projects.

Step 2. Select your project from the project list or create a new one by clicking the Add Project button.

Step 3. Go to Project Setting > General information, and click Add app. If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.

Step 4. On the Add app page, enter the app information, and click OK.

Configuring the Signing Certificate Fingerprint #

A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core (APK) through the HMS SDK. Before using the HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in the AppGallery Connect. You can refer to 3rd and 4th steps of Generating a Signing Certificate codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.

Step 1: Sign in to AppGallery Connect and select your project from My Projects. Then go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA-256 certificate fingerprint.

Step 2: After completing the configuration, click OK to save the changes. (Check mark icon)

Enabling the Huawei Contact Shield #

Step 1: Sign in to HUAWEI Developers and click Console in the upper right corner. Go to HMS API Services > My APIs, select the project for which you want to enable HUAWEI Contact Shield, and click Add API from library. The API Library page is displayed.

Step 2: Click Contact Shield.

Step 3: Click Enable to enable the Contact Shield service.

Step 4: Sign the HUAWEI Contact Shield Agreement.

Step 5: Go to HMS API Services > My APIs. The Contact Shield API is displayed.

Applying to Use the Service #

To protect users' rights and interests, Huawei strictly controls the permissions of developers to use Contact Shield. If you need to use Contact Shield, send an application email to contactshield@huawei.com in the following format. Huawei will get back to you soon after the review is complete.

ItemDescription
App package name: com.xxx.xxxProvide the package name of your app that needs to use Contact Shield.
App ID: 123456789 (example)Provide the ID of your app that needs to use Contact Shield.
Contact person: Bob (example)Provide your contact name for us to contact you.
Contact phone number: xxxProvide your phone number for us to contact you.
Have contact with Huawei expansion personnel: Yes, Huawei expansion personnel: LisaIf you have contacted Huawei expansion personnel, please provide their name so we can better serve you in the future.
Have authorization from the government: Yes (Provide a written authorization document.)Only developers authorized by governments can use Contact Shield to develop apps.
Screenshot of the web page indicating service enabling successProvide your screenshot of the service enabling success web page.

Integrating the Flutter Contact Shield Plugin #

Step 1: Go to Project Setting > General information page, under the App information field, click agconnect-services.json to download the configuration file.

Step 2: Copy the agconnect-services.json file to the android/app directory of your project.

Step 3: Open the build.gradle file in the android directory of your project.

  • Navigate to the buildscript section and configure the Maven repository address and agconnect plugin for the HMS SDK.

    buildscript {
      repositories {
          google()
          jcenter()
          maven { url 'https://developer.huawei.com/repo/' }
      }
    
      dependencies {
           /*
            * <Other dependencies>
            */
          classpath 'com.huawei.agconnect:agcp:1.4.1.300'
      }
    }
    
  • Go to allprojects and configure the Maven repository address for the HMS SDK.

    allprojects {
      repositories {
          google()
          jcenter()
          maven { url 'https://developer.huawei.com/repo/' }
      }
    }
    

Step 4: Open the build.gradle file in the android/app/ directory.

  • Add apply plugin: 'com.huawei.agconnect' line at the end of the file.

    ...
    
    apply plugin: 'com.huawei.agconnect'
    
  • Set your package name in defaultConfig > applicationId and set minSdkVersion to 21 or higher. Package name must match with the package_name entry in agconnect-services.json file.

    defaultConfig {
        applicationId "<package_name>"
        minSdkVersion 21
        /*
         * <Other configurations>
         */
    }
    

Step 5: Create a file <app_dir>/android/key.properties that contains a reference to your keystore which you generated on the previous step (Generating a Signing Certificate). Add the following lines to the key.properties file and change the values regarding to the keystore you've generated.

storeFile=<keystore_file>
storePassword=<keystore_password>
keyAlias=<key_alias>
keyPassword=<key_password>

WARNING: Keep this file private and don't include it on the public source control.

Step 6: Add the following code to build.gradle before android block for reading the key.properties file:

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    ...
}

Step 7: Edit buildTypes as follows and add signingConfigs below:

signingConfigs {
    config {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}

buildTypes {
    debug {
        signingConfig signingConfigs.config
    }
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config
    }
}

Step 8: On your Flutter project directory, find and open your pubspec.yaml file and add the huawei_contactshield library to dependencies. For more details please refer to the Using packages document.

  • Get library via pub package manager.

    dependencies:
      huawei_contactshield: { library version }
    

    or

  • If you downloaded the package from the HUAWEI Developer website, specify the library path on your local device.

    dependencies:
      huawei_contactshield:
        # Replace {library path} with actual library path of Huawei Contact Shield Kit Plugin for Flutter.
        path: { library path }
    
    • Replace {library path} with the actual library path of Flutter Contact Shield Plugin. The following are examples:
      • Relative path example: path: ../huawei_contactshield
      • Absolute path example: path: D:\Projects\Libraries\huawei_contactshield

Step 9: Run the following command to update package info.

[project_path]> flutter pub get

Step 10: Import the library to access all the classes and methods.

import 'package:huawei_contactshield/huawei_contactshield.dart';

Step 11 Run the following command to start the app.

[project_path]> flutter run

3. API Reference #

ContactShieldEngine #

Entry class for using Huawei Contact Shield Kit's APIs.

Properties

NameTypeDescription
contactShieldCallbackContactShieldCallbackCallback that will be triggered when putSharedKeyFiles or startContactShieldOld methods are called.

Constants

ConstantTypeValueDescription
DEFAULT_INCUBATION_PERIODint14Default incubation period for COVID-19.
TOKEN_AStringTOKEN_WINDOW_MODEToken indicating that the Window mode needs to be enabled.

Constructor Summary

ConstructorDescription
ContactShieldEngine()Default constructor.

Constructors

ContactShieldEngine()

Default constructor of the Contact Shield Engine.

Method Summary

MethodReturn TypeDescription
isContactShieldRunning()Future<void>Checks whether Contact Shield is running.
startContactShieldOld(int incubationPeriod)Future<bool>Enables Contact Shield.<br/><br/>This API has been deprecated. To ensure that the functions of earlier versions are normal, this API can still be used in the current version.
startContactShield(int incubationPeriod)Future<void>Enables Contact Shield. When a user exits the app, Contact Shield is still running in the background.
startContactShieldNonPersistent(int incubationPeriod)Future<void>Enables Contact Shield. When a user exits the app, Contact Shield stops running.
getPeriodicKey()Future<List<PeriodicKey>>Obtains the periodic key list from the Contact Shield SDK.<br/><br/>The periodic key list obtained by calling this API does not contain the periodic key of the current day.
putSharedKeyFilesOld(List<String> filePaths, DiagnosisConfiguration config, String token)Future<void>Provides the shared key list file obtained from the diagnosis server to the Contact Shield SDK.
putSharedKeyFiles(List<String> filePaths, DiagnosisConfiguration config, String token)Future<void>Provides the shared key list file obtained from the diagnosis server to the Contact Shield SDK.<br/>If the Window mode is used, that is, TOKEN_A, a maximum of 60 calls are allowed within 24 hours. A common token can be called for a maximum of 200 times within 24 hours.
getContactDetail(String token)Future<List<ContactDetail>>Obtains the latest diagnosis result details from Contact Shield.<br/><br/>This API has been deprecated. To ensure that the functions of earlier versions are normal, this API can still be used in the current version.
getContactSketch(String token)Future<ContactSketch>Obtains the latest diagnosis result summary from Contact Shield.
getContactWindow(String token)Future<List<ContactWindow>>Obtains the latest diagnosis result details from Contact Shield in Window mode.
clearData()Future<void>Deletes all data stored on the device by Contact Shield.
stopContactShield()Future<void>Disables Contact Shield.
enableLogger()Future<void>Enables HMS Logger.
disableLogger()Future<void>Disables HMS Logger.

Methods

Future<bool> isContactShieldRunning() async

Checks whether Contact Shield is running.

Return Type
TypeDescription
Future<bool>Future result of the Contact Shield status.
Call Example
bool status = await ContactShieldEngine().isContactShieldRunning();
Future<void> startContactShieldOld(int incubationPeriod) async

Enables Contact Shield. Before calling this method, your app must obtain the user's authorization for contact tracing.

NOTE: This API has been deprecated. To ensure that the functions of earlier versions are normal, this API can still be used in the current version.

Parameters
NameTypeDescription
incubationPeriodintIncubation period for COVID-19. This parameter is optional and its default value is 14 in days. The value range is [1,60].
Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
// Create instance of the ContactShieldEngine
ContactShieldEngine engine = ContactShieldEngine();

// Create callback which will handle incoming result
ContactShieldCallback callback = ContactShieldCallback(
  onHasContact: (token) {
    String status = 'Contact Status: Has contact. Token: $token';
    print(status);
  },
  onNoContact: (token) {
    String status = 'Contact Status: No contact. Token: $token';
    print(status);
  },
);

// Assign your callback to ContactShieldEngine
engine.contactShieldCallback = callback;

// Call the method
await engine.startContactShieldOld();
Future<void> startContactShield(int incubationPeriod) async

Enables Contact Shield. When a user exits the app, Contact Shield is still running in the background.

Before calling this method, your app must obtain the user's authorization for contact tracing.

Parameters
NameTypeDescription
incubationPeriodintIncubation period for COVID-19. This parameter is optional and its default value is 14 in days. The value range is [1,60].
Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
await ContactShieldEngine().startContactShield();
Future<void> startContactShieldNonPersistent(int incubationPeriod) async

Enables Contact Shield. When a user exits the app, Contact Shield stops running.

Before calling this method, your app must obtain the user's authorization for contact tracing.

Parameters
NameTypeDescription
incubationPeriodintIncubation period for COVID-19. This parameter is optional and its default value is 14 in days. The value range is [1,60].
Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
await ContactShieldEngine().startContactShieldNonPersistent();
Future<List<PeriodicKey>> getPeriodicKey() async

Obtains the periodic key list from the Contact Shield SDK. Before calling this method, your app must obtain the user's authorization. Your app can upload these periodic keys to the diagnosis server.

NOTE: The periodic key list obtained by calling this API does not contain the periodic key of the current day.

Return Type
TypeDescription
Future<List<PeriodicKey>>Future result of an execution that returns list of periodic keys.
Call Example
List<PeriodicKey> periodicKeys = await ContactShieldEngine().getPeriodicKey();
Future<void> putSharedKeyFilesOld(List<String> filePaths, DiagnosisConfiguration config, String token) async

Provides the shared key list file obtained from the diagnosis server to the Contact Shield SDK for future calls of APIs such as getContactSketch().

NOTE: This API has been deprecated. To ensure that the functions of earlier versions are normal, this API can still be used in the current version.

Parameters
NameTypeDescription
filePathsList<String>Paths of the shared keys.
configDiagnosisConfigurationCurrent diagnosis configuration.
tokenStringToken.
Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
List<String> filePaths = <String>[
  '/storage/emulated/0/keys1.zip',
  '/storage/emulated/0/keys2.zip',
];

DiagnosisConfiguration config = DiagnosisConfiguration();

await ContactShieldEngine().putSharedKeyFilesOld(filePaths, config, 'TOKEN_TEST');
Future<void> putSharedKeyFiles(List<String> filePaths, DiagnosisConfiguration config, String token) async

Provides the shared key list file obtained from the diagnosis server to the Contact Shield SDK for future calls of APIs such as getContactSketch().

If the Window mode is used, that is, TOKEN_A, a maximum of 60 calls are allowed within 24 hours. A common token can be called for a maximum of 200 times within 24 hours.

Parameters
NameTypeDescription
filePathsList<String>Paths of the shared keys.
configDiagnosisConfigurationCurrent diagnosis configuration.
tokenStringToken.
Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
// Create instance of the ContactShieldEngine
ContactShieldEngine engine = ContactShieldEngine();

// Create callback which will handle incoming result
ContactShieldCallback callback = ContactShieldCallback(
  onHasContact: (token) {
    String status = 'Contact Status: Has contact. Token: $token';
    print(status);
  },
  onNoContact: (token) {
    String status = 'Contact Status: No contact. Token: $token';
    print(status);
  },
);

// Assign your callback to ContactShieldEngine
engine.contactShieldCallback = callback;

// Confiugre arguments

List<String> filePaths = <String>[
  '/storage/emulated/0/keys1.zip',
  '/storage/emulated/0/keys2.zip',
];

DiagnosisConfiguration config = DiagnosisConfiguration();

// Call the method
await engine.putSharedKeyFiles(filePaths, config, 'TOKEN_TEST');
Future<List<ContactDetail>> getContactDetail(String token) async

Obtains the latest diagnosis result details from Contact Shield.

NOTICE: The diagnosis is asynchronous. When token != TOKEN_A, the original mode is used. When this method is called to obtain the latest diagnosis result, a ContactDetail list is returned.

This API has been deprecated. To ensure that the functions of earlier versions are normal, this API can still be used in the current version.

Parameters
NameTypeDescription
tokenStringToken.
Return Type
TypeDescription
Future<List<ContactDetail>>Future result of an execution that returns list of contact details.
Call Example
String token = 'TOKEN_TEST';

List<ContactDetail> contactDetails = await ContactShieldEngine().getContactDetail(token);
Future<ContactSketch> getContactSketch(String token) async

Obtains the latest diagnosis result summary from Contact Shield.

NOTICE: The diagnosis is asynchronous. When token != TOKEN_A, the original mode is used. When this method is called to obtain the latest diagnosis result, a ContactSketch instance is returned.

Parameters
NameTypeDescription
tokenStringToken.
Return Type
TypeDescription
Future<ContactSketch>Future result of an execution that returns contact sketch.
Call Example
String token = 'TOKEN_TEST';

List<ContactSketch> contactSketch = await ContactShieldEngine().getContactSketch(token);
Future<List<ContactWindow>> getContactWindow(String token) async

Obtains the latest diagnosis result details from Contact Shield in Window mode.

NOTICE: The diagnosis is asynchronous. When token == TOKEN_A, the original mode is used. When this method is called to obtain the latest diagnosis result, a ContactWindow list is returned.

Parameters
NameTypeDescription
tokenStringToken. This parameter is optional and its default value is TOKEN_A.
Return Type
TypeDescription
Future<List<ContactWindow>>Future result of an execution that returns list of contact windows.
Call Example
List<ContactWindow> contactWindows = await ContactShieldEngine().getContactWindow();
Future<void> clearData() async

Deletes all data stored on the device by Contact Shield, including periodic keys, historical shared keys detected, supplementary data, and diagnosis records.

Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
await ContactShieldEngine().clearData();
Future<void> stopContactShield() async

Disables Contact Shield. In this case, related data and keys are retained on the device and will not be deleted.

Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
await ContactShieldEngine().stopContactShield();
Future<void> enableLogger() async

This method enables the HMSLogger capability which is used for sending usage analytics of Map SDK's methods to improve the service quality.

Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
await ContactShieldEngine().enableLogger();
Future<void> disableLogger() async

This method disables the HMSLogger capability which is used for sending usage analytics of Map SDK's methods to improve the service quality.

Return Type
TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
await ContactShieldEngine().disableLogger();

ContactDetail #

Defines the contact diagnosis result details.

Properties

NameTypeDescription
attenuationDurationsList<int>Time-related details for the contact in a list. The unit is minute.<br/>attenuationDurations[0]: The sum of contact durations when the signal attenuation is less than the lower threshold.<br/>attenuationDurations[1]: The sum of contact durations when the signal attenuation is greater than or equal to the lower threshold and less than the upper threshold.<br/>attenuationDurations[2]: The sum of contact durations when the signal attenuation is greater than the upper threshold.
attenuationRiskValueintThe signal attenuation level during the contact. The signal attenuation level is related to the transmit power and received signal strength indicator (RSSI) and can reflect the distance between two devices. The value ranges from 0 to 255.
dayNumberintThe time when the contact occurred. The value is the number of days that have elapsed since the Unix epoch.
durationMinutesintThe duration of the contact, in minutes. To protect privacy, even if durationMinutes is set to a value greater than 60, the duration of the contact is still 60 minutes.
initialRiskLevelintThe initial risk level corresponding to a shared key that is successfully matched.
totalRiskValueintThe current risk level corresponding to a shared key that is successfully matched. The value ranges from 0 to 4096.

Constructor Summary

ConstructorDescription
ContactDetail({List<int> attenuationDurations, int attenuationRiskValue = 0, int dayNumber = 0, int durationMinutes = 0, int initialRiskLevel = 0, int totalRiskValue = 0}) : attenuationDurations = attenuationDurations ?? <int>[0, 0, 0]Default constructor.
ContactDetail.fromMap(Map<String, dynamic> map)Creates ContactDetail object from the Map.
ContactDetail.fromJson(String json)Creates ContactDetail object from the JSON string.

Constructors

ContactDetail({List<int> attenuationDurations, int attenuationRiskValue = 0, int dayNumber = 0, int durationMinutes = 0, int initialRiskLevel = 0, int totalRiskValue = 0}) : attenuationDurations = attenuationDurations ?? <int>[0, 0, 0]

Default constructor for ContactDetail object.

ContactDetail.fromMap(Map<String, dynamic> map)

Creates ContactDetail object from the Map.

ContactDetail.fromJson(String json)

Creates ContactDetail object from the JSON string.

ContactSketch #

Defines the contact diagnosis result summary.

Properties

NameTypeDescription
attenuationDurationsList<int>Time-related details for the contacts of all matched shared keys in a list. The unit is minute.<br/>attenDurations[0]: The sum of contact durations when the signal attenuation is less than the lower threshold.<br/>attenDurations[1]: The sum of contact durations when the signal attenuation is greater than or equal to the lower threshold and less than the upper threshold.<br/>attenDurations[2]: The sum of contact durations when the signal attenuation is greater than the upper threshold.
daysSinceLastHitintThe number of days elapsed since the last successful matching of a shared key. The daysSinceLastHit field is valid only when the value of numberOfHits is greater than 0. The value 0 indicates today, the value 1 indicates yesterday, and the value 2 indicates the day before yesterday. The others follow the same rule.
maxRiskValueintThe highest risk level among all shared keys that are successfully matched. The value is an integer ranging from 0 to 8.
numberOfHitsintThe number of shared keys that are successfully matched.
summationRiskValueintThe sum of contact risk values of all matched shared keys.

Constructor Summary

ConstructorDescription
ContactSketch({List<int> attenuationDurations, int daysSinceLastHit = 0, int maxRiskValue = 0, int numberOfHits = 0, int summationRiskValue = 0}) : attenuationDurations = attenuationDurations ?? <int>[0, 0, 0]Default constructor.
ContactSketch.fromMap(Map<String, dynamic> map)Creates ContactSketch object from the Map.
ContactSketch.fromJson(String json)Creates ContactSketch object from the JSON string.

Constructors

ContactSketch({List<int> attenuationDurations, int daysSinceLastHit = 0, int maxRiskValue = 0, int numberOfHits = 0, int summationRiskValue = 0}) : attenuationDurations = attenuationDurations ?? <int>[0, 0, 0]

Default constructor for ContactSketch object.

ContactSketch.fromMap(Map<String, dynamic> map)

Creates ContactSketch object from the Map.

PlaceHolder.fromJson(String json)

Creates ContactSketch object from the JSON string.

ContactWindow #

Class for storing the contact duration in Window mode when token = TOKEN_A

Properties

NameTypeDescription
dateMillisintThe date when the contact occurs.
reportTypeintThe diagnosis type that is set when a shared key is uploaded. The diagnosis type options can be defined as required.<br/>Example:<br/>The value of REPORT_TYPE_UNKNOW is 0.<br/>The value of REPORT_TYPE_CONFIRMED_TEST is 1.<br/>The value of REPORT_TYPE_CONFIRMED_CLINICAL_DIAGNOSIS is 2.<br/>The value of REPORT_TYPE_SELF_REPORT is 3.<br/>The value of REPORT_TYPE_RECURSIVE is 4.<br/>The value of REPORT_TYPE_REVOKED is 5.
scanInfosList<ScanInfo>The ScanInfo list recorded during the contact.

Constructor Summary

ConstructorDescription
ContactWindow({int dateMillis = 0, int reportType = 0, List<ScanInfo> scanInfos}) : scanInfos = scanInfos ?? <ScanInfo>[ScanInfo(), ScanInfo()]Default constructor.
ContactWindow.fromMap(Map<String, dynamic> map)Creates ContactWindow object from the Map.
ContactWindow.fromJson(String json)Creates ContactWindow object from the JSON string.

Constructors

ContactWindow({int dateMillis = 0, int reportType = 0, List<ScanInfo> scanInfos}) : scanInfos = scanInfos ?? <ScanInfo>[ScanInfo(), ScanInfo()]

Default constructor for ContactWindow object.

ContactWindow.fromMap(Map<String, dynamic> map)

Creates ContactWindow object from the Map.

ContactWindow.fromJson(String json)

Creates ContactWindow object from the JSON string.

DiagnosisConfiguration #

Defines default configurations for Contact Shield.

Properties

NameTypeDescription
attenuationDurationThresholdsList<int>Signal attenuation threshold details. Value contains two thresholds, each ranging from 0 to 255.
attenuationRiskValuesList<int>Signal attenuation risk values. The definition of each value is as follows:<br/>attenuationRiskValues[0]: The attenuation is greater than 73.<br/>attenuationRiskValues[1]: The attenuation is greater than 63 and less than or equal to 73.<br/>attenuationRiskValues[2]: The attenuation is greater than 51 and less than or equal to 63.<br/>attenuationRiskValues[3]: The attenuation is greater than 33 and less than or equal to 51.<br/>attenuationRiskValues[4]: The attenuation is greater than 27 and less than or equal to 33.<br/>attenuationRiskValues[5]: The attenuation is greater than 15 and less than or equal to 27.<br/>attenuationRiskValues[6]: The attenuation is greater than 10 and less than or equal to 15.<br/>attenuationRiskValues[7]: The attenuation is less than or equal to 10.
attenuationWeightintAttenuation weight.
daysAfterContactedRiskValuesList<int>The the risk value associated with the last contact based on the number of days elapsed since the last contact.<br/>The definition of each value is as follows:<br/> daysAfterContactedRiskValues[0]: The number of days elapsed since the last contact is greater than or equal to 14.<br/>daysAfterContactedRiskValues[1]: The number of days elapsed since the last contact is greater than or equal to 12.<br/>daysAfterContactedRiskValues[2]: The number of days elapsed since the last contact is greater than or equal to 10.<br/>daysAfterContactedRiskValues[3]: The number of days elapsed since the last contact is greater than or equal to 8.<br/>daysAfterContactedRiskValues[4]: The number of days elapsed since the last contact is greater than or equal to 6.<br/>daysAfterContactedRiskValues[5]: The number of days elapsed since the last contact is greater than or equal to 4.<br/>daysAfterContactedRiskValues[6]: The number of days elapsed since the last contact is greater than or equal to 2.<br/>daysAfterContactedRiskValues[7]: There is no restriction on the number of days elapsed since the last contact.
daysAfterContactedWeightintThe number of days elapsed since the last contact.
durationRiskValuesList<int>The risk value associated with the last contact based on the duration (in minutes) of the last contact. The definition of each value is as follows:<br/>durationRiskValues[0]: There is no contact.<br/>durationRiskValues[1]: The contact duration is less than or equal to 5 minutes.<br/>durationRiskValues[2]: The contact duration is less than or equal to 10 minutes.<br/>durationRiskValues[3]: The contact duration is less than or equal to 15 minutes.<br/>durationRiskValues[4]: The contact duration is less than or equal to 20 minutes.<br/>durationRiskValues[5]: The contact duration is less than or equal to 25 minutes.<br/>durationRiskValues[6]: The contact duration is less than or equal to 30 minutes.<br/>durationRiskValues[7]: The contact duration is over 30 minutes.
durationWeightintDuration weight.
initialRiskLevelRiskValuesList<int>The initial contact risk value. The definition of each value is as follows:<br/>initialRiskLevelRiskValues[0]: RISK_LEVEL_LOWEST<br/>initialRiskLevelRiskValues[1]: RISK_LEVEL_LOW<br/>initialRiskLevelRiskValues[2]: RISK_LEVEL_MEDIUM_LOW<br/>initialRiskLevelRiskValues[3]: RISK_LEVEL_MEDIUM<br/>initialRiskLevelRiskValues[4]: RISK_LEVEL_MEDIUM_HIGH<br/>initialRiskLevelRiskValues[5]: RISK_LEVEL_HIGH<br/>initialRiskLevelRiskValues[6]: RISK_LEVEL_EXT_HIGH<br/>initialRiskLevelRiskValues[7]: RISK_LEVEL_HIGHEST
initialRiskLevelWeightintInitial risk level weight.
minimumRiskValueThresholdintThe lowest risk value that would be recorded.

Constructor Summary

ConstructorDescription
DiagnosisConfiguration({List<int> attenuationDurationThresholds, List<int> attenuationRiskValues, int attenuationWeight = 50, List<int> daysAfterContactedRiskValues, int daysAfterContactedWeight = 50, List<int> durationRiskValues, int durationWeight = 50, List<int> initialRiskLevelRiskValues, int initialRiskLevelWeight = 50, int minimumRiskValueThreshold = 1}) : attenuationDurationThresholds = attenuationDurationThresholds ?? <int>[50, 74], attenuationRiskValues = attenuationRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4], daysAfterContactedRiskValues = daysAfterContactedRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4], durationRiskValues = durationRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4], initialRiskLevelRiskValues = initialRiskLevelRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4]Default constructor.
DiagnosisConfiguration.fromMap(Map<String, dynamic> map)Creates DiagnosisConfiguration object from the Map.
DiagnosisConfiguration.fromJson(String json)Creates DiagnosisConfiguration object from the JSON string.

Constructors

DiagnosisConfiguration({List<int> attenuationDurationThresholds, List<int> attenuationRiskValues, int attenuationWeight = 50, List<int> daysAfterContactedRiskValues, int daysAfterContactedWeight = 50, List<int> durationRiskValues, int durationWeight = 50, List<int> initialRiskLevelRiskValues, int initialRiskLevelWeight = 50, int minimumRiskValueThreshold = 1}) : attenuationDurationThresholds = attenuationDurationThresholds ?? <int>[50, 74], attenuationRiskValues = attenuationRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4], daysAfterContactedRiskValues = daysAfterContactedRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4], durationRiskValues = durationRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4], initialRiskLevelRiskValues = initialRiskLevelRiskValues ?? <int>[4, 4, 4, 4, 4, 4, 4, 4]

Default constructor for DiagnosisConfiguration object.

DiagnosisConfiguration.fromMap(Map<String, dynamic> map)

Creates DiagnosisConfiguration object from the Map.

DiagnosisConfiguration.fromJson(String json)

Creates DiagnosisConfiguration object from the JSON string.

PeriodicKey #

Defines a periodic key.

Properties

NameTypeDescription
contentUint8ListThe 16-byte content of the periodic key.
initialRiskLevelintThe initial risk level corresponding to the periodic key. The value is an integer ranging from 0 to 8.<br/>The following are the suggested risk types and their meaning. Before uploading each key to the server, set initialRiskLevel. The options include:<br/>0: currently not used<br/>1: low risk<br/>2: medium risk<br/>3: high risk<br/>4: confirmed positive with COVID-19<br/>5: self-report<br/>6: confirmed negative with COVID-19<br/>7: recursive case<br/>8: reserved field
periodicKeyLifeTimeintThe number of time segments elapsed since the periodic key takes effect. Each time segment contains 10 minutes.
periodicKeyValidTimeintThe time segment to which the periodic key effective time belongs.
reportTypeintThe diagnosis type that is specified when a shared key is uploaded. The diagnosis type options can be defined as required. Example:<br/>The value of REPORT_TYPE_UNKNOW is 0.<br/>The value of REPORT_TYPE_CONFIRMED_TEST is 1.<br/>The value of REPORT_TYPE_CONFIRMED_CLINICAL_DIAGNOSIS is 2.<br/>The value of REPORT_TYPE_SELF_REPORT is 3.<br/>The value of REPORT_TYPE_RECURSIVE is 4.<br/>The value of REPORT_TYPE_REVOKED is 5.

Constructor Summary

ConstructorDescription
PeriodicKey({Uint8List content, int initialRiskLevel = 0, int periodicKeyLifeTime = 0, int periodicKeyValidTime = 0, int reportType = 0})Default constructor.
PeriodicKey.fromMap(Map<String, dynamic> map)Creates PeriodicKey object from the Map.
PeriodicKey.fromJson(String json)Creates PeriodicKey object from the JSON string.

Constructors

PeriodicKey({Uint8List content, int initialRiskLevel = 0, int periodicKeyLifeTime = 0, int periodicKeyValidTime = 0, int reportType = 0})

Default constructor for PeriodicKey object.

PeriodicKey.fromMap(Map<String, dynamic> map)

Creates PeriodicKey object from the Map.

PeriodicKey.fromJson(String json)

Creates PeriodicKey object from the JSON string.

ScanInfo #

Class for storing scanning results.

Properties

NameTypeDescription
averageAttenuationintThe average of all attenuations detected during the scanning, in dB.
minimumAttenuationintThe minimum attenuation.
secondsSinceLastScanintThe number of seconds elapsed since last scanning. The value ranges from 120s to 180s.

Constructor Summary

ConstructorDescription
ScanInfo({int averageAttenuation = 0, int minimumAttenuation = 0, int secondsSinceLastScan = 0})Default constructor.
ScanInfo.fromMap(Map<String, dynamic> map)Creates ScanInfo object from the Map.
ScanInfo.fromJson(String json)Creates ScanInfo object from the JSON string.

Constructors

ScanInfo({int averageAttenuation = 0, int minimumAttenuation = 0, int secondsSinceLastScan = 0})

Default constructor for ScanInfo object.

ScanInfo.fromMap(Map<String, dynamic> map)

Creates ScanInfo object from the Map.

ScanInfo.fromJson(String json)

Creates ScanInfo object from the JSON string.

ContactShieldCallback #

Class which allows developers to define callback to handle contact status.

Type Definition Summary

NameReturn TypeParameters
OnHasContactvoidString token
OnNoContactvoidString token

Type Definitions

typedef void OnHasContact(String token)

Contact status type definition used as type for callback function which notifies the app that a shared key matches historical contact records stored on the device.

typedef void OnNoContact(String token)

Contact status type definition used as type for callback function which notifies the app that a shared key has not matched any historical contact records stored on the device.

Properties

NameTypeDescription
onHasContactOnHasContactCallback function that notifies the app that a shared key matches historical contact records stored on the device.
onNoContactOnNoContactCallback function that notifies the app that a shared key has not matched any historical contact records stored on the device.

Constructor Summary

ConstructorDescription
ContactShieldCallback({OnHasContact onHasContact, OnNoContact onNoContact})Default constructor.

Constructors

ContactShieldCallback({OnHasContact onHasContact, OnNoContact onNoContact})

Default constructor for ContactShieldCallback object.

RiskLevel #

Class which holds risk level constants.

Constants

ConstantTypeValueDescription
RISK_LEVEL_INVALIDint0Invalid risk level.
RISK_LEVEL_LOWESTint1Lowest risk level.
RISK_LEVEL_LOWint2Low risk level.
RISK_LEVEL_MEDIUM_LOWint3Low-medium risk level.
RISK_LEVEL_MEDIUMint4Medium risk level.
RISK_LEVEL_MEDIUM_HIGHint5Medium-high risk level.
RISK_LEVEL_HIGHint6High risk level.
RISK_LEVEL_EXT_HIGHint7Very high risk level.
RISK_LEVEL_HIGHESTint8Highest risk level.

4. Configuration and Description #

Configuring Obfuscation Scripts #

In order to prevent error while release build, you may need to add following lines in proguard-rules.pro file.

-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
-keep class com.huawei.hms.flutter.** { *; }

# Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-dontwarn io.flutter.embedding.**
-repackageclasses

Contact Shield Permissions #

To use Contact Shield you need to declare required permissions inside AndroidManifest.xml file as shown below.

<manifest ...>
    <uses-permission android:name="android.permission.INTERNET " />
    <uses-permission android:name="android.permission.BLUETOOTH" />

  <application ...>
    <activity ...>
      <!-- Other configurations -->
    </activity>
  </application>
</manifest>

5. Sample Project #

This plugin includes a demo project in the example folder, there you can find more usage examples.


6. Questions or Issues #

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • Github is the official repository for these plugins, You can open an issue or submit your ideas.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
  • Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the GitHub repository.


7. Licensing and Terms #

Huawei Contact Shield Kit Flutter Plugin is licensed under Apache 2.0 license

0
likes
80
pub points
0%
popularity

Publisher

developer.huawei.com

To help confront the global pandemic of coronavirus disease 2019 (COVID-19), Huawei provides HMS Core Contact Shield for developers to develop epidemic prevention and control apps.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache 2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on huawei_contactshield