导航菜单

页面标题

页面副标题

Brevistay v5.8.2 - Utils.java 源代码

正在查看: Brevistay v5.8.2 应用的 Utils.java JAVA 源代码文件

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


package com.clevertap.android.pushtemplates;

import a.a.a.o.f$;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.widget.RemoteViews;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
import androidx.tracing.Trace$;
import com.bumptech.glide.request.target.Target;
import com.clevertap.android.sdk.CleverTapAPI;
import com.clevertap.android.sdk.CleverTapInstanceConfig;
import com.clevertap.android.sdk.Constants;
import com.clevertap.android.sdk.task.CTExecutorFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import org.json.JSONArray;
import org.json.JSONObject;

public class Utils {
    public static Bitmap getNotificationBitmap(String str, boolean z, Context context) throws NullPointerException {
        if (str == null || str.equals("")) {
            if (z) {
                return getAppIcon(context);
            }
            return null;
        }
        if (!str.startsWith("http")) {
            str = "http://static.wizrocket.com/android/ico//" + str;
        }
        Bitmap bitmapFromURL = getBitmapFromURL(str);
        if (bitmapFromURL != null) {
            return bitmapFromURL;
        }
        if (z) {
            return getAppIcon(context);
        }
        return null;
    }

    private static Bitmap getAppIcon(Context context) throws NullPointerException {
        try {
            Drawable applicationLogo = context.getPackageManager().getApplicationLogo(context.getApplicationInfo());
            if (applicationLogo == null) {
                throw new Exception("Logo is null");
            }
            return drawableToBitmap(applicationLogo);
        } catch (Exception unused) {
            return drawableToBitmap(context.getPackageManager().getApplicationIcon(context.getApplicationInfo()));
        }
    }

    static Bitmap drawableToBitmap(Drawable drawable) throws NullPointerException {
        Bitmap createBitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return createBitmap;
    }

    private static android.graphics.Bitmap getBitmapFromURL(java.lang.String r20) {
        throw new UnsupportedOperationException("Method not decompiled: com.clevertap.android.pushtemplates.Utils.getBitmapFromURL(java.lang.String):android.graphics.Bitmap");
    }

    static String _getManifestStringValueForKey(Bundle bundle, String str) {
        try {
            Object obj = bundle.get(str);
            if (obj != null) {
                return obj.toString();
            }
        } catch (Throwable unused) {
        }
        return null;
    }

    static int getAppIconAsIntId(Context context) {
        return context.getApplicationInfo().icon;
    }

