• Home
Name Date Size #Lines LOC

..--

etc/init/12-May-2024-4743

interfaces/12-May-2024-1,021679

profile/12-May-2024-3229

services/12-May-2024-1,117791

test/fuzztest/12-May-2024-253171

utils/12-May-2024-261172

BUILD.gnD12-May-20241.1 KiB3530

LICENSED12-May-20249.9 KiB177150

README.mdD12-May-20243.7 KiB12599

README_zh.mdD12-May-20244.4 KiB135105

bundle.jsonD12-May-20241.3 KiB6362

cfi_blocklist.txtD12-May-2024722 1918

oaid.gniD12-May-2024910 2619

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/advertising/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/advertising/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   ```
31
32   {
33     "module": {
34       "requestPermissions": [
35         {
36           "name": "ohos.permission.APP_TRACKING_CONSENT" // 申请广告跟踪权限
37         }
38       ]
39     }
40   }
41   ```
42
432. 在应用启动时触发动态授权弹框,向用户请求授权。
44
45  ```
46  import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
47  import { BusinessError } from '@ohos.base';
48  import hilog from '@ohos.hilog';
49
50  private requestOAIDTrackingConsentPermissions(context: common.Context): void {
51    // 进入页面时触发动态授权弹框,向用户请求授权广告跟踪权限
52    const atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
53     try {
54       atManager.requestPermissionsFromUser(context, ["ohos.permission.APP_TRACKING_CONSENT"]).then((data) => {
55         if (data.authResults[0] == 0) {
56           hilog.info(0x0000, 'testTag', '%{public}s', 'request permission success');
57         } else {
58           hilog.info(0x0000, 'testTag', '%{public}s', `user rejected`);
59         }
60       }).catch((err) => {
61         const e: BusinessError = err as BusinessError;
62         hilog.error(0x0000, 'testTag', '%{public}s', `request permission failed, error message: ${e.message}`);
63       })
64     } catch(err) {
65       const e: BusinessError = err as BusinessError;
66       hilog.error(0x0000, 'testTag', '%{public}s', `catch err->${JSON.stringify(e)}`);
67     }
68   }
69  ```
70
713. 获取OAID信息
72
73- 通过Callback回调函数获取OAID
74
75  ```
76
77  import identifier from '@ohos.identifier.oaid';
78  import hilog from '@ohos.hilog';
79  import { BusinessError } from '@ohos.base';
80
81  try {
82    identifier.getOAID((err, data) => {
83      if (err.code) {
84        hilog.info(0x0000, 'testTag', '%{public}s', `getOAID failed, message: ${err.message}`);
85    } else {
86      const oaid: string = data;
87      hilog.info(0x0000, 'testTag', '%{public}s', `getOAID by callback success`);
88    }
89    });
90  } catch (err) {
91    const e: BusinessError = err as BusinessError;
92    hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', e.code, e.message);
93  }
94  ```
95
96- 通过Promise异步获取OAID
97
98  ```
99
100  import identifier from '@ohos.identifier.oaid';
101  import hilog from '@ohos.hilog';
102  import { BusinessError } from '@ohos.base';
103
104  try {
105    identifier.getOAID().then((data) => {
106      const oaid: string = data;
107      hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`);
108    }).catch((err) => {
109      hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${(err as BusinessError).message}`);
110    })
111  } catch (err) {
112    const e: BusinessError = err as BusinessError;
113    hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', e.code, e.message);
114  }
115  ```
116
117### 重置OAID
118
119可以使用此仓库内提供的接口重置OAID。以下步骤描述了如何使用接口重置OAID。该接口为系统接口。
120
121```
122
123  import identifier from '@ohos.identifier.oaid';
124  import hilog from '@ohos.hilog';
125  import { BusinessError } from '@ohos.base';
126
127  try {
128    identifier.resetOAID();
129  } catch (err) {
130    const e: BusinessError = err as BusinessError;
131    hilog.error(0x0000, 'testTag', 'reset oaid catch error: %{public}d %{public}s', e.code, e.message);
132  }
133```
134
135## 相关仓