Skip to content

Commit 6b0092b

Browse files
authored
Merge pull request #815 from MarcMil/improve-code
Prevent singleton from living on forever
2 parents efc333f + 783924a commit 6b0092b

2 files changed

Lines changed: 11 additions & 34 deletions

File tree

soot-infoflow-android/src/soot/jimple/infoflow/android/iccta/IccInstrumenter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package soot.jimple.infoflow.android.iccta;
22

33
import java.util.ArrayList;
4+
import java.util.Collection;
45
import java.util.HashMap;
56
import java.util.HashSet;
67
import java.util.Iterator;
@@ -44,6 +45,8 @@ public class IccInstrumenter implements PreAnalysisHandler {
4445
protected final Set<SootMethod> processedMethods = new HashSet<>();
4546
protected final MultiMap<Body, Unit> instrumentedUnits = new HashMultiMap<>();
4647

48+
private Collection<SootClass> handlers;
49+
4750
public IccInstrumenter(String iccModel, SootClass dummyMainClass,
4851
ComponentEntryPointCollection componentToEntryPoint) {
4952
this.iccModel = iccModel;
@@ -174,7 +177,8 @@ public void generateSendMessage(SootClass sootClass, Map<Value, String> appClass
174177
if (callee == smMessengerSend || callee == smSendMessage) {
175178
// collect the value for sendMessage()
176179
String hc = appClasses.get(stmt.getInvokeExpr().getUseBoxes().get(1).getValue());
177-
Set<SootClass> handlers = MessageHandler.v().getAllHandlers();
180+
if (handlers == null)
181+
handlers = MessageHandler.getAllHandlers();
178182
for (SootClass handler : handlers) {
179183
// matching the handler and its signature
180184
if (hc != null && handlerInner.get(hc) == handler.getName()) {
Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,19 @@
11
package soot.jimple.infoflow.android.iccta;
22

3-
import java.util.HashSet;
4-
import java.util.Iterator;
5-
import java.util.Set;
3+
import java.util.Collection;
64

75
import soot.Scene;
86
import soot.SootClass;
97

10-
public class MessageHandler {
11-
private static MessageHandler instance = new MessageHandler();
8+
public final class MessageHandler {
129

1310
private MessageHandler() {
14-
};
15-
16-
public static MessageHandler v() {
17-
return instance;
1811
}
1912

20-
private Set<SootClass> handlerImpls = null;
21-
22-
public Set<SootClass> getAllHandlers() {
23-
if (null == handlerImpls) {
24-
handlerImpls = new HashSet<SootClass>();
25-
26-
SootClass handler = Scene.v().getSootClass("android.os.Handler");
27-
28-
for (Iterator<SootClass> iter = Scene.v().getApplicationClasses().snapshotIterator(); iter.hasNext();) {
29-
SootClass sootClass = iter.next();
30-
31-
SootClass tmpClass = sootClass;
32-
33-
while (sootClass != null) {
34-
35-
if (sootClass.getName().equals(handler.getName())) {
36-
handlerImpls.add(tmpClass);
37-
break;
38-
}
39-
sootClass = sootClass.getSuperclassUnsafe();
40-
}
41-
}
42-
}
13+
public static Collection<SootClass> getAllHandlers() {
14+
SootClass handler = Scene.v().getSootClass("android.os.Handler");
15+
Collection<SootClass> h = Scene.v().getOrMakeFastHierarchy().getSubclassesOf(handler);
4316

44-
return handlerImpls;
17+
return h;
4518
}
4619
}

0 commit comments

Comments
 (0)