HiPushSDK.java 源代码
package com.hichip.push;
import android.content.Context;
import com.hichip.base.HiLog;
import com.hichip.base.HiThread;
import com.hichip.getuid.HiUID;
import com.meizu.cloud.pushsdk.notification.model.AdvanceSetting;
import com.meizu.cloud.pushsdk.notification.model.AdvertisementOption;
import com.ss.android.socialbase.downloader.segment.Segment;
import com.xiaomi.mipush.sdk.Constants;
import java.util.Locale;
import org.apache.poi.xwpf.converter.xhtml.internal.XHTMLConstants;
public class HiPushSDK {
public static final int PUSH_LANGUAGE_English = 0;
public static final int PUSH_LANGUAGE_French = 3;
public static final int PUSH_LANGUAGE_German = 4;
public static final int PUSH_LANGUAGE_Italian = 9;
public static final int PUSH_LANGUAGE_Japanese = 8;
public static final int PUSH_LANGUAGE_Korean = 7;
public static final int PUSH_LANGUAGE_Polish = 13;
public static final int PUSH_LANGUAGE_Portugal = 6;
public static final int PUSH_LANGUAGE_Russian = 14;
public static final int PUSH_LANGUAGE_SimplifiedChinese = 1;
public static final int PUSH_LANGUAGE_Spanish = 5;
public static final int PUSH_LANGUAGE_Thai = 11;
public static final int PUSH_LANGUAGE_TraditionalChinese = 2;
public static final int PUSH_LANGUAGE_Turkish = 10;
public static final int PUSH_LANGUAGE_Vietnam = 12;
public static final int PUSH_RESULT_FAIL = -1;
public static final int PUSH_RESULT_NULL_TOKEN = -2;
public static final int PUSH_RESULT_SUCESS = 0;
public static final int PUSH_TYPE_BIND = 0;
public static final int PUSH_TYPE_UNBIND = 1;
public static final int PUSH_TYPE_UPNAME = 2;
public static final String[] limit = {"AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "XXXX", "YYYY", "ZZZZ", "AAES", "DEAA", "FDTAA", "SECRUI", "NNNN", "WWWW", "TTTT", "UUUU", "SSSS", "PPPP", "AABB", "AACC", "SSAA", "SSAC", "AADD", "SSAE", "AAEE", "AAFF", "SSAH", "AAHH", "AAKK", "SSAK", "SSAM", "SSAS"};
private String HI_SERVER_MOBILE_IP_NEW;
private int[] SubID;
private String company;
private String devname;
private Context mContext;
private OnPushResult onPushResult;
private String pushname;
private String token;
private String uid;
public interface OnPushResult {
void pushBindResult(int i, int i2, int i3);
}
public HiPushSDK(Context context, String str, String str2, String str3, String str4, String str5, OnPushResult onPushResult, String str6) {
this.HI_SERVER_MOBILE_IP_NEW = "47.91.149.233";
this.pushname = null;
this.uid = null;
this.company = null;
this.token = null;
this.SubID = new int[1];
this.devname = null;
HiLog.e(str2 + ":::" + str6 + ":::" + str4 + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
this.mContext = context;
init(str, str2, str3, str4, str5, onPushResult, str6);
if (str6 != null) {
setPushServer(str6);
}
}
public HiPushSDK(Context context, String str, String str2, String str3, String str4, OnPushResult onPushResult, String str5) {
this.HI_SERVER_MOBILE_IP_NEW = "47.91.149.233";
this.pushname = null;
this.uid = null;
this.company = null;
this.token = null;
this.SubID = new int[1];
this.devname = null;
HiLog.e(str2 + ":::" + str5 + ":::" + str4 + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
this.mContext = context;
init(str, str2, str3, str4, onPushResult, str5);
if (str5 != null) {
setPushServer(str5);
}
}
public HiPushSDK(String str, String str2, String str3, OnPushResult onPushResult, String str4) {
this.HI_SERVER_MOBILE_IP_NEW = "47.91.149.233";
this.pushname = null;
this.uid = null;
this.company = null;
this.token = null;
this.SubID = new int[1];
this.devname = null;
HiLog.e(str2 + ":::" + str4 + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
init(str, str2, str3, onPushResult, str4);
if (str4 != null) {
setPushServer(str4);
}
}
public HiPushSDK(String str, String str2, String str3, OnPushResult onPushResult) {
this.HI_SERVER_MOBILE_IP_NEW = "47.91.149.233";
this.pushname = null;
this.uid = null;
this.company = null;
this.token = null;
this.SubID = new int[1];
this.devname = null;
init(str, str2, str3, onPushResult, null);
}
public void setPushServer(String str) {
String[] strArr;
HiLog.e("" + str + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
int indexOf = this.uid.indexOf(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
int[] iArr = new int[4];
if (indexOf > 6 || this.uid.length() < 6) {
return;
}
String substring = this.uid.substring(0, indexOf);
int i = 0;
while (true) {
strArr = limit;
if (i >= strArr.length) {
break;
}
if (substring.equalsIgnoreCase(strArr[i])) {
this.HI_SERVER_MOBILE_IP_NEW = str;
HiLog.e("" + str + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
break;
}
i++;
}
if (i == strArr.length) {
String HiFindUid_2M = HiUID.HiFindUid_2M(substring, iArr, 0);
HiLog.e("setPushServer setPushServer" + iArr[0] + "::" + iArr[1] + "::" + iArr[2] + ";;;;" + HiFindUid_2M, 1, 0);
if (iArr[2] != -1 && HiFindUid_2M != null) {
HiLog.e("setPushServer" + HiFindUid_2M + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
this.HI_SERVER_MOBILE_IP_NEW = HiFindUid_2M;
return;
}
Context context = this.mContext;
if (context != null) {
HiUID.isExistCreat(context);
String HiFindUidPush = HiUID.HiFindUidPush(substring, 0);
if (HiFindUidPush != null) {
HiLog.e("setPushServer" + HiFindUidPush + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
this.HI_SERVER_MOBILE_IP_NEW = HiFindUidPush;
}
}
}
}
public void setPushServer(String str, int i, int i2) {
String[] strArr;
HiLog.e("" + str + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
if (i == 1) {
this.HI_SERVER_MOBILE_IP_NEW = str;
return;
}
int indexOf = this.uid.indexOf(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
int[] iArr = new int[4];
if (indexOf > 6 || this.uid.length() < 6) {
return;
}
String substring = this.uid.substring(0, indexOf);
int i3 = 0;
while (true) {
strArr = limit;
if (i3 >= strArr.length) {
break;
}
if (substring.equalsIgnoreCase(strArr[i3])) {
this.HI_SERVER_MOBILE_IP_NEW = str;
HiLog.e("" + str + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
break;
}
i3++;
}
if (i3 == strArr.length) {
String HiFindUidEXT_2M = HiUID.HiFindUidEXT_2M(substring, iArr, 0, i2);
HiLog.e("setPushServer setPushServer" + iArr[0] + "::" + iArr[1] + "::" + iArr[2], 1, 0);
if (iArr[2] != -1 && HiFindUidEXT_2M != null) {
HiLog.e("" + HiFindUidEXT_2M + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
this.HI_SERVER_MOBILE_IP_NEW = HiFindUidEXT_2M;
return;
}
Context context = this.mContext;
if (context != null) {
HiUID.isExistCreat(context);
String HiFindUidPush = HiUID.HiFindUidPush(substring, i2);
if (HiFindUidPush != null) {
HiLog.e("" + HiFindUidPush + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
this.HI_SERVER_MOBILE_IP_NEW = HiFindUidPush;
}
}
}
}
public String getPushServer() {
return this.HI_SERVER_MOBILE_IP_NEW;
}
public void SetPushDevName(String str) {
this.devname = str;
}
public String GetPushDevName() {
return this.devname;
}
public void SetPushName(String str) {
this.pushname = str;
}
public void init(String str, String str2, String str3, OnPushResult onPushResult, String str4) {
this.token = str;
this.uid = str2;
if (str2 != null && str2.length() == 15) {
String substring = str2.substring(0, 4);
if (substring.equalsIgnoreCase("AAAA") || substring.equalsIgnoreCase("BBBB") || substring.equalsIgnoreCase("CCCC") || substring.equalsIgnoreCase("DDDD") || substring.equalsIgnoreCase("EEEE") || substring.equalsIgnoreCase("FFFF") || substring.equalsIgnoreCase("GGGG") || substring.equalsIgnoreCase("HHHH") || substring.equalsIgnoreCase("IIII") || substring.equalsIgnoreCase("JJJJ") || substring.equalsIgnoreCase("KKKK") || substring.equalsIgnoreCase("XXXX") || substring.equalsIgnoreCase("YYYY") || substring.equalsIgnoreCase("ZZZZ")) {
StringBuffer stringBuffer = new StringBuffer(str2);
stringBuffer.insert(4, Constants.ACCEPT_TIME_SEPARATOR_SERVER);
stringBuffer.insert(11, Constants.ACCEPT_TIME_SEPARATOR_SERVER);
this.uid = stringBuffer.toString();
}
}
this.company = str3;
this.onPushResult = onPushResult;
HiLog.e("" + str4 + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
if (str4 != null) {
this.HI_SERVER_MOBILE_IP_NEW = str4;
}
}
public void init(String str, String str2, String str3, String str4, OnPushResult onPushResult, String str5) {
this.token = str;
this.uid = str2;
if (str2 != null && str2.length() == 15) {
String substring = str2.substring(0, 4);
if (substring.equalsIgnoreCase("AAAA") || substring.equalsIgnoreCase("BBBB") || substring.equalsIgnoreCase("CCCC") || substring.equalsIgnoreCase("DDDD") || substring.equalsIgnoreCase("EEEE") || substring.equalsIgnoreCase("FFFF") || substring.equalsIgnoreCase("GGGG") || substring.equalsIgnoreCase("HHHH") || substring.equalsIgnoreCase("IIII") || substring.equalsIgnoreCase("JJJJ") || substring.equalsIgnoreCase("KKKK") || substring.equalsIgnoreCase("XXXX") || substring.equalsIgnoreCase("YYYY") || substring.equalsIgnoreCase("ZZZZ")) {
StringBuffer stringBuffer = new StringBuffer(str2);
stringBuffer.insert(4, Constants.ACCEPT_TIME_SEPARATOR_SERVER);
stringBuffer.insert(11, Constants.ACCEPT_TIME_SEPARATOR_SERVER);
this.uid = stringBuffer.toString();
}
}
this.company = str3;
this.onPushResult = onPushResult;
this.pushname = str4;
HiLog.e("" + str5 + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
if (str5 != null) {
this.HI_SERVER_MOBILE_IP_NEW = str5;
}
}
public void init(String str, String str2, String str3, String str4, String str5, OnPushResult onPushResult, String str6) {
this.token = str;
this.uid = str2;
if (str2 != null && str2.length() == 15) {
String substring = str2.substring(0, 4);
if (substring.equalsIgnoreCase("AAAA") || substring.equalsIgnoreCase("BBBB") || substring.equalsIgnoreCase("CCCC") || substring.equalsIgnoreCase("DDDD") || substring.equalsIgnoreCase("EEEE") || substring.equalsIgnoreCase("FFFF") || substring.equalsIgnoreCase("GGGG") || substring.equalsIgnoreCase("HHHH") || substring.equalsIgnoreCase("IIII") || substring.equalsIgnoreCase("JJJJ") || substring.equalsIgnoreCase("KKKK") || substring.equalsIgnoreCase("XXXX") || substring.equalsIgnoreCase("YYYY") || substring.equalsIgnoreCase("ZZZZ")) {
StringBuffer stringBuffer = new StringBuffer(str2);
stringBuffer.insert(4, Constants.ACCEPT_TIME_SEPARATOR_SERVER);
stringBuffer.insert(11, Constants.ACCEPT_TIME_SEPARATOR_SERVER);
this.uid = stringBuffer.toString();
}
}
this.company = str3;
this.onPushResult = onPushResult;
this.pushname = str4;
this.devname = str5;
HiLog.e("" + str6 + ":::::" + this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
if (str6 != null) {
this.HI_SERVER_MOBILE_IP_NEW = str6;
}
}
public void bind() {
String str = this.token;
if (str == null || str.length() <= 1) {
HiLog.v("bind token null", 1, 1);
OnPushResult onPushResult = this.onPushResult;
if (onPushResult != null) {
onPushResult.pushBindResult(this.SubID[0], 0, -2);
return;
}
return;
}
HiLog.e("bind", 1, 0);
new ThreadBindExt().startThread();
}
public void unbind(int i) {
HiLog.e("unbind", 1, 0);
this.SubID[0] = i;
if (i <= 1) {
new ThreadUnBind().startThread();
} else {
new ThreadUnBindExt().startThread();
}
}
public void UpdateName(int i, String str) {
HiLog.e("UpdateName", 1, 0);
this.SubID[0] = i;
this.devname = str;
new ThreadUpdateName().startThread();
}
private class ThreadBind extends HiThread {
private ThreadBind() {
}
@Override
public void run() {
String str;
if (HiPushSDK.this.pushname == null) {
str = "xinge:" + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token;
} else {
str = HiPushSDK.this.pushname + Constants.COLON_SEPARATOR + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token + "&language=" + HiPushSDK.this.JudgeSelfLanguage();
}
HiLog.e("" + str + "::::::::" + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
HiPushAPI.HIPUSHRegist(HiPushSDK.this.uid, str, HiPushSDK.this.SubID, HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW);
if (HiPushSDK.this.SubID[0] > 0) {
int i = HiPushAPI.HIPUSHBind(HiPushSDK.this.SubID[0], str, HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW) == 0 ? 0 : -1;
HiPushSDK hiPushSDK = HiPushSDK.this;
hiPushSDK.callbackPushResult(hiPushSDK.SubID[0], 0, i);
} else {
HiPushSDK hiPushSDK2 = HiPushSDK.this;
hiPushSDK2.callbackPushResult(hiPushSDK2.SubID[0], 0, -1);
}
}
}
private class ThreadBindExt extends HiThread {
private ThreadBindExt() {
}
@Override
public void run() {
String str;
if (HiPushSDK.this.pushname == null) {
str = "xinge:" + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token;
} else {
str = HiPushSDK.this.pushname + Constants.COLON_SEPARATOR + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token + "&language=" + HiPushSDK.this.JudgeSelfLanguage();
}
HiLog.e("" + str + "::::::::" + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
int HIPUSHBindExt = HiPushSDK.this.devname == null ? HiPushAPI.HIPUSHBindExt(HiPushSDK.this.uid, str, HiPushSDK.this.SubID, HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW) : HiPushAPI.HIPUSHBindAndName(HiPushSDK.this.uid, str, HiPushSDK.this.devname, HiPushSDK.this.SubID, HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW);
HiLog.e("bruce bind SubID:" + HiPushSDK.this.SubID[0] + "server ip " + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
if (HIPUSHBindExt == 0) {
if (HiPushSDK.this.SubID[0] <= 0) {
HiPushSDK hiPushSDK = HiPushSDK.this;
hiPushSDK.callbackPushResult(hiPushSDK.SubID[0], 0, -1);
return;
} else {
HiPushSDK hiPushSDK2 = HiPushSDK.this;
hiPushSDK2.callbackPushResult(hiPushSDK2.SubID[0], 0, 0);
return;
}
}
HiPushSDK hiPushSDK3 = HiPushSDK.this;
hiPushSDK3.callbackPushResult(hiPushSDK3.SubID[0], 0, -1);
}
}
public void callbackPushResult(int i, int i2, int i3) {
OnPushResult onPushResult = this.onPushResult;
if (onPushResult != null) {
onPushResult.pushBindResult(i, i2, i3);
}
}
private class ThreadUnBindExt extends HiThread {
private ThreadUnBindExt() {
}
@Override
public void run() {
String str;
if (HiPushSDK.this.pushname == null) {
str = "xinge:" + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token;
} else {
str = HiPushSDK.this.pushname + Constants.COLON_SEPARATOR + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token + "&language=" + HiPushSDK.this.JudgeSelfLanguage();
}
HiLog.e("" + str + "::::::::" + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
HiLog.e("bruce unbind SubID:" + HiPushSDK.this.SubID[0] + "server ip " + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
int HIPUSHUnBindExt = HiPushAPI.HIPUSHUnBindExt(str, HiPushSDK.this.SubID[0], HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW);
StringBuilder sb = new StringBuilder();
sb.append("unbind SubID:");
sb.append(HiPushSDK.this.SubID[0]);
HiLog.e(sb.toString(), 1, 0);
if (HIPUSHUnBindExt == 0) {
HiPushSDK hiPushSDK = HiPushSDK.this;
hiPushSDK.callbackPushResult(hiPushSDK.SubID[0], 1, 0);
} else {
HiPushSDK hiPushSDK2 = HiPushSDK.this;
hiPushSDK2.callbackPushResult(hiPushSDK2.SubID[0], 1, -1);
}
}
}
private class ThreadUpdateName extends HiThread {
private ThreadUpdateName() {
}
@Override
public void run() {
String str;
if (HiPushSDK.this.pushname == null) {
str = "xinge:" + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token;
} else {
str = HiPushSDK.this.pushname + Constants.COLON_SEPARATOR + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token + "&language=" + HiPushSDK.this.JudgeSelfLanguage();
}
HiLog.e("" + str + "::::::::" + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
HiLog.e("bruce unbind SubID:" + HiPushSDK.this.SubID[0] + "server ip " + HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW, 1, 0);
int HIPUSHUpLoadName = HiPushAPI.HIPUSHUpLoadName(str, HiPushSDK.this.devname, HiPushSDK.this.SubID[0], HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW);
StringBuilder sb = new StringBuilder();
sb.append("unbind SubID:");
sb.append(HiPushSDK.this.SubID[0]);
HiLog.e(sb.toString(), 1, 0);
if (HIPUSHUpLoadName == 0) {
HiPushSDK hiPushSDK = HiPushSDK.this;
hiPushSDK.callbackPushResult(hiPushSDK.SubID[0], 2, 0);
} else {
HiPushSDK hiPushSDK2 = HiPushSDK.this;
hiPushSDK2.callbackPushResult(hiPushSDK2.SubID[0], 2, -1);
}
}
}
private class ThreadUnBind extends HiThread {
private ThreadUnBind() {
}
@Override
public void run() {
String str;
if (HiPushSDK.this.pushname == null) {
str = "xinge:" + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token;
} else {
str = HiPushSDK.this.pushname + Constants.COLON_SEPARATOR + HiPushSDK.this.company + ":android:" + HiPushSDK.this.token + "&language=" + HiPushSDK.this.JudgeSelfLanguage();
}
HiPushAPI.HIPUSHRegist(HiPushSDK.this.uid, str, HiPushSDK.this.SubID, HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW);
if (HiPushSDK.this.SubID[0] > 0) {
int i = HiPushAPI.HIPUSHUnBind(HiPushSDK.this.SubID[0], str, HiPushSDK.this.HI_SERVER_MOBILE_IP_NEW) == 0 ? 0 : -1;
HiPushSDK hiPushSDK = HiPushSDK.this;
hiPushSDK.callbackPushResult(hiPushSDK.SubID[0], 1, i);
} else {
HiPushSDK hiPushSDK2 = HiPushSDK.this;
hiPushSDK2.callbackPushResult(hiPushSDK2.SubID[0], 1, -1);
}
}
}
public int JudgeSelfLanguage() {
String language = Locale.getDefault().getLanguage();
if (language != null) {
language.hashCode();
char c = 65535;
switch (language.hashCode()) {
case 3201:
if (language.equals("de")) {
c = 0;
break;
}
break;
case 3241:
if (language.equals(Segment.JsonKey.END)) {
c = 1;
break;
}
break;
case 3246:
if (language.equals("es")) {
c = 2;
break;
}
break;
case 3276:
if (language.equals("fr")) {
c = 3;
break;
}
break;
case 3371:
if (language.equals(AdvanceSetting.NETWORK_TYPE)) {
c = 4;
break;
}
break;
case 3383:
if (language.equals("ja")) {
c = 5;
break;
}
break;
case 3428:
if (language.equals("ko")) {
c = 6;
break;
}
break;
case 3580:
if (language.equals("pl")) {
c = 7;
break;
}
break;
case 3588:
if (language.equals(AdvertisementOption.PRIORITY_VALID_TIME)) {
c = '\b';
break;
}
break;
case 3651:
if (language.equals("ru")) {
c = '\t';
break;
}
break;
case 3700:
if (language.equals(XHTMLConstants.TH_ELEMENT)) {
c = '\n';
break;
}
break;
case 3710:
if (language.equals("tr")) {
c = 11;
break;
}
break;
case 3763:
if (language.equals("vi")) {
c = '\f';
break;
}
break;
case 3886:
if (language.equals("zh")) {
c = '\r';
break;
}
break;
}
switch (c) {
case 0:
return 4;
case 2:
return 5;
case 3:
return 3;
case 4:
return 9;
case 5:
return 8;
case 6:
return 7;
case 7:
return 13;
case '\b':
return 6;
case '\t':
return 14;
case '\n':
return 11;
case 11:
return 10;
case '\f':
return 12;
case '\r':
return 1;
}
}
return 0;
}
}