Skip to content

Commit 0da9b2b

Browse files
authored
Merge pull request #37 from jpage4500/feature/02-05
bugfixes; allow audio passthrough via scrcpy; logging changes
2 parents dba31ca + 13f7062 commit 0da9b2b

File tree

9 files changed

+203
-55
lines changed

9 files changed

+203
-55
lines changed

src/main/java/com/jpage4500/devicemanager/data/LogEntry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public LogEntry(String line, SimpleDateFormat dateFormat, int year) {
3535
String timeStr = lineArr[1];
3636
// remove micro-seconds (could be useful to parse but not necessary to display today)
3737
if (timeStr.length() > 4) timeStr = timeStr.substring(0, timeStr.length() - 4);
38-
// NOTE: appending year is necessary to parse to Date correctly
39-
date = year + "-" + dayStr + " " + timeStr;
38+
date = dayStr + " " + timeStr;
4039
try {
41-
Date eventDate = dateFormat.parse(date);
40+
// NOTE: appending year is necessary to parse to Date correctly
41+
Date eventDate = dateFormat.parse(year + "-" + date);
4242
timestamp = eventDate.getTime();
4343
} catch (Exception e) {
4444
System.out.println("Exception: " + date);

src/main/java/com/jpage4500/devicemanager/manager/DeviceManager.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void mirrorDevice(Device device, TaskListener listener) {
584584
appResult = runApp(app, true, "-s", device.serial,
585585
"-p", String.valueOf(port),
586586
"--window-title", device.getDisplayName(),
587-
"--show-touches", "--stay-awake", "--no-audio");
587+
"--show-touches", "--stay-awake");
588588
}
589589

590590
// TODO: figure out how to determine if scrcpy was run successfully..
@@ -1090,7 +1090,13 @@ private Map<String, String> getProcessMap(Device device) {
10901090
// 7617 com.android.traceur
10911091
// 7677 [csf_sync_update]
10921092
Map<String, String> pidMap = new HashMap<>();
1093-
for (String line : result.resultList) {
1093+
List<String> resultList = result.resultList;
1094+
for (int i = 0; i < resultList.size(); i++) {
1095+
String line = resultList.get(i);
1096+
if (i == 0 && TextUtils.startsWith(line, "bad pid")) {
1097+
// older devices may not support the ps args.. try another route
1098+
return getProcessMapAlternative(device);
1099+
}
10941100
String[] lineArr = line.trim().split(" ");
10951101
if (lineArr.length < 2) continue;
10961102
String pid = lineArr[0];
@@ -1104,6 +1110,47 @@ private Map<String, String> getProcessMap(Device device) {
11041110
return pidMap;
11051111
}
11061112

1113+
private Map<String, String> getProcessMapAlternative(Device device) {
1114+
ShellResult result = runShell(device, "ps");
1115+
// USER PID PPID VSIZE RSS WCHAN PC NAME
1116+
// root 1 0 21964 2880 SyS_epoll_ 00004d9054 S /init
1117+
// root 2 0 0 0 kthreadd 0000000000 S kthreadd
1118+
// root 3 2 0 0 smpboot_th 0000000000 S ksoftirqd/0
1119+
// bluetooth 30891 236 1061340 16884 SyS_epoll_ 00f5597304 S com.android.bluetooth
1120+
// u0_a74 30946 235 1468852 33996 SyS_epoll_ 7fa5ce1870 S com.ttxapps.wifiadb
1121+
// u0_a55 31235 235 1464020 32072 SyS_epoll_ 7fa5ce1870 S com.cyanogenmod.lockclock
1122+
Map<String, String> pidMap = new HashMap<>();
1123+
List<String> resultList = result.resultList;
1124+
int indexPid = -1;
1125+
int indexApp = -1;
1126+
for (String line : resultList) {
1127+
List<String> pidList = TextUtils.splitSafe(line);
1128+
if (pidList.size() < 2) continue;
1129+
1130+
if (indexApp == -1 || indexPid == -1) {
1131+
for (int i = 0; i < pidList.size(); i++) {
1132+
String label = pidList.get(i);
1133+
if (TextUtils.equals(label, "PID")) {
1134+
indexPid = i;
1135+
} else if (TextUtils.equals(label, "NAME")) {
1136+
indexApp = i;
1137+
// special case
1138+
if (pidList.size() == 8) indexApp++;
1139+
}
1140+
}
1141+
} else if (indexPid < pidList.size() && indexApp < pidList.size()) {
1142+
String pid = pidList.get(indexPid);
1143+
String app = pidList.get(indexApp);
1144+
int atPos = app.indexOf('@');
1145+
if (atPos > 0) {
1146+
app = app.substring(0, atPos);
1147+
}
1148+
pidMap.put(pid, app);
1149+
}
1150+
}
1151+
return pidMap;
1152+
}
1153+
11071154
public void stopLogging(Device device) {
11081155
AtomicBoolean loggingState = getLoggingState(device.serial, false);
11091156
if (loggingState != null && loggingState.get()) {

src/main/java/com/jpage4500/devicemanager/table/LogsTableModel.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class LogsTableModel extends AbstractTableModel {
2222
private String searchText;
2323

2424
private Columns[] visibleColumns;
25+
private int dateColumnWidth = 0;
2526

2627
/**
2728
* get text value for a given LogEntry and column
@@ -31,7 +32,20 @@ public String getTextValue(int row, int column) {
3132
if (logEntry == null) return null;
3233
Columns col = visibleColumns[column]; //LogsTableModel.Columns.values()[column];
3334
return switch (col) {
34-
case DATE -> logEntry.date;
35+
case DATE -> {
36+
// 05-13 15:20:12
37+
if (logEntry.date != null) {
38+
// TODO: 150 will vary based on font size
39+
if (dateColumnWidth < 150) {
40+
// truncate
41+
int space = logEntry.date.indexOf(' ');
42+
if (space > 0) {
43+
yield logEntry.date.substring(space + 1);
44+
}
45+
}
46+
}
47+
yield logEntry.date;
48+
}
3549
case APP -> {
3650
// set app using app <-> pid list
3751
logEntry.app = getAppForPid(logEntry.pid);
@@ -48,6 +62,11 @@ public String getTextValue(int row, int column) {
4862
};
4963
}
5064

65+
public void setDateColumnWidth(int width) {
66+
dateColumnWidth = width;
67+
fireTableDataChanged();
68+
}
69+
5170
public enum Columns {
5271
DATE("Date"),
5372
APP("App"),

src/main/java/com/jpage4500/devicemanager/ui/DeviceScreen.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public void setupTable() {
311311
table.setRowSorter(sorter);
312312

313313
table.setDoubleClickListener((row, column, e) -> {
314+
log.trace("table.setDoubleClickListener: row: {}, column: {}", row, column);
314315
if (column == DeviceTableModel.Columns.CUSTOM1.ordinal()) {
315316
// edit custom 1 field
316317
handleSetProperty(Device.CUSTOM_PROP_X + 1, DeviceTableModel.Columns.CUSTOM1.toString());
@@ -321,12 +322,10 @@ public void setupTable() {
321322
return;
322323
} else if (column == DeviceTableModel.Columns.PHONE.ordinal()) {
323324
Device device = getFirstSelectedDevice();
324-
if (device != null) {
325-
if (TextUtils.isEmpty(device.phone)) {
326-
// edit phone number field
327-
handleSetProperty(Device.CUST_PROP_PHONE, "Device Phone Number");
328-
return;
329-
}
325+
if (device != null && TextUtils.isEmpty(device.phone)) {
326+
// edit phone number field
327+
handleSetProperty(Device.CUST_PROP_PHONE, "Device Phone Number");
328+
return;
330329
}
331330
}
332331
// default double-click action
@@ -547,7 +546,7 @@ public void handleException(Exception e) {
547546
SwingUtilities.invokeLater(() -> {
548547
String[] choices = {"Retry", "Cancel"};
549548
if (!DialogHelper.showOptionDialog(DeviceScreen.this, "ADB Server",
550-
"Unable to connect to ADB server. Please check that it's running and re-try", choices)) return;
549+
"Unable to connect to ADB server. Please check that it's running and re-try", choices)) return;
551550

552551
connectAdbServer();
553552
});

0 commit comments

Comments
 (0)