Try to limit memory retention when downloading reports to avoid Out of

memory
Fix #57
This commit is contained in:
Schoumi 2019-10-01 15:46:11 +02:00
parent 3d0c16f9d4
commit 52e43fb849
3 changed files with 48 additions and 25 deletions

View File

@ -12,7 +12,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning"
android:largeHeap="true"
>
<activity android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
>

View File

@ -46,6 +46,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.Semaphore;
@ -201,8 +202,14 @@ public class NetworkManager {
JSONObject tracker = trackers.getJSONObject(trackerId);
Tracker track = parseTracker(tracker,trackerId);
trackersList.add(track);
}
if (trackersList.size() == 20) {
DatabaseManager.getInstance(mes.context).insertOrUpdateTrackers(trackersList);
trackersList.clear();
}
}
if(!trackersList.isEmpty())
DatabaseManager.getInstance(mes.context).insertOrUpdateTrackers(trackersList);
trackersList.clear();
} catch (JSONException e) {
mes.listener.onError(mes.context.getString(R.string.json_error));
}
@ -225,40 +232,55 @@ public class NetworkManager {
if(object != null) {
Map<String,String> handles = new HashMap<>();
ArrayList<String> packages = mes.args.getStringArrayList("packages");
if (packages == null)
return;
try {
JSONArray applications = object.getJSONArray("applications");
//manage handles map (handle,UAID)
for(int i = 0; i<applications.length(); i++) {
JSONObject app = applications.getJSONObject(i);
String handle = app.getString("handle");
String auid = app.getString("app_uid");
app.remove("id");
app.remove("name");
app.remove("creator");
app.remove("icon_phash");
app.remove("downloads");
if (packages.contains(handle))
handles.put(handle,auid);
}
} catch (JSONException e) {
mes.listener.onError(mes.context.getString(R.string.json_error));
}
getReports(mes,handles);
}
mes.listener.onSuccess();
app.remove("app_uid");
}
private void getReports(Message mes, Map<String,String> handles) {
ArrayList<String> packages = mes.args.getStringArrayList("packages");
if(packages == null)
return;
//remove app not analyzed by Exodus
packages.retainAll(handles.keySet());
// Add some random packages to avoid tracking
Random rand = new Random(Thread.currentThread().getId());
int alea = rand.nextInt(120) % 10 + 11;
List<String> handleList = new ArrayList<>(handles.keySet());
for(int i = 0 ; i < alea; i++) {
int val = rand.nextInt(handleList.size());
packages.add(handleList.get(val));
int val = rand.nextInt(applications.length());
JSONObject app = applications.getJSONObject(val);
String handle = app.getString("handle");
packages.add(handle);
}
//shuffle the list
Collections.shuffle(packages);
object.remove("applications");
} catch (JSONException e) {
e.printStackTrace();
mes.listener.onError(mes.context.getString(R.string.json_error));
}
object = null;
getReports(mes,handles,packages);
}
mes.listener.onSuccess();
}
Collections.shuffle(packages);
private void getReports(Message mes, Map<String, String> handles, ArrayList<String> packages) {
for(int i = 0; i < packages.size(); i++) {
mes.listener.onProgress(R.string.parse_application,i+1,packages.size());
getReport(mes,packages.get(i),handles.get(packages.get(i)));

View File

@ -1,7 +1,6 @@
#Mon May 20 19:52:15 CEST 2019
#Tue Oct 01 11:13:40 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionSha256Sum=14cd15fc8cc8705bd69dcfa3c8fefb27eb7027f5de4b47a8b279218f76895a91