导航菜单

页面标题

页面副标题

Plus 12 v10.13.1.1 - FirebaseHelper.java 源代码

正在查看: Plus 12 v10.13.1.1 应用的 FirebaseHelper.java JAVA 源代码文件

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


package org.telegram.plus;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.remoteconfig.ConfigUpdate;
import com.google.firebase.remoteconfig.ConfigUpdateListener;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
import java.util.Map;
import java.util.Set;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.plus.FirebaseHelper;
import org.telegram.ui.ActionBar.PlusSettings;
import org.telegram.ui.LaunchActivity;

public class FirebaseHelper {
    public static volatile FirebaseHelper Instance;
    public static final String[] TOPICS;
    public int currentAccount = UserConfig.selectedAccount;
    public FirebaseAnalytics firebaseAnalytics;
    public FirebaseRemoteConfig firebaseRemoteConfig;

    public void init() {
        this.firebaseAnalytics = FirebaseAnalytics.getInstance(ApplicationLoader.applicationContext);
        FirebaseCrashlytics.getInstance();
        this.firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        loadRemoteConfig();
    }

    public static FirebaseHelper getInstance() {
        FirebaseHelper firebaseHelper = Instance;
        if (firebaseHelper == null) {
            synchronized (FirebaseHelper.class) {
                firebaseHelper = Instance;
                if (firebaseHelper == null) {
                    firebaseHelper = new FirebaseHelper();
                    Instance = firebaseHelper;
                }
            }
        }
        return firebaseHelper;
    }

    public void loadRemoteConfig() {
        this.firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
        readPlusDialogConfig();
    }

