Skip to content

Commit 8c8073f

Browse files
Move public API for calculating memory footprint (#92)
1 parent df16529 commit 8c8073f

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluator.java

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.gson.Gson;
2323
import com.google.gson.GsonBuilder;
2424
import com.samsung.watchface.WatchFaceXmlValidator;
25-
import com.samsung.watchface.WatchFaceXmlValidator.WatchFaceFormatValidationException;
2625
import java.io.PrintWriter;
2726
import java.io.StringWriter;
2827
import java.util.List;
@@ -116,6 +115,7 @@ static List<MemoryFootprint> evaluateMemoryFootprint(EvaluationSettings evaluati
116115
WatchFaceData watchFaceData =
117116
WatchFaceData.fromResourcesStream(
118117
inputPackage.getWatchFaceFiles(), evaluationSettings);
118+
119119
if (!evaluationSettings.isHoneyfaceMode()) {
120120
String wffVersion =
121121
getWatchFaceFormatVersion(inputPackage.getManifest(), evaluationSettings);
@@ -125,42 +125,9 @@ static List<MemoryFootprint> evaluateMemoryFootprint(EvaluationSettings evaluati
125125
return watchFaceData.getWatchFaceDocuments().stream()
126126
.map(
127127
watchFaceDocument ->
128-
evaluateWatchFaceForLayout(
129-
watchFaceData.getResourceDetailsMap(),
128+
WatchFaceLayoutEvaluator.evaluate(
130129
watchFaceDocument,
131-
evaluationSettings))
132-
.collect(Collectors.toList());
133-
}
134-
}
135-
136-
/**
137-
* Parses a watch face package and evaluates the memory footprint for all of its layouts.
138-
*
139-
* @param evaluationSettings the settings object for running the watch face evaluation.
140-
* @return the list of memory footprints, one for each layout supported by the watch face.
141-
* @throws WatchFaceFormatValidationException if the schema for the validation was not
142-
* available.
143-
* @throws TestFailedException if the watch face memory footprint validation has failed.
144-
*/
145-
public static List<MemoryFootprint> evaluateMemoryFootprintOrThrow(
146-
EvaluationSettings evaluationSettings)
147-
throws TestFailedException, WatchFaceFormatValidationException {
148-
try (InputPackage inputPackage = InputPackage.open(evaluationSettings.getWatchFacePath())) {
149-
WatchFaceData watchFaceData =
150-
WatchFaceData.fromResourcesStream(
151-
inputPackage.getWatchFaceFiles(), evaluationSettings);
152-
if (!evaluationSettings.isHoneyfaceMode()) {
153-
String wffVersion =
154-
getWatchFaceFormatVersion(inputPackage.getManifest(), evaluationSettings);
155-
validateFormatOrThrow(watchFaceData, wffVersion);
156-
}
157-
158-
return watchFaceData.getWatchFaceDocuments().stream()
159-
.map(
160-
watchFaceDocument ->
161-
evaluateWatchFaceForLayout(
162130
watchFaceData.getResourceDetailsMap(),
163-
watchFaceDocument,
164131
evaluationSettings))
165132
.collect(Collectors.toList());
166133
}
@@ -199,20 +166,6 @@ private static String getWatchFaceFormatVersion(
199166
return cliWffVersion != null ? cliWffVersion : manifestWffVersion;
200167
}
201168

202-
private static void validateFormatOrThrow(
203-
WatchFaceData watchFaceData, String watchFaceFormatVersion)
204-
throws WatchFaceFormatValidationException {
205-
WatchFaceXmlValidator xmlValidator = new WatchFaceXmlValidator();
206-
for (Document watchFaceDocument : watchFaceData.getWatchFaceDocuments()) {
207-
boolean documentHasValidSchema =
208-
xmlValidator.validateOrThrow(watchFaceDocument, watchFaceFormatVersion);
209-
if (!documentHasValidSchema) {
210-
throw new TestFailedException(
211-
"Watch Face has syntactic errors and cannot be parsed.");
212-
}
213-
}
214-
}
215-
216169
/**
217170
* Runs the watch face format XSD validation.
218171
*

play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceLayoutEvaluator.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,30 @@
1919
import static com.google.wear.watchface.dfx.memory.DrawableResourceDetails.findInMap;
2020
import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode;
2121

22+
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Set;
25+
import java.util.stream.Collectors;
2426
import org.w3c.dom.Document;
2527

26-
class WatchFaceLayoutEvaluator {
28+
public class WatchFaceLayoutEvaluator {
29+
public static List<MemoryFootprint> evaluate(EvaluationSettings evaluationSettings) {
30+
try (InputPackage inputPackage = InputPackage.open(evaluationSettings.getWatchFacePath())) {
31+
WatchFaceData watchFaceData =
32+
WatchFaceData.fromResourcesStream(
33+
inputPackage.getWatchFaceFiles(), evaluationSettings);
34+
AndroidManifest manifest = inputPackage.getManifest();
35+
String wffVersion = manifest == null ? null : String.valueOf(manifest.getWffVersion());
36+
return watchFaceData.getWatchFaceDocuments().stream()
37+
.map(
38+
watchFaceDocument ->
39+
getMemoryFootprint(
40+
watchFaceDocument,
41+
watchFaceData.getResourceDetailsMap(),
42+
evaluationSettings))
43+
.collect(Collectors.toList());
44+
}
45+
}
2746

2847
static MemoryFootprint evaluate(
2948
Document currentLayout,

0 commit comments

Comments
 (0)