package de.philipphager.disclosure.feature.analyser.app;

import dalvik.system.DexFile;
import de.philipphager.disclosure.database.app.model.App;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import rx.Observable;
import timber.log.Timber;

public class Apk {
  private static final int MIN_INDEX = 0;
  private final App app;
  private List<String> sortedClassNames;

  public Apk(App app) throws IOException {
    this.app = app;
    load();
  }

  private void load() throws IOException {
    DexFile dexFile = new DexFile(app.sourceDir());
    List<String> classNames = Collections.list(dexFile.entries());

    sortedClassNames = Observable.from(classNames)
        .distinct()
        .toSortedList()
        .toBlocking()
        .first();
  }

  public boolean containsPackage(String packageName) {
    String currentThread = Thread.currentThread().getName();
    Timber.d("%s : Searching for package %s in app %s", currentThread, packageName, app.label());

    int index = Collections.binarySearch(sortedClassNames, packageName, (currentItem, key) -> {
      if(currentItem.startsWith(key)) {
        return 0;
      }
      return currentItem.compareTo(key);
    });
    return index >= MIN_INDEX;
  }
}

@@ -154,27 +154,76 @@
 java.io.
-IOException
+File;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList
 ;%0Aimport
@@ -577,20 +577,14 @@
     
-Dex
 File 
-dexF
+f
 ile 
@@ -589,19 +589,16 @@
 e = new 
-Dex
 File(app
@@ -642,16 +642,139 @@
 Names = 
+new ArrayList%3C%3E();%0A%0A    if (file.exists()) %7B%0A      DexFile dexFile = new DexFile(app.sourceDir());%0A      classNames.addAll(
 Collecti
@@ -800,17 +800,24 @@
 tries())
+)
 ;
+%0A    %7D
 %0A%0A    so
@@ -1265,16 +1265,16 @@
 %3E %7B%0A
-
       if
 (cur
@@ -1269,16 +1269,17 @@
       if
+ 
 (current

Fix not existing .apks failing