Skip to content

Commit 4363246

Browse files
forezacopybara-github
authored andcommitted
Internal changes.
PiperOrigin-RevId: 823682863
1 parent ac892f4 commit 4363246

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.android.gms.snippets;
16+
17+
import android.content.Context;
18+
import android.util.Log;
19+
import com.google.android.gms.ads.mediation.InitializationCompleteCallback;
20+
import com.google.android.gms.ads.mediation.MediationConfiguration;
21+
import com.google.android.gms.ads.mediation.VersionInfo;
22+
import com.google.android.gms.ads.mediation.rtb.RtbAdapter;
23+
import com.google.android.gms.ads.mediation.rtb.RtbSignalData;
24+
import com.google.android.gms.ads.mediation.rtb.SignalCallbacks;
25+
import java.util.List;
26+
27+
/** An example {@link RtbAdapter} implementation for secure signal collection guidance. */
28+
public class SampleAdapterSnippets extends RtbAdapter {
29+
private static final String TAG = "SampleAdapterSnippets";
30+
private static final String ADAPTER_VERSION_STRING = "4.5.6";
31+
private static final String SDK_VERSION_STRING = "1.2.3";
32+
private static final String SAMPLE_SIGNAL_PLACEHOLDER = "your_sdk_secure_signal_string";
33+
34+
// [START initialize_adapter]
35+
@Override
36+
public void initialize(
37+
Context context,
38+
InitializationCompleteCallback initializationCompleteCallback,
39+
List<MediationConfiguration> configurations) {
40+
41+
// Add your SDK initialization logic here.
42+
43+
// Invoke the InitializationCompleteCallback once initialization completes.
44+
initializationCompleteCallback.onInitializationSucceeded();
45+
}
46+
47+
// [END initialize_adapter]
48+
49+
// [START get_adapter_version_info]
50+
@Override
51+
public VersionInfo getVersionInfo() {
52+
// If your SDK implements this adapter in the same binary, return the same version as your
53+
// SDK.
54+
// return getSDKVersionInfo();
55+
56+
// If you built a separate binary for this adapter, return the adapter's version here.
57+
String versionString = ADAPTER_VERSION_STRING;
58+
String[] splits = versionString.split("\\.");
59+
if (splits.length >= 3) {
60+
try {
61+
int major = Integer.parseInt(splits[0]);
62+
int minor = Integer.parseInt(splits[1]);
63+
int micro = Integer.parseInt(splits[2]);
64+
return new VersionInfo(major, minor, micro);
65+
} catch (NumberFormatException e) {
66+
// Fall through to log warning and return 0.0.0.
67+
}
68+
}
69+
70+
Log.w(
71+
TAG,
72+
String.format(
73+
"Unexpected adapter version format: %s. Returning 0.0.0 for adapter version.",
74+
versionString));
75+
return new VersionInfo(0, 0, 0);
76+
}
77+
78+
// [END get_adapter_version_info]
79+
80+
// [START get_sdk_version_info]
81+
@Override
82+
public VersionInfo getSDKVersionInfo() {
83+
84+
// Return your SDK's version string here.
85+
String versionString = SDK_VERSION_STRING;
86+
String[] splits = versionString.split("\\.");
87+
if (splits.length >= 3) {
88+
try {
89+
int major = Integer.parseInt(splits[0]);
90+
int minor = Integer.parseInt(splits[1]);
91+
int micro = Integer.parseInt(splits[2]);
92+
return new VersionInfo(major, minor, micro);
93+
} catch (NumberFormatException e) {
94+
// Fall through to log warning and return 0.0.0.
95+
}
96+
}
97+
98+
Log.w(
99+
TAG,
100+
String.format(
101+
"Unexpected SDK version format: %s. Returning 0.0.0 for SDK version.", versionString));
102+
return new VersionInfo(0, 0, 0);
103+
}
104+
105+
// [END get_sdk_version_info]
106+
107+
// [START collect_signals]
108+
@Override
109+
public void collectSignals(RtbSignalData rtbSignalData, SignalCallbacks signalCallbacks) {
110+
111+
// Add your signal collection logic here.
112+
String signals = SAMPLE_SIGNAL_PLACEHOLDER;
113+
114+
// Return the signals as a string to the Google Mobile Ads SDK.
115+
signalCallbacks.onSuccess(signals);
116+
}
117+
118+
// [END collect_signals]
119+
120+
}

0 commit comments

Comments
 (0)