Skip to content

Commit 45e2f28

Browse files
authored
Merge pull request #774 from prebid/feature/hwv_field
Introduce `hwv` parameter
2 parents 3ce1f6c + b33c6ef commit 45e2f28

File tree

1 file changed

+69
-4
lines changed
  • PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests

1 file changed

+69
-4
lines changed

PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Device.java

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616

1717
package org.prebid.mobile.rendering.models.openrtb.bidRequests;
1818

19+
import android.os.Build;
20+
21+
import androidx.annotation.Nullable;
22+
1923
import org.json.JSONException;
2024
import org.json.JSONObject;
25+
import org.prebid.mobile.LogUtil;
2126
import org.prebid.mobile.rendering.models.openrtb.bidRequests.devices.Geo;
2227

2328
public class Device extends BaseBid {
2429

30+
@Nullable
31+
private static String deviceName = null;
32+
2533
// User Agent
2634
public String ua = null;
2735

@@ -37,10 +45,7 @@ public class Device extends BaseBid {
3745
public String model = null;
3846
public String os = null;
3947
public String osv = null;
40-
41-
//TODO: ORTB2.5: detect this? How?
42-
//Hardware version of the device (e.g., “5S” for iPhone 5S).
43-
public String hwv = null;
48+
public String hwv = getDeviceName();
4449

4550
public String flashver = null;
4651
public String language = null;
@@ -128,6 +133,66 @@ public Ext getExt() {
128133
return ext;
129134
}
130135

136+
@Nullable
137+
private static String getDeviceName() {
138+
if (deviceName == null) {
139+
deviceName = parseDeviceName();
140+
if (deviceName.isBlank()) return null;
141+
return deviceName;
142+
}
143+
144+
if (deviceName.isBlank()) {
145+
return null;
146+
}
147+
148+
return deviceName;
149+
}
150+
151+
private static String parseDeviceName() {
152+
try {
153+
String manufacturer = Build.MANUFACTURER;
154+
String model = Build.MODEL;
155+
156+
if (manufacturer.equals(Build.UNKNOWN)) {
157+
manufacturer = "";
158+
}
159+
if (model.equals(Build.UNKNOWN)) {
160+
model = "";
161+
}
162+
163+
String result;
164+
if (manufacturer.isBlank() && model.isBlank()) {
165+
result = "";
166+
} else if (model.isBlank()) {
167+
result = manufacturer;
168+
} else if (manufacturer.isBlank()) {
169+
result = model;
170+
} else {
171+
if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
172+
result = model;
173+
} else {
174+
result = manufacturer + " " + model;
175+
}
176+
}
177+
return capitalizeFirstLetter(result);
178+
} catch (Throwable any) {
179+
LogUtil.error("Can't get device name: " + any.getMessage());
180+
}
181+
return "";
182+
}
183+
184+
private static String capitalizeFirstLetter(String s) {
185+
if (s == null || s.isEmpty()) {
186+
return "";
187+
}
188+
char first = s.charAt(0);
189+
if (Character.isUpperCase(first)) {
190+
return s;
191+
} else {
192+
return Character.toUpperCase(first) + s.substring(1);
193+
}
194+
}
195+
131196
public enum DeviceType {
132197
MobileOrTablet(1),
133198
SMARTPHONE(4),

0 commit comments

Comments
 (0)