Skip to content

Commit

Permalink
- Fixed issue #5. Empty results will generate a nice message.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Watling committed Jan 16, 2016
1 parent 5423b4d commit f6c8fdf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
32 changes: 16 additions & 16 deletions src/main/java/com/danwatling/apkdecompiler/adb/Adb.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ private boolean exec(String command) {
}

public List<AndroidPackage> 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<AndroidPackage> 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;
}
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/danwatling/apkdecompiler/steps/FetchApk.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ public FetchApk(File workFolder, String filter, File apkFile) {
}

public boolean run() {
boolean result = true;
boolean result = false;

try {
List<AndroidPackage> 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();
}
Expand Down

0 comments on commit f6c8fdf

Please sign in to comment.