16
16
17
17
package org .prebid .mobile .rendering .models .openrtb .bidRequests ;
18
18
19
+ import android .os .Build ;
20
+
21
+ import androidx .annotation .Nullable ;
22
+
19
23
import org .json .JSONException ;
20
24
import org .json .JSONObject ;
25
+ import org .prebid .mobile .LogUtil ;
21
26
import org .prebid .mobile .rendering .models .openrtb .bidRequests .devices .Geo ;
22
27
23
28
public class Device extends BaseBid {
24
29
30
+ @ Nullable
31
+ private static String deviceName = null ;
32
+
25
33
// User Agent
26
34
public String ua = null ;
27
35
@@ -37,10 +45,7 @@ public class Device extends BaseBid {
37
45
public String model = null ;
38
46
public String os = null ;
39
47
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 ();
44
49
45
50
public String flashver = null ;
46
51
public String language = null ;
@@ -128,6 +133,66 @@ public Ext getExt() {
128
133
return ext ;
129
134
}
130
135
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
+
131
196
public enum DeviceType {
132
197
MobileOrTablet (1 ),
133
198
SMARTPHONE (4 ),
0 commit comments