Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
etc/init/ | 12-May-2024 | - | 47 | 43 | ||
interfaces/ | 12-May-2024 | - | 975 | 636 | ||
profile/ | 12-May-2024 | - | 32 | 29 | ||
services/ | 12-May-2024 | - | 1,035 | 712 | ||
test/fuzztest/ | 12-May-2024 | - | 228 | 153 | ||
utils/ | 12-May-2024 | - | 143 | 91 | ||
BUILD.gn | D | 12-May-2024 | 1.1 KiB | 36 | 32 | |
LICENSE | D | 12-May-2024 | 9.9 KiB | 177 | 150 | |
README.md | D | 12-May-2024 | 3.7 KiB | 125 | 99 | |
README_zh.md | D | 12-May-2024 | 4.4 KiB | 131 | 105 | |
bundle.json | D | 12-May-2024 | 1 KiB | 53 | 52 | |
oaid.gni | D | 12-May-2024 | 904 | 26 | 19 |
README.md
1# OAID Service Component 2 3## Introduction 4 5The Open Anonymous Device Identifier (OAID) service facilitates personalized ad placement based on OAIDs, each of which is a non-permanent device identifier. The service provides personalized ads for users while protecting their personal data privacy. It can also interact with third-party tracking platforms to provide conversion attribution analysis for advertisers. 6 7## Directory Structure 8 9``` 10/domains/cloud/oaid # Service code of the OAID service component 11├── interfaces # API code 12├── profile # Service configuration profile 13├── services # Service code 14├── test # Test cases 15├── LICENSE # License file 16└── bundle.json # Build file 17``` 18 19## How to Use 20 21### Obtaining an OAID 22 23You can use the APIs provided in this repository to obtain OAIDs. 24 251. Request the ad tracking permission. 26 27 Configure the [ohos.permission.APP_TRACKING_CONSENT](https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/security/permission-list.md/) permission in the **module.json5** file of the module. 28 29 ```javascript 30 { 31 "module": { 32 "requestPermissions": [ 33 { 34 "name": "ohos.permission.APP_TRACKING_CONSENT" // Request the ad tracking permission. 35 } 36 ] 37 } 38 } 39 ``` 40 412. Request authorization from the user by displaying a dialog box when the application is started. 42 43 ```javascript 44 import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; 45 46 private requestOAIDTrackingConsentPermissions(context: any): void { 47 // Display a dialog box when the page is displayed to request the user to grant the ad tracking permission. 48 const atManager = abilityAccessCtrl.createAtManager(); 49 try { 50 atManager.requestPermissionsFromUser(context, ["ohos.permission.APP_TRACKING_CONSENT"]).then((data) => { 51 if (data.authResults[0] == 0) { 52 console.info(`request permission success`); 53 } else { 54 console.info(`user rejected`); 55 } 56 }).catch((err) => { 57 console.error(`request permission failed, error message: ${err.message}`); 58 }) 59 } catch(err) { 60 console.error(`catch err->${JSON.stringify(err)}`); 61 } 62 } 63 ``` 64 653. Obtain an OAID. 66 67- Obtain an OAID through the callback function. 68 69 ```javascript 70 import identifier from '@ohos.identifier.oaid'; 71 72 private getOaidByCallback() { 73 try { 74 identifier.getOAID((err, data) => { 75 if (err.code) { 76 console.info(`getAdsIdentifierInfo failed, message: ${err.message}`); 77 } else { 78 const oaid = data; 79 console.error(`getOaidFromOaidSaAPi by callback success`); 80 } 81 }); 82 } catch (err) { 83 console.error(`catch err->${JSON.stringify(err)}`); 84 } 85 } 86 ``` 87 88- Obtain an OAID through the promise. 89 90 ```javascript 91 import identifier from '@ohos.identifier.oaid'; 92 93 private getOaidByPromise() { 94 try { 95 // Obtain an OAID. 96 identifier.getOAID().then((data) => { 97 const oaid = data; 98 console.info(`getAdsIdentifierInfo by promise success`); 99 }).catch((err) => { 100 console.error(`getAdsIdentifierInfo failed, message: ${err.message}`); 101 }) 102 } catch (err) { 103 console.error(`catch err->${JSON.stringify(err)}`); 104 } 105 } 106 ``` 107 108### Resetting the OAID 109 110You can use the API provided in this repository to reset OAIDs. The API is a system API. 111 112```javascript 113import identifier from '@ohos.identifier.oaid'; 114 115private resetOaid() { 116 try { 117 identifier.resetOAID(); 118 } catch (err) { 119 console.error(`reset oaid catch error: ${err.code} ${err.message}`); 120 } 121} 122``` 123 124## Repositories Involved 125
README_zh.md
1# 广告标识服务部件 2 3## 简介 4 5开放匿名设备标识符(Open Anonymous Device Identifier, OAID,以下简称OAID):是一种非永久性设备标识符,基于开放匿名设备标识符,可在保护用户个人数据隐私安全的前提下,向用户提供个性化广告,同时三方监测平台也可以向广告主提供转化归因分析。 6 7 8## 目录 9 10``` 11/domains/cloud/oaid # 广告标识服务部件业务代码 12├── interfaces # 接口代码 13├── profile # 服务配置文件 14├── services # 服务代码 15├── test # 测试用例 16├── LICENSE # 证书文件 17└── bundle.json # 编译文件 18``` 19 20## 使用说明 21 22### 获取OAID 23 24可以使用此仓库内提供的接口获取OAID。以下步骤描述了如何使用接口获取OAID。 25 261. 申请广告跟踪权限 27 28 在模块的module.json5文件中,申请[ohos.permission.APP_TRACKING_CONSENT](https://docs.openharmony.cn/pages/v4.0/zh-cn/application-dev/security/permission-list.md/)权限。 29 30 ```javascript 31 { 32 "module": { 33 "requestPermissions": [ 34 { 35 "name": "ohos.permission.APP_TRACKING_CONSENT" // 申请广告跟踪权限 36 } 37 ] 38 } 39 } 40 ``` 41 422. 在应用启动时触发动态授权弹框,向用户请求授权。 43 44 ```javascript 45 import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; 46 import { BusinessError } from '@ohos.base'; 47 import hilog from '@ohos.hilog'; 48 49 private requestOAIDTrackingConsentPermissions(context: common.Context): void { 50 // 进入页面时触发动态授权弹框,向用户请求授权广告跟踪权限 51 const atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 52 try { 53 atManager.requestPermissionsFromUser(context, ["ohos.permission.APP_TRACKING_CONSENT"]).then((data) => { 54 if (data.authResults[0] == 0) { 55 hilog.info(0x0000, 'testTag', '%{public}s', 'request permission success'); 56 } else { 57 hilog.info(0x0000, 'testTag', '%{public}s', `user rejected`); 58 } 59 }).catch((err) => { 60 const e: BusinessError = err as BusinessError; 61 hilog.error(0x0000, 'testTag', '%{public}s', `request permission failed, error message: ${e.message}`); 62 }) 63 } catch(err) { 64 const e: BusinessError = err as BusinessError; 65 hilog.error(0x0000, 'testTag', '%{public}s', `catch err->${JSON.stringify(e)}`); 66 } 67 } 68 ``` 69 703. 获取OAID信息 71 72- 通过Callback回调函数获取OAID 73 74 ```javascript 75 import identifier from '@ohos.identifier.oaid'; 76 import hilog from '@ohos.hilog'; 77 import { BusinessError } from '@ohos.base'; 78 79 try { 80 identifier.getOAID((err, data) => { 81 if (err.code) { 82 hilog.info(0x0000, 'testTag', '%{public}s', `getOAID failed, message: ${err.message}`); 83 } else { 84 const oaid: string = data; 85 hilog.info(0x0000, 'testTag', '%{public}s', `getOAID by callback success`); 86 } 87 }); 88 } catch (err) { 89 const e: BusinessError = err as BusinessError; 90 hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', e.code, e.message); 91 } 92 ``` 93 94- 通过Promise异步获取OAID 95 96 ```javascript 97 import identifier from '@ohos.identifier.oaid'; 98 import hilog from '@ohos.hilog'; 99 import { BusinessError } from '@ohos.base'; 100 101 try { 102 identifier.getOAID().then((data) => { 103 const oaid: string = data; 104 hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`); 105 }).catch((err) => { 106 hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${(err as BusinessError).message}`); 107 }) 108 } catch (err) { 109 const e: BusinessError = err as BusinessError; 110 hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', e.code, e.message); 111 } 112 ``` 113 114### 重置OAID 115 116可以使用此仓库内提供的接口重置OAID。以下步骤描述了如何使用接口重置OAID。该接口为系统接口。 117 118```javascript 119 import identifier from '@ohos.identifier.oaid'; 120 import hilog from '@ohos.hilog'; 121 import { BusinessError } from '@ohos.base'; 122 123 try { 124 identifier.resetOAID(); 125 } catch (err) { 126 const e: BusinessError = err as BusinessError; 127 hilog.error(0x0000, 'testTag', 'reset oaid catch error: %{public}d %{public}s', e.code, e.message); 128 } 129``` 130 131## 相关仓