1 package com.simpligility.maven.plugins.android.common;
2
3 import com.android.ddmlib.IDevice;
4 import org.apache.commons.lang3.StringUtils;
5
6
7
8
9
10
11 public class DeviceHelper
12 {
13
14 private static final String MANUFACTURER_PROPERTY = "ro.product.manufacturer";
15 private static final String MODEL_PROPERTY = "ro.product.model";
16 private static final String SEPARATOR = "_";
17
18
19
20
21
22
23
24 public static String getDescriptiveName( IDevice device )
25 {
26
27
28 StringBuilder identfier = new StringBuilder().append( device.getSerialNumber() );
29 if ( device.getAvdName() != null )
30 {
31 identfier.append( SEPARATOR ).append( device.getAvdName() );
32 }
33 String manufacturer = getManufacturer( device );
34 if ( StringUtils.isNotBlank( manufacturer ) )
35 {
36 identfier.append( SEPARATOR ).append( manufacturer );
37 }
38 String model = getModel( device );
39 if ( StringUtils.isNotBlank( model ) )
40 {
41 identfier.append( SEPARATOR ).append( model );
42 }
43
44 return FileNameHelper.fixFileName( identfier.toString() );
45 }
46
47 public static String getDeviceLogLinePrefix( IDevice device )
48 {
49 return getDescriptiveName( device ) + " : ";
50 }
51
52
53
54
55 public static String getManufacturer( IDevice device )
56 {
57 return StringUtils.deleteWhitespace( device.getProperty( MANUFACTURER_PROPERTY ) );
58 }
59
60
61
62
63 public static String getModel( IDevice device )
64 {
65 return StringUtils.deleteWhitespace( device.getProperty( MODEL_PROPERTY ) );
66 }
67
68
69
70
71 public static String getDescriptiveNameWithStatus( IDevice device )
72 {
73 String status;
74 if ( device.isOnline() )
75 {
76 status = "Online";
77 }
78 else
79 {
80 if ( device.isOffline() )
81 {
82 status = "Offline";
83 }
84 else
85 {
86 status = "Unknown";
87 }
88 }
89 return getDescriptiveName( device ) + " " + status;
90 }
91 }