├── .gitignore
├── .travis.yml
├── AndroidWiFiADB.iml
├── LICENSE.txt
├── README.md
├── art
├── AWADBIcon.xcf
├── AndroidWiFiADBIcon.png
├── android_devices_window.png
├── sampleButton.png
└── screenshot1.gif
├── build.gradle
├── config
└── checkstyle
│ └── checkstyle.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settigs.gradle
└── src
├── main
├── java
│ └── com
│ │ └── github
│ │ └── pedrovgs
│ │ └── androidwifiadb
│ │ ├── AndroidWiFiADB.java
│ │ ├── Device.java
│ │ ├── action
│ │ └── AndroidWiFiADBAction.java
│ │ ├── adb
│ │ ├── ADB.java
│ │ ├── ADBParser.java
│ │ └── CommandLine.java
│ │ ├── util
│ │ └── NotificationUtils.java
│ │ ├── view
│ │ ├── NotificationView.java
│ │ └── View.java
│ │ └── window
│ │ ├── ActionButtonListener.java
│ │ ├── AndroidDevicesTableModel.java
│ │ ├── AndroidWiFiADBWindow.form
│ │ ├── AndroidWiFiADBWindow.java
│ │ ├── CardLayoutDevices.java
│ │ ├── ConnectDisconnectEditor.java
│ │ ├── ConnectDisconnectPanel.java
│ │ ├── ConnectDisconnectRenderer.java
│ │ └── DeviceAction.java
└── resources
│ ├── META-INF
│ └── plugin.xml
│ └── icons
│ ├── androidWiFiADBIcon.png
│ └── androidWiFiADBIcon@2x.png
└── test
└── java
└── com
└── github
└── pedrovgs
└── androidwifiadb
├── AndroidWiFiADBTest.java
├── UnitTest.java
├── adb
└── ADBParserTest.java
└── window
└── AndroidDevicesTableModelTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # IntelliJ
2 | out/
3 | .idea/
4 | target/
5 | *.iml
6 | local.properties
7 |
8 | ### Java ###
9 | *.class
10 | classes/
11 |
12 | # Package Files #
13 | *.jar
14 |
15 | ### Gradle ###
16 | .gradle
17 | build/
18 |
19 | ### Specific ###
20 | *.zip
21 |
22 | # Ignore Gradle GUI config
23 | gradle-app.setting
24 |
25 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
26 | !gradle-wrapper.jar
27 |
28 | # Avoid ignoring AndroidWiFiADB.iml file to be able to import the project into any IntelliJ IDE and run/debug the pulgin without problems
29 | !AndroidWiFiADB.iml
30 |
31 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk: oraclejdk7
3 | env:
4 | matrix:
5 | - TERM=dumb
6 | after_success:
7 | - ./gradlew test jacocoTestReport coveralls
8 |
9 | script:
10 | ./gradlew checkstyle build
11 |
--------------------------------------------------------------------------------
/AndroidWiFiADB.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android WiFi ADB - IntelliJ/Android Studio Plugin [](http://android-arsenal.com/details/1/2654)
2 | =================================================
3 | ![Android WiFi ADB][1]
4 |
5 | **IntelliJ and Android Studio plugin** created to **quickly connect your Android device over WiFi** to install, run and debug your applications without a USB connected. Press one button and forget about your USB cable.
6 |
7 | **Android WiFI ADB plugin adds a button ![Android WiFi ADB Button][5] to your IntelliJ/Android Studio Toolbar** to connect your device to your computer over WiFi.
8 |
9 | *To use this plugin the project opened in your IntelliJ/Android Studio has to be an Android project configured with the Android SDK.*
10 |
11 | **Archived repository:** Maintaining this project up to date for all the different Android devices without having access to the physical devices is not possible at all right now. Most of the bugs reported ar related to the adb installation and not to the plugin code so this repository will keep archived for now.
12 |
13 | Screenshots
14 | -----------
15 | Connect all devices button:
16 |
17 | ![Android WiFi ADB Usage][2]
18 |
19 | Devices dashboard:
20 |
21 | ![Android Devices Window][7]
22 |
23 | Usage
24 | -----
25 |
26 | Connect your device to your computer using a USB cable. Then press the button, and a notification will pop up saying that the phone has been connected. Disconnect your USB once the plugin shows your device is connected. Open the Android WiFi ADB tab at the right side to see all the devices and manage your connections. Your device will be connected over WiFi now. You can now deploy, run and debug your device using your WiFi connection. Remember that your device and your computer have to be in the same WiFi connection. Also, you have to first connect your device with a USB every time you open Android Studio, for setting up the connection over WiFi.
27 |
28 | If you want to handle your devices connection individually, open the Android WiFi ADB dashboard you will find at the right of your IDE.
29 |
30 | Installation
31 | ------------
32 |
33 | Download and install **Android WiFi ADB** directly from Intellij / Android Studio:
34 | `Preferences/Settings->Plugins->Browse Repositories`
35 |
36 | Alternatively, you can [download the plugin][6] from the JetBrains plugin site and install it manually in:
37 | `Preferences/Settings->Plugins->Install plugin from disk`.
38 |
39 | Build the project
40 | -----------------
41 |
42 | If you need some information about how to build this project review [IntelliJ Idea's Gradle Plugin documentation](https://github.com/JetBrains/gradle-intellij-plugin).
43 |
44 | Do you want to contribute?
45 | --------------------------
46 |
47 | Please, do it! If you have any improvement or you've found any bug, send a pull request with the code or open an issue :)
48 |
49 | Libraries used on the sample project
50 | ------------------------------------
51 |
52 | * [JUnit][3]
53 | * [Mockito][4]
54 |
55 | Developed By
56 | ------------
57 |
58 | * Pedro Vicente Gómez Sánchez -
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | License
68 | -------
69 |
70 | Copyright 2015 Pedro Vicente Gómez Sánchez
71 |
72 | Licensed under the Apache License, Version 2.0 (the "License");
73 | you may not use this file except in compliance with the License.
74 | You may obtain a copy of the License at
75 |
76 | http://www.apache.org/licenses/LICENSE-2.0
77 |
78 | Unless required by applicable law or agreed to in writing, software
79 | distributed under the License is distributed on an "AS IS" BASIS,
80 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81 | See the License for the specific language governing permissions and
82 | limitations under the License.
83 |
84 | [1]: ./art/AndroidWiFiADBIcon.png
85 | [2]: ./art/screenshot1.gif
86 | [3]: https://github.com/junit-team/junit
87 | [4]: https://github.com/mockito/mockito
88 | [5]: ./art/sampleButton.png
89 | [6]: https://plugins.jetbrains.com/plugin/7983
90 | [7]: ./art/android_devices_window.png
91 |
--------------------------------------------------------------------------------
/art/AWADBIcon.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/art/AWADBIcon.xcf
--------------------------------------------------------------------------------
/art/AndroidWiFiADBIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/art/AndroidWiFiADBIcon.png
--------------------------------------------------------------------------------
/art/android_devices_window.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/art/android_devices_window.png
--------------------------------------------------------------------------------
/art/sampleButton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/art/sampleButton.png
--------------------------------------------------------------------------------
/art/screenshot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/art/screenshot1.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | }
6 |
7 | plugins {
8 | id "org.jetbrains.intellij" version "0.0.25"
9 | }
10 |
11 | apply plugin: 'org.jetbrains.intellij'
12 | apply plugin: 'java'
13 | apply plugin: 'checkstyle'
14 | apply plugin: 'jacoco'
15 |
16 | group 'com.github.pedrovgs'
17 | version '2.5-SNAPSHOT'
18 |
19 | sourceCompatibility = 1.6
20 |
21 | repositories {
22 | mavenCentral()
23 | }
24 |
25 | intellij {
26 | version '14.1.5'
27 | pluginName 'AndroidWiFiADB'
28 | plugins 'android'
29 | updateSinceUntilBuild false
30 | }
31 |
32 | dependencies {
33 | compile 'junit:junit:4.12'
34 | compile 'org.mockito:mockito-all:1.10.19'
35 | }
36 |
37 | task checkstyle(type: Checkstyle) {
38 | configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
39 | source 'src'
40 | include '**/*.java'
41 | exclude '**/gen/**'
42 |
43 | classpath = files()
44 | }
--------------------------------------------------------------------------------
/config/checkstyle/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/gradle.properties
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 15 00:42:48 CET 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >&-
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >&-
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settigs.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'AndroidWiFiADB'
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/AndroidWiFiADB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb;
18 |
19 | import com.github.pedrovgs.androidwifiadb.adb.ADB;
20 | import com.github.pedrovgs.androidwifiadb.view.View;
21 | import com.intellij.openapi.project.Project;
22 | import java.util.ArrayList;
23 | import java.util.Collection;
24 | import java.util.HashSet;
25 | import java.util.LinkedList;
26 | import java.util.List;
27 | import java.util.Set;
28 |
29 | public class AndroidWiFiADB {
30 |
31 | private static final Set DEVICES = new HashSet();
32 | private final ADB adb;
33 | private final View view;
34 |
35 | public AndroidWiFiADB(ADB adb, View view) {
36 | this.adb = adb;
37 | this.view = view;
38 | }
39 |
40 | public void connectDevices() {
41 | if (!isADBInstalled()) {
42 | view.showADBNotInstalledNotification();
43 | return;
44 | }
45 | DEVICES.clear();
46 | DEVICES.addAll(adb.getDevicesConnectedByUSB());
47 | if (DEVICES.isEmpty()) {
48 | view.showNoConnectedDevicesNotification();
49 | return;
50 | }
51 |
52 | DEVICES.addAll(adb.connectDevices(DEVICES));
53 | showConnectionResultNotification(DEVICES);
54 | }
55 |
56 | public boolean refreshDevicesList() {
57 | if (!isADBInstalled()) {
58 | return false;
59 | }
60 | removeNotConnectedDevices();
61 | final Collection connected = adb.getDevicesConnectedByUSB();
62 | for (Device connectedDevice : connected) {
63 | if (!checkDeviceExistance(connectedDevice)) {
64 | connectedDevice.setIp(adb.getDeviceIp(connectedDevice));
65 | DEVICES.add(connectedDevice);
66 | } else {
67 | updateDeviceConnectionState(connectedDevice);
68 | }
69 | }
70 | return true;
71 | }
72 |
73 | private void removeNotConnectedDevices() {
74 | List connectedDevices = new LinkedList();
75 | for (Device device : DEVICES) {
76 | if (device.isConnected()) {
77 | connectedDevices.add(device);
78 | }
79 | }
80 | DEVICES.clear();
81 | DEVICES.addAll(connectedDevices);
82 | }
83 |
84 | public Collection getDevices() {
85 | return DEVICES;
86 | }
87 |
88 | public void connectDevice(Device device) {
89 | if (!isADBInstalled()) {
90 | view.showADBNotInstalledNotification();
91 | return;
92 | }
93 |
94 | Collection connectedDevices = new ArrayList();
95 | connectedDevices.add(device);
96 | connectedDevices = adb.connectDevices(connectedDevices);
97 | for (Device connected : connectedDevices) {
98 | updateDeviceConnectionState(connected);
99 | }
100 | showConnectionResultNotification(connectedDevices);
101 | }
102 |
103 | public void disconnectDevice(Device device) {
104 | if (!isADBInstalled()) {
105 | view.showADBNotInstalledNotification();
106 | return;
107 | }
108 |
109 | List disconnectedDevices = new ArrayList();
110 | disconnectedDevices.add(device);
111 | disconnectedDevices = adb.disconnectDevices(disconnectedDevices);
112 | for (Device disconnected : disconnectedDevices) {
113 | updateDeviceConnectionState(disconnected);
114 | }
115 | showDisconnectionResultNotification(disconnectedDevices);
116 | }
117 |
118 | public void updateProject(Project project) {
119 | adb.updateProject(project);
120 | }
121 |
122 | private void updateDeviceConnectionState(final Device updatedDevice) {
123 | DEVICES.add(updatedDevice);
124 | }
125 |
126 | private boolean checkDeviceExistance(Device connectedDevice) {
127 | boolean deviceExists = false;
128 | for (Device device : DEVICES) {
129 | if (connectedDevice.getId().equals(device.getId())) {
130 | deviceExists = true;
131 | }
132 | }
133 | return deviceExists;
134 | }
135 |
136 | private boolean isADBInstalled() {
137 | return adb.isInstalled();
138 | }
139 |
140 | private void showConnectionResultNotification(Collection devices) {
141 | for (Device device : devices) {
142 | if (device.isConnected()) {
143 | view.showConnectedDeviceNotification(device);
144 | } else {
145 | view.showErrorConnectingDeviceNotification(device);
146 | }
147 | }
148 | }
149 |
150 | private void showDisconnectionResultNotification(Collection devices) {
151 | for (Device device : devices) {
152 | if (!device.isConnected()) {
153 | view.showDisconnectedDeviceNotification(device);
154 | } else {
155 | view.showErrorDisconnectingDeviceNotification(device);
156 | }
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/Device.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb;
18 |
19 | public class Device {
20 |
21 | private final String id;
22 | private String name;
23 | private String ip = "";
24 | private boolean connected;
25 |
26 | public Device(String name, String id) {
27 | this.name = name;
28 | this.id = id;
29 | }
30 |
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | public void setName(String name) {
36 | this.name = name;
37 | }
38 |
39 | public String getId() {
40 | return id;
41 | }
42 |
43 | public String getIp() {
44 | return ip;
45 | }
46 |
47 | public void setIp(String ip) {
48 | this.ip = ip;
49 | }
50 |
51 | public boolean isConnected() {
52 | return connected;
53 | }
54 |
55 | public void setConnected(boolean connected) {
56 | this.connected = connected;
57 | }
58 |
59 | @Override public boolean equals(Object o) {
60 | if (this == o) {
61 | return true;
62 | }
63 | if (o == null || getClass() != o.getClass()) {
64 | return false;
65 | }
66 |
67 | Device device = (Device) o;
68 |
69 | return id.equals(device.id);
70 | }
71 |
72 | @Override public int hashCode() {
73 | return id.hashCode();
74 | }
75 |
76 | @Override public String toString() {
77 | return name;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/action/AndroidWiFiADBAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.action;
18 |
19 | import com.github.pedrovgs.androidwifiadb.AndroidWiFiADB;
20 | import com.github.pedrovgs.androidwifiadb.view.NotificationView;
21 | import com.github.pedrovgs.androidwifiadb.adb.ADB;
22 | import com.github.pedrovgs.androidwifiadb.adb.ADBParser;
23 | import com.github.pedrovgs.androidwifiadb.adb.CommandLine;
24 | import com.intellij.openapi.actionSystem.AnAction;
25 | import com.intellij.openapi.actionSystem.AnActionEvent;
26 | import com.intellij.openapi.application.ApplicationManager;
27 |
28 | public class AndroidWiFiADBAction extends AnAction {
29 |
30 | private final AndroidWiFiADB androidWifiADB;
31 |
32 | public AndroidWiFiADBAction() {
33 | CommandLine commandLine = new CommandLine();
34 | ADBParser adbParser = new ADBParser();
35 | ADB adb = new ADB(commandLine, adbParser);
36 | this.androidWifiADB = new AndroidWiFiADB(adb, new NotificationView());
37 | }
38 |
39 | public void actionPerformed(final AnActionEvent event) {
40 | ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
41 | public void run() {
42 | androidWifiADB.updateProject(event.getProject());
43 | androidWifiADB.connectDevices();
44 | }
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/adb/ADB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.adb;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 | import com.intellij.openapi.project.Project;
21 | import java.io.File;
22 | import java.util.Collection;
23 | import java.util.List;
24 | import org.jetbrains.android.sdk.AndroidSdkUtils;
25 |
26 | public class ADB {
27 |
28 | private static final String TCPIP_PORT = "5555";
29 | private final CommandLine commandLine;
30 | private final ADBParser adbParser;
31 | private Project project;
32 |
33 | public ADB(CommandLine commandLine, ADBParser adbParser) {
34 | this.commandLine = commandLine;
35 | this.adbParser = adbParser;
36 | }
37 |
38 | public void updateProject(Project project) {
39 | this.project = project;
40 | }
41 |
42 | public boolean isInstalled() {
43 | return AndroidSdkUtils.isAndroidSdkAvailable();
44 | }
45 |
46 | public Collection getDevicesConnectedByUSB() {
47 | String getDevicesCommand = getCommand("devices -l");
48 | String adbDevicesOutput = commandLine.executeCommand(getDevicesCommand);
49 | return adbParser.parseGetDevicesOutput(adbDevicesOutput);
50 | }
51 |
52 | public Collection connectDevices(Collection devices) {
53 | for (Device device : devices) {
54 | boolean connected = connectDeviceByIp(device);
55 | device.setConnected(connected);
56 | }
57 | return devices;
58 | }
59 |
60 | public List disconnectDevices(List devices) {
61 | for (Device device : devices) {
62 | boolean disconnected = disconnectDevice(device.getIp());
63 | device.setConnected(disconnected);
64 | }
65 | return devices;
66 | }
67 |
68 | private boolean connectDeviceByIp(Device device) {
69 | String deviceIp = getDeviceIp(device);
70 | if (deviceIp.isEmpty()) {
71 | return false;
72 | } else {
73 | return connectDevice(deviceIp);
74 | }
75 | }
76 |
77 | private boolean disconnectDevice(String deviceIp) {
78 | enableTCPCommand();
79 | String connectDeviceCommand = getCommand("disconnect " + deviceIp);
80 | return commandLine.executeCommand(connectDeviceCommand).isEmpty();
81 | }
82 |
83 | public String getDeviceIp(Device device) {
84 | String getDeviceIpCommand =
85 | getCommand("-s " + device.getId() + " shell ip -f inet addr show wlan0");
86 | String ipInfoOutput = commandLine.executeCommand(getDeviceIpCommand);
87 | return adbParser.parseGetDeviceIp(ipInfoOutput);
88 | }
89 |
90 | private void enableTCPCommand() {
91 | if (!checkTCPCommandExecuted()) {
92 | String enableTCPCommand = getCommand("tcpip " + TCPIP_PORT);
93 | commandLine.executeCommand(enableTCPCommand);
94 | }
95 | }
96 |
97 | private boolean checkTCPCommandExecuted() {
98 | String getPropCommand = getCommand("adb shell getprop | grep adb");
99 | String getPropOutput = commandLine.executeCommand(getPropCommand);
100 | String adbTcpPort = adbParser.parseAdbServiceTcpPort(getPropOutput);
101 | return TCPIP_PORT.equals(adbTcpPort);
102 | }
103 |
104 | private boolean connectDevice(String deviceIp) {
105 | String enableTCPCommand = getCommand("tcpip 5555");
106 | commandLine.executeCommand(enableTCPCommand);
107 | String connectDeviceCommand = getCommand("connect " + deviceIp);
108 | String connectOutput = commandLine.executeCommand(connectDeviceCommand);
109 | return connectOutput.contains("connected");
110 | }
111 |
112 | private String getAdbPath() {
113 | String adbPath = "";
114 | File adbFile = AndroidSdkUtils.getAdb(project);
115 | if (adbFile != null) {
116 | adbPath = adbFile.getAbsolutePath();
117 | }
118 | return adbPath;
119 | }
120 |
121 | private String getCommand(String command) {
122 | return getAdbPath() + " " + command;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/adb/ADBParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.adb;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 | import java.util.regex.Matcher;
23 | import java.util.regex.Pattern;
24 |
25 | public class ADBParser {
26 |
27 | private static final String MODEL_INDICATOR = "model:";
28 | private static final String DEVICE_INDICATOR = "device:";
29 | private static final String IP_SEPARATOR = ".";
30 | private static final String END_DEVICE_IP_INDICATOR = "/";
31 | private static final String START_DEVICE_IP_INDICATOR = "inet";
32 | private static final String ERROR_PARSING_DEVICE_IP_KEY = "Object";
33 | private static final String DAEMON_INDICATOR = "daemon";
34 | private static final String START_TCPIP_PORT_INDICATOR = "[service.adb.tcp.port]: [";
35 | private static final String DEVICE_NOT_FOUND = "error: device '(null)' not found";
36 |
37 | public List parseGetDevicesOutput(String adbDevicesOutput) {
38 | List devices = new LinkedList();
39 | if (adbDevicesOutput.contains(DAEMON_INDICATOR)) {
40 | return devices;
41 | }
42 | String[] splittedOutput = adbDevicesOutput.split("\\n");
43 | if (splittedOutput.length == 1) {
44 | return devices;
45 | }
46 | for (int i = 1; i < splittedOutput.length; i++) {
47 | String line = splittedOutput[i];
48 | String[] deviceLine = line.split("\\t");
49 | String id = deviceLine[0].substring(0, deviceLine[0].indexOf(" "));
50 | if (id.contains(IP_SEPARATOR)) {
51 | continue;
52 | }
53 | String name = parseDeviceName(line);
54 | Device device = new Device(name, id);
55 | devices.add(device);
56 | }
57 | return devices;
58 | }
59 |
60 | public String parseGetDeviceIp(String ipInfo) {
61 | if (ipInfo.isEmpty() || ipInfo.contains(ERROR_PARSING_DEVICE_IP_KEY)) {
62 | return "";
63 | }
64 | try {
65 | int start = ipInfo.indexOf(START_DEVICE_IP_INDICATOR) + 5;
66 | int end = ipInfo.indexOf(END_DEVICE_IP_INDICATOR);
67 | return ipInfo.substring(start, end);
68 | } catch (StringIndexOutOfBoundsException e) {
69 | System.out.println(e);
70 | return "";
71 | }
72 | }
73 |
74 | public String parseAdbServiceTcpPort(String getPropOutput) {
75 | if (getPropOutput.isEmpty() || getPropOutput.contains(DEVICE_NOT_FOUND)
76 | || !getPropOutput.contains(START_TCPIP_PORT_INDICATOR)) {
77 | return "";
78 | }
79 |
80 | Matcher portMatcher =
81 | Pattern.compile("(?<=\\[(service\\.adb\\.tcp\\.port).: \\[)([^\\]]+)(?=\\])")
82 | .matcher(getPropOutput);
83 | if (portMatcher.find()) {
84 | return portMatcher.group(0);
85 | }
86 | return "";
87 | }
88 |
89 | private String parseDeviceName(String line) {
90 | int start = line.indexOf(MODEL_INDICATOR) + MODEL_INDICATOR.length();
91 | int end = line.indexOf(DEVICE_INDICATOR) - 1;
92 | if (end < 0) {
93 | end = line.length();
94 | }
95 | return line.substring(start, end);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/adb/CommandLine.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.adb;
18 |
19 | import java.io.BufferedReader;
20 | import java.io.IOException;
21 | import java.io.InputStreamReader;
22 |
23 | public class CommandLine {
24 |
25 | public String executeCommand(String command) {
26 | Process process;
27 | StringBuilder stringBuilder = new StringBuilder();
28 | try {
29 | process = Runtime.getRuntime().exec(command);
30 | process.waitFor();
31 | InputStreamReader in = new InputStreamReader(process.getInputStream());
32 | BufferedReader reader = new BufferedReader(in);
33 | String line;
34 | while ((line = reader.readLine()) != null) {
35 | stringBuilder.append(line + "\n");
36 | }
37 | } catch (InterruptedException e) {
38 | e.printStackTrace();
39 | } catch (IOException e) {
40 | e.printStackTrace();
41 | }
42 | return stringBuilder.toString();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/util/NotificationUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.util;
18 |
19 | import com.intellij.notification.Notification;
20 | import com.intellij.notification.NotificationGroup;
21 | import com.intellij.notification.NotificationType;
22 | import com.intellij.notification.Notifications;
23 | import com.intellij.openapi.application.ApplicationManager;
24 |
25 | public class NotificationUtils {
26 |
27 | private static final String ANDROID_WIFI_ADB_TITLE = "Android WiFi ADB";
28 | private static final NotificationGroup NOTIFICATION_GROUP =
29 | NotificationGroup.balloonGroup(ANDROID_WIFI_ADB_TITLE);
30 |
31 | public static void showNotification(final String message,
32 | final NotificationType type) {
33 | ApplicationManager.getApplication().invokeLater(new Runnable() {
34 | @Override public void run() {
35 | Notification notification =
36 | NOTIFICATION_GROUP.createNotification(ANDROID_WIFI_ADB_TITLE, message, type, null);
37 | Notifications.Bus.notify(notification);
38 | }
39 | });
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/view/NotificationView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.view;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 | import com.intellij.notification.NotificationType;
21 |
22 | import static com.github.pedrovgs.androidwifiadb.util.NotificationUtils.showNotification;
23 |
24 | public class NotificationView implements View {
25 | @Override public void showNoConnectedDevicesNotification() {
26 | showNotification("There are no devices connected. Review your USB connection and try again.",
27 | NotificationType.INFORMATION);
28 | }
29 |
30 | @Override public void showConnectedDeviceNotification(Device device) {
31 | showNotification("Device '" + device.getName() + "' connected.",
32 | NotificationType.INFORMATION);
33 | }
34 |
35 | @Override public void showDisconnectedDeviceNotification(Device device) {
36 | showNotification("Device '" + device.getName() + "' disconnected.",
37 | NotificationType.INFORMATION);
38 | }
39 |
40 | @Override public void showErrorConnectingDeviceNotification(Device device) {
41 | showNotification(
42 | "Unable to connect to device '" + device.getName() + "'. Make sure that your computer and your "
43 | + "device are connected to the same WiFi network.",
44 | NotificationType.INFORMATION);
45 | }
46 |
47 | @Override public void showErrorDisconnectingDeviceNotification(Device device) {
48 | showNotification(
49 | "Unable to disconnect device '" + device.getName() + "'. Make sure that your computer and your "
50 | + "device are connected to the same WiFi network.",
51 | NotificationType.INFORMATION);
52 | }
53 |
54 | @Override public void showADBNotInstalledNotification() {
55 | showNotification("'adb' command not found. Review your Android SDK installation.",
56 | NotificationType.ERROR);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/view/View.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.view;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 |
21 | public interface View {
22 |
23 | void showNoConnectedDevicesNotification();
24 |
25 | void showConnectedDeviceNotification(Device device);
26 |
27 | void showDisconnectedDeviceNotification(Device device);
28 |
29 | void showErrorConnectingDeviceNotification(Device device);
30 |
31 | void showErrorDisconnectingDeviceNotification(Device device);
32 |
33 | void showADBNotInstalledNotification();
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/ActionButtonListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | public interface ActionButtonListener {
20 | void onConnectClick(int row);
21 |
22 | void onDisconnectClick(int row);
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/AndroidDevicesTableModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import javax.swing.table.AbstractTableModel;
25 |
26 | public class AndroidDevicesTableModel extends AbstractTableModel {
27 | private static final int COLUMN_DEVICE = 0;
28 | private static final int COLUMN_STATE = 1;
29 | private static final int COLUMN_ACTION = 2;
30 | private static final int COLUMN_COUNT = 3;
31 | private static final String DEVICE = "Device";
32 | private static final String STATE = "State";
33 | private static final String ACTION = "Action";
34 | private static final String CONNECTED = "Connected";
35 | private static final String DISCONNECTED = "Disconnected";
36 | private final List devices = new ArrayList();
37 |
38 | @Override
39 | public String getColumnName(int column) {
40 | String value = null;
41 | switch (column) {
42 | case COLUMN_DEVICE:
43 | value = DEVICE;
44 | break;
45 | case COLUMN_STATE:
46 | value = STATE;
47 | break;
48 | case COLUMN_ACTION:
49 | value = ACTION;
50 | break;
51 | default:
52 | return value;
53 | }
54 | return value;
55 | }
56 |
57 | @Override
58 | public Class> getColumnClass(int columnIndex) {
59 | Class value = Object.class;
60 | switch (columnIndex) {
61 | case COLUMN_DEVICE:
62 | value = String.class;
63 | break;
64 | case COLUMN_STATE:
65 | value = String.class;
66 | break;
67 | default:
68 | return value;
69 | }
70 | return value;
71 | }
72 |
73 | @Override
74 | public int getRowCount() {
75 | return devices.size();
76 | }
77 |
78 | @Override
79 | public int getColumnCount() {
80 | return COLUMN_COUNT;
81 | }
82 |
83 | @Override
84 | public Object getValueAt(int rowIndex, int columnIndex) {
85 | Device obj = devices.get(rowIndex);
86 | Object value = null;
87 | switch (columnIndex) {
88 | case COLUMN_DEVICE:
89 | value = obj.toString();
90 | break;
91 | case COLUMN_STATE:
92 | value = obj.isConnected() ? CONNECTED : DISCONNECTED;
93 | break;
94 | case COLUMN_ACTION:
95 | break;
96 | default:
97 | return value;
98 | }
99 | return value;
100 | }
101 |
102 | @Override
103 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
104 | if (columnIndex == COLUMN_ACTION) {
105 | fireTableCellUpdated(rowIndex, columnIndex);
106 | }
107 | }
108 |
109 | @Override
110 | public boolean isCellEditable(int rowIndex, int columnIndex) {
111 | return columnIndex == COLUMN_ACTION;
112 | }
113 |
114 | public void clear() {
115 | if (devices != null) {
116 | devices.clear();
117 | }
118 | }
119 |
120 | public void add(Device value) {
121 | int startIndex = getRowCount();
122 | devices.add(value);
123 | fireTableRowsInserted(startIndex, getRowCount() - 1);
124 | }
125 |
126 | public Device get(int index) {
127 | if (index >= 0 && index < devices.size()) {
128 | return devices.get(index);
129 | }
130 | return null;
131 | }
132 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/AndroidWiFiADBWindow.form:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/AndroidWiFiADBWindow.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import com.github.pedrovgs.androidwifiadb.AndroidWiFiADB;
20 | import com.github.pedrovgs.androidwifiadb.Device;
21 | import com.github.pedrovgs.androidwifiadb.adb.ADB;
22 | import com.github.pedrovgs.androidwifiadb.adb.ADBParser;
23 | import com.github.pedrovgs.androidwifiadb.adb.CommandLine;
24 | import com.github.pedrovgs.androidwifiadb.view.NotificationView;
25 | import com.intellij.openapi.application.ApplicationManager;
26 | import com.intellij.openapi.project.Project;
27 | import com.intellij.openapi.wm.ToolWindow;
28 | import com.intellij.openapi.wm.ToolWindowFactory;
29 | import com.intellij.ui.content.Content;
30 | import com.intellij.ui.content.ContentFactory;
31 | import java.util.Timer;
32 | import java.util.TimerTask;
33 | import javax.swing.JPanel;
34 |
35 | public class AndroidWiFiADBWindow implements ToolWindowFactory, DeviceAction {
36 |
37 | private static final int INTERVAL_REFRESH_DEVICES = 1000;
38 |
39 | private final AndroidWiFiADB androidWifiADB;
40 | private final CardLayoutDevices cardLayoutDevices;
41 | private JPanel toolWindowContent;
42 |
43 | public AndroidWiFiADBWindow() {
44 | CommandLine commandLine = new CommandLine();
45 | ADBParser adbParser = new ADBParser();
46 | ADB adb = new ADB(commandLine, adbParser);
47 | this.androidWifiADB = new AndroidWiFiADB(adb, new NotificationView());
48 | cardLayoutDevices = new CardLayoutDevices(toolWindowContent, this);
49 | }
50 |
51 | @Override public void createToolWindowContent(Project project, ToolWindow toolWindow) {
52 | androidWifiADB.updateProject(project);
53 | createToolWindowContent(toolWindow);
54 | setupUI();
55 | monitorDevices();
56 | }
57 |
58 | @Override public void connectDevice(final Device device) {
59 | ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
60 | public void run() {
61 | androidWifiADB.connectDevice(device);
62 | updateUi();
63 | }
64 | });
65 | }
66 |
67 | @Override public void disconnectDevice(final Device device) {
68 | ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
69 | public void run() {
70 | androidWifiADB.disconnectDevice(device);
71 | updateUi();
72 | }
73 | });
74 | }
75 |
76 | private void createToolWindowContent(ToolWindow toolWindow) {
77 | ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
78 | Content content = contentFactory.createContent(toolWindowContent, "", false);
79 | toolWindow.getContentManager().addContent(content);
80 | }
81 |
82 | private void setupUI() {
83 | ApplicationManager.getApplication().invokeLater(new Runnable() {
84 | @Override public void run() {
85 | cardLayoutDevices.createAndShowGUI();
86 | }
87 | });
88 | }
89 |
90 | private void monitorDevices() {
91 | ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
92 | public void run() {
93 | new Timer().schedule(new TimerTask() {
94 | @Override public void run() {
95 | boolean refreshRequired = androidWifiADB.refreshDevicesList();
96 | if (refreshRequired) {
97 | updateUi();
98 | }
99 | }
100 | }, 0, INTERVAL_REFRESH_DEVICES);
101 | }
102 | });
103 | }
104 |
105 | private void updateUi() {
106 | ApplicationManager.getApplication().invokeLater(new Runnable() {
107 | @Override public void run() {
108 | cardLayoutDevices.setDevices(androidWifiADB.getDevices());
109 | cardLayoutDevices.updateUi();
110 | }
111 | });
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/CardLayoutDevices.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 | import com.intellij.ui.table.JBTable;
21 | import java.awt.BorderLayout;
22 | import java.awt.CardLayout;
23 | import java.awt.Container;
24 | import java.util.ArrayList;
25 | import java.util.Collection;
26 | import javax.swing.JCheckBox;
27 | import javax.swing.JLabel;
28 | import javax.swing.JPanel;
29 | import javax.swing.JTable;
30 | import javax.swing.SwingConstants;
31 | import javax.swing.table.DefaultTableCellRenderer;
32 |
33 | public class CardLayoutDevices implements ActionButtonListener {
34 |
35 | private static final String CARD_DEVICES = "Card with JTable devices";
36 | private static final String CARD_NO_DEVICES = "Card with no devices info";
37 | private static final String NO_DEVICE_CONNECTED = "No devices connected.";
38 |
39 | private Container parentContainer;
40 | private JPanel cards;
41 | private JPanel panelNoDevices;
42 | private JPanel panelDevices;
43 | private JTable tableDevices;
44 | private Collection devices;
45 | private DeviceAction deviceAction;
46 |
47 | public CardLayoutDevices(Container parentContainer, DeviceAction action) {
48 | this.deviceAction = action;
49 | this.parentContainer = parentContainer;
50 | this.devices = new ArrayList();
51 | }
52 |
53 | public void setDevices(Collection devices) {
54 | this.devices = devices;
55 | }
56 |
57 | public void createAndShowGUI() {
58 | cards = new JPanel(new CardLayout());
59 | createNoDevicesPanel();
60 | createTableDevices();
61 | cards.add(panelDevices, CARD_DEVICES);
62 | cards.add(panelNoDevices, CARD_NO_DEVICES);
63 | parentContainer.add(cards, BorderLayout.PAGE_START);
64 | setupUi();
65 | }
66 |
67 | public void updateUi() {
68 | if (devices != null && !devices.isEmpty()) {
69 | showCard(CARD_DEVICES);
70 | updateDevicesTable();
71 | } else {
72 | showCard(CARD_NO_DEVICES);
73 | }
74 | }
75 |
76 | @Override public void onConnectClick(int row) {
77 | Device device = getDeviceAt(row);
78 | if (device != null) {
79 | deviceAction.connectDevice(device);
80 | }
81 | }
82 |
83 | @Override public void onDisconnectClick(int row) {
84 | Device device = getDeviceAt(row);
85 | if (device != null) {
86 | deviceAction.disconnectDevice(device);
87 | }
88 | }
89 |
90 | private void setupUi() {
91 | if (devices != null && !devices.isEmpty()) {
92 | showCard(CARD_DEVICES);
93 | } else {
94 | showCard(CARD_NO_DEVICES);
95 | }
96 | }
97 |
98 | private void showCard(String cardName) {
99 | CardLayout cardLayout = (CardLayout) cards.getLayout();
100 | cardLayout.show(cards, cardName);
101 | }
102 |
103 | private void createNoDevicesPanel() {
104 | panelNoDevices = new JPanel(new BorderLayout());
105 | JLabel labelNoDevices = new JLabel(NO_DEVICE_CONNECTED);
106 | labelNoDevices.setHorizontalAlignment(SwingConstants.CENTER);
107 | panelNoDevices.add(labelNoDevices);
108 | }
109 |
110 | private void createTableDevices() {
111 | AndroidDevicesTableModel model = new AndroidDevicesTableModel();
112 | for (Device device : devices) {
113 | model.add(device);
114 | }
115 | tableDevices = new JBTable(model);
116 | configureTableAppearance();
117 |
118 | panelDevices = new JPanel(new BorderLayout());
119 | panelDevices.add(tableDevices.getTableHeader(), BorderLayout.NORTH);
120 | panelDevices.add(tableDevices, BorderLayout.CENTER);
121 | }
122 |
123 | private void configureTableAppearance() {
124 | tableDevices.setOpaque(false);
125 | ((DefaultTableCellRenderer) tableDevices.getDefaultRenderer(Object.class)).setOpaque(false);
126 | tableDevices.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
127 | tableDevices.getColumnModel().getColumn(0).setPreferredWidth(100);
128 | tableDevices.getColumnModel().getColumn(1).setMinWidth(85);
129 | tableDevices.getColumnModel().getColumn(1).setMaxWidth(85);
130 | tableDevices.getColumnModel().getColumn(2).setMinWidth(215);
131 | tableDevices.getColumnModel().getColumn(2).setMaxWidth(215);
132 | tableDevices.getColumnModel().getColumn(2).setCellRenderer(new ConnectDisconnectRenderer());
133 | tableDevices.getColumnModel()
134 | .getColumn(2)
135 | .setCellEditor(new ConnectDisconnectEditor(new JCheckBox(), this));
136 | }
137 |
138 | private void updateDevicesTable() {
139 | AndroidDevicesTableModel model = (AndroidDevicesTableModel) tableDevices.getModel();
140 | model.clear();
141 | for (Device device : devices) {
142 | model.add(device);
143 | }
144 | tableDevices.setModel(model);
145 | model.fireTableDataChanged();
146 | }
147 |
148 | private Device getDeviceAt(int row) {
149 | AndroidDevicesTableModel model = (AndroidDevicesTableModel) tableDevices.getModel();
150 | return model.get(row);
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/ConnectDisconnectEditor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import java.awt.Component;
20 | import java.awt.event.ActionEvent;
21 | import java.awt.event.ActionListener;
22 |
23 | import javax.swing.DefaultCellEditor;
24 | import javax.swing.JCheckBox;
25 | import javax.swing.JTable;
26 |
27 | public class ConnectDisconnectEditor extends DefaultCellEditor {
28 | private boolean clicked;
29 | private String clickedButtonAction;
30 | private int row, col;
31 | private ConnectDisconnectPanel buttonsPanel;
32 | private ActionButtonListener listener;
33 |
34 | public ConnectDisconnectEditor(JCheckBox checkBox, ActionButtonListener listener) {
35 | super(checkBox);
36 | this.listener = listener;
37 | buttonsPanel = new ConnectDisconnectPanel();
38 | buttonsPanel.addActionListeners(new ActionListener() {
39 | @Override
40 | public void actionPerformed(ActionEvent e) {
41 | clickedButtonAction = e.getActionCommand();
42 | fireEditingStopped();
43 | }
44 | });
45 | }
46 |
47 | @Override
48 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
49 | this.row = row;
50 | this.col = column;
51 |
52 | clicked = true;
53 | return buttonsPanel;
54 | }
55 |
56 | @Override
57 | public Object getCellEditorValue() {
58 | if (clicked && listener != null) {
59 | if (ConnectDisconnectPanel.ACTION_CONNECT.equals(clickedButtonAction)) {
60 | listener.onConnectClick(row);
61 | } else if (ConnectDisconnectPanel.ACTION_DISCONNECT.equals(clickedButtonAction)) {
62 | listener.onDisconnectClick(row);
63 | }
64 | }
65 | clickedButtonAction = "";
66 | clicked = false;
67 | return "";
68 | }
69 |
70 | @Override
71 | public boolean stopCellEditing() {
72 | clicked = false;
73 | return super.stopCellEditing();
74 | }
75 |
76 | @Override
77 | protected void fireEditingStopped() {
78 | super.fireEditingStopped();
79 | }
80 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/ConnectDisconnectPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import java.awt.GridBagLayout;
20 | import java.awt.event.ActionListener;
21 |
22 | import javax.swing.JButton;
23 | import javax.swing.JPanel;
24 |
25 | public class ConnectDisconnectPanel extends JPanel {
26 | public static final String ACTION_CONNECT = "Connect";
27 | public static final String ACTION_DISCONNECT = "Disconnect";
28 |
29 | private JButton connect;
30 | private JButton disconnect;
31 |
32 | public ConnectDisconnectPanel() {
33 | setLayout(new GridBagLayout());
34 | setOpaque(false);
35 | connect = new JButton(ACTION_CONNECT);
36 | connect.setActionCommand(ACTION_CONNECT);
37 | connect.setOpaque(false);
38 | disconnect = new JButton(ACTION_DISCONNECT);
39 | disconnect.setActionCommand(ACTION_DISCONNECT);
40 | disconnect.setOpaque(false);
41 |
42 | add(connect);
43 | add(disconnect);
44 | }
45 |
46 | public void addActionListeners(ActionListener listener) {
47 | connect.addActionListener(listener);
48 | disconnect.addActionListener(listener);
49 | }
50 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/ConnectDisconnectRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import java.awt.Component;
20 |
21 | import javax.swing.JPanel;
22 | import javax.swing.JTable;
23 | import javax.swing.table.TableCellRenderer;
24 |
25 | public class ConnectDisconnectRenderer extends JPanel implements TableCellRenderer {
26 | private final ConnectDisconnectPanel connectDisconnectPane = new ConnectDisconnectPanel();
27 |
28 | @Override
29 | public Component getTableCellRendererComponent(JTable table, Object value,
30 | boolean isSelected, boolean hasFocus,
31 | int row, int column) {
32 | if (isSelected) {
33 | connectDisconnectPane.setBackground(table.getSelectionBackground());
34 | } else {
35 | connectDisconnectPane.setBackground(table.getBackground());
36 | }
37 | return connectDisconnectPane;
38 | }
39 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/pedrovgs/androidwifiadb/window/DeviceAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.window;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 |
21 | public interface DeviceAction {
22 | void connectDevice(Device device);
23 |
24 | void disconnectDevice(Device device);
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.github.pedrovgs.androidwifiadb
4 | Android WiFi ADB
5 | 2.5-SNAPSHOT
6 |
7 | Pedro Vicente Gomez Sanchez
8 |
9 |
10 |
13 | Connect your device using a USB cable and press the Android WiFi ADB button. Once the device be connected over WiFi you'll see an IntelliJ/Android Studio notification. Now you can disconnect your USB cable and enjoy deploying, running and debugging your applications over WiFi.
14 |
15 | The version 2.0 enables a window to check which of your devices are connected or not and connect/disconnect it manually if needed.
16 | ]]>
17 |
18 |
19 |
21 | 2.3: Update the main action configuration to be shown in the NavBarToolBar and also in the MainToolBar if the first on is disabled.
22 | 2.2: Update error message shown when the device is not properly connected.
23 | 2.1: Fix bug associated to some device installations where the adb installation was not recognized.
24 | 2.0: Add a new Android WiFi ADB control panel showing all the devices connected by USB to be able to connect/disconnect devices individually.
25 | 1.2: Remove the usage of the ANDROID_HOME environment variable. This variable is not needed now.
26 | 1.1: Fixes for Windows and Linux.
27 | 1.0: Initial version.
28 | ]]>
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.jetbrains.android
53 |
54 |
55 |
56 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/main/resources/icons/androidWiFiADBIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/src/main/resources/icons/androidWiFiADBIcon.png
--------------------------------------------------------------------------------
/src/main/resources/icons/androidWiFiADBIcon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pedrovgs/AndroidWiFiADB/c54f1e8dba380c0d595cf70267f385362f0d4f14/src/main/resources/icons/androidWiFiADBIcon@2x.png
--------------------------------------------------------------------------------
/src/test/java/com/github/pedrovgs/androidwifiadb/AndroidWiFiADBTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb;
18 |
19 | import com.github.pedrovgs.androidwifiadb.adb.ADB;
20 | import com.github.pedrovgs.androidwifiadb.view.View;
21 | import java.util.ArrayList;
22 | import java.util.Arrays;
23 | import java.util.LinkedList;
24 | import java.util.List;
25 | import org.junit.Test;
26 | import org.mockito.Mock;
27 |
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.assertFalse;
30 | import static org.junit.Assert.assertTrue;
31 | import static org.mockito.Matchers.anyObject;
32 | import static org.mockito.Mockito.verify;
33 | import static org.mockito.Mockito.when;
34 |
35 | public class AndroidWiFiADBTest extends UnitTest {
36 |
37 | private static final int SOME_DEVICES = 4;
38 | private static final String ANY_DEVICE_NAME = "Device nº ";
39 | private static final String ANY_DEVICE_ID = "abcdef123";
40 | private static final String ANY_DEVICE_IP = "0.0.0.0";
41 |
42 | @Mock private ADB adb;
43 | @Mock private View view;
44 |
45 | @Test public void shouldShowErrorIfADBIsNotInstalled() {
46 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
47 | givenADBIsNotInstalled();
48 |
49 | androidWiFiAdb.connectDevices();
50 |
51 | verify(view).showADBNotInstalledNotification();
52 | }
53 |
54 | @Test public void shouldShowNoConnectedDevicesNotificationIfThereAreNotConnectedDevicesByUSB() {
55 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
56 | givenThereAreNoConnectedDevices();
57 |
58 | androidWiFiAdb.connectDevices();
59 |
60 | verify(view).showNoConnectedDevicesNotification();
61 | }
62 |
63 | @Test public void shouldShowDevicesConnectedIfADBWiFiWhenConnectionIsEstablished() {
64 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
65 | List devices = givenThereAreSomeDevicesConnectedByUSB();
66 | givenDevicesAreConnectedSuccessfully(devices);
67 |
68 | androidWiFiAdb.connectDevices();
69 |
70 | for (Device device : devices) {
71 | verify(view).showConnectedDeviceNotification(device);
72 | }
73 | }
74 |
75 | @Test public void shouldShowDeviceConnectionErrorWhenConnectionIsNotEstablished() {
76 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
77 | List devices = givenThereAreSomeDevicesConnectedByUSB();
78 | givenDevicesAreNotConnectedSuccessfully(devices);
79 |
80 | androidWiFiAdb.connectDevices();
81 |
82 | for (Device device : devices) {
83 | verify(view).showErrorConnectingDeviceNotification(device);
84 | }
85 | }
86 |
87 | @Test public void shouldNotRefreshDevicesListIfAdbIsNotIstalled() throws Exception {
88 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
89 | givenADBIsNotInstalled();
90 |
91 | assertFalse(androidWiFiAdb.refreshDevicesList());
92 | }
93 |
94 | @Test public void shouldRefreshDevicesListAddNewDevice() throws Exception {
95 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
96 | List devices = givenThereAreSomeDevicesConnectedByUSB();
97 | givenDevicesAreConnectedSuccessfully(devices);
98 | givenAnyIpToDevices();
99 |
100 | assertEquals(0, androidWiFiAdb.getDevices().size());
101 | androidWiFiAdb.refreshDevicesList();
102 | assertEquals(devices.size(), androidWiFiAdb.getDevices().size());
103 | }
104 |
105 | @Test public void shouldRefreshDevicesListUpdateExistingDevices() throws Exception {
106 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
107 | List devices = givenThereAreSomeDevicesConnectedByUSB();
108 | givenDevicesAreConnectedSuccessfully(devices);
109 |
110 | androidWiFiAdb.connectDevices();
111 | androidWiFiAdb.refreshDevicesList();
112 |
113 | assertEquals(devices.size(), androidWiFiAdb.getDevices().size());
114 | }
115 |
116 | @Test public void shouldDisconnectDevice() throws Exception {
117 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
118 | givenADBIsInstalled();
119 | Device device = givenAnyConnectedDevice();
120 | givenDevicesAreDisconnectedSuccessfully(Arrays.asList(device));
121 |
122 | androidWiFiAdb.disconnectDevice(device);
123 |
124 | assertFalse(device.isConnected());
125 | }
126 |
127 | @Test public void shouldConnectDevice() throws Exception {
128 | AndroidWiFiADB androidWiFiAdb = givenAnAndroidWiFiADB();
129 | givenADBIsInstalled();
130 | Device device = givenAnyDisonnectedDevice();
131 | givenDevicesAreConnectedSuccessfully(Arrays.asList(device));
132 |
133 | androidWiFiAdb.connectDevice(device);
134 |
135 | assertTrue(device.isConnected());
136 | }
137 |
138 | private Device givenAnyConnectedDevice() {
139 | Device device = new Device(ANY_DEVICE_NAME, ANY_DEVICE_ID);
140 | device.setConnected(true);
141 | return device;
142 | }
143 |
144 | private Device givenAnyDisonnectedDevice() {
145 | return new Device(ANY_DEVICE_NAME, ANY_DEVICE_ID);
146 | }
147 |
148 | private void givenDevicesAreNotConnectedSuccessfully(List devices) {
149 | for (Device device : devices) {
150 | device.setConnected(false);
151 | }
152 | when(adb.getDevicesConnectedByUSB()).thenReturn(devices);
153 | when(adb.connectDevices(devices)).thenReturn(devices);
154 | }
155 |
156 | private void givenDevicesAreConnectedSuccessfully(List devices) {
157 | for (Device device : devices) {
158 | device.setConnected(true);
159 | }
160 | when(adb.getDevicesConnectedByUSB()).thenReturn(devices);
161 | when(adb.connectDevices(devices)).thenReturn(new ArrayList(devices));
162 | }
163 |
164 | private void givenDevicesAreDisconnectedSuccessfully(final List devices) {
165 | for (Device device : devices) {
166 | device.setConnected(false);
167 | }
168 | when(adb.disconnectDevices(devices)).thenReturn(devices);
169 | }
170 |
171 | private List givenThereAreSomeDevicesConnectedByUSB() {
172 | when(adb.isInstalled()).thenReturn(true);
173 | return getSomeDevices(SOME_DEVICES);
174 | }
175 |
176 | private List getSomeDevices(int devicesCount) {
177 | List devices = new LinkedList();
178 | for (int i = 0; i < devicesCount; i++) {
179 | String name = ANY_DEVICE_NAME + i;
180 | String id = String.valueOf(i);
181 | Device device = new Device(name, id);
182 | devices.add(device);
183 | }
184 | return devices;
185 | }
186 |
187 | private void givenThereAreNoConnectedDevices() {
188 | when(adb.isInstalled()).thenReturn(true);
189 | when(adb.getDevicesConnectedByUSB()).thenReturn(new LinkedList());
190 | }
191 |
192 | private void givenADBIsNotInstalled() {
193 | when(adb.isInstalled()).thenReturn(false);
194 | }
195 |
196 | private void givenADBIsInstalled() {
197 | when(adb.isInstalled()).thenReturn(true);
198 | }
199 |
200 | private void givenAnyIpToDevices() {
201 | when(adb.getDeviceIp((Device) anyObject())).thenReturn(ANY_DEVICE_IP);
202 | }
203 |
204 | private AndroidWiFiADB givenAnAndroidWiFiADB() {
205 | return new AndroidWiFiADB(adb, view);
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/src/test/java/com/github/pedrovgs/androidwifiadb/UnitTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb;
18 |
19 | import org.junit.Before;
20 | import org.mockito.MockitoAnnotations;
21 |
22 | public class UnitTest {
23 |
24 | @Before public void setUp() {
25 | MockitoAnnotations.initMocks(this);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/java/com/github/pedrovgs/androidwifiadb/adb/ADBParserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.pedrovgs.androidwifiadb.adb;
18 |
19 | import com.github.pedrovgs.androidwifiadb.Device;
20 | import com.github.pedrovgs.androidwifiadb.UnitTest;
21 | import java.util.List;
22 | import org.junit.Test;
23 |
24 | import static org.junit.Assert.assertEquals;
25 | import static org.junit.Assert.assertTrue;
26 |
27 | public class ADBParserTest extends UnitTest {
28 |
29 | private static final String ADB_DEVICES_OUTPUT_ONE_DEVICE = "List of devices attached\n"
30 | + "0810a0dd00e3656f device usb:336592896X product:hammerhead model:Nexus_5 device:hammerhead";
31 | private static final String ADB_DEVICES_OUTPUT_SOME_DEVICES = "List of devices attached\n"
32 | + "0810a0dd00e3656f device usb:336592896X product:hammerhead model:Nexus_5 device:hammerhead\n"
33 | + "0810a0d333333656f device usb:336592896X product:hammerhead model:Nexus_6";
34 | private static final String ADB_DEVICES_NO_DEVICES = "List of devices attached\n";
35 | private static final String ADB_DEVICES_OUTPUT_WITH_DEVICES_BY_IP = "List of devices attached\n"
36 | + "0810a0dd00e3656f device usb:336592896X product:hammerhead model:Nexus_5 device:hammerhead\n"
37 | + "192.168.1.128:5555f device usb:336592896X product:hammerhead model:Nexus_6 device:hammerhead\n";
38 | private static final String GET_IP_OUTPUT =
39 | "21: wlan0: mtu 1500 qdisc pfifo_fast state UP qlen 1000\n"
40 | + " inet 192.168.1.128/24 brd 192.168.1.255 scope global wlan0";
41 | private static final String GET_ADB_PROP_DEVICE_NOT_FOUND = "error: device '(null)' not found";
42 | private static final String GET_ADP_PROP_NO_TCP_PORT_INFO = "[init.svc.adbd]: [running]\n"
43 | + "[persist.sys.usb.config]: [mtp,adb]\n"
44 | + "[ro.adb.secure]: [1]\n"
45 | + "[sys.usb.config]: [mtp,adb]\n"
46 | + "[sys.usb.state]: [mtp,adb]";
47 | private static final String TCPIP_PORT = "5555";
48 | private static final String GET_ADB_PROP_WITH_TCP_PORT = " [init.svc.adbd]: [running]\n"
49 | + " [persist.sys.usb.config]: [mtp,adb]\n"
50 | + " [ro.adb.secure]: [1]\n"
51 | + " [service.adb.tcp.port]: [" + TCPIP_PORT + "]\n"
52 | + " [sys.usb.config]: [mtp,adb]\n"
53 | + " [sys.usb.state]: [mtp,adb]\n";
54 |
55 | @Test
56 | public void shouldParseAdbDevicesOutputAndReturnTheListOfDevicesWithJustOneDeviceConnected() {
57 | ADBParser parser = givenAADBParser();
58 |
59 | List devices = parser.parseGetDevicesOutput(ADB_DEVICES_OUTPUT_ONE_DEVICE);
60 |
61 | assertEquals(1, devices.size());
62 | Device device = devices.get(0);
63 | assertEquals("0810a0dd00e3656f", device.getId());
64 | assertEquals("Nexus_5", device.getName());
65 | }
66 |
67 | @Test public void shouldParseAdbDevicesOutputAndReturnTheListOfDevicesWithMoreThanOneDevice() {
68 | ADBParser parser = givenAADBParser();
69 |
70 | List devices = parser.parseGetDevicesOutput(ADB_DEVICES_OUTPUT_SOME_DEVICES);
71 |
72 | assertEquals(2, devices.size());
73 | Device firstDevice = devices.get(0);
74 | Device secondDevice = devices.get(1);
75 | assertEquals("0810a0dd00e3656f", firstDevice.getId());
76 | assertEquals("Nexus_5", firstDevice.getName());
77 | assertEquals("0810a0d333333656f", secondDevice.getId());
78 | assertEquals("Nexus_6", secondDevice.getName());
79 | }
80 |
81 | @Test public void shouldReturnAnEmptyListIfThereAreNoDevices() {
82 | ADBParser parser = givenAADBParser();
83 |
84 | List devices = parser.parseGetDevicesOutput(ADB_DEVICES_NO_DEVICES);
85 |
86 | assertTrue(devices.isEmpty());
87 | }
88 |
89 | @Test public void shouldNotReturnDevicesConnectedByIp() {
90 | ADBParser parser = givenAADBParser();
91 |
92 | List devices = parser.parseGetDevicesOutput(ADB_DEVICES_OUTPUT_WITH_DEVICES_BY_IP);
93 |
94 | assertEquals(1, devices.size());
95 | Device device = devices.get(0);
96 | assertEquals("0810a0dd00e3656f", device.getId());
97 | assertEquals("Nexus_5", device.getName());
98 | }
99 |
100 | @Test public void shouldReturnDeviceIp() {
101 | ADBParser parser = givenAADBParser();
102 |
103 | String deviceIp = parser.parseGetDeviceIp(GET_IP_OUTPUT);
104 |
105 | assertEquals("192.168.1.128", deviceIp);
106 | }
107 |
108 | @Test public void shouldReturnEmptyIfDeviceIpIsAnEmptyString() {
109 | ADBParser parser = givenAADBParser();
110 |
111 | String deviceIp = parser.parseGetDeviceIp("");
112 |
113 | assertEquals("", deviceIp);
114 | }
115 |
116 | @Test
117 | public void shouldReturnEmptyStringIfDeviceNotFound() throws Exception {
118 | ADBParser parser = givenAADBParser();
119 |
120 | String tcpPort = parser.parseAdbServiceTcpPort(GET_ADB_PROP_DEVICE_NOT_FOUND);
121 |
122 | assertEquals("", tcpPort);
123 | }
124 |
125 | @Test
126 | public void shouldReturnEmptyStringIfAdbPropertiesDoesNotContainTCPPort() throws Exception {
127 | ADBParser parser = givenAADBParser();
128 |
129 | String tcpPort = parser.parseAdbServiceTcpPort(GET_ADP_PROP_NO_TCP_PORT_INFO);
130 |
131 | assertEquals("", tcpPort);
132 | }
133 |
134 | @Test
135 | public void shouldReturnTCPPort() throws Exception {
136 | ADBParser parser = givenAADBParser();
137 |
138 | String tcpPort = parser.parseAdbServiceTcpPort(GET_ADB_PROP_WITH_TCP_PORT);
139 |
140 | assertEquals(TCPIP_PORT, tcpPort);
141 | }
142 |
143 | private ADBParser givenAADBParser() {
144 | return new ADBParser();
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/test/java/com/github/pedrovgs/androidwifiadb/window/AndroidDevicesTableModelTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.
4 | * *
5 | * * Licensed under the Apache License, Version 2.0 (the "License");
6 | * * you may not use this file except in compliance with the License.
7 | * * You may obtain a copy of the License at
8 | * *
9 | * * http://www.apache.org/licenses/LICENSE-2.0
10 | * *
11 | * * Unless required by applicable law or agreed to in writing, software
12 | * * distributed under the License is distributed on an "AS IS" BASIS,
13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * * See the License for the specific language governing permissions and
15 | * * limitations under the License.
16 | *
17 | */
18 |
19 | package com.github.pedrovgs.androidwifiadb.window;
20 |
21 | import com.github.pedrovgs.androidwifiadb.Device;
22 | import com.github.pedrovgs.androidwifiadb.UnitTest;
23 | import javax.swing.event.TableModelEvent;
24 | import javax.swing.event.TableModelListener;
25 | import org.junit.Test;
26 | import org.mockito.Mock;
27 |
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.assertFalse;
30 | import static org.junit.Assert.assertNull;
31 | import static org.junit.Assert.assertTrue;
32 | import static org.mockito.Matchers.anyObject;
33 | import static org.mockito.Mockito.atLeastOnce;
34 | import static org.mockito.Mockito.verify;
35 |
36 | public class AndroidDevicesTableModelTest extends UnitTest {
37 |
38 | private static final int COLUMN_DEVICE = 0;
39 | private static final int COLUMN_STATE = 1;
40 | private static final int COLUMN_ACTION = 2;
41 | private static final int COLUMN_WITH_NOT_VALID_INDEX = -1;
42 | private static final String ANY_DEVICE_ID = "abcdef";
43 | private static final String ANY_DEVICE_NAME = "test_name";
44 | private static final String CONNECTED = "Connected";
45 | private static final String DISCONNECTED = "Disconnected";
46 |
47 | @Mock
48 | TableModelListener tableModelListener;
49 |
50 | @Test
51 | public void shouldAddDevice() throws Exception {
52 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
53 | assertNull(androidDevicesTableModel.get(0));
54 |
55 | Device device = givenAnyDevice();
56 | androidDevicesTableModel.add(device);
57 |
58 | assertEquals(device, androidDevicesTableModel.get(0));
59 | }
60 |
61 | @Test
62 | public void shouldClearDevicesList() throws Exception {
63 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
64 |
65 | androidDevicesTableModel.add(givenAnyDevice());
66 |
67 | assertEquals(1, androidDevicesTableModel.getRowCount());
68 | androidDevicesTableModel.clear();
69 | assertEquals(0, androidDevicesTableModel.getRowCount());
70 | }
71 |
72 | @Test
73 | public void shouldReturnValueDeviceAsStringForDeviceColumn() throws Exception {
74 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
75 |
76 | Device device = givenAnyDevice();
77 | androidDevicesTableModel.add(device);
78 |
79 | assertEquals(device.toString(), androidDevicesTableModel.getValueAt(0, COLUMN_DEVICE));
80 | }
81 |
82 | @Test
83 | public void shouldReturnValueConnectedStringForConnectedDevice() throws Exception {
84 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
85 |
86 | Device device = givenAnyDevice();
87 | device.setConnected(true);
88 | androidDevicesTableModel.add(device);
89 |
90 | assertEquals(CONNECTED, androidDevicesTableModel.getValueAt(0, COLUMN_STATE));
91 | }
92 |
93 | @Test
94 | public void shouldReturnValueDisconnectedStringForDisconnectedDevice() throws Exception {
95 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
96 |
97 | Device device = givenAnyDevice();
98 | device.setConnected(false);
99 | androidDevicesTableModel.add(device);
100 |
101 | assertEquals(DISCONNECTED, androidDevicesTableModel.getValueAt(0, COLUMN_STATE));
102 | }
103 |
104 | @Test
105 | public void shouldReturnNullValueForActionColumn() throws Exception {
106 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
107 |
108 | androidDevicesTableModel.add(givenAnyDevice());
109 |
110 | assertEquals(null, androidDevicesTableModel.getValueAt(0, COLUMN_ACTION));
111 | }
112 |
113 | @Test
114 | public void shouldReturnNullValueForUnknownColumn() throws Exception {
115 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
116 |
117 | androidDevicesTableModel.add(givenAnyDevice());
118 |
119 | assertEquals(null, androidDevicesTableModel.getValueAt(0, COLUMN_WITH_NOT_VALID_INDEX));
120 | }
121 |
122 | @Test
123 | public void shouldReturnEditableCellForActionColumn() throws Exception {
124 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
125 |
126 | androidDevicesTableModel.add(givenAnyDevice());
127 |
128 | assertFalse(androidDevicesTableModel.isCellEditable(0, COLUMN_STATE)
129 | || androidDevicesTableModel.isCellEditable(0, COLUMN_DEVICE));
130 | assertTrue(androidDevicesTableModel.isCellEditable(0, COLUMN_ACTION));
131 | }
132 |
133 | @Test
134 | public void shouldFireCellUpdateOnlyForActionColumn() throws Exception {
135 | AndroidDevicesTableModel androidDevicesTableModel = givenEmptyDevicesTableModel();
136 |
137 | androidDevicesTableModel.addTableModelListener(tableModelListener);
138 | androidDevicesTableModel.setValueAt(anyObject(), 0, COLUMN_ACTION);
139 |
140 | verify(tableModelListener, atLeastOnce()).tableChanged((TableModelEvent) anyObject());
141 | }
142 |
143 | private Device givenAnyDevice() {
144 | return new Device(ANY_DEVICE_NAME, ANY_DEVICE_ID);
145 | }
146 |
147 | private AndroidDevicesTableModel givenEmptyDevicesTableModel() {
148 | return new AndroidDevicesTableModel();
149 | }
150 | }
151 |
--------------------------------------------------------------------------------