Integration Requirements
- Load and collect the SDK only after the user has agreed to the privacy policy.
- Pass the obtained
blackBoxdirectly to your server. Do not cache it on the client. - It is recommended to complete SDK loading and data collection during app startup, and retrieve
blackBoxin real time at key business points.
Compliance Notice
Please note that when integrating the SDK product provided by TrustDecision into your app:
- In accordance with applicable laws and regulations such as the Cybersecurity Law, the Telecommunications Regulations, and the Provisions on the Protection of Personal Information of Telecommunications and Internet Users, as well as regulatory practices, before your end users first launch the app and before you begin collecting information, you should fully inform end users through an interactive interface or design, such as a privacy policy popup, of the purpose, method, and scope of collecting, using, and sharing their personal information with third parties, and obtain their explicit consent.
- Inform users in text of the following:
- SDK name: TrustDecision Device Fingerprinting SDK
- Developer name: Zhejiang Xiaodun Future Technology Co., Ltd.
- Types of personal information collected: device type, device model, operating system type, device software version, device identifier ODID (optional), GPS location information (optional), Wi-Fi information (including BSSID, SSID, and MAC address, optional), IP address (optional), Wi-Fi status (optional), storage status (optional), screen resolution (optional), battery status (optional), carrier information (optional)
- Purpose of use: to provide business security and risk control services
- To ensure your use of the relevant services is compliant, your privacy policy should include authorization for the TrustDecision SDK to provide services and collect, process, and use the relevant information. The above content is for your reference only. The specific wording may be determined by you based on the overall framework and content of your privacy policy.
- Privacy Policy: https://xiaodun.com/other/privacy/id=4
- If compliance requirements make it necessary to disable certain collection capabilities, you can disable the corresponding collection items through configuration parameters. If the SDK supports module trimming, you can also exclude the corresponding modules at the dependency stage.
Environment Requirements
| Item | Description |
|---|---|
| Compatible Versions | API 12 and above |
| Supported Architectures | arm64-v8a, x86_64 |
Installation and Configuration
Install the SDK
ohpm install @trustdecision/mobriskConfigure oh-package.json5
oh-package.json5Add the third-party package dependency in your project's oh-package.json5:
{
"dependencies": {
"@trustdecision/mobrisk": "1.3.1"
}
}Declare Permissions
Add the following requestPermissions configuration under the module node in your project's module.json5:
"requestPermissions": [
{
"name": "ohos.permission.INTERNET"
},
{
"name": "ohos.permission.GET_NETWORK_INFO"
},
{
"name": "ohos.permission.GET_WIFI_INFO"
},
{
"name": "ohos.permission.STORE_PERSISTENT_DATA"
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION"
}
]Permission Description
| Permission | Required | Purpose | When Used | Impact If Not Granted |
|---|---|---|---|---|
ohos.permission.INTERNET | Yes | Communicates with the server and reports device risk data | Request and reporting phase after loading and collection | Network requests and risk data reporting cannot be completed |
ohos.permission.GET_NETWORK_INFO | Yes | Obtains the current network connection status | During loading, collection, and reporting | Network status cannot be accurately determined, which may affect request stability |
ohos.permission.GET_WIFI_INFO | Yes | Obtains Wi-Fi connection status and related information | During device environment information collection | Some network environment information cannot be obtained, affecting risk identification |
ohos.permission.STORE_PERSISTENT_DATA | Yes | Allows the app to store persistent data | During SDK runtime and local persistence | Affects the SDK's local data storage capability |
ohos.permission.APPROXIMATELY_LOCATION | No | Obtains approximate location information | During location-related information collection | Some location data will not be collected, affecting certain risk identification capabilities |
Initialization and Collection
Notes
- Call
initWithOptionsonly after the user has agreed to the privacy policy.
Method Definition
public static async initWithOptions(context: Context, params: TDRiskOption): Promise<void>Example
Execute the following code after the user has agreed to the privacy policy:
import AbilityStage from '@ohos.app.ability.AbilityStage'
import { TDRisk, TDRiskOption } from '@trustdecision/mobrisk'
export default class MyAbilityStage extends AbilityStage {
async onCreate() {
const options: TDRiskOption = {
partnerCode: 'your partnerCode', //please fill in the partnerCode, not the partnerKey
appKey: 'your appKey', // Configure AppKey, please contact the operator to obtain
dataCenter: 'your data center' //Data-center parameters. For the list, please refer to all the configuration instructions below.
}
await TDRisk.initWithOptions(this.context, options)
}
}Get blackBox
blackBoxNotes
- Call
getBlackBoxAsync/getBlackBoxonly afterinitWithOptionshas completed. - Do not cache the returned
blackBoxin the app. Call the corresponding method each time you need it. - It is recommended to use the asynchronous method to obtain
blackBoxfor the first time, and then call the synchronous method as needed after the async callback is completed.
Method Definition
/**
* Asynchronously gets the blackbox.
* @param priorityCache Whether to return the cached value first. Default is false.
* false: waits until the current data reporting is completed, then returns the latest blackbox.
* true: starts data reporting, then returns the cached blackbox first if available for immediate use.
*/
public static async getBlackBoxAsync(priorityCache: boolean = false): Promise<string>
/**
* Synchronously gets the blackbox and directly returns the current available blackbox.
*/
public static getBlackBox(): stringExamples
Asynchronous Retrieval
For the first retrieval and at key business points, it is recommended to use the asynchronous method:
import { TDRisk } from '@trustdecision/mobrisk'
async function getBlackBox() {
const blackBox = await TDRisk.getBlackBoxAsync();
console.info('TD_TS', `async blackBox: ${blackBox}`);
}Synchronous Retrieval
After the first asynchronous retrieval is completed, you can synchronously get it as needed at business points:
import { TDRisk } from '@trustdecision/mobrisk'
function getBlackBox() {
const blackBox = TDRisk.getBlackBox();
console.info('TD_TS', `sync blackBox: ${blackBox}`);
}Best Practices
- Complete SDK loading and collection during app startup after the user has agreed to the privacy policy.
- Retrieve
blackBoxin real time at key business points such as registration, login, payment, and marketing. - Rely on synchronous retrieval only after the first asynchronous retrieval has completed.
- Do not reuse historical
blackBoxvalues.
Status Check
- When initialization and collection succeed, you can see
TD_TS: td sdk init successin the logs. - When the SDK successfully reports data, the result returned by
getBlackBoxAsync()is typically a normalblackBoxwith a fixed length of 26 characters. - In exceptional cases, the length of the result returned by
getBlackBoxAsync()may increase significantly. For details, refer to Differences Between Normal blackBox and Degraded blackBox
Get SDK Version
const version: string = TDRisk.getSDKVersion()All Configurations
| Parameter | Required | Description | Default | Example | Removed Field / Notes |
|---|---|---|---|---|---|
partnerCode | Yes | Partner code. Please contact operations to obtain it. | None | options.partnerCode = 'partnerCode' | Required |
appKey | Yes | Application identifier. Contact operations after providing the app bundleName. | None | options.appKey = 'appKey' | bundleName can be found in AppScope/app.json5 |
dataCenter | Yes | Data Center: TDRisk.DATA_CENTER_US (North America) TDRisk.DATA_CENTER_FRA (Europe) TDRisk.DATA_CENTER_SG(Singapore) TDRisk.DATA_CENTER_IDNA (Indonesia) TDRisk.DATA_CENTER_CN (China) | None | options.dataCenter = TDRisk.DATA_CENTER_CN | This document only shows examples for the China region |
appName | No | Application name. Please contact operations to obtain it. | Empty | options.appName = 'appName' | Optional |
disableGPS | No | Disables collection of GPS information | false | options["disableGPS"] = true | latitude、longitude、altitude、gpsSwitch |
disableWifiInfo | No | Disables collection of Wi-Fi information, including BSSID, SSID, and MAC address | false | options.disableWifiInfo = true | bssid、ssid |
disableODID | No | Disables collection of ODID | false | options.disableODID = true | odid |
disableIP | No | Disables collection of IP address | false | options.disableIP = true | cellIp、wifiIp、vpnIp |
disableWifiStatus | No | Disables collection of Wi-Fi status | false | options.disableWifiStatus = true | networkType、networkNames |
disableStorageInfo | No | Disables collection of storage status | false | options.disableStorageInfo = true | totalStorage、availableStorage |
disableScreenResolution | No | Disables collection of screen resolution | false | options.disableScreenResolution = true | screenResolution |
disableBatteryInfo | No | Disables collection of battery status | false | options.disableBatteryInfo = true | batteryStatus、batteryLevelRatio、batteryPluggedType、batteryTechnology |
disableCarrierInfo | No | Disables collection of carrier information | false | options.disableCarrierInfo = true | simCountryIso、simCarrier、simState |
disablePrivacyData | No | Disables collection of privacy-related information | false | options.disablePrivacyData = true | screenResolution、deviceType、brand、marketName、batteryStatus、batteryLevelRatio、batteryPluggedType、batteryTechnology、totalStorage、availableStorage、networkType、networkNames、cellIp、wifiIp、vpnIp、simCountryIso、simCarrier、simState、latitude、longitude、altitude、gpsSwitch、bssid、ssid、odid |
httpTimeOut | No | Network request callback timeout in milliseconds | 60000 | options.httpTimeOut = 60000 | Optional |
customMessage | No | Custom message. The SDK supports passthrough and storage. | Empty | options.customMessage = 'customMessage' |
