-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a client class for joining a custom audience
Summary: ## Context GPS Protected Audience API is an on-device technology for ads retargeting purpose. It allows ad tech to join users into custom audience groups based on their app events, and shows more personalized ads to users based on the groups. We will utilize the API on our client-side reranking product. ## This diff * Added stub classes for PA library * Added PA configuration to app settings. * Added the skeleton of PACustomAudienceClient, which performs joining a user to CA group. * Triggered the PA when an app event is logged (gated). Reviewed By: youerkang Differential Revision: D66840709 fbshipit-source-id: 432522c4c0b6ea29b80285bcc927b6e7e7eaff37
- Loading branch information
1 parent
9af77af
commit 0fb74d3
Showing
15 changed files
with
353 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
facebook-core/src/main/java/android/adservices/common/AdData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package android.adservices.common; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class AdData { | ||
public static final class Builder { | ||
public AdData.Builder setMetadata(@NonNull String metadata) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
public AdData build() { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
facebook-core/src/main/java/android/adservices/common/AdTechIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package android.adservices.common; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class AdTechIdentifier { | ||
@NonNull | ||
public static AdTechIdentifier fromString(@NonNull String source) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
facebook-core/src/main/java/android/adservices/customaudience/CustomAudience.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package android.adservices.customaudience; | ||
|
||
import android.adservices.common.AdData; | ||
import android.adservices.common.AdTechIdentifier; | ||
import android.net.Uri; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class CustomAudience { | ||
public static class Builder { | ||
@NonNull | ||
public CustomAudience.Builder setBuyer(@NonNull AdTechIdentifier buyer) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
@NonNull | ||
public CustomAudience.Builder setName(@NonNull String name) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
@NonNull | ||
public CustomAudience.Builder setDailyUpdateUri(@NonNull Uri dailyUpdateUri) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
@NonNull | ||
public CustomAudience.Builder setBiddingLogicUri(@NonNull Uri biddingLogicUri) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
public CustomAudience.Builder setAds(@Nullable List<AdData> ads) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
public CustomAudience build() { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
facebook-core/src/main/java/android/adservices/customaudience/CustomAudienceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package android.adservices.customaudience; | ||
|
||
import android.content.Context; | ||
import android.os.OutcomeReceiver; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
public class CustomAudienceManager { | ||
|
||
public static CustomAudienceManager get(@NonNull Context context) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
public void joinCustomAudience( | ||
@NonNull JoinCustomAudienceRequest joinCustomAudienceRequest, | ||
@NonNull Executor executor, | ||
@NonNull OutcomeReceiver<Object, Exception> receiver) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
facebook-core/src/main/java/android/adservices/customaudience/JoinCustomAudienceRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package android.adservices.customaudience; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class JoinCustomAudienceRequest { | ||
public static class Builder { | ||
public JoinCustomAudienceRequest.Builder setCustomAudience( | ||
@NonNull CustomAudience customAudience) { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
|
||
@NonNull | ||
public JoinCustomAudienceRequest build() { | ||
throw new RuntimeException("Stub!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
facebook-core/src/main/java/com/facebook/appevents/gps/GpsCapabilityChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
facebook-core/src/main/java/com/facebook/appevents/gps/pa/PACustomAudienceClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
package com.facebook.appevents.gps.pa | ||
|
||
import android.adservices.common.AdTechIdentifier | ||
import android.adservices.customaudience.CustomAudience | ||
import android.adservices.customaudience.CustomAudienceManager | ||
import android.adservices.customaudience.JoinCustomAudienceRequest | ||
import android.annotation.TargetApi | ||
import android.net.Uri | ||
import android.os.OutcomeReceiver | ||
import android.util.Log | ||
import com.facebook.FacebookSdk | ||
import com.facebook.internal.instrument.crashshield.AutoHandleExceptions | ||
import java.util.concurrent.Executors | ||
|
||
@AutoHandleExceptions | ||
object PACustomAudienceClient { | ||
private val TAG = "Fledge: " + PACustomAudienceClient::class.java.simpleName | ||
private const val BUYER = "facebook.com" | ||
private var enabled = false | ||
private var customAudienceManager: CustomAudienceManager? = null | ||
|
||
@JvmStatic | ||
@TargetApi(34) | ||
fun enable() { | ||
val context = FacebookSdk.getApplicationContext() | ||
try { | ||
customAudienceManager = CustomAudienceManager.get(context) | ||
if (customAudienceManager != null) { | ||
enabled = true | ||
} | ||
} catch (e: Exception) { | ||
Log.w(TAG, "Failed to get CustomAudienceManager: " + e.message) | ||
} catch (e: NoClassDefFoundError) { | ||
Log.w(TAG, "Failed to get CustomAudienceManager: " + e.message) | ||
} catch (e: NoSuchMethodError) { | ||
Log.w(TAG, "Failed to get CustomAudienceManager: " + e.message) | ||
} | ||
} | ||
|
||
@TargetApi(34) | ||
fun joinCustomAudience() { | ||
if (!enabled) return | ||
|
||
val callback: OutcomeReceiver<Any, Exception> = | ||
object : OutcomeReceiver<Any, Exception> { | ||
override fun onResult(result: Any) { | ||
Log.i(TAG, "Successfully joined custom audience") | ||
} | ||
|
||
override fun onError(error: Exception) { | ||
Log.e(TAG, error.toString()) | ||
} | ||
} | ||
|
||
try { | ||
val ca: CustomAudience = | ||
CustomAudience.Builder().setName("").setBuyer(AdTechIdentifier.fromString(BUYER)) | ||
.setDailyUpdateUri(Uri.parse("")).setBiddingLogicUri(Uri.parse("")) | ||
.build() | ||
val request: JoinCustomAudienceRequest = | ||
JoinCustomAudienceRequest.Builder().setCustomAudience(ca).build() | ||
customAudienceManager?.joinCustomAudience( | ||
request, | ||
Executors.newSingleThreadExecutor(), | ||
callback | ||
) | ||
} catch (e: Exception) { | ||
Log.w(TAG, "Failed to join Custom Audience: " + e.message) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.