7
7
import com .github .xsavikx .androidscreencast .api .injector .OutputStreamShellOutputReceiver ;
8
8
import com .github .xsavikx .androidscreencast .exception .AndroidScreenCastRuntimeException ;
9
9
import com .github .xsavikx .androidscreencast .exception .ExecuteCommandException ;
10
- import org .apache .log4j .Logger ;
11
- import org .springframework .beans .factory .annotation .Autowired ;
12
- import org .springframework .stereotype .Component ;
10
+ import org .slf4j .Logger ;
11
+ import org .slf4j .LoggerFactory ;
13
12
13
+ import javax .inject .Inject ;
14
+ import javax .inject .Singleton ;
14
15
import java .io .ByteArrayOutputStream ;
15
16
import java .io .File ;
16
17
import java .lang .reflect .Method ;
17
18
import java .util .ArrayList ;
18
19
import java .util .List ;
19
20
20
- @ Component
21
+ @ Singleton
21
22
public class AndroidDeviceImpl implements AndroidDevice {
22
- private static final Logger logger = Logger .getLogger (AndroidDeviceImpl .class );
23
+ private static final Logger LOGGER = LoggerFactory .getLogger (AndroidDeviceImpl .class );
23
24
private final IDevice device ;
24
25
25
- @ Autowired
26
- public AndroidDeviceImpl (IDevice device ) {
26
+ @ Inject
27
+ public AndroidDeviceImpl (final IDevice device ) {
27
28
this .device = device ;
28
29
}
29
30
30
31
@ Override
31
- public String executeCommand (String cmd ) {
32
- if (logger .isDebugEnabled ()) {
33
- logger .debug ("executeCommand(String) - start" );
32
+ public String executeCommand (final String cmd ) {
33
+ if (LOGGER .isDebugEnabled ()) {
34
+ LOGGER .debug ("executeCommand(String) - start" );
34
35
}
35
- try (ByteArrayOutputStream bos = new ByteArrayOutputStream ();) {
36
+ try (final ByteArrayOutputStream bos = new ByteArrayOutputStream ();) {
36
37
device .executeShellCommand (cmd , new OutputStreamShellOutputReceiver (bos ));
37
- String returnString = new String (bos .toByteArray (), "UTF-8" );
38
- if (logger .isDebugEnabled ()) {
39
- logger .debug ("executeCommand(String) - end" );
38
+ final String returnString = new String (bos .toByteArray (), "UTF-8" );
39
+ if (LOGGER .isDebugEnabled ()) {
40
+ LOGGER .debug ("executeCommand(String) - end" );
40
41
}
41
42
return returnString ;
42
- } catch (Exception ex ) {
43
- logger .error ("executeCommand(String)" , ex );
43
+ } catch (final Exception ex ) {
44
+ LOGGER .error ("executeCommand(String)" , ex );
44
45
throw new ExecuteCommandException (cmd );
45
46
}
46
47
}
47
48
48
49
@ Override
49
- public List <FileInfo > list (String path ) {
50
- if (logger .isDebugEnabled ()) {
51
- logger .debug ("list(String) - start" );
50
+ public List <FileInfo > list (final String path ) {
51
+ if (LOGGER .isDebugEnabled ()) {
52
+ LOGGER .debug ("list(String) - start" );
52
53
}
53
54
54
55
try {
55
- String s = executeCommand ("ls -l " + path );
56
- String [] entries = s .split ("\r \n " );
57
- List <FileInfo > fileInfos = new ArrayList <>();
58
- for (String entry : entries ) {
56
+ final String s = executeCommand ("ls -l " + path );
57
+ final String [] entries = s .split ("\r \n " );
58
+ final List <FileInfo > fileInfos = new ArrayList <>();
59
+ for (final String entry : entries ) {
59
60
String [] data = entry .split (" " );
60
61
if (data .length < 4 )
61
62
continue ;
62
63
String attributes = data [0 ];
63
64
boolean directory = attributes .charAt (0 ) == 'd' ;
64
65
String name = data [data .length - 1 ];
65
66
66
- FileInfo fi = new FileInfo ();
67
+ final FileInfo fi = new FileInfo ();
67
68
fi .attribs = attributes ;
68
69
fi .directory = directory ;
69
70
fi .name = name ;
@@ -73,59 +74,59 @@ public List<FileInfo> list(String path) {
73
74
fileInfos .add (fi );
74
75
}
75
76
76
- if (logger .isDebugEnabled ()) {
77
- logger .debug ("list(String) - end" );
77
+ if (LOGGER .isDebugEnabled ()) {
78
+ LOGGER .debug ("list(String) - end" );
78
79
}
79
80
return fileInfos ;
80
- } catch (Exception ex ) {
81
- logger .error ("list(String)" , ex );
81
+ } catch (final Exception ex ) {
82
+ LOGGER .error ("list(String)" , ex );
82
83
throw new AndroidScreenCastRuntimeException (ex );
83
84
}
84
85
}
85
86
86
87
@ Override
87
- public void openUrl (String url ) {
88
- if (logger .isDebugEnabled ()) {
89
- logger .debug ("openUrl(String) - start" );
88
+ public void openUrl (final String url ) {
89
+ if (LOGGER .isDebugEnabled ()) {
90
+ LOGGER .debug ("openUrl(String) - start" );
90
91
}
91
92
92
93
executeCommand ("am start " + url );
93
94
94
- if (logger .isDebugEnabled ()) {
95
- logger .debug ("openUrl(String) - end" );
95
+ if (LOGGER .isDebugEnabled ()) {
96
+ LOGGER .debug ("openUrl(String) - end" );
96
97
}
97
98
}
98
99
99
100
@ Override
100
- public void pullFile (String removeFrom , File localTo ) {
101
- if (logger .isDebugEnabled ()) {
102
- logger .debug ("pullFile(String, File) - start" );
101
+ public void pullFile (final String removeFrom , final File localTo ) {
102
+ if (LOGGER .isDebugEnabled ()) {
103
+ LOGGER .debug ("pullFile(String, File) - start" );
103
104
}
104
105
105
106
// ugly hack to call the method without FileEntry
106
107
try {
107
108
if (device .getSyncService () == null )
108
- throw new RuntimeException ("SyncService is null, ADB crashed ?" );
109
- Method m = device .getSyncService ().getClass ().getDeclaredMethod ("doPullFile" , String .class , String .class ,
109
+ throw new AndroidScreenCastRuntimeException ("SyncService is null, ADB crashed ?" );
110
+ final Method m = device .getSyncService ().getClass ().getDeclaredMethod ("doPullFile" , String .class , String .class ,
110
111
ISyncProgressMonitor .class );
111
112
m .setAccessible (true );
112
113
device .getSyncService ();
113
114
m .invoke (device .getSyncService (), removeFrom , localTo .getAbsolutePath (), SyncService .getNullProgressMonitor ());
114
- } catch (Exception ex ) {
115
- logger .error ("pullFile(String, File)" , ex );
115
+ } catch (final Exception ex ) {
116
+ LOGGER .error ("pullFile(String, File)" , ex );
116
117
117
118
throw new AndroidScreenCastRuntimeException (ex );
118
119
}
119
120
120
- if (logger .isDebugEnabled ()) {
121
- logger .debug ("pullFile(String, File) - end" );
121
+ if (LOGGER .isDebugEnabled ()) {
122
+ LOGGER .debug ("pullFile(String, File) - end" );
122
123
}
123
124
}
124
125
125
126
@ Override
126
- public void pushFile (File localFrom , String remoteTo ) {
127
- if (logger .isDebugEnabled ()) {
128
- logger .debug ("pushFile(File, String) - start" );
127
+ public void pushFile (final File localFrom , final String remoteTo ) {
128
+ if (LOGGER .isDebugEnabled ()) {
129
+ LOGGER .debug ("pushFile(File, String) - start" );
129
130
}
130
131
131
132
try {
@@ -134,14 +135,14 @@ public void pushFile(File localFrom, String remoteTo) {
134
135
135
136
device .getSyncService ().pushFile (localFrom .getAbsolutePath (), remoteTo , SyncService .getNullProgressMonitor ());
136
137
137
- } catch (Exception ex ) {
138
- logger .error ("pushFile(File, String)" , ex );
138
+ } catch (final Exception ex ) {
139
+ LOGGER .error ("pushFile(File, String)" , ex );
139
140
140
141
throw new AndroidScreenCastRuntimeException (ex );
141
142
}
142
143
143
- if (logger .isDebugEnabled ()) {
144
- logger .debug ("pushFile(File, String) - end" );
144
+ if (LOGGER .isDebugEnabled ()) {
145
+ LOGGER .debug ("pushFile(File, String) - end" );
145
146
}
146
147
}
147
148
0 commit comments