Browse Source

Add LeakCanary library, fix a few memory leaks

master
Anthony Restaino 9 years ago
parent
commit
5dff2db5df
  1. 15
      app/app.iml
  2. 9
      app/build.gradle
  3. 2
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  4. 3
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  5. 12
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  6. 4
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

15
app/app.iml

@ -98,6 +98,7 @@ @@ -98,6 +98,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.squareup.leakcanary/leakcanary-android/1.3.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/net.i2p.android/client/0.7/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
@ -117,17 +118,21 @@ @@ -117,17 +118,21 @@
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="client-0.7" level="project" />
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="leakcanary-analyzer-1.3.1" level="project" />
<orderEntry type="library" exported="" name="jsr250-api-1.0" level="project" />
<orderEntry type="library" exported="" name="dagger-2.0.1" level="project" />
<orderEntry type="library" exported="" name="leakcanary-watcher-1.3.1" level="project" />
<orderEntry type="library" exported="" name="otto-1.3.8" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="haha-1.3" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.8.1" level="project" />
<orderEntry type="library" exported="" name="leakcanary-android-1.3.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="library" exported="" name="otto-1.3.8" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.0.1" level="project" />
<orderEntry type="module" module-name="libnetcipher" exported="" />
</component>
</module>

9
app/build.gradle

@ -55,9 +55,14 @@ dependencies { @@ -55,9 +55,14 @@ dependencies {
// Only Lightning Plus needs the proxy libraries
lightningPlusCompile 'net.i2p.android:client:0.7'
lightningPlusCompile(project(':libnetcipher'))
provided 'javax.annotation:jsr250-api:1.0'
// Use the following code to update the libnetcipher submodule
// git submodule foreach git reset --hard
// git submodule update --remote
lightningPlusCompile(project(':libnetcipher'))
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
provided 'javax.annotation:jsr250-api:1.0'
}

2
app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java

@ -29,7 +29,7 @@ public class ProxyUtils { @@ -29,7 +29,7 @@ public class ProxyUtils {
private ProxyUtils(Context context) {
mPreferences = PreferenceManager.getInstance();
mI2PHelper = new I2PAndroidHelper(context);
mI2PHelper = new I2PAndroidHelper(context.getApplicationContext());
}
public static ProxyUtils getInstance(@NonNull Context context) {

3
app/src/main/java/acr/browser/lightning/app/BrowserApp.java

@ -3,6 +3,8 @@ package acr.browser.lightning.app; @@ -3,6 +3,8 @@ package acr.browser.lightning.app;
import android.app.Application;
import android.content.Context;
import com.squareup.leakcanary.LeakCanary;
public class BrowserApp extends Application {
private static Context context;
@ -12,6 +14,7 @@ public class BrowserApp extends Application { @@ -12,6 +14,7 @@ public class BrowserApp extends Application {
public void onCreate() {
super.onCreate();
context = getApplicationContext();
LeakCanary.install(this);
buildDepencyGraph();
}

12
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -51,7 +51,7 @@ public class BookmarkManager { @@ -51,7 +51,7 @@ public class BookmarkManager {
private final String DEFAULT_BOOKMARK_TITLE;
private Map<String, HistoryItem> mBookmarksMap = new HashMap<>();
private final Map<String, HistoryItem> mBookmarksMap = new HashMap<>();
// private final List<HistoryItem> mBookmarkList = new ArrayList<>();
private String mCurrentFolder = "";
private final ExecutorService mExecutor;
@ -84,8 +84,8 @@ public class BookmarkManager { @@ -84,8 +84,8 @@ public class BookmarkManager {
}
/**
* Initialize the Bookmaneger, it's a one-time operation and will be executed asynchronously.
* When done, mReady flag will been setted to true.
* Initialize the BookmarkManager, it's a one-time operation and will be executed asynchronously.
* When done, mReady flag will been set to true.
*/
private class BookmarkInitializer implements Runnable{
private final Context mContext;
@ -131,7 +131,8 @@ public class BookmarkManager { @@ -131,7 +131,8 @@ public class BookmarkManager {
} finally {
Utils.close(bookmarksReader);
}
mBookmarksMap = bookmarks;
mBookmarksMap.clear();
mBookmarksMap.putAll(bookmarks);
mReady = true;
}
}
@ -282,7 +283,8 @@ public class BookmarkManager { @@ -282,7 +283,8 @@ public class BookmarkManager {
bookmarks.put(url, item);
}
}
mBookmarksMap = bookmarks;
mBookmarksMap.clear();
mBookmarksMap.putAll(bookmarks);
mExecutor.execute(new BookmarksWriter(new LinkedList<>(mBookmarksMap.values())));
}

4
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -353,11 +353,11 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -353,11 +353,11 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
private File downloadSuggestionsForQuery(String query) {
File cacheFile = new File(mContext.getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
File cacheFile = new File(BrowserApp.getAppContext().getCacheDir(), query.hashCode() + CACHE_FILE_TYPE);
if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) {
return cacheFile;
}
if (!isNetworkConnected(mContext)) {
if (!isNetworkConnected(BrowserApp.getAppContext())) {
return cacheFile;
}
InputStream in = null;

Loading…
Cancel
Save