    static ArrayList<String> getImageListFromExtras(Bundle bundle) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String str : bundle.keySet()) {
            if (str.contains("pt_img")) {
                arrayList.add(bundle.getString(str));
            }
        }
        return arrayList;
    }

    static ArrayList<String> getCTAListFromExtras(Bundle bundle) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String str : bundle.keySet()) {
            if (str.contains("pt_cta")) {
                arrayList.add(bundle.getString(str));
            }
        }
        return arrayList;
    }

    static ArrayList<String> getDeepLinkListFromExtras(Bundle bundle) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String str : bundle.keySet()) {
            if (str.contains("pt_dl")) {
                arrayList.add(bundle.getString(str));
            }
        }
        return arrayList;
    }

    static ArrayList<String> getBigTextFromExtras(Bundle bundle) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String str : bundle.keySet()) {
            if (str.contains("pt_bt")) {
                arrayList.add(bundle.getString(str));
            }
        }
        return arrayList;
    }

    static ArrayList<String> getSmallTextFromExtras(Bundle bundle) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String str : bundle.keySet()) {
            if (str.contains("pt_st")) {
                arrayList.add(bundle.getString(str));
            }
        }
        return arrayList;
    }

    static ArrayList<String> getPriceFromExtras(Bundle bundle) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (String str : bundle.keySet()) {
            if (str.contains("pt_price") && !str.contains(PTConstants.PT_PRICE_LIST)) {
                arrayList.add(bundle.getString(str));
            }
        }
        return arrayList;
    }

    public static void loadImageBitmapIntoRemoteView(int i, Bitmap bitmap, RemoteViews remoteViews) {
        remoteViews.setImageViewBitmap(i, bitmap);
    }

    public static void loadImageURLIntoRemoteView(int i, String str, RemoteViews remoteViews) {
        Bitmap bitmapFromURL = getBitmapFromURL(str);
        setFallback(false);
        if (bitmapFromURL != null) {
            remoteViews.setImageViewBitmap(i, bitmapFromURL);
            return;
        }
        PTLog.debug("Image was not perfect. URL:" + str + " hiding image view");
        setFallback(true);
    }

    public static void loadImageURLIntoRemoteView(int i, String str, RemoteViews remoteViews, Context context) {
        Bitmap bitmapFromURL = getBitmapFromURL(str);
        setFallback(false);
        if (bitmapFromURL != null) {
            remoteViews.setImageViewBitmap(i, bitmapFromURL);
            return;
        }
        PTLog.debug("Image was not perfect. URL:" + str + " hiding image view");
        setFallback(true);
    }

    public static void loadImageRidIntoRemoteView(int i, int i2, RemoteViews remoteViews) {
        remoteViews.setImageViewResource(i, i2);
    }

    public static String getTimeStamp(Context context) {
        return DateUtils.formatDateTime(context, System.currentTimeMillis(), 1);
    }

    public static String getApplicationName(Context context) {
        ApplicationInfo applicationInfo = context.getApplicationInfo();
        int i = applicationInfo.labelRes;
        if (i == 0) {
            return applicationInfo.nonLocalizedLabel.toString();
        }
        return context.getString(i);
    }

    static Bundle fromJson(JSONObject jSONObject) {
        Bundle bundle = new Bundle();
        Iterator<String> keys = jSONObject.keys();
        while (keys.hasNext()) {
            String next = keys.next();
            JSONArray optJSONArray = jSONObject.optJSONArray(next);
            String optString = jSONObject.optString(next);
            if (optJSONArray != null && optJSONArray.length() <= 0) {
                bundle.putStringArray(next, new String[0]);
            } else if (optJSONArray != null && optJSONArray.optString(0) != null) {
                String[] strArr = new String[optJSONArray.length()];
                for (int i = 0; i < optJSONArray.length(); i++) {
                    strArr[i] = optJSONArray.optString(i);
                }
                bundle.putStringArray(next, strArr);
            } else if (optString != null) {
                bundle.putString(next, optString);
            } else {
                System.err.println("unable to transform json to bundle " + next);
            }
        }
        return bundle;
    }

    static void cancelNotification(Context context, int i) {
        ((NotificationManager) context.getSystemService("notification")).cancel(i);
    }

    static int getTimerThreshold(Bundle bundle) {
        String str = "-1";
        for (String str2 : bundle.keySet()) {
            if (str2.contains(PTConstants.PT_TIMER_THRESHOLD)) {
                str = bundle.getString(str2);
            }
        }
        return Integer.parseInt(str != null ? str : "-1");
    }

    static void setPackageNameFromResolveInfoList(Context context, Intent intent) {
        List<ResolveInfo> queryIntentActivities = context.getPackageManager().queryIntentActivities(intent, 0);
        String packageName = context.getPackageName();
        Iterator<ResolveInfo> it = queryIntentActivities.iterator();
        while (it.hasNext()) {
            if (packageName.equals(it.next().activityInfo.packageName)) {
                intent.setPackage(packageName);
                return;
            }
        }
    }

    static void raiseCleverTapEvent(Context context, CleverTapInstanceConfig cleverTapInstanceConfig, Bundle bundle) {
        CleverTapAPI defaultInstance;
        if (cleverTapInstanceConfig != null) {
            defaultInstance = CleverTapAPI.instanceWithConfig(context, cleverTapInstanceConfig);
        } else {
            defaultInstance = CleverTapAPI.getDefaultInstance(context);
        }
        HashMap<String, Object> eventPropertiesFromExtras = getEventPropertiesFromExtras(bundle);
        String eventNameFromExtras = getEventNameFromExtras(bundle);
        if (eventNameFromExtras == null || eventNameFromExtras.isEmpty()) {
            return;
        }
        if (defaultInstance != null) {
            defaultInstance.pushEvent(eventNameFromExtras, eventPropertiesFromExtras);
        } else {
            PTLog.debug("CleverTap instance is NULL, not raising the event");
        }
    }

    static void raiseCleverTapEvent(Context context, CleverTapInstanceConfig cleverTapInstanceConfig, Bundle bundle, String str) {
        CleverTapAPI defaultInstance;
        if (cleverTapInstanceConfig != null) {
            defaultInstance = CleverTapAPI.instanceWithConfig(context, cleverTapInstanceConfig);
        } else {
            defaultInstance = CleverTapAPI.getDefaultInstance(context);
        }
        HashMap<String, Object> eventPropertiesFromExtras = getEventPropertiesFromExtras(bundle, str, bundle.getString(str));
        String eventNameFromExtras = getEventNameFromExtras(bundle);
        if (eventNameFromExtras == null || eventNameFromExtras.isEmpty()) {
            return;
        }
        if (defaultInstance != null) {
            defaultInstance.pushEvent(eventNameFromExtras, eventPropertiesFromExtras);
        } else {
            PTLog.debug("CleverTap instance is NULL, not raising the event");
        }
    }

    static void raiseCleverTapEvent(Context context, CleverTapInstanceConfig cleverTapInstanceConfig, String str, HashMap<String, Object> hashMap) {
        CleverTapAPI defaultInstance;
        if (cleverTapInstanceConfig != null) {
            defaultInstance = CleverTapAPI.instanceWithConfig(context, cleverTapInstanceConfig);
        } else {
            defaultInstance = CleverTapAPI.getDefaultInstance(context);
        }
        if (str == null || str.isEmpty()) {
            return;
        }
        if (defaultInstance != null) {
            defaultInstance.pushEvent(str, hashMap);
        } else {
            PTLog.debug("CleverTap instance is NULL, not raising the event");
        }
    }

    static HashMap<String, Object> convertRatingBundleObjectToHashMap(Bundle bundle) {
        bundle.remove(Constants.KEY_CONFIG);
        HashMap<String, Object> hashMap = new HashMap<>();
        for (String str : bundle.keySet()) {
            if (str.contains(Constants.WZRK_PREFIX) || str.equals(PTConstants.PT_ID)) {
                Object obj = bundle.get(str);
                if (obj instanceof Bundle) {
                    hashMap.putAll(convertRatingBundleObjectToHashMap((Bundle) obj));
                } else {
                    hashMap.put(str, bundle.get(str));
                }
            }
        }
        return hashMap;
    }

    static String getEventNameFromExtras(Bundle bundle) {
        String str = null;
        for (String str2 : bundle.keySet()) {
            if (str2.contains(PTConstants.PT_EVENT_NAME_KEY)) {
                str = bundle.getString(str2);
            }
        }
        return str;
    }

    static HashMap<String, Object> getEventPropertiesFromExtras(Bundle bundle, String str, String str2) {
        HashMap<String, Object> hashMap = new HashMap<>();
        for (String str3 : bundle.keySet()) {
            if (str3.contains(PTConstants.PT_EVENT_PROPERTY_KEY)) {
                if (bundle.getString(str3) == null || bundle.getString(str3).isEmpty()) {
                    PTLog.verbose("Property Key is Empty. Skipping Property: " + str3);
                } else if (str3.contains(PTConstants.PT_EVENT_PROPERTY_SEPERATOR)) {
                    String[] split = str3.split(PTConstants.PT_EVENT_PROPERTY_SEPERATOR);
                    if (bundle.getString(str3).equalsIgnoreCase(str)) {
                        hashMap.put(split[1], str2);
                    } else {
                        hashMap.put(split[1], bundle.getString(str3));
                    }
                } else {
                    PTLog.verbose("Property " + str3 + " does not have the separator");
                }
            }
        }
        return hashMap;
    }

    static HashMap<String, Object> getEventPropertiesFromExtras(Bundle bundle) {
        HashMap<String, Object> hashMap = new HashMap<>();
        for (String str : bundle.keySet()) {
            if (str.contains(PTConstants.PT_EVENT_PROPERTY_KEY)) {
                if (bundle.getString(str) == null || bundle.getString(str).isEmpty()) {
                    PTLog.verbose("Property Key is Empty. Skipping Property: " + str);
                } else if (str.contains(PTConstants.PT_EVENT_PROPERTY_SEPERATOR)) {
                    hashMap.put(str.split(PTConstants.PT_EVENT_PROPERTY_SEPERATOR)[1], bundle.getString(str));
                } else {
                    PTLog.verbose("Property " + str + " does not have the separator");
                }
            }
        }
        return hashMap;
    }

    public static int getTimerEnd(Bundle bundle) {
        String str = "-1";
        for (String str2 : bundle.keySet()) {
            if (str2.contains(PTConstants.PT_TIMER_END)) {
                str = bundle.getString(str2);
            }
        }
        if (str.contains("$D_")) {
            str = str.split(PTConstants.PT_TIMER_SPLIT)[1];
        }
        return str.equals("-1") ? Target.SIZE_ORIGINAL : (int) (Long.parseLong(str) - (System.currentTimeMillis() / 1000));
    }

    public static boolean isNotificationInTray(Context context, int i) {
        for (StatusBarNotification statusBarNotification : ((NotificationManager) context.getSystemService("notification")).getActiveNotifications()) {
            if (statusBarNotification.getId() == i) {
                return true;
            }
        }
        return false;
    }

    public static Notification getNotificationById(Context context, int i) {
        for (StatusBarNotification statusBarNotification : ((NotificationManager) context.getSystemService("notification")).getActiveNotifications()) {
            if (statusBarNotification.getId() == i) {
                return statusBarNotification.getNotification();
            }
        }
        return null;
    }

    public static ArrayList<Integer> getNotificationIds(Context context) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (StatusBarNotification statusBarNotification : ((NotificationManager) context.getSystemService("notification")).getActiveNotifications()) {
            if (statusBarNotification.getPackageName().equalsIgnoreCase(context.getPackageName())) {
                arrayList.add(Integer.valueOf(statusBarNotification.getId()));
            }
        }
        return arrayList;
    }

    static void raiseNotificationClicked(Context context, Bundle bundle, CleverTapInstanceConfig cleverTapInstanceConfig) {
        CleverTapAPI defaultInstance;
        if (cleverTapInstanceConfig != null) {
            defaultInstance = CleverTapAPI.instanceWithConfig(context, cleverTapInstanceConfig);
        } else {
            defaultInstance = CleverTapAPI.getDefaultInstance(context);
        }
        if (defaultInstance != null) {
            defaultInstance.pushNotificationClickedEvent(bundle);
        }
    }

    static JSONArray getActionKeys(Bundle bundle) {
        String string = bundle.getString(Constants.WZRK_ACTIONS);
        if (string == null) {
            return null;
        }
        try {
            return new JSONArray(string);
        } catch (Throwable th) {
            PTLog.debug("error parsing notification actions: " + th.getLocalizedMessage());
            return null;
        }
    }

    static void showToast(final Context context, final String str, CleverTapInstanceConfig cleverTapInstanceConfig) {
        if (cleverTapInstanceConfig != null) {
            CTExecutorFactory.executors(cleverTapInstanceConfig).mainTask().execute("PushTemplatesUtils#showToast", new Callable<Void>() {
                @Override
                public Void call() {
                    if (TextUtils.isEmpty(str)) {
                        return null;
                    }
                    Toast.makeText(context, str, 0).show();
                    return null;
                }
            });
        }
    }

    static void createSilentNotificationChannel(Context context) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        if (notificationManager != null && Build.VERSION.SDK_INT >= 26) {
            if (f$.ExternalSyntheticApiModelOutline0.m(notificationManager, PTConstants.PT_SILENT_CHANNEL_ID) == null || !(f$.ExternalSyntheticApiModelOutline0.m(notificationManager, PTConstants.PT_SILENT_CHANNEL_ID) == null || isNotificationChannelEnabled(f$.ExternalSyntheticApiModelOutline0.m(notificationManager, PTConstants.PT_SILENT_CHANNEL_ID)))) {
                Uri parse = Uri.parse("android.resource://" + context.getPackageName() + "/raw/pt_silent_sound");
                Trace$.ExternalSyntheticApiModelOutline0.m$1();
                NotificationChannel m = f$.ExternalSyntheticApiModelOutline0.m(PTConstants.PT_SILENT_CHANNEL_ID, PTConstants.PT_SILENT_CHANNEL_NAME, 4);
                if (parse != null) {
                    Trace$.ExternalSyntheticApiModelOutline0.m(m, parse, new AudioAttributes.Builder().setUsage(5).build());
                }
                Trace$.ExternalSyntheticApiModelOutline0.m(m, PTConstants.PT_SILENT_CHANNEL_DESC);
                Trace$.ExternalSyntheticApiModelOutline0.m(m, false);
                f$.ExternalSyntheticApiModelOutline0.m(notificationManager, m);
            }
        }
    }

    static void deleteSilentNotificationChannel(Context context) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        if (notificationManager != null && Build.VERSION.SDK_INT >= 26 && f$.ExternalSyntheticApiModelOutline0.m(notificationManager, PTConstants.PT_SILENT_CHANNEL_ID) != null && isNotificationChannelEnabled(f$.ExternalSyntheticApiModelOutline0.m(notificationManager, PTConstants.PT_SILENT_CHANNEL_ID))) {
            Trace$.ExternalSyntheticApiModelOutline0.m(notificationManager, PTConstants.PT_SILENT_CHANNEL_ID);
        }
    }

    static boolean isNotificationChannelEnabled(NotificationChannel notificationChannel) {
        return (Build.VERSION.SDK_INT < 26 || notificationChannel == null || f$.ExternalSyntheticApiModelOutline0.m(notificationChannel) == 0) ? false : true;
    }

    public static Bitmap setBitMapColour(Context context, int i, String str) throws NullPointerException {
        if (str == null || str.isEmpty()) {
            return null;
        }
        int colour = getColour(str, "#A6A6A6");
        Drawable mutate = ((Drawable) Objects.requireNonNull(ContextCompat.getDrawable(context, i))).mutate();
        mutate.setColorFilter(new PorterDuffColorFilter(colour, PorterDuff.Mode.SRC_IN));
        return drawableToBitmap(mutate);
    }

    public static int getColour(String str, String str2) {
        try {
            return Color.parseColor(str);
        } catch (Exception unused) {
            PTLog.debug("Can not parse colour value: " + str + " Switching to default colour: " + str2);
            return Color.parseColor(str2);
        }
    }

    static void setFallback(Boolean bool) {
        PTConstants.PT_FALLBACK = bool.booleanValue();
    }

    public static boolean getFallback() {
        return PTConstants.PT_FALLBACK;
    }

    public static int getFlipInterval(Bundle bundle) {
        String string = bundle.getString(PTConstants.PT_FLIP_INTERVAL);
        if (string != null) {
            try {
                return Math.max(Integer.parseInt(string), PTConstants.PT_FLIP_INTERVAL_TIME);
            } catch (Exception unused) {
                PTLog.debug("Flip Interval couldn't be converted to number: " + string + " - Defaulting to base value: 4000");
            }
        }
        return PTConstants.PT_FLIP_INTERVAL_TIME;
    }

    static void deleteImageFromStorage(Context context, Intent intent) {
        String stringExtra = intent.getStringExtra(Constants.WZRK_PUSH_ID);
        File dir = new ContextWrapper(context.getApplicationContext()).getDir(PTConstants.PT_DIR, 0);
        String absolutePath = dir.getAbsolutePath();
        String[] list = dir.list();
        if (list != null) {
            for (String str : list) {
                if (stringExtra != null && str.contains(stringExtra)) {
                    if (!new File(absolutePath + "/" + str).delete()) {
                        PTLog.debug("Failed to clean up the following file: " + str);
                    }
                } else if (stringExtra == null && str.contains("null")) {
                    if (!new File(absolutePath + "/" + str).delete()) {
                        PTLog.debug("Failed to clean up the following file: " + str);
                    }
                }
            }
        }
    }
}