智能工厂.apk(点击下载) / a.java


package cn.jpush.android.p;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import cn.jpush.android.helper.Logger;
import java.util.Locale;

public class a {

    /* renamed from: cn.jpush.android.p.a$a  reason: collision with other inner class name */
    public static class C0011a {
        public String a;
        public CharSequence b;
        public int c;
        public int d;
        public int e;
        public String f;
        public Uri g;
        public boolean h;

        public C0011a(String str, CharSequence charSequence, int i, int i2, String str2) {
            this.a = str;
            this.b = charSequence;
            this.c = i;
            this.e = i2;
            this.f = str2;
        }
    }

    private static int a(int i) {
        switch (i) {
            case -2:
                return 1;
            case -1:
                return 2;
            case 0:
            default:
                return 3;
            case 1:
            case 2:
                return 4;
        }
    }

    private static NotificationChannel a(Context context, String str) {
        try {
            if (Build.VERSION.SDK_INT >= 26 && !TextUtils.isEmpty(str)) {
                NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
                NotificationChannel notificationChannel = notificationManager != null ? notificationManager.getNotificationChannel(str) : null;
                if (notificationChannel != null) {
                    Logger.dd("ChannelHelper", "channel has created: " + str);
                    return notificationChannel;
                }
                Logger.dd("ChannelHelper", "not found channed id from user set,will use sdk default channel ID");
            }
        } catch (Throwable th) {
            Logger.e("ChannelHelper", "config channelID error,will use sdk default channel ID:" + th);
        }
        return null;
    }

    private static String a(Context context, int i) {
        String str;
        String str2;
        String str3;
        switch (i) {
            case -2:
                str = "MIN";
                break;
            case -1:
                str = "LOW";
                break;
            case 0:
            default:
                str = "DEFAULT";
                break;
            case 1:
            case 2:
                str = "HIGH";
                break;
        }
        String str4 = "";
        try {
            String str5 = "jg_channel_name_p_" + str.toLowerCase();
            int identifier = context.getResources().getIdentifier(str5, "string", context.getPackageName());
            if (identifier != 0) {
                str4 = context.getResources().getString(identifier);
                str2 = "ChannelHelper";
                str3 = "found " + str4 + " from resource by name:" + str5;
            } else {
                str2 = "ChannelHelper";
                str3 = "not found string value from resource by name:" + str5;
            }
            Logger.dd(str2, str3);
        } catch (Throwable th) {
            Logger.ww("ChannelHelper", "get resource channel ID failed:" + th.getMessage());
        }
        if (!TextUtils.isEmpty(str4)) {
            return str4;
        }
        boolean z = true;
        try {
            z = Locale.getDefault().getLanguage().contains("zh");
        } catch (Throwable th2) {
            Logger.ww("ChannelHelper", "get language failed:" + th2.getMessage());
        }
        switch (i) {
            case -2:
            case -1:
                return z ? "不重要" : "LOW";
            case 0:
            default:
                return z ? "普通" : "NORMAL";
            case 1:
            case 2:
                return z ? "重要" : "HIGH";
        }
    }

    private static String a(Context context, int i, int i2) {
        int a = a(i);
        String str = "JPush_" + a + "_" + i2;
        String a2 = a(context, i);
        Logger.d("ChannelHelper", "channelId:" + str + ",channelName:" + a2);
        return a(context, str, a2, a, i2, null) ? str : "";
    }

    private static String a(C0011a aVar) {
        String str = "JPush_" + aVar.d + "_" + aVar.e;
        if (aVar.g == null) {
            return str;
        }
        return str + "_" + aVar.f;
    }

    public static void a(Context context) {
        a(context, -1, 0);
        a(context, 0, 7);
    }

    public static void a(Context context, Notification.Builder builder, String str, CharSequence charSequence, int i, int i2, String str2) {
        C0011a aVar = new C0011a(str, charSequence, i, i2, str2);
        a(context, aVar);
        b.a(context, builder, aVar);
    }

    public static void a(Context context, Notification notification, String str, CharSequence charSequence, int i, int i2, String str2) {
        C0011a aVar = new C0011a(str, charSequence, i, i2, str2);
        a(context, aVar);
        b.a(notification, aVar);
    }

