Skip to content

Commit

Permalink
refactor(analytics): obfuscate android id (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-elimu authored Aug 26, 2024
2 parents bdfc51d + bef81b5 commit 0817b90
Show file tree
Hide file tree
Showing 3 changed files with 473 additions and 467 deletions.
7 changes: 6 additions & 1 deletion src/main/java/ai/elimu/model/analytics/LearningEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public void setTimestamp(Calendar timestamp) {
}

public String getAndroidId() {
return androidId;
if (!androidId.contains("***")) {
// Hide parts of the Android ID, e.g. "7161a85a0e4751cd" --> "7161***51cd"
return androidId.substring(0, 4) + "***" + androidId.substring(12);
} else {
return androidId;
}
}

public void setAndroidId(String androidId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ public void handleRequest(
List<StoryBookLearningEvent> storyBookLearningEvents = storyBookLearningEventDao.readAll();
logger.info("storyBookLearningEvents.size(): " + storyBookLearningEvents.size());

CSVFormat csvFormat = CSVFormat.DEFAULT
.withHeader(
"id", // The Room database ID
"timestamp",
"android_id",
"package_name",
"storybook_id",
"storybook_title",
"learning_event_type"
);
CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
.setHeader(
"id", // The Room database ID
"timestamp",
"android_id",
"package_name",
"storybook_id",
"storybook_title",
"learning_event_type"
)
.build();

StringWriter stringWriter = new StringWriter();
CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
Expand All @@ -63,9 +64,9 @@ public void handleRequest(
storyBookLearningEvent.getStoryBookTitle(),
storyBookLearningEvent.getLearningEventType()
);

csvPrinter.flush();
}
csvPrinter.close();

String csvFileContent = stringWriter.toString();

Expand Down
Loading

0 comments on commit 0817b90

Please sign in to comment.