Skip to content

Commit

Permalink
Merge pull request #30 from jpage4500/feature/12-10
Browse files Browse the repository at this point in the history
- download apps (apk) from phone, use property for column, auto-resize all
  • Loading branch information
jpage4500 authored Dec 25, 2024
2 parents cb09082 + 8c0cc4f commit a7b9ae1
Show file tree
Hide file tree
Showing 16 changed files with 382 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private void setupLogging() {
File deviceManagerFolder = Utils.getDeviceManagerFolder();
logger.setFileLog(new File(deviceManagerFolder, "device_manager_log.txt"));

boolean isDebugMode = PreferenceUtils.getPreference(PreferenceUtils.PrefBoolean.PREF_DEBUG_MODE, false);
logger.setFileLogLevel(isDebugMode ? Log.DEBUG : Log.INFO);
int logLevel = PreferenceUtils.getPreference(PreferenceUtils.PrefInt.PREF_LOG_LEVEL, Log.INFO);
logger.setFileLogLevel(logLevel);
} else {
System.out.println("ERROR: no logger found: " + iLoggerFactory.getClass().getSimpleName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public void setFileLogLevel(int fileLogLevel) {
this.fileLogLevel = fileLogLevel;
}

/**
* @return log level which app is logging at
*/
public int getFileLogLevel() {
return fileLogLevel;
}

@Override
public org.slf4j.Logger getLogger(final String name) {
AppLogger appLogger = this.nameToLogMap.get(name);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jpage4500/devicemanager/logging/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public final class Log {
* Priority constant for the println method.
*/
public static final int ASSERT = 7;

}
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ private void fetchDeviceDetails(Device device, boolean fullRefresh, DeviceListen
// -- disk free space --
fetchFreeDiskSpace(device);

// -- version of installed apps --
fetchInstalledAppVersions(device);
// -- custom apps --
fetchCustomColumns(device);

// -- battery level, charging status, etc --
fetchBatteryInfo(device);
Expand Down Expand Up @@ -369,12 +369,32 @@ private void fetchBatteryInfo(Device device) {
}
}

private void fetchInstalledAppVersions(Device device) {
List<String> customApps = SettingsDialog.getCustomApps();
for (String customApp : customApps) {
String versionName = getAppVersion(device, customApp);
if (device.customAppVersionList == null) device.customAppVersionList = new HashMap<>();
device.customAppVersionList.put(customApp, versionName);
private void fetchCustomColumns(Device device) {
List<String> entryList = SettingsDialog.getCustomColumns();
for (String entry : entryList) {
if (TextUtils.isEmpty(entry) || TextUtils.startsWithAny(entry, false, "#", "//")) continue;
String[] entryArr = entry.split(":");
String label = entryArr.length >= 1 ? entryArr[0].trim() : entry;
String type = entryArr.length >= 2 ? entryArr[1].trim() : "VER";
String val = entryArr.length >= 3 ? entryArr[2].trim() : null;

String value = null;
if (TextUtils.equalsIgnoreCase(type, "VER")) {
value = getAppVersion(device, val);
} else if (TextUtils.equalsIgnoreCase(type, "PROP")) {
ShellResult result = runShell(device, "getprop " + val);
log.trace("fetchCustomColumns: {} -> {}", val, result);
if (result.isSuccess) {
value = result.getResult(0);
}
} else {
log.trace("fetchCustomColumns: unknown type:{}", type);
}

if (value != null) {
if (device.customAppVersionList == null) device.customAppVersionList = new HashMap<>();
device.customAppVersionList.put(label, value);
}
}
}

Expand Down Expand Up @@ -479,8 +499,8 @@ public List<Device> getDevices() {
}

public static class ShellResult {
boolean isSuccess;
List<String> resultList;
public boolean isSuccess;
public List<String> resultList;

public String getResult(int index) {
if (resultList != null && resultList.size() > index) return resultList.get(index);
Expand Down Expand Up @@ -697,7 +717,7 @@ public void installApp(Device device, File file, TaskListener listener) {
packageManager.install(file);
if (listener != null) listener.onTaskComplete(true, null);
} catch (Exception e) {
log.error("installApp: {}, {}", file.getAbsolutePath(), e.getMessage());
log.error("installApp: ERROR: {}, file:{}", e.getMessage(), file.getAbsolutePath());
device.status = "failed: " + e.getMessage();
if (listener != null) listener.onTaskComplete(false, e.getMessage());
}
Expand Down Expand Up @@ -750,17 +770,12 @@ public void restartDevice(Device device, TaskListener listener) {
});
}

public void runCustomCommand(Device device, String customCommand, TaskListener listener) {
public void runCustomCommand(Device device, String customCommand, CommandListener listener) {
commandExecutorService.submit(() -> {
ShellResult result = runShell(device, customCommand);
boolean isSuccess = result.isSuccess;
log.trace("runCustomCommand: DONE: success:{}, {}", isSuccess, GsonHelper.toJson(result.resultList));
String displayStr = TextUtils.join(result.resultList, "\n");
// check if command runs but fails
if (TextUtils.containsIgnoreCase(displayStr, "inaccessible or not found")) {
isSuccess = false;
}
if (listener != null) listener.onTaskComplete(isSuccess, displayStr);
if (listener != null) listener.onTaskComplete(result);
});
}

Expand Down Expand Up @@ -847,9 +862,17 @@ public interface TaskListener {
void onTaskComplete(boolean isSuccess, String error);
}

public interface CommandListener {
void onTaskComplete(ShellResult result);
}

public void downloadFile(Device device, String path, DeviceFile file, File saveFile, TaskListener listener) {
log.debug("downloadFile: {}/{} -> {}", path, file.name, saveFile.getAbsolutePath());
commandExecutorService.submit(() -> downloadFileInternal(device, path, file, saveFile));
commandExecutorService.submit(() -> {
downloadFileInternal(device, path, file, saveFile);
// test if file was created
listener.onTaskComplete(saveFile.exists(), null);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DeviceTableModel extends AbstractTableModel {
private static final Logger log = LoggerFactory.getLogger(DeviceTableModel.class);

private final List<Device> deviceList;
private final List<String> appList;
private final List<String> customColumnList;
private Columns[] visibleColumns;

public enum Columns {
Expand Down Expand Up @@ -44,7 +44,7 @@ public String toString() {

public DeviceTableModel() {
deviceList = new ArrayList<>();
appList = new ArrayList<>();
customColumnList = new ArrayList<>();
setHiddenColumns(null);
}

Expand Down Expand Up @@ -125,17 +125,17 @@ public int getRowForDevice(Device device) {
return -1;
}

public void setAppList(List<String> appList) {
if (this.appList.equals(appList)) return;
this.appList.clear();
this.appList.addAll(appList);
public void setCustomColumnList(List<String> appList) {
if (this.customColumnList.equals(appList)) return;
this.customColumnList.clear();
this.customColumnList.addAll(appList);

// update columns
fireTableStructureChanged();
}

public int getColumnCount() {
return visibleColumns.length + appList.size();
return visibleColumns.length + customColumnList.size();
}

@Override
Expand All @@ -148,7 +148,7 @@ public String getColumnName(int i) {
Columns colType = visibleColumns[i];
return colType.toString();
} else {
return appList.get(i - visibleColumns.length);
return customColumnList.get(i - visibleColumns.length);
}
}

Expand Down Expand Up @@ -181,9 +181,9 @@ public String deviceValue(Device device, int column) {
case CUSTOM2 -> device.getCustomProperty(Device.CUST_PROP_2);
};
} else {
// custom app version
// custom columns
if (device.customAppVersionList != null) {
String appName = appList.get(column - visibleColumns.length);
String appName = customColumnList.get(column - visibleColumns.length);
return device.customAppVersionList.get(appName);
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ private int getCellDataWidth(int row, int column) {
*/
private void updateTableColumn(int column, int width) {
final TableColumn tableColumn = table.getColumnModel().getColumn(column);
log.trace("updateTableColumn: col:{}, wid:{}", column, width);
//log.trace("updateTableColumn: col:{}, wid:{}", column, width);
if (!tableColumn.getResizable()) return;

width += spacing;

// Don't shrink the column width

if (isOnlyAdjustLarger) {
width = Math.max(width, tableColumn.getPreferredWidth());
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/jpage4500/devicemanager/ui/BaseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ public void windowClosed(WindowEvent e) {
});

// TODO: handle window resizing
if (PreferenceUtils.getPreference(PreferenceUtils.PrefBoolean.PREF_DEBUG_MODE)) {
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent componentEvent) {
log.trace("componentResized: {}: W:{}, H:{}", prefKey, getWidth(), getHeight());
}
});
}
//addComponentListener(new ComponentAdapter() {
// @Override
// public void componentResized(ComponentEvent componentEvent) {
// log.trace("componentResized: {}: W:{}, H:{}", prefKey, getWidth(), getHeight());
// }
//});

// NOTE: this breaks dragging the scrollbar on Mac
// getRootPane().putClientProperty("apple.awt.draggableWindowBackground", true);
Expand Down
Loading

0 comments on commit a7b9ae1

Please sign in to comment.