    public static void a(Context context, C0011a aVar) {
        NotificationChannel a;
        NotificationChannel a2;
        if (b.c(context)) {
            Logger.d("ChannelHelper", "in silence push time,change defaults to 0");
            aVar.a = "";
            aVar.e = 0;
            aVar.f = null;
        } else if (Build.VERSION.SDK_INT >= 26 && (a2 = a(context, aVar.a)) != null) {
            aVar.a = a2.getId();
            aVar.b = a2.getName();
            aVar.d = a2.getImportance();
            aVar.c = b(aVar.d);
            aVar.g = a2.getSound();
            if (aVar.g != null) {
                aVar.f = aVar.g.getPath();
            }
            aVar.h = true;
            return;
        }
        if (aVar.c == -2 || aVar.c == -1) {
            aVar.e = 0;
            aVar.f = null;
        } else if (aVar.c >= 0 && aVar.e == 0 && TextUtils.isEmpty(aVar.f)) {
            aVar.c = -1;
        }
        aVar.e &= 7;
        if (aVar.c == 2) {
            aVar.c = 1;
        }
        aVar.d = a(aVar.c);
        aVar.c = b(aVar.d);
        aVar.g = b.a(context, aVar.f);
        if (aVar.g != null) {
            aVar.e &= -2;
        } else {
            aVar.f = null;
        }
        if (TextUtils.isEmpty(aVar.a)) {
            aVar.a = a(aVar);
            if (Build.VERSION.SDK_INT >= 26 && (a = a(context, aVar.a)) != null) {
                aVar.a = a.getId();
                aVar.b = a.getName();
                aVar.h = true;
                return;
            }
        }
        if (TextUtils.isEmpty(aVar.b)) {
            aVar.b = a(context, aVar.c);
        }
        Logger.d("ChannelHelper", "create channelId:" + aVar.a + ",channelName:" + ((Object) aVar.b) + " soundUri:" + aVar.g);
        aVar.h = a(context, aVar.a, aVar.b, aVar.d, aVar.e, aVar.g);
    }

    private static boolean a(Context context, String str, CharSequence charSequence, int i, int i2, Uri uri) {
        if (Build.VERSION.SDK_INT < 26 || context.getApplicationInfo().targetSdkVersion < 26) {
            Logger.d("ChannelHelper", "sdkversion < 26, no need use notificationChannel!");
            return false;
        }
        try {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
            if (notificationManager == null) {
                Logger.ee("ChannelHelper", "NotificationManager is null!");
                return false;
            }
            Logger.dd("ChannelHelper", "prepare NotificationChannel, channelId=" + str + "");
            try {
                NotificationChannel notificationChannel = notificationManager.getNotificationChannel(str);
                if (notificationChannel != null) {
                    notificationChannel.setName(charSequence);
                    notificationManager.createNotificationChannel(notificationChannel);
                    return true;
                }
            } catch (Throwable th) {
                Logger.w("ChannelHelper", "check channelID failed:" + th.getMessage());
            }
            NotificationChannel notificationChannel2 = new NotificationChannel(str, charSequence, i);
            try {
                if (Build.VERSION.SDK_INT < 28 || notificationManager.getNotificationChannelGroup("JIGUANG_CHANNEL_GROUP") == null) {
                    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("JIGUANG_CHANNEL_GROUP", cn.jpush.android.u.a.b(context)));
                }
                notificationChannel2.setGroup("JIGUANG_CHANNEL_GROUP");
            } catch (Throwable th2) {
                Logger.ww("ChannelHelper", "config channel group failed:" + th2.getMessage());
            }
            try {
                notificationChannel2.enableLights((i2 & 4) != 0);
            } catch (Throwable th3) {
                Logger.ww("ChannelHelper", "enableLights fail:" + th3);
            }
            try {
                notificationChannel2.enableVibration((i2 & 2) != 0);
            } catch (Throwable th4) {
                Logger.ww("ChannelHelper", "enableVibration fail:" + th4);
            }
            if (uri != null) {
                try {
                    notificationChannel2.setSound(uri, null);
                } catch (Throwable th5) {
                    Logger.ww("ChannelHelper", "setSound fail:" + th5);
                }
            } else {
                if (!((i2 & 1) != 0)) {
                    notificationChannel2.setSound(null, null);
                }
            }
            notificationManager.createNotificationChannel(notificationChannel2);
            return true;
        } catch (Throwable th6) {
            Logger.ee("ChannelHelper", "new NotificationChannel fail:" + th6);
            return false;
        }
    }

    private static int b(int i) {
        switch (i) {
            case 1:
                return -2;
            case 2:
                return -1;
            case 3:
            default:
                return 0;
            case 4:
            case 5:
                return 1;
        }
    }
}