Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce hwv parameter #774

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@

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

import android.os.Build;

import androidx.annotation.Nullable;

import org.json.JSONException;
import org.json.JSONObject;
import org.prebid.mobile.LogUtil;
import org.prebid.mobile.rendering.models.openrtb.bidRequests.devices.Geo;

public class Device extends BaseBid {

@Nullable
private static String deviceName = null;

// User Agent
public String ua = null;

Expand All @@ -37,10 +45,7 @@ public class Device extends BaseBid {
public String model = null;
public String os = null;
public String osv = null;

//TODO: ORTB2.5: detect this? How?
//Hardware version of the device (e.g., “5S” for iPhone 5S).
public String hwv = null;
public String hwv = getDeviceName();

public String flashver = null;
public String language = null;
Expand Down Expand Up @@ -128,6 +133,66 @@ public Ext getExt() {
return ext;
}

@Nullable
private static String getDeviceName() {
if (deviceName == null) {
deviceName = parseDeviceName();
if (deviceName.isBlank()) return null;
return deviceName;
}

if (deviceName.isBlank()) {
return null;
}

return deviceName;
}

private static String parseDeviceName() {
try {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;

if (manufacturer.equals(Build.UNKNOWN)) {
manufacturer = "";
}
if (model.equals(Build.UNKNOWN)) {
model = "";
}

String result;
if (manufacturer.isBlank() && model.isBlank()) {
result = "";
} else if (model.isBlank()) {
result = manufacturer;
} else if (manufacturer.isBlank()) {
result = model;
} else {
if (model.toLowerCase().startsWith(manufacturer.toLowerCase())) {
result = model;
} else {
result = manufacturer + " " + model;
}
}
return capitalizeFirstLetter(result);
} catch (Throwable any) {
LogUtil.error("Can't get device name: " + any.getMessage());
}
return "";
}

private static String capitalizeFirstLetter(String s) {
if (s == null || s.isEmpty()) {
return "";
}
char first = s.charAt(0);
if (Character.isUpperCase(first)) {
return s;
} else {
return Character.toUpperCase(first) + s.substring(1);
}
}

public enum DeviceType {
MobileOrTablet(1),
SMARTPHONE(4),
Expand Down