导航菜单

页面标题

页面副标题

Crafto v9.3.3 - CTFirebaseMessagingReceiver.java 源代码

正在查看: Crafto v9.3.3 应用的 CTFirebaseMessagingReceiver.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.clevertap.android.sdk.pushnotification.fcm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import com.clevertap.android.sdk.CTXtensions;
import com.clevertap.android.sdk.CleverTapAPI;
import com.clevertap.android.sdk.Constants;
import com.clevertap.android.sdk.Logger;
import com.clevertap.android.sdk.Utils;
import com.clevertap.android.sdk.interfaces.NotificationRenderedListener;
import com.clevertap.android.sdk.pushnotification.PushNotificationUtil;
import com.google.firebase.messaging.RemoteMessage;
import java.util.concurrent.TimeUnit;

public class CTFirebaseMessagingReceiver extends BroadcastReceiver implements NotificationRenderedListener {
    private static final String TAG = "CTRM";
    private CountDownTimer countDownTimer;
    private boolean isPRFinished;
    private String key = "";
    private BroadcastReceiver.PendingResult pendingResult;
    private long start;

    public void finishReceiverAndCancelTimer(String str) {
        try {
            Logger.v(TAG, "got a signal to kill receiver and timer because " + str);
            if (!this.key.trim().isEmpty()) {
                CleverTapAPI.removeNotificationRenderedListener(this.key);
            }
            long nanoTime = System.nanoTime();
            if (this.pendingResult == null || this.isPRFinished) {
                Logger.v(TAG, "have already informed OS to kill receiver, can not inform again else OS will get angry :-O");
                return;
            }
            Logger.v(TAG, "informing OS to kill receiver...");
            this.pendingResult.finish();
            this.isPRFinished = true;
            CountDownTimer countDownTimer = this.countDownTimer;
            if (countDownTimer != null) {
                countDownTimer.cancel();
            }
            Logger.v(TAG, "informed OS to kill receiver...");
            Logger.v(TAG, "receiver was alive for " + TimeUnit.NANOSECONDS.toSeconds(nanoTime - this.start) + " seconds");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void lambda$onReceive$0(Context context, Bundle bundle) {
        try {
            try {
                CleverTapAPI globalInstance = CleverTapAPI.getGlobalInstance(context, PushNotificationUtil.getAccountIdFromNotificationBundle(bundle));
                if (globalInstance != null) {
                    CTXtensions.flushPushImpressionsOnPostAsyncSafely(globalInstance, "CTRM#flushQueueSync", Constants.D_SRC_PI_R, context);
                }
            } catch (Exception e) {
                e.printStackTrace();
                Logger.v(TAG, "Failed executing CTRM flushQueueSync thread.", e);
            }
        } finally {
            finishReceiverAndCancelTimer("flush from receiver is done!");
        }
    }

    @Override
    public void onNotificationRendered(boolean z) {
        Logger.v(TAG, "push impression sent successfully by core, i should inform OS to kill receiver. my callback key is " + this.key);
        finishReceiverAndCancelTimer("push impression sent successfully by core");
    }

    @Override
    public void onReceive(final Context context, Intent intent) {
        RemoteMessage remoteMessage;
        final Bundle bundle;
        this.start = System.nanoTime();
        Logger.d(TAG, "received a message from Firebase");
        if (context == null || intent == null || (bundle = new FcmNotificationParser().toBundle((remoteMessage = new RemoteMessage(intent.getExtras())))) == null) {
            return;
        }
        if (remoteMessage.D() != 2) {
            Logger.d(TAG, "returning from CTRM because message priority is not normal");
            return;
        }
        long parseLong = Long.parseLong(bundle.getString("ctrmt", "4500"));
        this.pendingResult = goAsync();
        if (!CleverTapAPI.getNotificationInfo(bundle).fromCleverTap) {
            Logger.v(TAG, "Notification payload is not from CleverTap.");
            finishReceiverAndCancelTimer("push is not from CleverTap.");
            return;
        }
        if (!Utils.isRenderFallback(remoteMessage, context)) {
            Logger.v(TAG, "Notification payload does not have a fallback key.");
            finishReceiverAndCancelTimer("isRenderFallback is false");
            return;
        }
        String buildPushNotificationRenderedListenerKey = PushNotificationUtil.buildPushNotificationRenderedListenerKey(PushNotificationUtil.getAccountIdFromNotificationBundle(bundle), PushNotificationUtil.getPushIdFromNotificationBundle(bundle));
        this.key = buildPushNotificationRenderedListenerKey;
        CleverTapAPI.addNotificationRenderedListener(buildPushNotificationRenderedListenerKey, this);
        CountDownTimer countDownTimer = new CountDownTimer(parseLong, 1000L) {
            @Override
            public void onFinish() {
                CTFirebaseMessagingReceiver.this.finishReceiverAndCancelTimer("receiver life time is expired");
            }

            @Override
            public void onTick(long j) {
            }
        };
        this.countDownTimer = countDownTimer;
        countDownTimer.start();
        new Thread(new Runnable() {
            @Override
            public final void run() {
                CTFirebaseMessagingReceiver.this.lambda$onReceive$0(context, bundle);
            }
        }).start();
    }
}