工作空间 v3.6.5.2版本的 MD5 值为:58e65af156c65a63bf64ed2e64960853
以下内容为反编译后的 SDKManager.java 源代码,内容仅作参考
package com.paic.crm.sdk.sensitive;
import android.content.Context;
import android.text.TextUtils;
import com.paic.crm.sdk.sensitive.data.DataFile;
import com.paic.crm.sdk.sensitive.data.DataModel;
import com.paic.crm.sdk.sensitive.data.Model;
import com.paic.crm.sdk.sensitive.data.Packet;
import com.paic.crm.sdk.sensitive.data.Unit;
import com.paic.crm.sdk.sensitive.data.Vector;
import com.paic.crm.sdk.sensitive.file.FileConfig;
import com.paic.crm.sdk.sensitive.http.SDKHttp;
import com.paic.crm.sdk.sensitive.listener.ErrorListener;
import com.paic.crm.sdk.sensitive.log.SDKLog;
import com.paic.crm.sdk.sensitive.parser.ModelParser;
import com.paic.crm.sdk.sensitive.parser.SymbolParser;
import com.paic.crm.sdk.sensitive.utils.Utils;
import com.uusafe.emm.client.service.keyword.DefaultModel;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class SDKManager {
private static volatile SDKManager mManager;
private FileConfig mConfig;
private SDKHttp mHttp;
private ErrorListener mListener;
private volatile boolean iUpdate = false;
private final ModelParser mModelParser = new ModelParser();
private final List<DataFile> mModelList = new ArrayList();
private SDKManager() {
}
public static void error(String str, String str2) {
SDKLog.e(str, str2);
ErrorListener errorListener = getInstance().mListener;
if (errorListener != null) {
errorListener.onError(str, str2);
}
}
public static SDKManager getInstance() {
if (mManager == null) {
synchronized (SDKManager.class) {
if (mManager == null) {
mManager = new SDKManager();
}
}
}
return mManager;
}
private void model_default(InputStream inputStream) {
if (this.mConfig.hasModelFile()) {
return;
}
parserModel(this.mConfig.loadOrigin(inputStream), SDKConfig.ERROR_MODEL_DEFAULT);
}
private synchronized int parserModel(String str, String str2) {
Vector<String> parser;
int i = 0;
if (TextUtils.isEmpty(str)) {
error(str2, "模型文本为空");
return 0;
}
this.mConfig.saveOrigin(str);
String symbol_12 = SymbolParser.symbol_12(str);
SDKLog.i("model", symbol_12);
try {
ArrayList arrayList = new ArrayList();
JSONArray jSONArray = new JSONArray(symbol_12);
for (int i2 = 0; i2 < jSONArray.length(); i2++) {
String string = jSONArray.getString(i2);
DataModel parserJson = this.mModelParser.parserJson(string);
if (parserJson != null && (parser = this.mModelParser.parser(parserJson)) != null) {
if (TextUtils.equals(parser.x, parser.y)) {
parser.y = "";
}
String replaceAll = string.replaceAll("[\\r\\n\\t ]", "");
DataFile dataFile = new DataFile();
dataFile.mID = parserJson.mID;
dataFile.mName = parserJson.mName;
dataFile.mMD5 = Utils.md5(replaceAll.getBytes());
dataFile.mRegex = parser.x;
dataFile.mAppend = parser.y;
arrayList.add(dataFile);
}
}
if (this.mConfig.saveConfig(arrayList)) {
synchronized (this.mModelList) {
this.mModelList.clear();
this.mModelList.addAll(arrayList);
}
}
i = 1;
} catch (Exception e2) {
error(str2, e2.getMessage());
}
return i;
}
public void init(boolean z, Context context, File file) {
init(z, context, file, Integer.MAX_VALUE);
}
public void init(boolean z, Context context, File file, int i) {
this.mHttp = new SDKHttp(context, z ? "https://umap-crm.pa18.com/umap-crm-mobile/" : "https://test-umap-crm.pa18.com:56434/umap-crm-mobile/", file, DefaultModel.CRT_NAME);
this.mConfig = new FileConfig(file, z);
SDKLog.setLevel(i);
String str = z ? DefaultModel.PRD_NAME : DefaultModel.STG_NAME;
File file2 = new File(file, str);
try {
model_default(file2.exists() ? new FileInputStream(file2) : context.getAssets().open(str));
} catch (Exception unused) {
}
List<DataFile> loadConfig = this.mConfig.loadConfig();
if (loadConfig.isEmpty()) {
return;
}
synchronized (this.mModelList) {
this.mModelList.clear();
this.mModelList.addAll(loadConfig);
}
}
public Packet packer(String str, long j, long j2) {
String jSONArray;
List<Model> test = test(str);
Packet packet = new Packet();
if (test != null) {
packet.mMatch = new ArrayList();
if (test.isEmpty()) {
packet.mCode = 1;
jSONArray = "";
} else {
packet.mCode = 2;
JSONArray jSONArray2 = new JSONArray();
for (Model model : test) {
JSONObject jSONObject = new JSONObject();
JSONArray jSONArray3 = new JSONArray();
try {
jSONObject.put("modelId", model.mID);
jSONObject.put("modelName", model.mName);
jSONObject.put("matchResult", jSONArray3);
jSONArray2.put(jSONObject);
} catch (Exception e2) {
error(SDKConfig.ERROR_PARKET, e2.getMessage());
}
for (Unit unit : model.mMatch) {
packet.mMatch.add(unit.mText);
JSONObject jSONObject2 = new JSONObject();
try {
jSONObject2.put("matchText", unit.mText);
jSONObject2.put("matchType", unit.mType);
jSONObject2.put("startTime", j);
jSONObject2.put("endTime", j2);
jSONArray3.put(jSONObject2);
} catch (JSONException e3) {
error(SDKConfig.ERROR_PARKET, e3.getMessage());
}
}
}
jSONArray = jSONArray2.toString();
}
packet.mUcp = jSONArray;
} else {
packet.mCode = 0;
}
return packet;
}
public void setErrorListener(ErrorListener errorListener) {
this.mListener = errorListener;
}
public List<Model> test(String str) {
String str2;
String str3;
ArrayList<DataFile> arrayList;
long currentTimeMillis = System.currentTimeMillis();
ArrayList arrayList2 = null;
if (this.mHttp == null) {
str2 = SDKConfig.ERROR_INIT;
str3 = "未初始化";
} else if (TextUtils.isEmpty(str)) {
str2 = SDKConfig.ERROR_INPUT;
str3 = "文本不能为空";
} else {
synchronized (this.mModelList) {
arrayList = new ArrayList(this.mModelList);
}
if (!arrayList.isEmpty()) {
for (DataFile dataFile : arrayList) {
try {
List<Unit> parser = ModelParser.parser(str, dataFile);
if (arrayList2 == null) {
arrayList2 = new ArrayList();
}
if (!parser.isEmpty()) {
Model model = new Model();
model.mID = dataFile.mID;
model.mName = dataFile.mName;
model.mMatch = parser;
arrayList2.add(model);
}
} catch (Exception e2) {
error(SDKConfig.ERROR_PARSER, e2.getMessage());
}
}
SDKLog.i("test", "耗时: " + (System.currentTimeMillis() - currentTimeMillis));
return arrayList2;
}
str2 = SDKConfig.ERROR_INPUT;
str3 = "当前并无模型";
}
error(str2, str3);
SDKLog.i("test", "耗时: " + (System.currentTimeMillis() - currentTimeMillis));
return arrayList2;
}
public int update(Map<String, String> map) {
String str;
String str2;
if (this.mHttp == null) {
str = SDKConfig.ERROR_INIT;
str2 = "未初始化";
} else if (!this.iUpdate) {
this.iUpdate = true;
int parserModel = parserModel(this.mHttp.request(map), SDKConfig.ERROR_MODEL_JSON);
if (parserModel == 0) {
parserModel = -1;
}
this.iUpdate = false;
return parserModel;
} else {
str = SDKConfig.ERROR_UPDATE;
str2 = "同步更新中";
}
error(str, str2);
return 0;
}
}