Search in sources :

Example 1 with EmojiData

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;
}
Also used : EmojiJsonRequest(org.thoughtcrime.securesms.emoji.EmojiJsonRequest) UUID(java.util.UUID) EmojiFiles(org.thoughtcrime.securesms.emoji.EmojiFiles) EmojiData(org.thoughtcrime.securesms.emoji.EmojiData) NonNull(androidx.annotation.NonNull)

Example 2 with EmojiData

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.");
    }
}
Also used : ScreenDensity(org.thoughtcrime.securesms.util.ScreenDensity) AutoDownloadEmojiConstraint(org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) EmojiPageModel(org.thoughtcrime.securesms.components.emoji.EmojiPageModel) EmojiFiles(org.thoughtcrime.securesms.emoji.EmojiFiles) EmojiData(org.thoughtcrime.securesms.emoji.EmojiData)

Aggregations

EmojiData (org.thoughtcrime.securesms.emoji.EmojiData)2 EmojiFiles (org.thoughtcrime.securesms.emoji.EmojiFiles)2 NonNull (androidx.annotation.NonNull)1 UUID (java.util.UUID)1 EmojiPageModel (org.thoughtcrime.securesms.components.emoji.EmojiPageModel)1 EmojiJsonRequest (org.thoughtcrime.securesms.emoji.EmojiJsonRequest)1 AutoDownloadEmojiConstraint (org.thoughtcrime.securesms.jobmanager.impl.AutoDownloadEmojiConstraint)1 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)1 ScreenDensity (org.thoughtcrime.securesms.util.ScreenDensity)1