Skip to content

Commit 62b530d

Browse files
committed
fix #401
1 parent 5def460 commit 62b530d

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

cSploit/src/org/csploit/android/plugins/mitm/Sniffer.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,59 +145,68 @@ else if(va < vb)
145145
}
146146
}
147147

148-
public class StatListAdapter extends ArrayAdapter<AddressStats>{
148+
public class StatListAdapter extends ArrayAdapter<AddressStats> {
149149
private int mLayoutId = 0;
150-
private ArrayList<AddressStats> mStats = null;
150+
private final ArrayList<AddressStats> mStats;
151151

152-
public class StatsHolder{
152+
public class StatsHolder {
153153
TextView address;
154154
TextView description;
155155
}
156156

157-
public StatListAdapter(int layoutId){
157+
public StatListAdapter(int layoutId) {
158158
super(Sniffer.this, layoutId);
159159

160160
mLayoutId = layoutId;
161-
mStats = new ArrayList<AddressStats>();
161+
mStats = new ArrayList<>();
162162
}
163163

164-
public AddressStats getStats(String address){
165-
for(AddressStats stats : mStats){
166-
if(stats.mAddress.equals(address))
167-
return stats;
164+
public AddressStats getStats(String address) {
165+
synchronized (mStats) {
166+
for (AddressStats stats : mStats) {
167+
if (stats.mAddress.equals(address))
168+
return stats;
169+
}
168170
}
169171

170172
return null;
171173
}
172174

173-
public synchronized void addStats(AddressStats stats){
175+
public synchronized void addStats(AddressStats stats) {
174176
boolean found = false;
175177

176-
for(AddressStats sstats : mStats){
177-
if(sstats.mAddress.equals(stats.mAddress)){
178-
sstats.mBytes = stats.mBytes;
179-
sstats.mBandwidth = stats.mBandwidth;
180-
sstats.mSampledTime = stats.mSampledTime;
181-
sstats.mSampledBytes = stats.mSampledBytes;
178+
synchronized (mStats) {
182179

183-
found = true;
184-
break;
180+
for (AddressStats sstats : mStats) {
181+
if (sstats.mAddress.equals(stats.mAddress)) {
182+
sstats.mBytes = stats.mBytes;
183+
sstats.mBandwidth = stats.mBandwidth;
184+
sstats.mSampledTime = stats.mSampledTime;
185+
sstats.mSampledBytes = stats.mSampledBytes;
186+
187+
found = true;
188+
break;
189+
}
185190
}
186-
}
187191

188-
if(!found)
189-
mStats.add(stats);
192+
if (!found)
193+
mStats.add(stats);
190194

191-
Collections.sort(mStats);
195+
Collections.sort(mStats);
196+
}
192197
}
193198

194-
private synchronized AddressStats getByPosition(int position){
195-
return mStats.get(position);
199+
private synchronized AddressStats getByPosition(int position) {
200+
synchronized (mStats) {
201+
return mStats.get(position);
202+
}
196203
}
197204

198205
@Override
199206
public int getCount(){
200-
return mStats.size();
207+
synchronized (mStats) {
208+
return mStats.size();
209+
}
201210
}
202211

203212
private String formatSize(long size){

0 commit comments

Comments
 (0)