use of org.thoughtcrime.securesms.emoji.EmojiData in project Signal-Android by WhisperSystems.
the class DownloadLatestEmojiDataJob method downloadJson.
@NonNull
private static EmojiData downloadJson(@NonNull Context context, @NonNull EmojiFiles.Version version) throws IOException, InvalidEmojiDataJsonException {
EmojiFiles.NameCollection names = EmojiFiles.NameCollection.read(context, version);
UUID emojiData = names.getUUIDForEmojiData();
byte[] remoteHash = EmojiRemote.getMd5(new EmojiJsonRequest(version.getVersion()));
byte[] localHash;
if (emojiData != null) {
localHash = EmojiFiles.getMd5(context, version, emojiData);
} else {
localHash = null;
}
if (!Arrays.equals(localHash, remoteHash)) {
Log.d(TAG, "Downloading JSON from Remote");
assertRemoteDownloadConstraints(context);
EmojiFiles.Name name = EmojiDownloader.downloadAndVerifyJsonFromRemote(context, version);
EmojiFiles.NameCollection.append(context, names, name);
} else {
Log.d(TAG, "Already have JSON from remote, skipping download");
}
EmojiData latestData = EmojiFiles.getLatestEmojiData(context, version);
if (latestData == null) {
throw new InvalidEmojiDataJsonException();
}
return latestData;
}
use of org.thoughtcrime.securesms.emoji.EmojiData in project Signal-Android by WhisperSystems.
the class DownloadLatestEmojiDataJob method onRun.
@Override
protected void onRun() throws Exception {
EmojiFiles.Version version = EmojiFiles.Version.readVersion(context);
int localVersion = (version != null) ? version.getVersion() : 0;
int serverVersion = EmojiRemote.getVersion();
String bucket;
if (targetVersion == null) {
ScreenDensity density = ScreenDensity.get(context);
bucket = getDesiredRemoteBucketForDensity(density);
} else {
bucket = targetVersion.getDensity();
}
Log.d(TAG, "LocalVersion: " + localVersion + ", ServerVersion: " + serverVersion + ", Bucket: " + bucket);
if (bucket == null) {
Log.d(TAG, "This device has too low a display density to download remote emoji.");
} else if (localVersion == serverVersion) {
Log.d(TAG, "Already have latest emoji data. Skipping.");
} else if (serverVersion > localVersion) {
Log.d(TAG, "New server data detected. Starting download...");
if (targetVersion == null || targetVersion.getVersion() != serverVersion) {
targetVersion = new EmojiFiles.Version(serverVersion, UUID.randomUUID(), bucket);
}
if (isCanceled()) {
Log.w(TAG, "Job was cancelled prior to downloading json.");
return;
}
EmojiData emojiData = downloadJson(context, targetVersion);
List<String> supportedDensities = emojiData.getDensities();
String format = emojiData.getFormat();
List<String> imagePaths = Stream.of(emojiData.getDataPages()).map(EmojiPageModel::getSpriteUri).map(Uri::getLastPathSegment).toList();
String density = resolveDensity(supportedDensities, targetVersion.getDensity());
targetVersion = new EmojiFiles.Version(targetVersion.getVersion(), targetVersion.getUuid(), density);
if (isCanceled()) {
Log.w(TAG, "Job was cancelled after downloading json.");
return;
}
downloadImages(context, targetVersion, imagePaths, format, this::isCanceled);
if (isCanceled()) {
Log.w(TAG, "Job was cancelled during or after downloading images.");
return;
}
clearOldEmojiData(context, targetVersion);
markComplete(targetVersion);
EmojiSource.refresh();
JumboEmoji.updateCurrentVersion(context);
} else {
Log.d(TAG, "Server has an older version than we do. Skipping.");
}
}
Aggregations