mirror of
https://gitee.com/openharmony/advertising_ads_framework
synced 2025-02-16 23:59:51 +00:00
update readme and common code
Signed-off-by: xiangjiang <xiangjiang@huawei.com>
This commit is contained in:
parent
95e667968c
commit
0ec77d69b0
177
LICENSE
Normal file
177
LICENSE
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
36
README.en.md
36
README.en.md
@ -1,36 +0,0 @@
|
||||
# cloud_advertising
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
39
README.md
39
README.md
@ -1,39 +0,0 @@
|
||||
# cloud_advertising
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
411
advertising_README.md
Normal file
411
advertising_README.md
Normal file
@ -0,0 +1,411 @@
|
||||
# Advertising Service Component
|
||||
|
||||
## Introduction
|
||||
|
||||
The HarmonyOS advertising service enables you to implement ad access without SDK integration, helping you easily monetize your traffic.
|
||||
|
||||
### Concepts
|
||||
|
||||
- SA
|
||||
|
||||
SA, short for SystemAbility, is a binder entity that runs in the server process. After receiving an external request, SA processes the request and returns the processing result, thereby implementing service provisioning for external systems.
|
||||
|
||||
### Architecture
|
||||
|
||||
![img](figures/en-us_architecture-of-the-advertising.png)
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
/domain/cloud/advertising # Service code of the advertising service component
|
||||
├── frameworks # Framework code
|
||||
│ └── js # External JS API implementation
|
||||
│ └── napi # External native API implementation
|
||||
├── sa_profile # Service configuration profile
|
||||
├── services # Service code
|
||||
├── test # Test code
|
||||
├── LICENSE # License file
|
||||
├── BUILD.gn # Build entry
|
||||
└── bundle.json # Component description file
|
||||
```
|
||||
|
||||
## How to Use
|
||||
|
||||
### Usage Description
|
||||
|
||||
The advertising SA receives an ad request, processes the request, and forwards the request to the ad platform. The ad platform finds the best ad content and sends it to the SA for display.
|
||||
|
||||
### Creating an Ad Platform
|
||||
|
||||
The following steps walk you (application developer) through on how to create an ad platform and interact with the system.
|
||||
|
||||
1. Create a server component that implements the ServiceExtensionAbility.
|
||||
|
||||
This component is the entry for SA interaction.
|
||||
|
||||
```javascript
|
||||
export default class AdsCoreService extends ServiceExtensionAbility {
|
||||
private descriptor = 'com.xxx.xxx';
|
||||
|
||||
onCreate(want) {
|
||||
HiAdLog.i(TAG, `service onCreate`);
|
||||
HGlobalVariableManager.set("hmscoreFramework", "coreServiceAbilityContext", this.context);
|
||||
}
|
||||
|
||||
onRequest(want, startId) {
|
||||
HiAdLog.i(TAG, `service onRequest`);
|
||||
}
|
||||
|
||||
onConnect(want) {
|
||||
HiAdLog.i(TAG, `service onConnect, want: ${JSON.stringify(want)}`);
|
||||
return new AdsCoreServiceRpcObj(this.descriptor);
|
||||
}
|
||||
|
||||
onDisconnect(want) {
|
||||
HiAdLog.i(TAG, `service onDisconnect`);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
HiAdLog.i(TAG, `service onDestory`);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Create an RPC object, which will be returned by the ServiceExtensionAbility server component to the SA.
|
||||
|
||||
This RPC object is used to receive requests from the SA and send callback data to the SA.
|
||||
|
||||
```javascript
|
||||
import rpc from '@ohos.rpc';
|
||||
import bundleManager from '@ohos.bundle.bundleManager';
|
||||
|
||||
/**
|
||||
* RPC object returned by AdsCoreService to the caller, which is used by the caller to send data to AdsCoreService.
|
||||
*/
|
||||
export default class AdsCoreServiceRpcObj extends rpc.RemoteObject {
|
||||
constructor(descriptor) {
|
||||
super(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* System API for receiving requests from the SA
|
||||
*
|
||||
* @param code Service request code sent by the peer end.
|
||||
* @param data Object that carries the parameters called by the client. The parameters are called in the following sequence: Uid, RemoteObject, AdRequestParams, AdOptions, and custom collection data. The parameters must be read in the same sequence.
|
||||
* @param reply MessageSequence object to which the result is written.
|
||||
* @param options Whether the operation is synchronous or asynchronous.
|
||||
* @returns
|
||||
*/
|
||||
async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, options: rpc.MessageOption) {
|
||||
// code: 1, indicating an ad request.
|
||||
console.info(`onRemoteMessageRequest, the code is: ${code}`);
|
||||
|
||||
try {
|
||||
// 1. Read the ad request data in the specified data read sequence.
|
||||
// Read the RPC remote object on the SA side.
|
||||
const replyRpcObj: rpc.IRemoteObject = data.readRemoteObject();
|
||||
const req = {
|
||||
// Read ad request parameters. For details about the data structure, see AdRequestParams in the API document.
|
||||
reqParams: data.readString(),
|
||||
// Read ad configuration parameters. For details about the data structure, see AdOptions in the API document.
|
||||
adOptions: data.readString(),
|
||||
// Read custom collection data.
|
||||
collectedData: data.readString(),
|
||||
};
|
||||
// 2. Request data validation.
|
||||
// 3. Request ad processing.
|
||||
// Return the ad data. For details, see advertising.Advertisement in the API document.
|
||||
const ads: Array<advertising.Advertisement> = [];
|
||||
// 4. Send a response to the SA.
|
||||
const respData = rpc.MessageSequence.create();
|
||||
/**
|
||||
* The following service response codes are possible:
|
||||
* CODE_SUCCESS = 200
|
||||
* CODE_INVALID_PARAMETERS = 401
|
||||
* CODE_INTERNAL_ERROR = 100001
|
||||
* CODE_INIT_CONFIG_FAILURE = 100002
|
||||
* CODE_LOAD_ADS_FAILURE = 100003
|
||||
*/
|
||||
respData.writeInt(200);
|
||||
respData.writeString(JSON.stringify(ads));
|
||||
const reply = rpc.MessageSequence.create();
|
||||
replyRpcObj.sendMessageRequest(code, respData, reply, new rpc.MessageOption(1))
|
||||
.catch(e => {
|
||||
console.error(`send message from kit to caller failed, error msg: ${e.message}`);
|
||||
});
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error(`handle rpc request failed, msg: ${e.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Configure application information.
|
||||
|
||||
Modify the **ad_service_config.json** file in **services/advertising_manager/resource**.
|
||||
|
||||
**providerBundleName**: bundle name of the application, which corresponds to **bundleName** in **app.json5** under **AppScope**.
|
||||
|
||||
**providerAbilityName**: name of the server component that implements the ServiceExtensionAbility. This component is used to interact with the SA. It is **AdsCoreService** in the preceding example.
|
||||
|
||||
**providerUIAbilityName**: name of the component that implements the UIAbility. This component is used to display full-screen ads.
|
||||
|
||||
**providerUEAAbilityName**: name of the component that implements the UIExtensionAbility. This component is used to display non-full-screen ads.
|
||||
|
||||
4. Publish a full-screen ad.
|
||||
|
||||
You can use the common event capability provided by the system to send the interactive operations of the full-screen ad to the application.
|
||||
|
||||
```javascript
|
||||
import commonEvent from '@ohos.commonEventManager';
|
||||
|
||||
// Publish a common event.
|
||||
commonEvent.publish("event", (err) => {
|
||||
if (err.code) {
|
||||
console.error("[CommonEvent]PublishCallBack err=" + JSON.stringify(err))
|
||||
} else {
|
||||
console.info("[CommonEvent]Publish")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Requesting an Ad
|
||||
|
||||
To request an ad, you must create an **AdLoader** object and call its **loadAd** method to initiate the request. You also need to use the **AdLoadListener** callback function to listen for the ad loading status.
|
||||
|
||||
```javascript
|
||||
import advertising from '@ohos.advertising';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
try {
|
||||
const context = getContext(this) as common.UIAbilityContext;
|
||||
const adRequestParam = {
|
||||
adType: 3, // Ad type, for example, native ad.
|
||||
adId: "test", // Ad slot ID.
|
||||
};
|
||||
const adOption = {
|
||||
adContentClassification: 'A', // Set the maximum ad content rating.
|
||||
};
|
||||
// Listen for the ad loading status.
|
||||
const adLoaderListener = {
|
||||
// Called when an ad request fails.
|
||||
onAdLoadFailure: (errorCode: number, errorMsg: string) => {
|
||||
console.info(`request ad errorCode is: ${errorCode}, errorMsg is: ${errorMsg}`);
|
||||
},
|
||||
// Called when an ad request is successful.
|
||||
onAdLoadSuccess: (ads: Array<advertising.Advertisement>) => {
|
||||
console.info(`request ad success!`);
|
||||
// Save the requested ad content for display.
|
||||
const ads = ads;
|
||||
}
|
||||
};
|
||||
// Create an AdLoader object.
|
||||
const adLoader = new advertising.AdLoader(context);
|
||||
// Call the loadAd method.
|
||||
console.info(`request ad!`);
|
||||
adLoader.loadAd(adReqParams, adOptions, adLoaderListener);
|
||||
} catch (err) {
|
||||
console.error(`load ad catch error: ${err.code} ${err.message}`);
|
||||
}
|
||||
```
|
||||
|
||||
### Showing a Full-Screen Ad
|
||||
|
||||
1. Subscribe to the event.
|
||||
|
||||
Subscribe to the com.huawei.hms.pps.action.PPS_REWARD_STATUS_CHANGED event to listen for changes on the reward ad page and receive reward information. The subscription must be initiated each time before an ad is displayed.
|
||||
|
||||
After receiving the common event, use **reward_ad_status** and **reward_ad_data** as keys in the **parameters** parameter of [CommonEventData](https://docs.openharmony.cn/pages/v4.0/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventData.md/) to obtain changes on the reward ad page and obtain reward information, respectively. You can use the **rewardType** and **rewardAmount** attributes to obtain the name of a reward and its quantity.
|
||||
|
||||
```javascript
|
||||
import commonEvent from '@ohos.commonEventManager';
|
||||
|
||||
const KEY_REWARD_DATA = "reward_ad_data";
|
||||
const KEY_REWARD_STATUS = "reward_ad_status";
|
||||
|
||||
export class RewardAdStatusHandler {
|
||||
// Used to save the created subscriber object for subsequent subscription and unsubscription.
|
||||
private subscriber;
|
||||
|
||||
// Subscription method, which must be called each time before an ad is displayed.
|
||||
public registerPPSReceiver(): void {
|
||||
if (this.subscriber) {
|
||||
this.unRegisterPPSReceiver();
|
||||
}
|
||||
// Subscriber information.
|
||||
const subscribeInfo = {
|
||||
events: ["com.huawei.hms.pps.action.PPS_REWARD_STATUS_CHANGED"],
|
||||
};
|
||||
// Callback for subscriber creation.
|
||||
commonEvent.createSubscriber(subscribeInfo, (err, commonEventSubscriber) => {
|
||||
if (err) {
|
||||
console.error(`createSubscriber error, ${JSON.stringify(err)}`);
|
||||
return;
|
||||
}
|
||||
console.debug(`createSubscriber success`);
|
||||
this.subscriber = commonEventSubscriber;
|
||||
// Callback for common event subscription.
|
||||
if (!this.subscriber) {
|
||||
console.warn(`need create subscriber`);
|
||||
return;
|
||||
}
|
||||
commonEvent.subscribe(this.subscriber, (err, commonEventData) => {
|
||||
if (err) {
|
||||
console.error(`subscribe error, ${JSON.stringify(err)}`);
|
||||
} else {
|
||||
// The subscriber receives the common event.
|
||||
console.debug(`subscribe data, ${JSON.stringify(commonEventData)}`);
|
||||
// Obtain the changes on the reward ad page.
|
||||
const status: string = commonEventData.parameters[KEY_REWARD_STATUS];
|
||||
switch (status) {
|
||||
case AdStatus.AD_OPEN:
|
||||
console.info(`onAdOpen`);
|
||||
break;
|
||||
case AdStatus.AD_CLICKED:
|
||||
console.info(`onAdClick`);
|
||||
break;
|
||||
case AdStatus.AD_CLOSED:
|
||||
console.info(`onAdClose`);
|
||||
this.unRegisterPPSReceiver();
|
||||
break;
|
||||
case AdStatus.AD_REWARDED:
|
||||
// Obtain reward information.
|
||||
const rewardData = commonEventData.parameters[KEY_REWARD_DATA];
|
||||
const rewardType = rewardData?.rewardType;
|
||||
const rewardAmount = rewardData?.rewardAmount;
|
||||
console.info(`onAdReward, rewardType: ${rewardType}, rewardAmount: ${rewardAmount}`);
|
||||
break;
|
||||
case AdStatus.AD_VIDEO_START:
|
||||
console.info(`onAdVideoStart`);
|
||||
break;
|
||||
case AdStatus.AD_COMPLETED:
|
||||
console.info(`onAdCompleted`);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Unsubscribe from the event.
|
||||
public unRegisterPPSReceiver(): void {
|
||||
commonEvent.unsubscribe(this.subscriber, (err) => {
|
||||
if (err) {
|
||||
console.error(`unsubscribe error, ${JSON.stringify(err)}`);
|
||||
} else {
|
||||
console.info(`unsubscribe success`);
|
||||
this.subscriber = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Ad page changes
|
||||
enum AdStatus {
|
||||
AD_OPEN = "onAdOpen",
|
||||
AD_CLICKED = "onAdClick",
|
||||
AD_CLOSED = "onAdClose",
|
||||
AD_REWARDED = "onAdReward",
|
||||
AD_VIDEO_START = "onVideoPlayBegin",
|
||||
AD_COMPLETED = "onVideoPlayEnd",
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Show an ad.
|
||||
|
||||
Call the **showAd** method to show an ad.
|
||||
|
||||
```javascript
|
||||
import advertising from '@ohos.advertising';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
export struct ShowAd {
|
||||
private context = getContext(this) as common.UIAbilityContext;
|
||||
// Requested ad content.
|
||||
private ad: advertising.Advertisement = void 0;
|
||||
// Ad display parameters.
|
||||
private adDisplayOptions: advertising.AdDisplayOptions = {
|
||||
// Whether to mute the ad. By default, the ad is not muted.
|
||||
mute: false,
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Button ("Show Ad")
|
||||
.backgroundColor('#d3d4d6')
|
||||
.fontSize(20)
|
||||
.fontColor('#000')
|
||||
.fontWeight(FontWeight.Normal)
|
||||
.align(Alignment.Center)
|
||||
.type(ButtonType.Capsule)
|
||||
.width('90%')
|
||||
.height(40)
|
||||
.margin({ top: 10, bottom: 5 })
|
||||
.onClick(() => {
|
||||
try {
|
||||
// Show a full-screen ad, such as a reward ad.
|
||||
advertising.showAd(this.ad, this.adDisplayOptions, this.context);
|
||||
} catch (err) {
|
||||
hilog.error(0x0000, 'testTag', 'show ad catch error: %{public}d %{public}s', err.code, err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Showing a Non-Full-Screen Ad
|
||||
|
||||
Use the AdComponent component to show a non-full-screen ad.
|
||||
|
||||
```javascript
|
||||
import advertising from '@ohos.advertising';
|
||||
import { AdComponent } from '@ohos.cloud.AdComponent';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
export struct ShowAd {
|
||||
// Requested ad content.
|
||||
private ads: Array[advertising.Advertisement] = [];
|
||||
// Ad display parameters.
|
||||
private adDisplayOptions: advertising.AdDisplayOptions = {
|
||||
// Whether to mute the ad. By default, the ad is not muted.
|
||||
mute: false,
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// Show a non-full-screen ad, such as a native ad.
|
||||
AdComponent({ ads: this.ads, displayOptions: this.adDisplayOptions,
|
||||
interactionListener: {
|
||||
// Ad status change callback.
|
||||
onStatusChanged: (status: string, ad: advertising.Advertisement, data: string) => {
|
||||
switch(status) {
|
||||
case AdStatus.AD_OPEN:
|
||||
console.info(`onAdOpen`);
|
||||
break;
|
||||
case AdStatus.AD_CLICKED:
|
||||
console.info(`onAdClick`);
|
||||
break;
|
||||
case AdStatus.AD_CLOSED:
|
||||
console.info(`onAdClose`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}.width('100%').height('100%')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Repositories Involved
|
47
common/BUILD.gn
Normal file
47
common/BUILD.gn
Normal file
@ -0,0 +1,47 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//domains/cloud/advertising/advertising.gni")
|
||||
|
||||
config("common_config") {
|
||||
include_dirs = [
|
||||
"error_code",
|
||||
"ipc/include",
|
||||
"log/include",
|
||||
"model/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//third_party/jsoncpp/include/json"
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("advertising_common") {
|
||||
configs = [ ":common_config" ]
|
||||
|
||||
sources = [
|
||||
"ipc/src/ad_load_proxy.cpp",
|
||||
"ipc/src/ad_load_callback_stub.cpp",
|
||||
"model/src/request_data.cpp",
|
||||
]
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "advertising"
|
||||
}
|
87
common/error_code/ad_inner_error_code.h
Normal file
87
common/error_code/ad_inner_error_code.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ADS_ERROR_CODE_H
|
||||
#define ADS_ERROR_CODE_H
|
||||
|
||||
#include <map>
|
||||
#include <cstdint>
|
||||
#include "errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
#define ADS_SERVICE_NAME "AdsService"
|
||||
|
||||
// The param input is invalid
|
||||
const int32_t ERR_AD_INPUT_PARAM_INVALID = 401;
|
||||
|
||||
// check descriptor fail
|
||||
const int32_t ERR_AD_COMMON_CHECK_DESCRIPTOR_ERROR = 1;
|
||||
|
||||
// read ad size fail
|
||||
const int32_t ERR_AD_COMMON_READ_AD_SIZE_ERROR = 2;
|
||||
|
||||
// read ad fail
|
||||
const int32_t ERR_AD_COMMON_READ_AD_ERROR = 3;
|
||||
|
||||
// send request fail
|
||||
const int32_t ERR_AD_COMMON_SEND_REQUEST_ERROR = 4;
|
||||
|
||||
// excute napi callback is null
|
||||
const int32_t ERR_AD_COMMON_NAPI_CALLBACK_NULL_ERROR = 5;
|
||||
|
||||
// ad proxy is null
|
||||
const int32_t ERR_AD_COMMON_AD_PROXY_NULL_ERROR = 6;
|
||||
|
||||
// write descriptor error
|
||||
const int32_t ERR_AD_COMMON_AD_WRITE_DESCRIPTOR_ERROR = 7;
|
||||
|
||||
// write parcel error
|
||||
const int32_t ERR_AD_COMMON_AD_WRITE_PARCEL_ERROR = 8;
|
||||
|
||||
// read parcel error
|
||||
const int32_t ERR_AD_COMMON_AD_READ_PARCEL_ERROR = 9;
|
||||
|
||||
// null ptr error
|
||||
const int32_t ERR_AD_COMMON_AD_NULL_PTR_ERROR = 10;
|
||||
|
||||
// service invalid parameters
|
||||
const int32_t ERR_AD_COMMON_AD_SERVICE_INVALID_PARAMETER_ERROR = 11;
|
||||
|
||||
// connect ad kit fail
|
||||
const int32_t ERR_AD_COMMON_AD_CONNECT_KIT_ERROR = 12;
|
||||
|
||||
// kit remoteobject is null
|
||||
const int32_t ERR_AD_COMMON_AD_KIT_REMOTE_OBJECT_ERROR = 13;
|
||||
|
||||
// ad service remoteobject is null
|
||||
const int32_t ERR_AD_COMMON_AD_SA_REMOTE_OBJECT_ERROR = 14;
|
||||
|
||||
// ad request object to json fail
|
||||
const int32_t ERR_AD_COMMON_AD_REQUEST_TO_JSON_ERROR = 15;
|
||||
|
||||
// show ad fail
|
||||
const int32_t ERR_AD_COMMON_AD_SHOW_AD_ERROR = 16;
|
||||
|
||||
enum AdsError : int32_t {
|
||||
ERR_SEND_OK = 0,
|
||||
PARAM_ERR = 401,
|
||||
INNER_ERR = 21800001,
|
||||
REQUEST_FAIL = 21800003,
|
||||
};
|
||||
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // ADS_ERROR_CODE_H
|
32
common/ipc/include/ad_load_callback_stub.h
Normal file
32
common/ipc/include/ad_load_callback_stub.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADVERTISING_LOAD_CALLBACK_STUB_H
|
||||
#define OHOS_CLOUD_ADVERTISING_LOAD_CALLBACK_STUB_H
|
||||
|
||||
#include "iad_load_callback.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
class AdLoadCallbackStub : public IRemoteStub<IAdLoadCallback> {
|
||||
public:
|
||||
AdLoadCallbackStub();
|
||||
~AdLoadCallbackStub() override;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
};
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADVERTISING_LOAD_CALLBACK_STUB_H
|
38
common/ipc/include/ad_load_proxy.h
Normal file
38
common/ipc/include/ad_load_proxy.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADVERTISING_LOAD_PROXY_H
|
||||
#define OHOS_CLOUD_ADVERTISING_LOAD_PROXY_H
|
||||
|
||||
#include <iremote_proxy.h>
|
||||
#include "iad_load_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
class AdLoadSendRequestProxy : public IRemoteProxy<IAdLoadSendRequest> {
|
||||
public:
|
||||
explicit AdLoadSendRequestProxy(const sptr<IRemoteObject> &remote) : IRemoteProxy<IAdLoadSendRequest>(remote) {}
|
||||
|
||||
virtual ~AdLoadSendRequestProxy() {}
|
||||
|
||||
ErrCode SendAdLoadRequest(uint32_t callingUid, const sptr<AdRequestData> &data,
|
||||
const sptr<IAdLoadCallback> &callback, int32_t loadAdType) override;
|
||||
|
||||
private:
|
||||
ErrCode SendAdLoadIpcRequest(int32_t code, MessageParcel &data);
|
||||
};
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADVERTISING_LOAD_PROXY_H
|
45
common/ipc/include/iad_load_callback.h
Normal file
45
common/ipc/include/iad_load_callback.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADVERTISING_LOAD_CALLBACK_H
|
||||
#define OHOS_CLOUD_ADVERTISING_LOAD_CALLBACK_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
class IAdLoadCallback : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.cloud.Ads.IAdLoadCallback");
|
||||
|
||||
virtual void OnAdLoadSuccess(const std::vector<AAFwk::Want> &result) = 0;
|
||||
virtual void OnAdLoadMultiSlotsSuccess(const std::map<std::string, std::vector<AAFwk::Want>> &result) = 0;
|
||||
virtual void OnAdLoadFailure(int32_t resultCode, const std::string &resultMsg) = 0;
|
||||
|
||||
enum class Message {
|
||||
AD_LOAD = 1,
|
||||
MULTI_AD_LOAD = 2,
|
||||
AD_LOAD_PARAMS_ERROR = 401,
|
||||
AD_LOAD_INNER_ERROR = 100001,
|
||||
AD_LOAD_FAIL = 100003,
|
||||
};
|
||||
};
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADVERTISING_LOAD_CALLBACK_H
|
47
common/ipc/include/iad_load_proxy.h
Normal file
47
common/ipc/include/iad_load_proxy.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADVERTISING_LOAD_IPROXY_H
|
||||
#define OHOS_CLOUD_ADVERTISING_LOAD_IPROXY_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iad_load_callback.h"
|
||||
#include "refbase.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
struct AdRequestData : public RefBase {
|
||||
std::string adRequest;
|
||||
std::string adOption;
|
||||
std::string collection;
|
||||
|
||||
AdRequestData(std::string remoteAdRequest, std::string remoteAdOption, std::string remoteCollection)
|
||||
: adRequest(remoteAdRequest), adOption(remoteAdOption), collection(remoteCollection)
|
||||
{}
|
||||
};
|
||||
|
||||
class IAdLoadSendRequest : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Cloud.Ads.IAdLoadSendRequest");
|
||||
|
||||
virtual ErrCode SendAdLoadRequest(uint32_t callingUid, const sptr<AdRequestData> &data,
|
||||
const sptr<IAdLoadCallback> &callback, int32_t loadAdType) = 0;
|
||||
};
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADVERTISING_LOAD_IPROXY_H
|
131
common/ipc/src/ad_load_callback_stub.cpp
Normal file
131
common/ipc/src/ad_load_callback_stub.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "want.h"
|
||||
#include "json/json.h"
|
||||
#include "ad_hilog_wreapper.h"
|
||||
#include "ad_constant.h"
|
||||
#include "ad_load_callback_stub.h"
|
||||
#include "ad_hilog_wreapper.h"
|
||||
#include "ad_inner_error_code.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
static const int32_t LOAD_AD_SUCCESS = 200;
|
||||
|
||||
AdLoadCallbackStub::AdLoadCallbackStub() {}
|
||||
AdLoadCallbackStub::~AdLoadCallbackStub() {}
|
||||
|
||||
inline std::string Str16ToStr8(const std::u16string &str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||
std::string result = convert.to_bytes(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void CommonParse(AAFwk::Want &want, Json::Value &root)
|
||||
{
|
||||
want.SetParam(AD_RESPONSE_AD_TYPE, root[AD_RESPONSE_AD_TYPE].asInt());
|
||||
std::string rewardConfig = Json::FastWriter().write(root[AD_RESPONSE_REWARD_CONFIG]);
|
||||
want.SetParam(AD_RESPONSE_REWARD_CONFIG, rewardConfig);
|
||||
want.SetParam(AD_RESPONSE_UNIQUE_ID, root[AD_RESPONSE_UNIQUE_ID].asString());
|
||||
want.SetParam(AD_RESPONSE_REWARDED, root[AD_RESPONSE_REWARDED].asBool());
|
||||
want.SetParam(AD_RESPONSE_SHOWN, root[AD_RESPONSE_SHOWN].asBool());
|
||||
want.SetParam(AD_RESPONSE_CLICKED, root[AD_RESPONSE_CLICKED].asBool());
|
||||
}
|
||||
|
||||
inline void ParseSingleAd(std::vector<AAFwk::Want> &ads, Json::Value &root)
|
||||
{
|
||||
AAFwk::Want want;
|
||||
CommonParse(want, root);
|
||||
ads.emplace_back(want);
|
||||
}
|
||||
|
||||
void ParseAdArray(std::string adsString, std::vector<AAFwk::Want> &ads)
|
||||
{
|
||||
Json::Reader reader;
|
||||
Json::Value root;
|
||||
if (reader.parse(adsString, root)) {
|
||||
if (root.type() == Json::arrayValue) {
|
||||
uint32_t size = root.size();
|
||||
ADS_HILOGW(OHOS::Cloud::ADS_MODULE_COMMON, "ads size is: %{public}u.", size);
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
ParseSingleAd(ads, root[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParseAdMap(std::string adsString, std::map<std::string, std::vector<AAFwk::Want>> &ads)
|
||||
{
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_COMMON, "multi solts kit return enter");
|
||||
Json::Reader reader;
|
||||
Json::Value root;
|
||||
bool parseResult = reader.parse(adsString, root);
|
||||
if (!parseResult) {
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_COMMON, "parse ad map result is = %{public}d", parseResult);
|
||||
return;
|
||||
}
|
||||
for (Json::ValueIterator itr = root.begin(); itr != root.end(); itr++) {
|
||||
std::string key = itr.key().asString();
|
||||
std::vector<AAFwk::Want> want;
|
||||
std::string value = Json::FastWriter().write(*itr);
|
||||
ParseAdArray(value, want);
|
||||
ads[key] = want;
|
||||
}
|
||||
}
|
||||
|
||||
int AdLoadCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
switch (code) {
|
||||
case static_cast<uint32_t>(IAdLoadCallback::Message::AD_LOAD): {
|
||||
int32_t resultCode = data.ReadInt32();
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_COMMON, "single slot kit return code = %{public}u", resultCode);
|
||||
std::string resultMsg = Str16ToStr8(data.ReadString16());
|
||||
if (resultCode == LOAD_AD_SUCCESS) {
|
||||
std::vector<AAFwk::Want> ads;
|
||||
ParseAdArray(resultMsg, ads);
|
||||
OnAdLoadSuccess(ads);
|
||||
} else {
|
||||
OnAdLoadFailure(resultCode, resultMsg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case static_cast<uint32_t>(IAdLoadCallback::Message::MULTI_AD_LOAD): {
|
||||
int32_t resultCode = data.ReadInt32();
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_COMMON, "multi slots kit return code = %{public}u", resultCode);
|
||||
std::string msg = Str16ToStr8(data.ReadString16());
|
||||
if (resultCode == LOAD_AD_SUCCESS) {
|
||||
std::map<std::string, std::vector<AAFwk::Want>> adsMap;
|
||||
ParseAdMap(msg, adsMap);
|
||||
OnAdLoadMultiSlotsSuccess(adsMap);
|
||||
} else {
|
||||
OnAdLoadFailure(resultCode, msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_COMMON, "default, code = %{public}u, flags = %{public}u", code,
|
||||
option.GetFlags());
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
82
common/ipc/src/ad_load_proxy.cpp
Normal file
82
common/ipc/src/ad_load_proxy.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ad_load_proxy.h"
|
||||
#include "ad_inner_error_code.h"
|
||||
#include "ad_constant.h"
|
||||
#include "ad_hilog_wreapper.h"
|
||||
#include "errors.h"
|
||||
#include "iad_load_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
inline std::u16string Str8ToStr16(const std::string &str)
|
||||
{
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_SERVICE, "Str8ToStr16");
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||
std::u16string result = convert.from_bytes(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrCode AdLoadSendRequestProxy::SendAdLoadRequest(uint32_t callingUid, const sptr<AdRequestData> &requestData,
|
||||
const sptr<IAdLoadCallback> &callback, int32_t loadAdType)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_SERVICE, "callback is null");
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInt32(callingUid)) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to callingUid");
|
||||
return ERR_AD_COMMON_AD_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to WriteRemoteObject");
|
||||
return ERR_AD_COMMON_AD_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteString16(Str8ToStr16(requestData->adRequest))) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to adRequest");
|
||||
return ERR_AD_COMMON_AD_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteString16(Str8ToStr16(requestData->adOption))) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to adOption");
|
||||
return ERR_AD_COMMON_AD_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteString16(Str8ToStr16(requestData->collection))) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to collection");
|
||||
return ERR_AD_COMMON_AD_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
return SendAdLoadIpcRequest(loadAdType, data);
|
||||
}
|
||||
|
||||
ErrCode AdLoadSendRequestProxy::SendAdLoadIpcRequest(int32_t code, MessageParcel &data)
|
||||
{
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
ErrCode result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
|
||||
ADS_HILOGI(OHOS::Cloud::ADS_MODULE_SERVICE, "AdLoadSendRequestProxy SendRequest result = %{public}d", result);
|
||||
if (result != ERR_OK) {
|
||||
ADS_HILOGW(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to SendRequest, code = %{public}d, result = %{public}d",
|
||||
code, result);
|
||||
return ERR_AD_COMMON_SEND_REQUEST_ERROR;
|
||||
}
|
||||
if (!reply.ReadInt32()) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_SERVICE, "failed to read result for ad kit service return");
|
||||
return ERR_AD_COMMON_AD_READ_PARCEL_ERROR;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
58
common/log/include/ad_hilog_wreapper.h
Normal file
58
common/log/include/ad_hilog_wreapper.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADS_HILOG_WRAPPER_H
|
||||
#define OHOS_CLOUD_ADS_HILOG_WRAPPER_H
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
// param of log interface, such as ADS_HILOGF.
|
||||
enum AdsSubModule {
|
||||
ADS_MODULE_INNERKIT = 0,
|
||||
ADS_MODULE_CLIENT,
|
||||
ADS_MODULE_SERVICE,
|
||||
ADS_MODULE_COMMON,
|
||||
ADS_MODULE_JS_NAPI,
|
||||
ADS_MODULE_BUTT,
|
||||
};
|
||||
|
||||
static constexpr unsigned int ADS_DOMAIN_ID = 0xD004704;
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel ADS_MODULE_LABEL[ADS_MODULE_BUTT] = {
|
||||
{LOG_CORE, ADS_DOMAIN_ID, "AdsInnerKit"},
|
||||
{LOG_CORE, ADS_DOMAIN_ID, "AdsClient"},
|
||||
{LOG_CORE, ADS_DOMAIN_ID, "AdsService"},
|
||||
{LOG_CORE, ADS_DOMAIN_ID, "AdsCommon"},
|
||||
{LOG_CORE, ADS_DOMAIN_ID, "AdsJSNAPI"},
|
||||
};
|
||||
|
||||
#define R_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
#define R_FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, R_FILENAME, __FUNCTION__, ##__VA_ARGS__
|
||||
|
||||
#define ADS_HILOGF(module, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::Cloud::ADS_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
|
||||
#define ADS_HILOGE(module, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Error(OHOS::Cloud::ADS_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
|
||||
#define ADS_HILOGW(module, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Warn(OHOS::Cloud::ADS_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
|
||||
#define ADS_HILOGI(module, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Info(OHOS::Cloud::ADS_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
|
||||
#define ADS_HILOGD(module, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Debug(OHOS::Cloud::ADS_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADS_HILOG_WRAPPER_H
|
120
common/model/include/ad_constant.h
Normal file
120
common/model/include/ad_constant.h
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADS_INIT_DEFINE_H
|
||||
#define OHOS_CLOUD_ADS_INIT_DEFINE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
// The system component ID of the advertising is 6104.
|
||||
static const int32_t ADVERTISING_ID = 6104;
|
||||
|
||||
// request ad
|
||||
static const int32_t SEND_LOAD_AD_REQUEST_CODE = 1;
|
||||
|
||||
// request multi solts ad
|
||||
static const int32_t SEND_LOAD_MULTI_SOLTS_AD_REQUEST_CODE = 2;
|
||||
|
||||
// The connection timeout is 3s.
|
||||
static const int8_t CONNECT_TIME_OUT = 3;
|
||||
|
||||
// user id
|
||||
static const int32_t USER_ID = 100;
|
||||
|
||||
// config
|
||||
static const std::string DEPENDENCY_CONFIG_FILE_RELATIVE_PATH = "etc/cloud/advertising/ad_service_config.json";
|
||||
|
||||
// AdRequestParams-adId
|
||||
static const std::string AD_REQUEST_PARAM_ID = "adId";
|
||||
|
||||
// AdRequestParams-adType
|
||||
static const std::string AD_REQUEST_PARAM_TYPE = "adType";
|
||||
|
||||
// AdRequestParams-adCount
|
||||
static const std::string AD_REQUEST_PARAM_COUNT = "adCount";
|
||||
|
||||
// AdRequestParams-adWidth
|
||||
static const std::string AD_REQUEST_PARAM_WIDTH = "adWidth";
|
||||
|
||||
// AdRequestParams-adHeight
|
||||
static const std::string AD_REQUEST_PARAM_HEIGHT = "adHeight";
|
||||
|
||||
// AdRequestParams-extra
|
||||
static const std::string AD_REQUEST_PARAM_EXTRA = "adExtra";
|
||||
|
||||
// AdOptions-tagForChildProtection
|
||||
static const std::string TAG_FOR_CHILD_PROTECTION = "tagForChildProtection";
|
||||
|
||||
// AdOptions-adContentClassification
|
||||
static const std::string AD_CONTENT_CLASSIFICATION = "adContentClassification";
|
||||
|
||||
// AdOptions-nonPersonalizedAd
|
||||
static const std::string NON_PERSONALIZED_AD = "nonPersonalizedAd";
|
||||
|
||||
// AdOptions-nonPersonalizedAd
|
||||
static const std::string AD_OPTIONS_EXTRA = "optionsExtra";
|
||||
|
||||
// AdDisplayOptions-customData
|
||||
static const std::string AD_DISPLAY_OPTIONS_DATA = "customData";
|
||||
|
||||
// AdDisplayOptions-userId
|
||||
static const std::string AD_DISPLAY_OPTIONS_USER = "userId";
|
||||
|
||||
// AdDisplayOptions-useMobileDataReminder
|
||||
static const std::string AD_DISPLAY_OPTIONS_REMINDER = "useMobileDataReminder";
|
||||
|
||||
// AdDisplayOptions-mute
|
||||
static const std::string AD_DISPLAY_OPTIONS_MUTE = "mute";
|
||||
|
||||
// AdDisplayOptions-audioFocusType
|
||||
static const std::string AD_DISPLAY_OPTIONS_TYPE = "audioFocusType";
|
||||
|
||||
// Advertisement-adType
|
||||
static const std::string AD_RESPONSE_AD_TYPE = "adType";
|
||||
|
||||
// Advertisement-rewardVerifyConfig
|
||||
static const std::string AD_RESPONSE_REWARD_CONFIG = "rewardVerifyConfig";
|
||||
|
||||
// Advertisement-uniqueId
|
||||
static const std::string AD_RESPONSE_UNIQUE_ID = "uniqueId";
|
||||
|
||||
// Advertisement-rewarded
|
||||
static const std::string AD_RESPONSE_REWARDED = "rewarded";
|
||||
|
||||
// Advertisement-shown
|
||||
static const std::string AD_RESPONSE_SHOWN = "shown";
|
||||
|
||||
// Advertisement-clicked
|
||||
static const std::string AD_RESPONSE_CLICKED = "clicked";
|
||||
|
||||
// bundle name
|
||||
static const std::string AD_DEFAULT_BUNDLE_NAME = "";
|
||||
|
||||
// ability name
|
||||
static const std::string AD_DEFAULT_ABILITY_NAME = "";
|
||||
|
||||
// show ad ability name
|
||||
static const std::string AD_DEFAULT_SHOW_AD_ABILITY_NAME = "";
|
||||
|
||||
// AdDisplayOptions
|
||||
static const std::string AD_DISPLAY_OPTIONS = "AdDisplayOptions";
|
||||
|
||||
// Advertisement
|
||||
static const std::string AD_ADVERTISMENT = "Advertisement";
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADS_INIT_DEFINE_H
|
55
common/model/include/request_data.h
Normal file
55
common/model/include/request_data.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_CLOUD_ADVERTISING_AD_DATA_H
|
||||
#define OHOS_CLOUD_ADVERTISING_AD_DATA_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <new>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "want.h"
|
||||
#include "want_params.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
namespace AdsSAData {
|
||||
struct AdRequestParams : public Parcelable {
|
||||
std::string adId;
|
||||
uint32_t adType;
|
||||
uint32_t adCount;
|
||||
uint32_t adWidth;
|
||||
uint32_t adHeight;
|
||||
AAFwk::WantParams adRequestExtra;
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
static AdRequestParams *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
|
||||
struct AdOptions : public Parcelable {
|
||||
uint32_t tagForChildProtection;
|
||||
std::string adContentClassification = "";
|
||||
uint32_t nonPersonalizedAd;
|
||||
AAFwk::WantParams adOptionsExtrea;
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
static AdOptions *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
} // namespace AdsSAData
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_CLOUD_ADVERTISING_CLIENT_H
|
86
common/model/src/request_data.cpp
Normal file
86
common/model/src/request_data.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <new>
|
||||
|
||||
#include "request_data.h"
|
||||
#include "ad_hilog_wreapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Cloud {
|
||||
namespace AdsSAData {
|
||||
bool AdRequestParams::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if ((!parcel.ReadString(adId)) || (!parcel.ReadUint32(adType)) || (!parcel.ReadUint32(adCount)) ||
|
||||
(!parcel.ReadUint32(adWidth)) || (!parcel.ReadUint32(adHeight))) {
|
||||
return false;
|
||||
}
|
||||
sptr<AAFwk::WantParams> paramsPtr = parcel.ReadParcelable<AAFwk::WantParams>();
|
||||
if (paramsPtr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
adRequestExtra = *paramsPtr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AdRequestParams::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return parcel.WriteString(adId) && parcel.WriteUint32(adType) && parcel.WriteUint32(adCount) &&
|
||||
parcel.WriteUint32(adWidth) && parcel.WriteUint32(adHeight);
|
||||
}
|
||||
|
||||
AdRequestParams *AdRequestParams::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
AdRequestParams *info = new (std::nothrow) AdRequestParams();
|
||||
if ((info != nullptr) && (!info->ReadFromParcel(parcel))) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_COMMON, "ad requestParams read from parcel failed");
|
||||
delete info;
|
||||
info = nullptr;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
bool AdOptions::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if ((!parcel.ReadUint32(tagForChildProtection)) || (!parcel.ReadString(adContentClassification)) ||
|
||||
(!parcel.ReadUint32(nonPersonalizedAd))) {
|
||||
return false;
|
||||
}
|
||||
sptr<AAFwk::WantParams> paramsPtr = parcel.ReadParcelable<AAFwk::WantParams>();
|
||||
if (paramsPtr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
adOptionsExtrea = *paramsPtr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AdOptions::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return parcel.WriteUint32(tagForChildProtection) && parcel.WriteString(adContentClassification) &&
|
||||
parcel.WriteUint32(nonPersonalizedAd);
|
||||
}
|
||||
|
||||
AdOptions *AdOptions::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
AdOptions *info = new (std::nothrow) AdOptions();
|
||||
if ((info != nullptr) && (!info->ReadFromParcel(parcel))) {
|
||||
ADS_HILOGE(OHOS::Cloud::ADS_MODULE_COMMON, "ad options read from parcel failed");
|
||||
delete info;
|
||||
info = nullptr;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
} // namespace AdsSAData
|
||||
} // namespace Cloud
|
||||
} // namespace OHOS
|
Loading…
x
Reference in New Issue
Block a user