├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
└── java
└── com
└── testinium
└── deviceinformation
├── DeviceInfo.java
├── DeviceInfoImpl.java
├── device
├── AllDeviceFinder.java
├── AndroidDeviceFinder.java
├── DeviceFinder.java
├── DeviceFinderFactory.java
├── DeviceType.java
├── IosDeviceFinder.java
└── IosSimulatorDeviceFinder.java
├── exception
└── DeviceNotFoundException.java
├── helper
├── JsonHelper.java
└── ProcessHelper.java
└── model
├── Android.java
├── Device.java
├── DeviceInfoModel.java
├── Ios.java
└── IosSimulator.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | .classpath
3 | .project
4 | .settings/
5 |
6 | # Intellij
7 | .idea/
8 | *.iml
9 | *.iws
10 |
11 | # Mac
12 | .DS_Store
13 |
14 | # Maven
15 | log/
16 | target/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MobileDeviceInfo
2 |
3 | MobileDeviceInfo helps you fetch information from your mobile device such as UUID, Device Name, etc.
4 | You can integrate MobileDeviceInfo library into your Appium projects to manage your capabilities dynamically.
5 |
6 | ## Prerequisites:
7 | You need to have **ADB** and **libimobiledevice** installed on your machine
8 |
9 | ADB installation can be done via this [link](https://developer.android.com/studio/index.html )
10 |
11 | libimobiledevice can be found on this [link](https://github.com/libimobiledevice/libimobiledevice)
12 |
13 | or
14 |
15 | brew cask install android-platform-tools
16 |
17 | brew install --HEAD libimobiledevice
18 |
19 |
20 | ## Basic Usage
21 | ```
22 | DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.ANDROID);
23 | if (deviceInfo.anyDeviceConnected()) {
24 | Device device = deviceInfo.getFirstDevice();
25 | System.out.println("Device Name - " + device.getDeviceProductName());
26 | System.out.println("Device id - " + device.getUniqueDeviceID());
27 | ```
28 |
29 | or
30 |
31 | ```
32 | DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.IOS);
33 | if (deviceInfo.anyDeviceConnected()) {
34 | Device device = deviceInfo.getFirstDevice();
35 | System.out.println("Device Name - " + device.getDeviceProductName());
36 | System.out.println("Device id - " + device.getUniqueDeviceID());
37 | ```
38 |
39 | or ( Attention - Data Comes Late )
40 |
41 | ```
42 | DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.IOSSIMULATOR);
43 | if (deviceInfo.anyDeviceConnected()) {
44 | Device device = deviceInfo.getFirstDevice();
45 | System.out.println("Device Name - " + device.getDeviceProductName());
46 | System.out.println("Device id - " + device.getUniqueDeviceID());
47 | ```
48 |
49 | or ( Only Android and IOS Devices Except IOS Simulator )
50 |
51 | ```
52 | DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.ALL);
53 | if (deviceInfo.anyDeviceConnected()) {
54 | Device device = deviceInfo.getFirstDevice();
55 | System.out.println("Device Name - " + device.getDeviceProductName());
56 | System.out.println("Device id - " + device.getUniqueDeviceID());
57 | ```
58 |
59 | or ( Attention - Data Comes Late Due To IOS Simulator)
60 |
61 | ```
62 | DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.ALLANDIOSSIMULATOR);
63 | if (deviceInfo.anyDeviceConnected()) {
64 | Device device = deviceInfo.getFirstDevice();
65 | System.out.println("Device Name - " + device.getDeviceProductName());
66 | System.out.println("Device id - " + device.getUniqueDeviceID());
67 | ```
68 |
69 | For **Appium** projects, here's a usage:
70 | ```
71 | DesiredCapabilities capabilities = new DesiredCapabilities();
72 | capabilities.setCapability(CapabilityType.PLATFORM, device.getDeviceProductName());
73 | capabilities.setCapability("platformName", device.getDeviceProductName());
74 | capabilities.setCapability(CapabilityType.VERSION, device.getProductVersion());
75 | capabilities.setCapability("deviceName", device.getModelNumber());
76 | capabilities.setCapability("udid", device.getUniqueDeviceID());
77 | capabilities.setCapability("app", "#Your App File#");
78 |
79 |
80 | driver = new RemoteWebDriver(new URL(URL), capabilities);
81 | ```
82 |
83 |
84 | You can add your project as a maven dependency.
85 |
86 | ```
87 |
88 | com.testinium.deviceinformation
89 | device-information
90 | 2.0
91 |
92 | ```
93 |
94 | You have to add our repository to your pom.xml because it hasn't released to Maven Central repositories.
95 |
96 | ```
97 |
98 |
99 | public
100 | public
101 | http://mvn.testinium.com/repository/public/
102 |
103 | true
104 |
105 |
106 | true
107 |
108 |
109 |
110 | ```
111 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.testinium.deviceinformation
6 | device-information
7 | 2.0
8 | jar
9 |
10 | DeviceInformation
11 | http://www.testinium.com
12 |
13 |
14 | UTF-8
15 | github
16 |
17 |
18 |
19 |
20 | org.apache.commons
21 | commons-lang3
22 | 3.7
23 |
24 |
25 | com.google.code.gson
26 | gson
27 | 2.8.2
28 |
29 |
30 | org.apache.commons
31 | commons-exec
32 | 1.3
33 |
34 |
35 | org.json
36 | json
37 | 20090211
38 |
39 |
40 | junit
41 | junit
42 | 4.12
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.apache.maven.plugins
50 | maven-compiler-plugin
51 | 3.0
52 |
53 | 1.8
54 | 1.8
55 |
56 |
57 |
58 | com.github.github
59 | site-maven-plugin
60 | 0.12
61 |
62 | Maven artifacts for ${project.name}-${project.version}
63 | true
64 | ${project.build.directory}/mvn-repo
65 | refs/heads/mvn-repo
66 | **/*
67 | MobileDeviceInfo
68 | Testinium
69 |
70 |
71 |
72 |
73 | site
74 |
75 | deploy
76 |
77 |
78 |
79 |
80 | maven-deploy-plugin
81 | 2.8.1
82 |
83 | internal.repo::default::file://${project.build.directory}/mvn-repo
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | internal.repo
92 | Temporary Staging Repository
93 | file://${project.build.directory}/mvn-repo
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/src/main/java/com/testinium/deviceinformation/DeviceInfo.java:
--------------------------------------------------------------------------------
1 | package com.testinium.deviceinformation;
2 |
3 | import com.testinium.deviceinformation.exception.DeviceNotFoundException;
4 | import com.testinium.deviceinformation.model.Android;
5 | import com.testinium.deviceinformation.model.Device;
6 | import com.testinium.deviceinformation.model.Ios;
7 | import com.testinium.deviceinformation.model.IosSimulator;
8 |
9 | import java.io.IOException;
10 | import java.util.List;
11 | import java.util.stream.Collectors;
12 |
13 | public interface DeviceInfo {
14 |
15 | default boolean anyDeviceConnected() throws IOException, DeviceNotFoundException {
16 | return getDevices().size() > 0;
17 | }
18 |
19 | default Device getFirstDevice() throws IOException, DeviceNotFoundException {
20 | return getDevices().stream().findFirst().orElse(null);
21 | }
22 |
23 | default Android getFirstAndroid() throws IOException, DeviceNotFoundException {
24 | return (Android) getDevices().stream().filter(device -> device.getDeviceProductName().contains("Android")).filter(device -> device.getSerialNumber() != null).filter(device -> !device.getModelNumber().contains("SDK")).findFirst().orElse(null);
25 | }
26 |
27 | default Android getFirstAndroidEmulator() throws IOException, DeviceNotFoundException {
28 | return (Android) getDevices().stream().filter(device -> device.getDeviceProductName().contains("Android")).filter(device -> device.getSerialNumber() == null).filter(device -> device.getModelNumber().contains("SDK")).findFirst().orElse(null);
29 | }
30 |
31 | default Ios getFirstIos() throws IOException, DeviceNotFoundException {
32 | return (Ios) getDevices().stream().filter(device -> device.getDeviceProductName().contains("Ios")).findFirst().orElse(null);
33 | }
34 |
35 | default IosSimulator getFirstIosSimulator() throws IOException, DeviceNotFoundException {
36 | return (IosSimulator) getDevices().stream().filter(device -> device.getDeviceProductName().contains("Ios Simulator")).findFirst().orElse(null);
37 | }
38 |
39 | default Device getFirstAndroidDevice() throws IOException, DeviceNotFoundException {
40 | return getDevices().stream().filter(device -> device.getDeviceProductName().contains("Android")).filter(device -> device.getSerialNumber() != null).filter(device -> !device.getModelNumber().contains("SDK")).findFirst().orElse(null);
41 | }
42 |
43 | default Device getFirstAndroidEmulatorDevice() throws IOException, DeviceNotFoundException {
44 | return getDevices().stream().filter(device -> device.getDeviceProductName().contains("Android")).filter(device -> device.getSerialNumber() == null).filter(device -> device.getModelNumber().contains("SDK")).findFirst().orElse(null);
45 | }
46 |
47 | default Device getFirstIosDevice() throws IOException, DeviceNotFoundException {
48 | return getDevices().stream().filter(device -> device.getDeviceProductName().contains("Ios")).findFirst().orElse(null);
49 | }
50 |
51 | default Device getFirstIosSimulatorDevice() throws IOException, DeviceNotFoundException {
52 | return getDevices().stream().filter(device -> device.getDeviceProductName().contains("Ios Simulator")).findFirst().orElse(null);
53 | }
54 |
55 | default List getAndroidDevices() throws IOException, DeviceNotFoundException {
56 | return getAndroidDevices();
57 | }
58 |
59 | default List getAndroidEmulatorDevices() throws IOException, DeviceNotFoundException {
60 | return getAndroidDevices().stream().filter(device -> device.getDeviceProductName().contains("Android")).filter(device -> device.getSerialNumber() == null).filter(device -> device.getModelNumber().contains("SDK")).collect(Collectors.toList());
61 | }
62 |
63 | default List getIosDevices() throws IOException, DeviceNotFoundException {
64 | return getIosDevices();
65 | }
66 |
67 | default List getIosSimulatorDevices() throws IOException, DeviceNotFoundException {
68 | return getIosSimulatorDevices();
69 | }
70 |
71 | // default Device searchDeviceByName(String name) throws IOException, DeviceNotFoundException {
72 | // return getDevices().stream().filter(device -> device.getDeviceProductName().equals(name)).findFirst().orElse(null);
73 | // }
74 |
75 | List getDevices() throws IOException, DeviceNotFoundException;
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/testinium/deviceinformation/DeviceInfoImpl.java:
--------------------------------------------------------------------------------
1 | package com.testinium.deviceinformation;
2 |
3 | import com.testinium.deviceinformation.device.DeviceFinder;
4 | import com.testinium.deviceinformation.device.DeviceFinderFactory;
5 | import com.testinium.deviceinformation.device.DeviceType;
6 | import com.testinium.deviceinformation.exception.DeviceNotFoundException;
7 | import com.testinium.deviceinformation.model.Android;
8 | import com.testinium.deviceinformation.model.Device;
9 | import com.testinium.deviceinformation.model.Ios;
10 | import com.testinium.deviceinformation.model.IosSimulator;
11 | import org.apache.commons.exec.OS;
12 | import org.apache.commons.lang3.StringUtils;
13 |
14 | import java.io.IOException;
15 | import java.util.List;
16 |
17 | public class DeviceInfoImpl implements DeviceInfo {
18 |
19 | private DeviceFinder deviceFinder;
20 |
21 | public DeviceInfoImpl(DeviceType deviceType) throws UnsupportedOperationException {
22 | if (!StringUtils.isEmpty(System.getProperty("key"))) {
23 | throw new IllegalArgumentException(getClass().getSimpleName() + " - " + System.getProperty("key") + " - will not work if you have any key value.");
24 | }
25 |
26 | if (deviceType == DeviceType.IOS && !isOperationSystemMacOs()) {
27 | throw new UnsupportedOperationException("Operation System Is Not Valid! Ios device info only run macos operation system.");
28 | }
29 |
30 | if (deviceType == DeviceType.IOSSIMULATOR && !isOperationSystemMacOs()) {
31 | throw new UnsupportedOperationException("Operation System Is Not Valid! Ios Simulator device info only run macos operation system.");
32 | }
33 |
34 | deviceFinder = DeviceFinderFactory.createDeviceFinder(deviceType);
35 | }
36 |
37 | private boolean isOperationSystemMacOs() {
38 | return OS.isFamilyMac();
39 | }
40 |
41 | @Override
42 | public List getDevices() throws IOException, DeviceNotFoundException {
43 | return deviceFinder.findDevices().getDevices();
44 | }
45 |
46 | @Override
47 | public List getAndroidDevices() throws IOException, DeviceNotFoundException {
48 | return deviceFinder.findDevices().getAndroidDevices();
49 | }
50 |
51 | @Override
52 | public List getIosDevices() throws IOException, DeviceNotFoundException {
53 | return deviceFinder.findDevices().getIosDevices();
54 | }
55 |
56 | @Override
57 | public List getIosSimulatorDevices() throws IOException, DeviceNotFoundException {
58 | return deviceFinder.findDevices().getIosSimulatorDevices();
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/testinium/deviceinformation/device/AllDeviceFinder.java:
--------------------------------------------------------------------------------
1 | package com.testinium.deviceinformation.device;
2 |
3 | import com.testinium.deviceinformation.exception.DeviceNotFoundException;
4 | import com.testinium.deviceinformation.model.*;
5 |
6 | import java.io.IOException;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | public class AllDeviceFinder implements DeviceFinder {
12 |
13 | private DeviceType deviceType;
14 |
15 | public AllDeviceFinder(DeviceType deviceType) {
16 | this.deviceType = deviceType;
17 | }
18 |
19 | public AllDeviceFinder() { }
20 |
21 | @Override
22 | public DeviceInfoModel findDevices(String localPath) throws IOException {
23 | DeviceInfoModel deviceDeviceInfoModel = new DeviceInfoModel<>();
24 | List devices = new ArrayList<>();
25 |
26 | List deviceAndroid = new AndroidDeviceFinder().findDevices(localPath).getDevices();
27 | List deviceIos = new IosDeviceFinder().findDevices(localPath).getDevices();
28 | List deviceIosSimulator = null;
29 |
30 | if (deviceType == DeviceType.ALLANDIOSSIMULATOR)
31 | deviceIosSimulator = new IosSimulatorDeviceFinder().findDevices(localPath).getDevices();
32 |
33 | if (deviceAndroid != null)
34 | devices.addAll(deviceAndroid);
35 | if (deviceIos != null)
36 | devices.addAll(deviceIos);
37 | if (deviceIosSimulator != null)
38 | devices.addAll(deviceIosSimulator);
39 | if(deviceAndroid == null && deviceIos == null && deviceType == null || deviceAndroid == null && deviceIos == null && deviceIosSimulator.size() == 0){
40 | try {
41 | throw new DeviceNotFoundException("No device is plugged in !!!");
42 | }catch (DeviceNotFoundException e){
43 | System.err.println(e.toString());
44 | }
45 | }
46 | deviceDeviceInfoModel.setDevices(devices);
47 | return deviceDeviceInfoModel;
48 | }
49 |
50 | @Override
51 | public Map readDeviceInfo(String localPath) {
52 | return null;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/testinium/deviceinformation/device/AndroidDeviceFinder.java:
--------------------------------------------------------------------------------
1 | package com.testinium.deviceinformation.device;
2 |
3 | import com.google.gson.reflect.TypeToken;
4 | import com.testinium.deviceinformation.exception.DeviceNotFoundException;
5 | import com.testinium.deviceinformation.helper.JsonHelper;
6 | import com.testinium.deviceinformation.helper.ProcessHelper;
7 | import com.testinium.deviceinformation.model.Android;
8 | import com.testinium.deviceinformation.model.DeviceInfoModel;
9 | import org.apache.commons.lang3.StringUtils;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.IOException;
13 | import java.io.InputStreamReader;
14 | import java.util.ArrayList;
15 | import java.util.HashMap;
16 | import java.util.List;
17 | import java.util.Map;
18 |
19 | public class AndroidDeviceFinder implements DeviceFinder {
20 |
21 | private final String ADB_LIST_SHELL_COMMAND = "adb devices";
22 | private final String ADB_SERIAL_NUMBER_PUT_SHELL_COMMAND = "adb -s serialNumber shell getprop";
23 | private final String ADB_INTEGRATED_CIRCUIT_CARD_IDENTITY_SHELL_COMMAND = "adb -s serialNumber shell dumpsys CustomFrequencyManagerService | grep 'mIccid sim'";
24 |
25 | @Override
26 | public DeviceInfoModel findDevices(String localPath) throws IOException {
27 | DeviceInfoModel deviceInfoModel = JsonHelper.convertJsonToDeviceInfo(readDeviceInfo(localPath), new TypeToken>() {});
28 | if (deviceInfoModel == null || (deviceInfoModel.getDevices() == null || deviceInfoModel.getDevices().size() == 0)) {
29 | try {
30 | throw new DeviceNotFoundException("Android Device Not Found !!!");
31 | }catch (DeviceNotFoundException e){
32 | System.err.println(e.toString());
33 | }
34 | }
35 | return deviceInfoModel;
36 | }
37 |
38 | @Override
39 | public Map readDeviceInfo(String localPath) throws IOException {
40 | Map parentMap;
41 | List