35
35
import org .jetbrains .annotations .TestOnly ;
36
36
37
37
@ ApiStatus .Internal
38
- public class DeviceInfoUtil {
38
+ public final class DeviceInfoUtil {
39
39
40
40
@ SuppressLint ("StaticFieldLeak" )
41
41
private static volatile DeviceInfoUtil instance ;
@@ -61,7 +61,8 @@ public DeviceInfoUtil(
61
61
ContextUtils .retrieveSideLoadedInfo (context , options .getLogger (), buildInfoProvider );
62
62
}
63
63
64
- public static @ NotNull DeviceInfoUtil getInstance (
64
+ @ NotNull
65
+ public static DeviceInfoUtil getInstance (
65
66
final @ NotNull Context context , final @ NotNull SentryAndroidOptions options ) {
66
67
if (instance == null ) {
67
68
synchronized (DeviceInfoUtil .class ) {
@@ -139,7 +140,8 @@ public Device collectDeviceInformation(
139
140
return device ;
140
141
}
141
142
142
- public final @ NotNull OperatingSystem getOperatingSystem () {
143
+ @ NotNull
144
+ public OperatingSystem getOperatingSystem () {
143
145
return os ;
144
146
}
145
147
@@ -164,7 +166,8 @@ protected OperatingSystem retrieveOperatingSystemInformation() {
164
166
return os ;
165
167
}
166
168
167
- public @ Nullable ContextUtils .SideLoadedInfo getSideLoadedInfo () {
169
+ @ Nullable
170
+ public ContextUtils .SideLoadedInfo getSideLoadedInfo () {
168
171
return sideLoadedInfo ;
169
172
}
170
173
@@ -226,6 +229,7 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
226
229
}
227
230
228
231
@ SuppressWarnings ("NewApi" )
232
+ @ NotNull
229
233
private TimeZone getTimeZone () {
230
234
if (buildInfoProvider .getSdkInfoVersion () >= Build .VERSION_CODES .N ) {
231
235
LocaleList locales = context .getResources ().getConfiguration ().getLocales ();
@@ -238,7 +242,8 @@ private TimeZone getTimeZone() {
238
242
}
239
243
240
244
@ SuppressWarnings ("JdkObsolete" )
241
- private @ Nullable Date getBootTime () {
245
+ @ Nullable
246
+ private Date getBootTime () {
242
247
try {
243
248
// if user changes the clock, will give a wrong answer, consider ACTION_TIME_CHANGED.
244
249
// currentTimeMillis returns UTC already
@@ -249,7 +254,8 @@ private TimeZone getTimeZone() {
249
254
return null ;
250
255
}
251
256
252
- private @ Nullable Intent getBatteryIntent () {
257
+ @ Nullable
258
+ private Intent getBatteryIntent () {
253
259
return context .registerReceiver (null , new IntentFilter (Intent .ACTION_BATTERY_CHANGED ));
254
260
}
255
261
@@ -258,7 +264,8 @@ private TimeZone getTimeZone() {
258
264
*
259
265
* @return the device's current battery level (as a percentage of total), or null if unknown
260
266
*/
261
- private @ Nullable Float getBatteryLevel (final @ NotNull Intent batteryIntent ) {
267
+ @ Nullable
268
+ private Float getBatteryLevel (final @ NotNull Intent batteryIntent ) {
262
269
try {
263
270
int level = batteryIntent .getIntExtra (BatteryManager .EXTRA_LEVEL , -1 );
264
271
int scale = batteryIntent .getIntExtra (BatteryManager .EXTRA_SCALE , -1 );
@@ -281,7 +288,8 @@ private TimeZone getTimeZone() {
281
288
*
282
289
* @return whether or not the device is currently plugged in and charging, or null if unknown
283
290
*/
284
- private @ Nullable Boolean isCharging (final @ NotNull Intent batteryIntent ) {
291
+ @ Nullable
292
+ private Boolean isCharging (final @ NotNull Intent batteryIntent ) {
285
293
try {
286
294
int plugged = batteryIntent .getIntExtra (BatteryManager .EXTRA_PLUGGED , -1 );
287
295
return plugged == BatteryManager .BATTERY_PLUGGED_AC
@@ -292,7 +300,8 @@ private TimeZone getTimeZone() {
292
300
}
293
301
}
294
302
295
- private @ Nullable Float getBatteryTemperature (final @ NotNull Intent batteryIntent ) {
303
+ @ Nullable
304
+ private Float getBatteryTemperature (final @ NotNull Intent batteryIntent ) {
296
305
try {
297
306
int temperature = batteryIntent .getIntExtra (EXTRA_TEMPERATURE , -1 );
298
307
if (temperature != -1 ) {
@@ -309,7 +318,8 @@ private TimeZone getTimeZone() {
309
318
*
310
319
* @return the device's current screen orientation, or null if unknown
311
320
*/
312
- private @ Nullable Device .DeviceOrientation getOrientation () {
321
+ @ Nullable
322
+ private Device .DeviceOrientation getOrientation () {
313
323
Device .DeviceOrientation deviceOrientation = null ;
314
324
try {
315
325
deviceOrientation =
@@ -329,7 +339,8 @@ private TimeZone getTimeZone() {
329
339
}
330
340
331
341
@ SuppressWarnings ({"ObsoleteSdkInt" , "NewApi" })
332
- private @ NotNull Long getMemorySize (final @ NotNull ActivityManager .MemoryInfo memInfo ) {
342
+ @ NotNull
343
+ private Long getMemorySize (final @ NotNull ActivityManager .MemoryInfo memInfo ) {
333
344
if (buildInfoProvider .getSdkInfoVersion () >= Build .VERSION_CODES .JELLY_BEAN ) {
334
345
return memInfo .totalMem ;
335
346
}
@@ -342,7 +353,8 @@ private TimeZone getTimeZone() {
342
353
*
343
354
* @return the total amount of internal storage, in bytes
344
355
*/
345
- private @ Nullable Long getTotalInternalStorage (final @ NotNull StatFs stat ) {
356
+ @ Nullable
357
+ private Long getTotalInternalStorage (final @ NotNull StatFs stat ) {
346
358
try {
347
359
long blockSize = getBlockSizeLong (stat );
348
360
long totalBlocks = getBlockCountLong (stat );
@@ -397,7 +409,8 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
397
409
*
398
410
* @return the unused amount of internal storage, in bytes
399
411
*/
400
- private @ Nullable Long getUnusedInternalStorage (final @ NotNull StatFs stat ) {
412
+ @ Nullable
413
+ private Long getUnusedInternalStorage (final @ NotNull StatFs stat ) {
401
414
try {
402
415
long blockSize = getBlockSizeLong (stat );
403
416
long availableBlocks = getAvailableBlocksLong (stat );
@@ -410,7 +423,8 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
410
423
}
411
424
}
412
425
413
- private @ Nullable StatFs getExternalStorageStat (final @ Nullable File internalStorage ) {
426
+ @ Nullable
427
+ private StatFs getExternalStorageStat (final @ Nullable File internalStorage ) {
414
428
if (!isExternalStorageMounted ()) {
415
429
File path = getExternalStorageDep (internalStorage );
416
430
if (path != null ) { // && path.canRead()) { canRead() will read return false
@@ -424,7 +438,8 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
424
438
}
425
439
426
440
@ SuppressWarnings ({"ObsoleteSdkInt" , "NewApi" })
427
- private @ Nullable File [] getExternalFilesDirs () {
441
+ @ Nullable
442
+ private File [] getExternalFilesDirs () {
428
443
if (buildInfoProvider .getSdkInfoVersion () >= Build .VERSION_CODES .KITKAT ) {
429
444
return context .getExternalFilesDirs (null );
430
445
} else {
@@ -436,7 +451,8 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
436
451
return null ;
437
452
}
438
453
439
- private @ Nullable File getExternalStorageDep (final @ Nullable File internalStorage ) {
454
+ @ Nullable
455
+ private File getExternalStorageDep (final @ Nullable File internalStorage ) {
440
456
final @ Nullable File [] externalFilesDirs = getExternalFilesDirs ();
441
457
442
458
if (externalFilesDirs != null ) {
@@ -471,7 +487,8 @@ private int getAvailableBlocksDep(final @NotNull StatFs stat) {
471
487
* @return the total amount of external storage, in bytes, or null if no external storage is
472
488
* mounted
473
489
*/
474
- private @ Nullable Long getTotalExternalStorage (final @ NotNull StatFs stat ) {
490
+ @ Nullable
491
+ private Long getTotalExternalStorage (final @ NotNull StatFs stat ) {
475
492
try {
476
493
final long blockSize = getBlockSizeLong (stat );
477
494
final long totalBlocks = getBlockCountLong (stat );
@@ -495,7 +512,8 @@ private boolean isExternalStorageMounted() {
495
512
* @return the unused amount of external storage, in bytes, or null if no external storage is
496
513
* mounted
497
514
*/
498
- private @ Nullable Long getUnusedExternalStorage (final @ NotNull StatFs stat ) {
515
+ @ Nullable
516
+ private Long getUnusedExternalStorage (final @ NotNull StatFs stat ) {
499
517
try {
500
518
final long blockSize = getBlockSizeLong (stat );
501
519
final long availableBlocks = getAvailableBlocksLong (stat );
@@ -508,7 +526,8 @@ private boolean isExternalStorageMounted() {
508
526
}
509
527
}
510
528
511
- private @ Nullable String getDeviceId () {
529
+ @ Nullable
530
+ private String getDeviceId () {
512
531
try {
513
532
return Installation .id (context );
514
533
} catch (Throwable e ) {
0 commit comments