This module provides functions for querying privacy agreement URLs, checking the privacy agreement signing status, revoking the consent record, and requesting user consent.
Exceptions need to be captured when an API is called.
Since: 5.0.0(12)
Enumerated privacy agreement management types.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| UNSUPPORTED | 0 | Not supported. |
| FULL_MODE | 1 | Full mode. |
Enumerated privacy agreement signing results.
Atomic service API: This API can be used in atomic services since version 5.0.0(12).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| DISAGREED | 0 | The user has not agreed to the privacy agreement. |
| FULL_MODE_AGREED | 1 | The user has agreed to the privacy agreement for enabling full-mode access. |
| REQUIRE_RESIGNING_VERSION_UPDATE | 2 | The agreement has changed and needs to be signed again. |
Enumerated privacy agreement URL types.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| PRIVACY_STATEMENT_LINK | 1 | Privacy statement URL. |
| USER_AGREEMENT_LINK | 2 | User agreement URL. |
Enumerated privacy agreement types.
Atomic service API: This API can be used in atomic services since version 5.0.0(12).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Value | Description |
|---|---|---|
| PRIVACY_AGREEMENT | 1 | Privacy agreement. |
| USER_AGREEMENT | 2 | User agreement. |
Privacy agreement management information.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| type | AppPrivacyMgmtType | Yes | No | Privacy agreement management type. |
| privacyInfo | AppPrivacyLink[] | Yes | No | Privacy agreement URL information. |
Privacy agreement URL.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| type | AppPrivacyLinkType | Yes | No | Privacy agreement URL type. |
| versionCode | number | Yes | No | Agreement version number. |
| url | string | Yes | No | URL. |
| id | string | Yes | No | Privacy agreement ID. |
| name | string | Yes | Yes | User agreement name. This parameter is mandatory when AppPrivacyLinkType is set to USER_AGREEMENT_LINK. Since: 5.0.2(14) |
Privacy agreement signing result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| type | AppPrivacyType | Yes | No | Privacy agreement type. Atomic service API: This API can be used in atomic services since version 5.0.0(12). |
| versionCode | number | Yes | No | Agreement version number. Atomic service API: This API can be used in atomic services since version 5.0.0(12). |
| result | AppPrivacyResultType | Yes | No | Privacy agreement signing result. Atomic service API: This API can be used in atomic services since version 5.0.0(12). |
| id | string | Yes | No | Privacy agreement ID. Atomic service API: This API can be used in atomic services since version 5.0.0(12). |
| signingTimestamp | number | Yes | Yes | Privacy agreement signing time, in milliseconds. Since: 5.0.2(14) Atomic service API: This API can be used in atomic services since version 5.0.2(14). |
Result of launching the standardized privacy agreement pop-up.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.2(14)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| results | AppPrivacyResult[] | Yes | No | Privacy agreement signing result. |
getAppPrivacyMgmtInfo(): AppPrivacyMgmtInfo
Queries privacy agreement URLs.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
Returns:
| Type | Description |
|---|---|
| AppPrivacyMgmtInfo | Privacy agreement URL information. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 1006700001 | System internal error. |
| 1006700003 | The application does not use privacy manager service. |
Example:
import { hilog } from '@kit.PerformanceAnalysisKit';
import { privacyManager } from '@kit.AppGalleryKit';
const TAG: string = 'getAppPrivacyMgmtInfo';
@Entry
@Component
struct GetAppPrivacyMgmtInfo {
@State result: string = '';
@State message: string = 'getAppPrivacyMgmtInfo';
build() {
Column() {
Button(this.message)
.onClick(() => {
this.query()
})
.width('100%')
Text(this.result)
.fontSize(15)
.fontWeight(FontWeight.Bold)
.margin(20)
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
query() {
this.result = '';
try {
// Query privacy agreement URLs.
let appPrivacyManageInfo: privacyManager.AppPrivacyMgmtInfo = privacyManager.getAppPrivacyMgmtInfo();
hilog.info(0, TAG, "GetAppPrivacyManageInfo type:" + appPrivacyManageInfo["type"]);
this.result += 'GetAppPrivacyManageInfo type:' + appPrivacyManageInfo["type"] + ";\n";
// Privacy agreement URL information array.
let privacyLinkInfoArray : privacyManager.AppPrivacyLink[] = appPrivacyManageInfo.privacyInfo;
hilog.info(0, TAG, "GetAppPrivacyManageInfo size = " + privacyLinkInfoArray.length);
for (let i = 0; i < privacyLinkInfoArray.length; i++) {
this.result += 'uri: ' + privacyLinkInfoArray[i]["url"] + ";\n";
}
} catch (error) {
hilog.error(0, TAG, `getAppPrivacyMgmtInfo failed. code is ${error.code}, message is ${error.message}`);
this.result = `getAppPrivacyMgmtInfo failed, error code: ${error.code}, error message: ${error.message}`;
}
}
} getAppPrivacyResult(): AppPrivacyResult[]
Queries the privacy agreement signing status.
Atomic service API: This API can be used in atomic services since version 5.0.0(12).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
Returns:
| Type | Description |
|---|---|
| AppPrivacyResult[] | Privacy agreement signing result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 1006700001 | System internal error. |
| 1006700003 | The application does not use privacy manager service. |
Example:
import { hilog } from '@kit.PerformanceAnalysisKit';
import { privacyManager } from '@kit.AppGalleryKit';
const TAG: string = 'getAppPrivacyResult';
@Entry
@Component
struct GetAppPrivacyResult {
@State result: string = '';
@State message: string = 'getAppPrivacyResult';
build() {
Column() {
Button(this.message)
.onClick(() => {
this.query()
})
.width('100%')
Text(this.result)
.fontSize(15)
.fontWeight(FontWeight.Bold)
.margin(20)
}
.margin(16)
.height('100%')
.justifyContent(FlexAlign.Center)
}
query() {
this.result = '';
try {
// Query the privacy agreement signing status.
let appPrivacyResults: privacyManager.AppPrivacyResult[] = privacyManager.getAppPrivacyResult();
hilog.info(0, TAG, "getAppPrivacyResult size = " + appPrivacyResults.length);
if (appPrivacyResults.length == 0) {
this.result += 'privacy result is empty!';
return;
}
for (let i = 0; i < appPrivacyResults.length; i++) {
hilog.info(0, TAG, "getAppPrivacyResult type = " + appPrivacyResults[i]["type"] + ", version = " + appPrivacyResults[i]["versionCode"] + ", result = " + appPrivacyResults[i]["result"]);
this.result += 'getAppPrivacyResult type = ' + appPrivacyResults[i]["type"] + ", result = " + appPrivacyResults[i]["result"] + ";\n";
}
} catch (error) {
hilog.error(0, TAG, `getAppPrivacyResult failed. code is ${error.code}, message is ${error.message}`);
this.result = `getAppPrivacyResult failed, error code: ${error.code}, error message: ${error.message}`;
}
}
} disableService(): void
Revokes the consent record.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.0(12)
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 1006700001 | System internal error. |
| 1006700002 | The specified service extension connect failed. |
| 1006700003 | The application does not use privacy manager service. |
Example:
import { privacyManager } from '@kit.AppGalleryKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
privacyManager.disableService();
hilog.info(0, 'TAG', "Succeeded in disabling service.");
} catch (error) {
hilog.error(0, 'TAG', "DisableService exception code: " + error.code + ", exception message: " + error.message);
} requestAppPrivacyConsent(context:common.UIAbilityContext):Promise<ConsentResult>
Launches the standardized privacy agreement pop-up to request user consent. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since version 6.1.0(23).
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AppGalleryService.PrivacyManager
Since: 5.0.2(14)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Context of the app that calls the API. |
Returns:
| Type | Description |
|---|---|
| Promise<ConsentResult> | Promise used to return the pop-up launch result. |
Error codes:
For details about the error codes, please refer to ArkTS API Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter error. |
| 1006700001 | System internal error. |
| 1006700003 | The application does not use privacy manager service. |
Example:
import { privacyManager } from '@kit.AppGalleryKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import type { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
@State message: string = 'requestAppPrivacyConsent test'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
try {
const uiContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
// Request user consent by launching the standardized privacy agreement pop-up and return the result.
privacyManager.requestAppPrivacyConsent(uiContext).then((consentResult : privacyManager.ConsentResult) => {
let appPrivacyResults: privacyManager.AppPrivacyResult[] = consentResult["results"];
for (let i = 0; i < appPrivacyResults.length; i++) {
hilog.info(0, 'TAG', "GetAppPrivacyResult type = " + appPrivacyResults[i]["type"] + ", version = " + appPrivacyResults[i]["versionCode"] + ", result = " + appPrivacyResults[i]["result"] + ", signingTimestamp = " + appPrivacyResults[i]["signingTimestamp"]);
}
}).catch((error: BusinessError<Object>) => {
hilog.error(0, 'TAG', `requestAppPrivacyConsent failed, Code: ${error.code}, message: ${error.message}`);
});
} catch (error) {
hilog.error(0, 'TAG', "requestAppPrivacyConsent exception code: " + error.code + ", exception message: " + error.message);
}
})
}
.width('100%')
}
.height('100%')
}
}