From f6c8fdf93ee7fc4edff43d50769ac68ca47be71d Mon Sep 17 00:00:00 2001 From: Dan Watling Date: Sat, 16 Jan 2016 05:17:47 -0600 Subject: [PATCH] - Fixed issue #5. Empty results will generate a nice message. --- .../com/danwatling/apkdecompiler/adb/Adb.java | 32 +++++++++---------- .../apkdecompiler/steps/FetchApk.java | 23 ++++++------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/danwatling/apkdecompiler/adb/Adb.java b/src/main/java/com/danwatling/apkdecompiler/adb/Adb.java index ca8634d..7618750 100644 --- a/src/main/java/com/danwatling/apkdecompiler/adb/Adb.java +++ b/src/main/java/com/danwatling/apkdecompiler/adb/Adb.java @@ -81,26 +81,26 @@ private boolean exec(String command) { } public List listPackages(String filter) { - if (!exec("pm list packages -3 -f " + filter)) { - return null; - } - String output = getProcessOutput(process.getInputStream()); - BufferedReader reader = new BufferedReader(new StringReader(output)); - Logger.info(output); - List result = new ArrayList<>(); - String line; - try { - while ((line = reader.readLine()) != null) { - if (line.trim().length() > 0) { - AndroidPackage pkg = new AndroidPackage(line); - if (pkg.getPath() != null) { - result.add(pkg); + + if (exec("pm list packages -3 -f " + filter)) { + String output = getProcessOutput(process.getInputStream()); + BufferedReader reader = new BufferedReader(new StringReader(output)); + Logger.info(output); + + String line; + try { + while ((line = reader.readLine()) != null) { + if (line.trim().length() > 0) { + AndroidPackage pkg = new AndroidPackage(line); + if (pkg.getPath() != null) { + result.add(pkg); + } } } + } catch (IOException ex) { + Logger.error("Unable to process output of 'pm list packages'", ex); } - } catch (IOException ex) { - Logger.error("Unable to process output of 'pm list packages'", ex); } return result; } diff --git a/src/main/java/com/danwatling/apkdecompiler/steps/FetchApk.java b/src/main/java/com/danwatling/apkdecompiler/steps/FetchApk.java index f076de3..894ecff 100644 --- a/src/main/java/com/danwatling/apkdecompiler/steps/FetchApk.java +++ b/src/main/java/com/danwatling/apkdecompiler/steps/FetchApk.java @@ -26,22 +26,23 @@ public FetchApk(File workFolder, String filter, File apkFile) { } public boolean run() { - boolean result = true; + boolean result = false; try { List packages = adb.listPackages(this.filter); - if (packages == null) { - return false; - } - - if (packages.size() > 1) { - Logger.info("Found " + packages.size() + " applications that match: " + this.filter); - for (AndroidPackage p : packages) { - Logger.info("\t" + p.getPath() + " - " + p.getPackage()); + if (packages.size() > 0) { + if (packages.size() > 1) { + Logger.info("Found " + packages.size() + " applications that match: " + this.filter); + for (AndroidPackage p : packages) { + Logger.info("\t" + p.getPath() + " - " + p.getPackage()); + } } - } - adb.pull(packages.get(0), this.apkFile); + adb.pull(packages.get(0), this.apkFile); + result = true; + } else { + Logger.info("No applications matched '" + this.filter + "'"); + } } finally { adb.exit(); }