-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
107 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 77 additions & 28 deletions
105
jadx-gui/src/main/java/jadx/gui/device/protocol/ADBDeviceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,91 @@ | ||
package jadx.gui.device.protocol; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import jadx.core.utils.log.LogUtils; | ||
|
||
public class ADBDeviceInfo { | ||
public String adbHost; | ||
public int adbPort; | ||
public String serial; | ||
public String state; | ||
public String model; | ||
public String allInfo; | ||
private static final Logger LOG = LoggerFactory.getLogger(ADBDeviceInfo.class); | ||
private final String adbHost; | ||
private final int adbPort; | ||
private final String serial; | ||
private final String state; | ||
private final String model; | ||
private final String allInfo; | ||
|
||
/** | ||
* Store the device info property values like "device" "model" "product" or "transport_id" | ||
*/ | ||
private final Map<String, String> propertiesMap = new TreeMap<>(); | ||
|
||
ADBDeviceInfo(String info, String host, int port) { | ||
String[] infoFields = info.trim().split("\\s+"); | ||
allInfo = String.join(" ", infoFields); | ||
if (infoFields.length > 2) { | ||
serial = infoFields[0]; | ||
state = infoFields[1]; | ||
|
||
for (int i = 2; i < infoFields.length; i++) { | ||
String field = infoFields[i]; | ||
int idx = field.indexOf(':'); | ||
if (idx > 0) { | ||
String key = field.substring(0, idx); | ||
String value = field.substring(idx + 1); | ||
if (!value.isEmpty()) { | ||
propertiesMap.put(key, value); | ||
} | ||
} | ||
} | ||
model = propertiesMap.getOrDefault("model", serial); | ||
} else { | ||
LOG.error("Unable to extract device information from {}", LogUtils.escape(info)); | ||
serial = ""; | ||
state = "unknown"; | ||
model = "unknown"; | ||
} | ||
adbHost = host; | ||
adbPort = port; | ||
} | ||
|
||
public boolean isOnline() { | ||
return state.equals("device"); | ||
} | ||
|
||
public String getAdbHost() { | ||
return adbHost; | ||
} | ||
|
||
public int getAdbPort() { | ||
return adbPort; | ||
} | ||
|
||
public String getSerial() { | ||
return serial; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public String getModel() { | ||
return model; | ||
} | ||
|
||
public String getAllInfo() { | ||
return allInfo; | ||
} | ||
|
||
public String getProperty(String key) { | ||
return this.propertiesMap.get(key); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return allInfo; | ||
} | ||
|
||
static ADBDeviceInfo make(String info, String host, int port) { | ||
ADBDeviceInfo deviceInfo = new ADBDeviceInfo(); | ||
String[] infoFields = info.trim().split("\\s+"); | ||
deviceInfo.allInfo = String.join(" ", infoFields); | ||
if (infoFields.length > 2) { | ||
deviceInfo.serial = infoFields[0]; | ||
deviceInfo.state = infoFields[1]; | ||
} | ||
int pos = info.indexOf("model:"); | ||
if (pos != -1) { | ||
int spacePos = info.indexOf(" ", pos); | ||
if (spacePos != -1) { | ||
deviceInfo.model = info.substring(pos + "model:".length(), spacePos); | ||
} | ||
} | ||
if (deviceInfo.model == null || deviceInfo.model.equals("")) { | ||
deviceInfo.model = deviceInfo.serial; | ||
} | ||
deviceInfo.adbHost = host; | ||
deviceInfo.adbPort = port; | ||
return deviceInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters