package cn.jpush.android.s; import android.app.Application; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import cn.jpush.android.api.CallBackParams; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JThirdPlatFormInterface; import cn.jpush.android.helper.JCoreHelper; import cn.jpush.android.helper.Logger; import cn.jpush.android.helper.g; import cn.jpush.android.local.JPushConstants; import cn.jpush.android.r.b; import cn.jpush.android.service.TagAliasReceiver; import cn.jpush.android.u.f; import com.tencent.smtt.sdk.TbsReaderView; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import org.json.JSONArray; import org.json.JSONObject; public class a { private static ConcurrentLinkedQueue<Long> a = new ConcurrentLinkedQueue<>(); private static int a(long j) { if (a.size() >= 10) { long longValue = j - a.element().longValue(); if (longValue < 0) { a.clear(); return 2; } else if (longValue <= 10000) { return 1; } else { while (a.size() >= 10) { a.poll(); } } } a.offer(Long.valueOf(j)); return 0; } public static long a(Context context, String str, int i, long j) { Logger.d("TagAliasHelper", "action - onRecvTagAliasCallBack"); try { JSONObject jSONObject = new JSONObject(str); int optInt = jSONObject.optInt("code", JPushInterface.ErrorCode.UNKNOWN_ERROR); if (i == 0) { j = jSONObject.optLong("sequence"); } Intent intent = new Intent(); if (i == 0) { intent.setAction(TagAliasReceiver.ACTION_TAG_ALIAS_CALLBACK); } else { String messageReceiverClass = JPushConstants.getMessageReceiverClass(context); if (!TextUtils.isEmpty(messageReceiverClass)) { intent = new Intent(context, Class.forName(messageReceiverClass)); } intent.setAction("cn.jpush.android.intent.RECEIVE_MESSAGE"); if (i == 1) { intent.putExtra("message_type", 1); } else { intent.putExtra("message_type", 2); } } intent.addCategory(context.getPackageName()); intent.putExtra("proto_type", i); intent.setPackage(context.getPackageName()); intent.putExtra(TagAliasReceiver.KEY_TAGALIASOPERATOR_CALLBACKCODE, optInt); intent.putExtra(TagAliasReceiver.KEY_TAGALIASOPERATOR_SEQID, j); Intent a2 = b.a().a(context, j, optInt, jSONObject, intent); if (a2 != null) { context.sendBroadcast(a2); } return j; } catch (Throwable unused) { Logger.w("TagAliasHelper", "tagalias msgContent:" + str); return -1; } } protected static String a(Context context, String str, long j, int i) { if (c(i)) { try { JSONObject a2 = a(i); if (b(2, i)) { if (TextUtils.isEmpty(str)) { Logger.ee("TagAliasHelper", "alias was empty. Give up action."); a(context, 2, JPushInterface.ErrorCode.NULL_TAGANDALIAS, j); return null; } else if (!a(context, 2, str, j)) { return null; } else { a2.put("alias", str); } } String jSONObject = a2.toString(); Logger.d("TagAliasHelper", "alias str:" + jSONObject); if (!TextUtils.isEmpty(jSONObject)) { return jSONObject; } Logger.d("TagAliasHelper", "alias request action was empty"); } catch (Throwable th) { Logger.w("TagAliasHelper", "alias exception:" + th); } } else { Logger.e("TagAliasHelper", "unsupport alias action type"); a(context, 2, JPushInterface.ErrorCode.UNKNOWN_ERROR, j); } return null; } /* JADX DEBUG: Multi-variable search result rejected for r2v4, resolved type: org.json.JSONArray */ /* JADX WARN: Multi-variable type inference failed */ protected static String a(Context context, List<String> list, long j, int i, int i2, int i3) { String str; String str2; if (i != 0) { try { JSONObject a2 = a(i); if (a(1, i)) { if (list != null) { if (!list.isEmpty()) { HashSet hashSet = new HashSet(list); if (!a(context, 1, hashSet, j)) { return null; } String b = b(hashSet); if (!b(context, b, j, 1)) { return null; } if (i != 6) { JSONArray jSONArray = new JSONArray(); for (String str3 : list) { jSONArray.put(str3); } str = "tags"; str2 = jSONArray; } else if (TextUtils.isEmpty(b)) { Logger.ee("TagAliasHelper", "stags was empty. Give up action."); a(context, 1, JPushInterface.ErrorCode.NULL_TAGANDALIAS, j); return null; } else { str = "tags"; str2 = b; } a2.put(str, str2); } } Logger.ee("TagAliasHelper", "tags was empty. Give up action."); a(context, 1, JPushInterface.ErrorCode.NULL_TAGANDALIAS, j); return null; } if (i == 5) { if (i3 == -1) { i3 = 1; } a2.put("curr", i3); } String jSONObject = a2.toString(); Logger.d("TagAliasHelper", "tag str:" + jSONObject); if (!TextUtils.isEmpty(jSONObject)) { return jSONObject; } Logger.d("TagAliasHelper", "tag request action was empty"); } catch (Throwable th) { Logger.w("TagAliasHelper", "tag exception:" + th); } } else { Logger.e("TagAliasHelper", "unsupport tag action type"); a(context, 1, JPushInterface.ErrorCode.UNKNOWN_ERROR, j); } return null; } private static String a(Context context, List<String> list, String str, long j) { HashSet hashSet = list != null ? new HashSet(list) : null; if (str != null && !a(context, 0, str, j)) { return null; } if (hashSet != null && !a(context, 0, hashSet, j)) { return null; } String b = b(hashSet); if (!b(context, b, j, 0)) { return null; } if (b == null && str == null) { Logger.ee("TagAliasHelper", "NULL alias and tags. Give up action."); a(context, 0, JPushInterface.ErrorCode.NULL_TAGANDALIAS, j); return null; } Logger.dd("TagAliasHelper", "action:setAliasAndTags - alias:" + str + ", tags:" + b); try { JSONObject jSONObject = new JSONObject(); jSONObject.put(JThirdPlatFormInterface.KEY_PLATFORM, "a"); if (str != null) { jSONObject.put("alias", str); } if (hashSet != null) { jSONObject.put("tags", b); } String jSONObject2 = jSONObject.toString(); Logger.d("TagAliasHelper", "tagalias str:" + jSONObject2); if (!TextUtils.isEmpty(jSONObject2)) { return jSONObject2; } Logger.d("TagAliasHelper", "tagalias request action was empty"); return null; } catch (Throwable th) { Logger.w("TagAliasHelper", "tagalias exception:" + th); a(context, 0, JPushInterface.ErrorCode.UNKNOWN_ERROR, j); } } public static Set<String> a(Set<String> set) { if (set == null) { return null; } if (set.isEmpty()) { return set; } LinkedHashSet linkedHashSet = new LinkedHashSet(); int i = 0; for (String str : set) { if (TextUtils.isEmpty(str) || !f.a(str)) { Logger.ee("TagAliasHelper", "Invalid tag : " + str); } else { linkedHashSet.add(str); i++; if (i >= 1000) { Logger.ww("TagAliasHelper", "The lenght of tags maybe more than 1000."); return linkedHashSet; } } } return linkedHashSet; } private static JSONObject a(int i) { JSONObject jSONObject = new JSONObject(); jSONObject.put(JThirdPlatFormInterface.KEY_PLATFORM, "a"); jSONObject.put("op", b(i)); return jSONObject; } public static void a(Context context, int i, int i2, long j) { try { Intent intent = new Intent(); intent.addCategory(context.getPackageName()); intent.setPackage(context.getPackageName()); if (i == 0) { intent.setAction(TagAliasReceiver.ACTION_TAG_ALIAS_CALLBACK); } else { intent.setAction("cn.jpush.android.intent.RECEIVE_MESSAGE"); intent.setClass(context, Class.forName(JPushConstants.getMessageReceiverClass(context))); if (i == 1) { intent.putExtra("message_type", 1); } else { intent.putExtra("message_type", 2); } } intent.putExtra(TagAliasReceiver.KEY_TAGALIASOPERATOR_CALLBACKCODE, i2); intent.putExtra(TagAliasReceiver.KEY_TAGALIASOPERATOR_SEQID, j); context.sendBroadcast(intent); } catch (Throwable th) { Logger.ww("TagAliasHelper", "NotifyTagAliasError:" + th.getMessage()); } } protected static void a(Context context, int i, long j, String str) { Logger.dd("TagAliasHelper", "tagalias:" + str); if (str != null) { int i2 = i == 0 ? 10 : i == 1 ? 28 : 29; JCoreHelper.sendRequest(context, JPushConstants.SDK_TYPE, i2, i == 0 ? 4 : i == 1 ? 1 : 2, j, 20000, b.a(JCoreHelper.getAppKey(context), i2, str)); return; } Logger.w("TagAliasHelper", "tagaliasRequest was null"); } public static void a(Context context, Bundle bundle) { int i; int i2; String str; int i3; String str2; String str3; String string = bundle.getString("alias"); ArrayList<String> stringArrayList = bundle.getStringArrayList("tags"); long j = bundle.getLong("seq", 0); try { i = Integer.parseInt(bundle.getString("proto_type")); } catch (Throwable th) { Logger.w("TagAliasHelper", "load tag/alias proto type failed - error:" + th); a(context, 0, JPushInterface.ErrorCode.UNKNOWN_ERROR, j); i = 0; } try { i2 = Integer.parseInt(bundle.getString("action_type")); } catch (Throwable th2) { Logger.w("TagAliasHelper", "load tag/alias action type failed - error:" + th2); a(context, i, JPushInterface.ErrorCode.UNKNOWN_ERROR, j); i2 = 0; } if (cn.jpush.android.cache.a.d(context)) { i3 = JPushInterface.ErrorCode.PUSH_STOPED; } else { int a2 = a(System.currentTimeMillis()); if (a2 != 0) { if (a2 == 1) { str3 = "TagAliasHelper"; str2 = "set tags/alias too soon,over 10 times in 10s"; } else { str3 = "TagAliasHelper"; str2 = "set tags/alias failed,time shaft error,please try again"; } Logger.w(str3, str2); a(context, i, a2 == 1 ? JPushInterface.ErrorCode.INVOKE_TOO_SOON : JPushInterface.ErrorCode.INCORRECT_TIME, j); return; } else if (b.a().a(context, i, j)) { i3 = JPushInterface.ErrorCode.ERROR_CODE_SERVER_UNAVAILABLE; } else { String str4 = null; if (i == 0) { Logger.d("TagAliasHelper", "old tag/alias proto"); str4 = a(context, stringArrayList, string, j); } else if (i == 1) { str4 = a(context, stringArrayList, j, i2, -1, -1); } else if (i == 2) { str4 = a(context, string, j, i2); } if (str4 == null || !(i == 1 || i == 2)) { str = str4; } else if (b.a().a(i)) { str = str4; b.a().a(i, i2, j, stringArrayList, string); } else { StringBuilder sb = new StringBuilder(); sb.append(i == 1 ? "tag" : "alias"); sb.append(" is operatoring, please wait last operator complete"); Logger.w("TagAliasHelper", sb.toString()); a(context, i, i == 1 ? JPushInterface.ErrorCode.ERROR_CODE_TAG_OPERATORING : JPushInterface.ErrorCode.ERROR_CODE_ALIAS_OPERATORING, j); return; } a(context, i, j, str); return; } } a(context, i, i3, j); } public static void a(Context context, String str, Set<String> set, CallBackParams callBackParams) { long a2 = g.a(); if (callBackParams != null) { c.a().a(context, Long.valueOf(a2), callBackParams); } if (!(context instanceof Application)) { context = context.getApplicationContext(); } if (callBackParams != null && callBackParams.protoType == 0) { c.a().a(context); } Bundle bundle = new Bundle(); bundle.putString("alias", str); ArrayList<String> arrayList = null; if (set != null) { arrayList = new ArrayList<>(set); } bundle.putStringArrayList("tags", arrayList); bundle.putLong("seq", a2); StringBuilder sb = new StringBuilder(); int i = 0; sb.append(callBackParams != null ? callBackParams.protoType : 0); sb.append(""); bundle.putString("proto_type", sb.toString()); StringBuilder sb2 = new StringBuilder(); if (callBackParams != null) { i = callBackParams.action; } sb2.append(i); sb2.append(""); bundle.putString("action_type", sb2.toString()); JCoreHelper.runActionWithService(context, JPushConstants.SDK_TYPE, "tagalis", bundle); } private static boolean a(int i, int i2) { return i == 1 && (i2 == 1 || i2 == 2 || i2 == 3 || i2 == 6); } private static boolean a(Context context, int i, String str, long j) { int b = f.b(str); if (b == 0) { return true; } Logger.dd("TagAliasHelper", "Invalid alias: " + str + ", will not set alias this time."); a(context, i, b, j); return false; } private static boolean a(Context context, int i, Set<String> set, long j) { int a2 = f.a(set); if (a2 == 0) { return true; } Logger.dd("TagAliasHelper", "Invalid tags, will not set tags this time."); a(context, i, a2, j); return false; } private static boolean a(String str, boolean z) { int length = !TextUtils.isEmpty(str) ? str.getBytes().length + 0 : 0; Logger.v("TagAliasHelper", "tags length:" + length); if (z) { if (length <= 5000) { return true; } } else if (length <= 7000) { return true; } return false; } private static String b(int i) { switch (i) { case 1: return "add"; case 2: return "set"; case 3: return "del"; case 4: return "clean"; case 5: return "get"; case 6: return "valid"; default: return null; } } public static String b(Set<String> set) { String str = null; if (set == null) { return null; } if (set.isEmpty()) { return ""; } int i = 0; for (String str2 : set) { if (TextUtils.isEmpty(str2) || !f.a(str2)) { Logger.ee("TagAliasHelper", "Invalid tag: " + str2); } else { if (str != null) { str2 = str + "," + str2; } i++; if (i >= 1000) { return str2; } str = str2; } } return str; } private static boolean b(int i, int i2) { return i == 2 && i2 == 2; } private static boolean b(Context context, String str, long j, int i) { if (str != null) { if (!a(str.replaceAll(",", ""), i != 0)) { a(context, i, JPushInterface.ErrorCode.TOO_LONG_TAGALIAS, j); StringBuilder sb = new StringBuilder(); sb.append("The length of tags should be less than "); sb.append(i != 0 ? TbsReaderView.ReaderCallback.GET_BAR_ANIMATING : 7000); sb.append(" bytes."); Logger.ww("TagAliasHelper", sb.toString()); return false; } } return true; } private static boolean c(int i) { return i == 2 || i == 3 || i == 5; } }