    public void readPlusDialogConfig() {
        try {
            this.firebaseRemoteConfig.getBoolean("showPlusHintDialogCell");
            this.firebaseRemoteConfig.getLong("plusDialogEnabled");
            this.firebaseRemoteConfig.fetchAndActivate().addOnCompleteListener(new OnCompleteListener() {
                public final void onComplete(Task task) {
                    FirebaseHelper.this.lambda$readPlusDialogConfig$3(task);
                }
            });
            this.firebaseRemoteConfig.addOnConfigUpdateListener(new AnonymousClass1());
        } catch (Throwable unused) {
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    FirebaseHelper.lambda$readPlusDialogConfig$4();
                }
            });
        }
    }

    public void lambda$readPlusDialogConfig$3(Task task) {
        final boolean isSuccessful = task.isSuccessful();
        Utilities.stageQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                FirebaseHelper.this.lambda$readPlusDialogConfig$2(isSuccessful);
            }
        });
    }

    public void lambda$readPlusDialogConfig$2(boolean z) {
        if (z) {
            PlusSettings.setShowPlusHintDialogCell(this.firebaseRemoteConfig.getBoolean("showPlusHintDialogCell"));
            PlusSettings.setDisableCheckForThemes(this.firebaseRemoteConfig.getBoolean("disableCheckForThemes"));
            PlusSettings.setShowPlusDialogEvenIfInstalled(this.firebaseRemoteConfig.getBoolean("showPlusDialogEvenIfInstalled"));
            PlusSettings.setHidePlusDialogUntilLoaded(this.firebaseRemoteConfig.getBoolean("hidePlusDialogUntilLoaded"));
            PlusSettings.setPlusLoadConsent(this.firebaseRemoteConfig.getBoolean("plusLoadConsent"));
            PlusSettings.setPlusDialogEnabled(this.firebaseRemoteConfig.getLong("plusDialogEnabled"));
            PlusSettings.setPlusDialogType(this.firebaseRemoteConfig.getLong("plusDialogType"));
            PlusSettings.setPlusDialogTypePlayStore(this.firebaseRemoteConfig.getLong("plusDialogTypePlayStore"));
            PlusSettings.setPlusDialogTitle(this.firebaseRemoteConfig.getString("plusDialogTitle"));
            PlusSettings.setPlusDialogSubtitle(this.firebaseRemoteConfig.getString("plusDialogSubtitle"));
            PlusSettings.setPlusDialogLink(this.firebaseRemoteConfig.getString("plusDialogLink"));
            PlusSettings.setPlusDialogThemesAppLink(this.firebaseRemoteConfig.getString("plusDialogThemesAppLink"));
            PlusSettings.setPlusPromoDialogEnabled(this.firebaseRemoteConfig.getLong("plusPromoDialogEnabled"));
            PlusSettings.setPlusPromoDialogId(this.firebaseRemoteConfig.getLong("plusPromoDialogId"));
            PlusSettings.setPlusPromoDialogUsername(this.firebaseRemoteConfig.getString("plusPromoDialogUsername"));
            PlusSettings.setPlusPromoDialogHideOptionEnabled(this.firebaseRemoteConfig.getLong("plusPromoDialogHideOptionEnabled"));
            PlusSettings.setPlusPromoDialogEnabledLangs(this.firebaseRemoteConfig.getString("plusPromoDialogEnabledLangs"));
            if (PlusSettings.isPlusPromoDialogEnabled()) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        FirebaseHelper.this.lambda$readPlusDialogConfig$0();
                    }
                }, 1000L);
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    FirebaseHelper.this.lambda$readPlusDialogConfig$1();
                }
            });
        }
        Bundle bundle = new Bundle();
        bundle.putString("success", z + BuildConfig.APP_CENTER_HASH);
        sendAnalytics("onRemoteConfigFetchAndActivate", bundle);
    }

    public void lambda$readPlusDialogConfig$0() {
        MessagesController.getInstance(this.currentAccount).checkPromoInfo(true);
    }

    public void lambda$readPlusDialogConfig$1() {
        NotificationCenter.getInstance(this.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.plusDialogHintCellUpdated, new Object[0]);
    }

    public class AnonymousClass1 implements ConfigUpdateListener {
        public AnonymousClass1() {
        }

        public void onUpdate(final ConfigUpdate configUpdate) {
            FirebaseHelper.this.firebaseRemoteConfig.activate().addOnCompleteListener(new OnCompleteListener() {
                public final void onComplete(Task task) {
                    FirebaseHelper.AnonymousClass1.this.lambda$onUpdate$1(configUpdate, task);
                }
            });
        }

        public void lambda$onUpdate$1(final ConfigUpdate configUpdate, Task task) {
            final boolean isSuccessful = task.isSuccessful();
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    FirebaseHelper.AnonymousClass1.this.lambda$onUpdate$0(isSuccessful, configUpdate);
                }
            });
        }

        public void lambda$onUpdate$0(boolean z, ConfigUpdate configUpdate) {
            if (z) {
                FirebaseHelper.this.updateFromRemoteConfig(configUpdate.getUpdatedKeys());
            }
        }

        public void onError(FirebaseRemoteConfigException error) {
            Bundle bundle = new Bundle();
            bundle.putString("code", error.getCode() + BuildConfig.APP_CENTER_HASH);
            bundle.putString("error", error.getMessage());
            FirebaseHelper.this.sendAnalytics("onRemoteConfigError", bundle);
        }
    }

    public static void lambda$readPlusDialogConfig$4() {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("failed to get firebase result");
        }
    }

    public void sendAnalytics(String event, Bundle bundle) {
        bundle.putString("versionCode", SharedConfig.buildVersion() + BuildConfig.APP_CENTER_HASH);
        bundle.putString("version", BuildVars.BUILD_VERSION_STRING);
        if (this.firebaseAnalytics == null) {
            this.firebaseAnalytics = FirebaseAnalytics.getInstance(ApplicationLoader.applicationContext);
        }
        this.firebaseAnalytics.logEvent(event, bundle);
    }

    public final void updateFromRemoteConfig(Set<String> set) {
        boolean z;
        boolean z2 = false;
        boolean z3 = true;
        if (set.contains("showPlusHintDialogCell")) {
            PlusSettings.setShowPlusHintDialogCell(this.firebaseRemoteConfig.getBoolean("showPlusHintDialogCell"));
            z = true;
        } else {
            z = false;
        }
        if (set.contains("hidePlusDialogUntilLoaded")) {
            PlusSettings.setHidePlusDialogUntilLoaded(this.firebaseRemoteConfig.getBoolean("hidePlusDialogUntilLoaded"));
            z = true;
        }
        if (set.contains("plusLoadConsent")) {
            PlusSettings.setPlusLoadConsent(this.firebaseRemoteConfig.getBoolean("plusLoadConsent"));
            z = true;
        }
        if (set.contains("disableCheckForThemes")) {
            PlusSettings.setDisableCheckForThemes(this.firebaseRemoteConfig.getBoolean("disableCheckForThemes"));
        }
        if (set.contains("showPlusDialogEvenIfInstalled")) {
            PlusSettings.setShowPlusDialogEvenIfInstalled(this.firebaseRemoteConfig.getBoolean("showPlusDialogEvenIfInstalled"));
            z = true;
        }
        if (set.contains("plusDialogEnabled")) {
            PlusSettings.setPlusDialogEnabled(this.firebaseRemoteConfig.getLong("plusDialogEnabled"));
            z = true;
        }
        if (set.contains("plusDialogType")) {
            PlusSettings.setPlusDialogType(this.firebaseRemoteConfig.getLong("plusDialogType"));
            z = true;
        }
        if (set.contains("plusDialogTypePlayStore")) {
            PlusSettings.setPlusDialogTypePlayStore(this.firebaseRemoteConfig.getLong("plusDialogTypePlayStore"));
            z = true;
        }
        if (set.contains("resetPlusDialog")) {
            PlusSettings.resetPlusDialogClicked(this.firebaseRemoteConfig.getLong("resetPlusDialog"));
            z = true;
        }
        if (set.contains("plusDialogTitle")) {
            PlusSettings.setPlusDialogTitle(this.firebaseRemoteConfig.getString("plusDialogTitle"));
            z = true;
        }
        if (set.contains("plusDialogSubtitle")) {
            PlusSettings.setPlusDialogSubtitle(this.firebaseRemoteConfig.getString("plusDialogSubtitle"));
            z = true;
        }
        if (set.contains("plusDialogLink")) {
            PlusSettings.setPlusDialogLink(this.firebaseRemoteConfig.getString("plusDialogLink"));
            z = true;
        }
        if (set.contains("plusDialogThemesAppLink")) {
            PlusSettings.setPlusDialogThemesAppLink(this.firebaseRemoteConfig.getString("plusDialogThemesAppLink"));
            z = true;
        }
        if (set.contains("plusPromoDialogEnabled")) {
            PlusSettings.setPlusPromoDialogEnabled(this.firebaseRemoteConfig.getLong("plusPromoDialogEnabled"));
            z2 = true;
        }
        if (set.contains("plusPromoDialogId")) {
            PlusSettings.setPlusPromoDialogId(this.firebaseRemoteConfig.getLong("plusPromoDialogId"));
            z2 = true;
        }
        if (set.contains("plusPromoDialogUsername")) {
            PlusSettings.setPlusPromoDialogUsername(this.firebaseRemoteConfig.getString("plusPromoDialogUsername"));
            PlusSettings.setPlusPromoDialogId(this.firebaseRemoteConfig.getLong("plusPromoDialogId"));
            z2 = true;
        }
        if (set.contains("plusPromoDialogEnabledLangs")) {
            PlusSettings.setPlusPromoDialogEnabledLangs(this.firebaseRemoteConfig.getString("plusPromoDialogEnabledLangs"));
            z2 = true;
        }
        if (set.contains("plusPromoDialogHideOptionEnabled")) {
            PlusSettings.setPlusPromoDialogHideOptionEnabled(this.firebaseRemoteConfig.getLong("plusPromoDialogHideOptionEnabled"));
        } else {
            z3 = z2;
        }
        if (z3) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    FirebaseHelper.this.lambda$updateFromRemoteConfig$5();
                }
            }, 1000L);
        }
        if (z) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    FirebaseHelper.this.lambda$updateFromRemoteConfig$6();
                }
            });
        }
        Bundle bundle = new Bundle();
        bundle.putString("key", "plusPromoDialogHideOptionEnabled");
        bundle.putString("notify", z + BuildConfig.APP_CENTER_HASH);
        sendAnalytics("onUpdateFromRemoteConfig", bundle);
    }

    public void lambda$updateFromRemoteConfig$5() {
        MessagesController.getInstance(this.currentAccount).checkPromoInfo(true);
    }

    public void lambda$updateFromRemoteConfig$6() {
        NotificationCenter.getInstance(this.currentAccount).lambda$postNotificationNameOnUIThread$1(NotificationCenter.plusDialogHintCellUpdated, new Object[0]);
    }

    static {
        String[] strArr = new String[11];
        strArr[0] = "general";
        strArr[1] = "all";
        strArr[2] = "load";
        strArr[3] = "update";
        strArr[4] = "reset_plus_dialog";
        strArr[5] = "plus_promo_dialog";
        strArr[6] = "reset_check_for_themes";
        strArr[7] = "subscribe";
        strArr[8] = "user";
        strArr[9] = BuildVars.BETA ? "beta_private" : BuildVars.BETA_HOCKEY ? "beta_hockey" : BuildVars.BETA_DIRECT ? "beta_direct" : BuildVars.BETA_2 ? "beta_all" : BuildVars.BETA_PS ? "beta_ps" : BuildVars.STANDALONE ? "standalone" : "stable";
        strArr[10] = "test";
        TOPICS = strArr;
    }

    public boolean checkMessage(RemoteMessage message) {
        boolean checkTopics = checkTopics(message);
        if (!checkTopics && message.getNotification() != null) {
            createNotification(message.getNotification().getTitle(), message.getNotification().getBody());
        }
        return checkTopics;
    }

    public boolean checkTopics(RemoteMessage message) {
        boolean z;
        String from = message.getFrom();
        String to = message.getTo();
        Map data = message.getData();
        if ((from == null || !from.contains("/topics/")) && !data.containsKey("topic")) {
            z = false;
        } else {
            z = true;
            readTopic(message);
        }
        Bundle bundle = new Bundle();
        bundle.putString("from", from);
        bundle.putString("to", to);
        bundle.putString("data", data.toString());
        bundle.putString("stopNotification", z + BuildConfig.APP_CENTER_HASH);
        sendAnalytics("checkTopics", bundle);
        return z;
    }

    public final boolean readTopic(com.google.firebase.messaging.RemoteMessage r10) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.plus.FirebaseHelper.readTopic(com.google.firebase.messaging.RemoteMessage):boolean");
    }

    public void lambda$readTopic$7() {
        MessagesController.getInstance(this.currentAccount).checkPromoInfo(true);
    }

    public void subscribeTopics(Boolean force) {
        subscribeTopics(SharedConfig.pushString, force.booleanValue());
    }

    public void subscribeTopics(String token, boolean force) {
        final SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("plusconfig", 0);
        if (TextUtils.isEmpty(token)) {
            return;
        }
        if (!sharedPreferences.getBoolean("token_subscribed", false) || force) {
            for (final String str : TOPICS) {
                if ((!str.equals("beta") && !str.equals("test")) || BuildVars.BETA_2) {
                    subscribeToTopic(str, new Runnable(this) {
                        @Override
                        public void run() {
                            if (str.equals("general")) {
                                sharedPreferences.edit().putBoolean("token_subscribed", true).apply();
                            }
                        }
                    });
                }
            }
            Bundle bundle = new Bundle();
            bundle.putString("force", force + BuildConfig.APP_CENTER_HASH);
            sendAnalytics("subscribeTopics", bundle);
        }
    }

    public void subscribeToTopic(String topic, final Runnable runnable) {
        FirebaseMessaging.getInstance().subscribeToTopic(topic).addOnCompleteListener(new OnCompleteListener<Void>(this) {
            public void onComplete(Task<Void> task) {
                Runnable runnable2 = runnable;
                if (runnable2 != null) {
                    runnable2.run();
                }
            }
        });
    }

    public void createNotification(String title, String body) {
        createNotification(title, body, false, null);
    }

    public void createNotification(String title, String body, boolean update, String remoteUrl) {
        Intent intent = new Intent(ApplicationLoader.applicationContext, (Class<?>) LaunchActivity.class);
        intent.setFlags(67108864);
        if (update) {
            Intent intent2 = new Intent("android.intent.action.VIEW", Uri.parse(!TextUtils.isEmpty(remoteUrl) ? remoteUrl : "https://play.google.com/store/apps/details?id=org.telegram.plus"));
            intent2.addFlags(268435456);
            intent = intent2;
        }
        Context context = ApplicationLoader.applicationContext;
        int i = Build.VERSION.SDK_INT;
        PendingIntent activity = PendingIntent.getActivity(context, 0, intent, i < 23 ? 0 : 67108864);
        Uri defaultUri = RingtoneManager.getDefaultUri(4);
        String string = LocaleController.getString(R.string.default_notification_channel_id);
        NotificationCompat.Builder contentIntent = new NotificationCompat.Builder(ApplicationLoader.applicationContext, string).setSmallIcon(R.drawable.notification).setContentTitle(title).setContentText(body).setAutoCancel(true).setChannelId(string).setSound(defaultUri).setColor(ApplicationLoader.applicationContext.getResources().getColor(R.color.primary_dark)).setContentIntent(activity);
        NotificationManager notificationManager = (NotificationManager) ApplicationLoader.applicationContext.getSystemService("notification");
        if (i >= 26) {
            notificationManager.createNotificationChannel(new NotificationChannel(string, string, 2));
        }
        notificationManager.notify(0, contentIntent.build());
        Bundle bundle = new Bundle();
        bundle.putString("body", body);
        bundle.putString("title", title);
        bundle.putString("update", update + BuildConfig.APP_CENTER_HASH);
        bundle.putString("remoteUrl", remoteUrl);
        sendAnalytics("createNotification", bundle);
    }
}