package com.huawei.hms.push; import android.net.Uri; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; import com.huawei.hms.push.constant.RemoteMessageConst; import com.huawei.hms.push.utils.DateUtil; import com.huawei.hms.push.utils.JsonUtil; import com.huawei.hms.support.api.push.PushException; import com.huawei.hms.support.log.HMSLog; import java.io.Serializable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.text.ParseException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; public class RemoteMessage implements Parcelable { public static final Parcelable.Creator<RemoteMessage> CREATOR = new b(); public static final int PRIORITY_HIGH = 1; public static final int PRIORITY_NORMAL = 2; public static final int PRIORITY_UNKNOWN = 0; public static final String[] a = new String[0]; public static final int[] b = new int[0]; public static final long[] c = new long[0]; public static final HashMap<String, Object> d; public static final HashMap<String, Object> e; public static final HashMap<String, Object> f; public static final HashMap<String, Object> g; public static final HashMap<String, Object> h; public Bundle i; public Notification j; public static class Builder { public final Bundle a = new Bundle(); public final Map<String, String> b = new HashMap(); public Builder(String str) { this.a.putString(RemoteMessageConst.TO, str); } public Builder addData(String str, String str2) { if (str != null) { this.b.put(str, str2); return this; } throw new IllegalArgumentException("add data failed, key is null."); } public RemoteMessage build() { Bundle bundle = new Bundle(); JSONObject jSONObject = new JSONObject(); try { for (Map.Entry<String, String> entry : this.b.entrySet()) { jSONObject.put(entry.getKey(), entry.getValue()); } try { String jSONObject2 = jSONObject.toString(); JSONObject jSONObject3 = new JSONObject(); jSONObject3.put(RemoteMessageConst.COLLAPSE_KEY, this.a.getString(RemoteMessageConst.COLLAPSE_KEY)); jSONObject3.put(RemoteMessageConst.TTL, this.a.getInt(RemoteMessageConst.TTL)); jSONObject3.put(RemoteMessageConst.SEND_MODE, this.a.getInt(RemoteMessageConst.SEND_MODE)); jSONObject3.put(RemoteMessageConst.RECEIPT_MODE, this.a.getInt(RemoteMessageConst.RECEIPT_MODE)); JSONObject jSONObject4 = new JSONObject(); if (jSONObject.length() != 0) { jSONObject4.put(RemoteMessageConst.DATA, jSONObject2); } jSONObject4.put(RemoteMessageConst.MSGID, this.a.getString(RemoteMessageConst.MSGID)); jSONObject3.put(RemoteMessageConst.MessageBody.MSG_CONTENT, jSONObject4); bundle.putByteArray(RemoteMessageConst.MSGBODY, jSONObject3.toString().getBytes(w.a)); bundle.putString(RemoteMessageConst.TO, this.a.getString(RemoteMessageConst.TO)); bundle.putString("message_type", this.a.getString("message_type")); return new RemoteMessage(bundle); } catch (JSONException unused) { HMSLog.w("RemoteMessage", "JSONException: parse message body failed."); throw new PushException(PushException.EXCEPTION_SEND_FAILED); } } catch (JSONException unused2) { HMSLog.w("RemoteMessage", "JSONException: parse data to json failed."); throw new PushException(PushException.EXCEPTION_SEND_FAILED); } } public Builder clearData() { this.b.clear(); return this; } public Builder setCollapseKey(String str) { this.a.putString(RemoteMessageConst.COLLAPSE_KEY, str); return this; } public Builder setData(Map<String, String> map) { this.b.clear(); for (Map.Entry<String, String> entry : map.entrySet()) { this.b.put(entry.getKey(), entry.getValue()); } return this; } public Builder setMessageId(String str) { this.a.putString(RemoteMessageConst.MSGID, str); return this; } public Builder setMessageType(String str) { this.a.putString("message_type", str); return this; } public Builder setReceiptMode(int i) { if (i == 1 || i == 0) { this.a.putInt(RemoteMessageConst.RECEIPT_MODE, i); return this; } throw new IllegalArgumentException("receipt mode can only be 0 or 1."); } public Builder setSendMode(int i) { if (i == 0 || i == 1) { this.a.putInt(RemoteMessageConst.SEND_MODE, i); return this; } throw new IllegalArgumentException("send mode can only be 0 or 1."); } public Builder setTtl(int i) { if (i <= 0 || i > 1296000) { throw new IllegalArgumentException("ttl must be greater than or equal to 1 and less than or equal to 1296000"); } this.a.putInt(RemoteMessageConst.TTL, i); return this; } } @Retention(RetentionPolicy.SOURCE) public @interface MessagePriority { } public static class Notification implements Serializable { public final long[] A; public final String B; public final String a; public final String b; public final String[] c; public final String d; public final String e; public final String[] f; public final String g; public final String h; public final String i; public final String j; public final String k; public final String l; public final String m; public final Uri n; public final int o; public final String p; public final int q; public final int r; public final int s; public final int[] t; public final String u; public final int v; public final String w; public final int x; public final String y; public final String z; public /* synthetic */ Notification(Bundle bundle, b bVar) { this(bundle); } public final Integer a(String str) { if (str != null) { try { return Integer.valueOf(str); } catch (NumberFormatException unused) { HMSLog.w("RemoteMessage", "NumberFormatException: get " + str + " failed."); } } return null; } public Integer getBadgeNumber() { return a(this.w); } public String getBody() { return this.d; } public String[] getBodyLocalizationArgs() { String[] strArr = this.f; return strArr == null ? new String[0] : (String[]) strArr.clone(); } public String getBodyLocalizationKey() { return this.e; } public String getChannelId() { return this.m; } public String getClickAction() { return this.k; } public String getColor() { return this.j; } public String getIcon() { return this.g; } public Uri getImageUrl() { String str = this.p; if (str == null) { return null; } return Uri.parse(str); } public Integer getImportance() { return a(this.y); } public String getIntentUri() { return this.l; } public int[] getLightSettings() { int[] iArr = this.t; return iArr == null ? new int[0] : (int[]) iArr.clone(); } public Uri getLink() { return this.n; } public int getNotifyId() { return this.o; } public String getSound() { return this.h; } public String getTag() { return this.i; } public String getTicker() { return this.z; } public String getTitle() { return this.a; } public String[] getTitleLocalizationArgs() { String[] strArr = this.c; return strArr == null ? new String[0] : (String[]) strArr.clone(); } public String getTitleLocalizationKey() { return this.b; } public long[] getVibrateConfig() { long[] jArr = this.A; return jArr == null ? new long[0] : (long[]) jArr.clone(); } public Integer getVisibility() { return a(this.B); } public Long getWhen() { if (!TextUtils.isEmpty(this.u)) { try { return Long.valueOf(DateUtil.parseUtcToMillisecond(this.u)); } catch (ParseException unused) { HMSLog.w("RemoteMessage", "ParseException: parse when failed."); } catch (StringIndexOutOfBoundsException unused2) { HMSLog.w("RemoteMessage", "StringIndexOutOfBoundsException: parse when failed."); } } return null; } public boolean isAutoCancel() { return this.x == 1; } public boolean isDefaultLight() { return this.q == 1; } public boolean isDefaultSound() { return this.r == 1; } public boolean isDefaultVibrate() { return this.s == 1; } public boolean isLocalOnly() { return this.v == 1; } public Notification(Bundle bundle) { this.a = bundle.getString(RemoteMessageConst.Notification.NOTIFY_TITLE); this.d = bundle.getString("content"); this.b = bundle.getString(RemoteMessageConst.Notification.TITLE_LOC_KEY); this.e = bundle.getString(RemoteMessageConst.Notification.BODY_LOC_KEY); this.c = bundle.getStringArray(RemoteMessageConst.Notification.TITLE_LOC_ARGS); this.f = bundle.getStringArray(RemoteMessageConst.Notification.BODY_LOC_ARGS); this.g = bundle.getString(RemoteMessageConst.Notification.ICON); this.j = bundle.getString(RemoteMessageConst.Notification.COLOR); this.h = bundle.getString(RemoteMessageConst.Notification.SOUND); this.i = bundle.getString(RemoteMessageConst.Notification.TAG); this.m = bundle.getString(RemoteMessageConst.Notification.CHANNEL_ID); this.k = bundle.getString(RemoteMessageConst.Notification.CLICK_ACTION); this.l = bundle.getString(RemoteMessageConst.Notification.INTENT_URI); this.o = bundle.getInt(RemoteMessageConst.Notification.NOTIFY_ID); String string = bundle.getString("url"); this.n = !TextUtils.isEmpty(string) ? Uri.parse(string) : null; this.p = bundle.getString(RemoteMessageConst.Notification.NOTIFY_ICON); this.q = bundle.getInt(RemoteMessageConst.Notification.DEFAULT_LIGHT_SETTINGS); this.r = bundle.getInt(RemoteMessageConst.Notification.DEFAULT_SOUND); this.s = bundle.getInt(RemoteMessageConst.Notification.DEFAULT_VIBRATE_TIMINGS); this.t = bundle.getIntArray(RemoteMessageConst.Notification.LIGHT_SETTINGS); this.u = bundle.getString(RemoteMessageConst.Notification.WHEN); this.v = bundle.getInt(RemoteMessageConst.Notification.LOCAL_ONLY); this.w = bundle.getString(RemoteMessageConst.Notification.BADGE_SET_NUM, null); this.x = bundle.getInt(RemoteMessageConst.Notification.AUTO_CANCEL); this.y = bundle.getString(RemoteMessageConst.Notification.PRIORITY, null); this.z = bundle.getString(RemoteMessageConst.Notification.TICKER); this.A = bundle.getLongArray(RemoteMessageConst.Notification.VIBRATE_TIMINGS); this.B = bundle.getString(RemoteMessageConst.Notification.VISIBILITY, null); } } public RemoteMessage(Bundle bundle) { this.i = a(bundle); } public static JSONObject b(Bundle bundle) { try { return new JSONObject(v.a(bundle.getByteArray(RemoteMessageConst.MSGBODY))); } catch (JSONException unused) { HMSLog.w("RemoteMessage", "JSONException:parse message body failed."); return null; } } public static JSONObject c(JSONObject jSONObject) { if (jSONObject != null) { return jSONObject.optJSONObject(RemoteMessageConst.MessageBody.PARAM); } return null; } public static JSONObject d(JSONObject jSONObject) { if (jSONObject != null) { return jSONObject.optJSONObject(RemoteMessageConst.MessageBody.PS_CONTENT); } return null; } public final Bundle a(Bundle bundle) { Bundle bundle2 = new Bundle(); JSONObject b2 = b(bundle); JSONObject a2 = a(b2); String string = JsonUtil.getString(a2, RemoteMessageConst.DATA, null); bundle2.putString(RemoteMessageConst.ANALYTIC_INFO, JsonUtil.getString(a2, RemoteMessageConst.ANALYTIC_INFO, null)); bundle2.putString(RemoteMessageConst.DEVICE_TOKEN, bundle.getString(RemoteMessageConst.DEVICE_TOKEN)); JSONObject d2 = d(a2); JSONObject b3 = b(d2); JSONObject c2 = c(d2); if (bundle.getInt(RemoteMessageConst.INPUT_TYPE) != 1 || !s.a(a2, d2, string)) { String string2 = bundle.getString(RemoteMessageConst.TO); String string3 = bundle.getString("message_type"); String string4 = JsonUtil.getString(a2, RemoteMessageConst.MSGID, null); bundle2.putString(RemoteMessageConst.TO, string2); bundle2.putString(RemoteMessageConst.DATA, string); bundle2.putString(RemoteMessageConst.MSGID, string4); bundle2.putString("message_type", string3); JsonUtil.transferJsonObjectToBundle(b2, bundle2, d); bundle2.putBundle(RemoteMessageConst.NOTIFICATION, a(b2, a2, d2, b3, c2)); return bundle2; } bundle2.putString(RemoteMessageConst.DATA, v.a(bundle.getByteArray(RemoteMessageConst.MSGBODY))); return bundle2; } public final int describeContents() { return 0; } public String getAnalyticInfo() { return this.i.getString(RemoteMessageConst.ANALYTIC_INFO); } public Map<String, String> getAnalyticInfoMap() { HashMap hashMap = new HashMap(); String string = this.i.getString(RemoteMessageConst.ANALYTIC_INFO); if (string != null && !string.trim().isEmpty()) { try { JSONObject jSONObject = new JSONObject(string); Iterator<String> keys = jSONObject.keys(); while (keys.hasNext()) { String valueOf = String.valueOf(keys.next()); hashMap.put(valueOf, String.valueOf(jSONObject.get(valueOf))); } } catch (JSONException unused) { HMSLog.w("RemoteMessage", "JSONException: get analyticInfo from map failed."); } } return hashMap; } public String getCollapseKey() { return this.i.getString(RemoteMessageConst.COLLAPSE_KEY); } public String getData() { return this.i.getString(RemoteMessageConst.DATA); } public Map<String, String> getDataOfMap() { HashMap hashMap = new HashMap(); String string = this.i.getString(RemoteMessageConst.DATA); if (string != null && !string.trim().isEmpty()) { try { JSONObject jSONObject = new JSONObject(string); Iterator<String> keys = jSONObject.keys(); while (keys.hasNext()) { String valueOf = String.valueOf(keys.next()); hashMap.put(valueOf, String.valueOf(jSONObject.get(valueOf))); } } catch (JSONException unused) { HMSLog.w("RemoteMessage", "JSONException: get data from map failed"); } } return hashMap; } public String getFrom() { return this.i.getString(RemoteMessageConst.FROM); } public String getMessageId() { return this.i.getString(RemoteMessageConst.MSGID); } public String getMessageType() { return this.i.getString("message_type"); } public Notification getNotification() { Bundle bundle = this.i.getBundle(RemoteMessageConst.NOTIFICATION); if (this.j == null && bundle != null) { this.j = new Notification(bundle, null); } if (this.j == null) { this.j = new Notification(new Bundle(), null); } return this.j; } public int getOriginalUrgency() { int i2 = this.i.getInt(RemoteMessageConst.ORI_URGENCY); if (i2 == 1 || i2 == 2) { return i2; } return 0; } public int getReceiptMode() { return this.i.getInt(RemoteMessageConst.RECEIPT_MODE); } public int getSendMode() { return this.i.getInt(RemoteMessageConst.SEND_MODE); } public long getSentTime() { try { String string = this.i.getString(RemoteMessageConst.SEND_TIME); if (!TextUtils.isEmpty(string)) { return Long.parseLong(string); } return 0; } catch (NumberFormatException unused) { HMSLog.w("RemoteMessage", "NumberFormatException: get sendTime error."); return 0; } } public String getTo() { return this.i.getString(RemoteMessageConst.TO); } public String getToken() { return this.i.getString(RemoteMessageConst.DEVICE_TOKEN); } public int getTtl() { return this.i.getInt(RemoteMessageConst.TTL); } public int getUrgency() { int i2 = this.i.getInt(RemoteMessageConst.URGENCY); if (i2 == 1 || i2 == 2) { return i2; } return 0; } public void writeToParcel(Parcel parcel, int i2) { parcel.writeBundle(this.i); parcel.writeSerializable(this.j); } public RemoteMessage(Parcel parcel) { this.i = parcel.readBundle(); this.j = (Notification) parcel.readSerializable(); } public static JSONObject b(JSONObject jSONObject) { if (jSONObject != null) { return jSONObject.optJSONObject(RemoteMessageConst.MessageBody.NOTIFY_DETAIL); } return null; } static { HashMap<String, Object> hashMap = new HashMap<>(8); d = hashMap; hashMap.put(RemoteMessageConst.FROM, ""); d.put(RemoteMessageConst.COLLAPSE_KEY, ""); d.put(RemoteMessageConst.SEND_TIME, ""); d.put(RemoteMessageConst.TTL, Integer.valueOf((int) RemoteMessageConst.DEFAULT_TTL)); d.put(RemoteMessageConst.URGENCY, 2); d.put(RemoteMessageConst.ORI_URGENCY, 2); d.put(RemoteMessageConst.SEND_MODE, 0); d.put(RemoteMessageConst.RECEIPT_MODE, 0); HashMap<String, Object> hashMap2 = new HashMap<>(8); e = hashMap2; hashMap2.put(RemoteMessageConst.Notification.TITLE_LOC_KEY, ""); e.put(RemoteMessageConst.Notification.BODY_LOC_KEY, ""); e.put(RemoteMessageConst.Notification.NOTIFY_ICON, ""); e.put(RemoteMessageConst.Notification.TITLE_LOC_ARGS, a); e.put(RemoteMessageConst.Notification.BODY_LOC_ARGS, a); e.put(RemoteMessageConst.Notification.TICKER, ""); e.put(RemoteMessageConst.Notification.NOTIFY_TITLE, ""); e.put("content", ""); HashMap<String, Object> hashMap3 = new HashMap<>(8); f = hashMap3; hashMap3.put(RemoteMessageConst.Notification.ICON, ""); f.put(RemoteMessageConst.Notification.COLOR, ""); f.put(RemoteMessageConst.Notification.SOUND, ""); f.put(RemoteMessageConst.Notification.DEFAULT_LIGHT_SETTINGS, 1); f.put(RemoteMessageConst.Notification.LIGHT_SETTINGS, b); f.put(RemoteMessageConst.Notification.DEFAULT_SOUND, 1); f.put(RemoteMessageConst.Notification.DEFAULT_VIBRATE_TIMINGS, 1); f.put(RemoteMessageConst.Notification.VIBRATE_TIMINGS, c); HashMap<String, Object> hashMap4 = new HashMap<>(8); g = hashMap4; hashMap4.put(RemoteMessageConst.Notification.TAG, ""); g.put(RemoteMessageConst.Notification.WHEN, ""); g.put(RemoteMessageConst.Notification.LOCAL_ONLY, 1); g.put(RemoteMessageConst.Notification.BADGE_SET_NUM, ""); g.put(RemoteMessageConst.Notification.PRIORITY, ""); g.put(RemoteMessageConst.Notification.AUTO_CANCEL, 1); g.put(RemoteMessageConst.Notification.VISIBILITY, ""); g.put(RemoteMessageConst.Notification.CHANNEL_ID, ""); HashMap<String, Object> hashMap5 = new HashMap<>(3); h = hashMap5; hashMap5.put(RemoteMessageConst.Notification.CLICK_ACTION, ""); h.put(RemoteMessageConst.Notification.INTENT_URI, ""); h.put("url", ""); } public final Bundle a(JSONObject jSONObject, JSONObject jSONObject2, JSONObject jSONObject3, JSONObject jSONObject4, JSONObject jSONObject5) { Bundle bundle = new Bundle(); JsonUtil.transferJsonObjectToBundle(jSONObject3, bundle, e); JsonUtil.transferJsonObjectToBundle(jSONObject4, bundle, f); JsonUtil.transferJsonObjectToBundle(jSONObject, bundle, g); JsonUtil.transferJsonObjectToBundle(jSONObject5, bundle, h); bundle.putInt(RemoteMessageConst.Notification.NOTIFY_ID, JsonUtil.getInt(jSONObject2, RemoteMessageConst.Notification.NOTIFY_ID, 0)); return bundle; } public static JSONObject a(JSONObject jSONObject) { if (jSONObject != null) { return jSONObject.optJSONObject(RemoteMessageConst.MessageBody.MSG_CONTENT); } return null; } }