号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0
以下内容为反编译后的 IntelligentCacheService.java 源代码,内容仅作参考
package com.yulore.superyellowpage.service;
import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Environment;
import android.os.Handler;
import com.ricky.android.common.http.NetUtils;
import com.ricky.android.common.pool.ThreadManager;
import com.ricky.android.common.utils.Logger;
import com.yulore.collect.YuloreCollectManager;
import com.yulore.superyellowpage.PkgDecoderApi;
import com.yulore.superyellowpage.db.biz.DAOBizFactory;
import com.yulore.superyellowpage.db.biz.TagDaoBiz;
import com.yulore.superyellowpage.impl.YuloreApiFactory;
import com.yulore.superyellowpage.modelbean.OfflinePkgInfos;
import com.yulore.superyellowpage.modelbean.TagTelephone;
import com.yulore.superyellowpage.utils.Constant;
import com.yulore.superyellowpage.utils.CrashHandler;
import com.yulore.superyellowpage.utils.MultipartUtility;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;
public class IntelligentCacheService extends IntentService {
private static final String CHARSET = "utf-8";
private static final String CRASH_TIME = "crash_log_time";
private static final String SHAREPREFERENCE_NAME = "super_yellowpage";
protected static final String TAG = IntelligentCacheService.class.getSimpleName();
private static final String TIME_TAG = "statistic_time";
private static final long WAIT_TIME_MILLIS = 129600000;
private String mDestUrl;
private Handler mHandler;
private TagDaoBiz mMarkDaoBiz;
private PkgDecoderApi mPkgDecoderApi;
private SharedPreferences mSharedPreferences;
public IntelligentCacheService() {
super("com.yulore.superyellowpage.service.IntelligentCacheService");
this.mMarkDaoBiz = null;
this.mHandler = new Handler();
this.mDestUrl = null;
}
@Override
public void onCreate() {
super.onCreate();
this.mPkgDecoderApi = YuloreApiFactory.createFileDecoderApi(this);
Logger.i(TAG, "onCreate");
this.mSharedPreferences = getSharedPreferences("super_yellowpage", 0);
this.mMarkDaoBiz = DAOBizFactory.createMarkDaoBiz(this);
this.mDestUrl = "https://apis.dianhua.cn/errorlog/index.php";
Logger.i(TAG, "url=" + this.mDestUrl);
}
public File[] hasNonUploadedCrashLog() {
int pointer;
if (!Environment.getExternalStorageState().equals("mounted")) {
return null;
}
File logDir = new File(Environment.getExternalStorageDirectory() + "/.YulorePageCrashReport");
if (logDir.listFiles() == null || logDir.listFiles().length == 0) {
return null;
}
File[] files = new File[logDir.listFiles().length];
File[] listFiles = logDir.listFiles();
int length = listFiles.length;
int i = 0;
int pointer2 = 0;
while (i < length) {
File file = listFiles[i];
if (file.getName().endsWith(".log")) {
pointer = pointer2 + 1;
files[pointer2] = file;
} else {
pointer = pointer2;
}
i++;
pointer2 = pointer;
}
if (files.length == 0) {
files = null;
}
return files;
}
public boolean uploadCrashInfo(File file, String destUrl) {
List<String> response;
String status;
if (!Environment.getExternalStorageState().equals("mounted")) {
return false;
}
try {
MultipartUtility multipart = new MultipartUtility(destUrl, "utf-8");
multipart.addHeaderField(HTTP.USER_AGENT, "Mozilla/5.0");
multipart.addHeaderField("Test-Header", "Header-Value");
multipart.addFormField("APIKey", Constant.API_KEY);
multipart.addFormField("android_version", CrashHandler.mVersionName);
multipart.addFormField("device_name", CrashHandler.mDeviceName);
multipart.addFormField("sdk_version", "1.1");
multipart.addFilePart("file", file);
response = multipart.finish();
JSONObject object = new JSONObject(response.get(0));
status = object.getString("status");
Logger.i(TAG, response.toString());
} catch (IOException e1) {
e1.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if ("0".equals(status)) {
file.delete();
this.mSharedPreferences.edit().putLong(CRASH_TIME, System.currentTimeMillis()).commit();
return true;
}
Logger.i(TAG, response.toString());
return false;
}
private void processCrashLog() {
ThreadManager.getInstance().getLongPool().execute(new Runnable() {
@Override
public void run() {
try {
File[] allLogFiles = IntelligentCacheService.this.hasNonUploadedCrashLog();
if (allLogFiles != null) {
for (File file : allLogFiles) {
if (file != null && file.exists()) {
IntelligentCacheService.this.uploadCrashInfo(file, IntelligentCacheService.this.mDestUrl);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void uploadMarkData() {
ThreadManager.getInstance().getLongPool().execute(new Runnable() {
@Override
public void run() {
try {
List<TagTelephone> entities = IntelligentCacheService.this.mMarkDaoBiz.getNonUploadedTels();
for (TagTelephone markEntity : entities) {
YuloreApiFactory.createRecognitionTagApi(IntelligentCacheService.this.getApplicationContext()).tagTelNumber(markEntity.getNumber(), markEntity.getMarkTag(), markEntity.getTimestamp());
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void updateOfflineData() {
ThreadManager.getInstance().getLongPool().execute(new Runnable() {
@Override
public void run() {
try {
OfflinePkgInfos pkgInfos = IntelligentCacheService.this.mPkgDecoderApi.newCheckPkgUpdate(IntelligentCacheService.this);
if (pkgInfos != null && NetUtils.isWifiDataEnable(IntelligentCacheService.this)) {
IntelligentCacheService.this.mSharedPreferences.edit().putLong(IntelligentCacheService.TIME_TAG, System.currentTimeMillis()).commit();
YuloreApiFactory.createFileDecoderApi(IntelligentCacheService.this).newDownloadPkg(IntelligentCacheService.this, pkgInfos);
}
YuloreCollectManager.getInstance().asyncCollect();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
protected void onHandleIntent(Intent intent) {
try {
Logger.i(TAG, "onHandleIntent()");
if (NetUtils.hasNetwork(this)) {
long last = this.mSharedPreferences.getLong(TIME_TAG, 0L);
if (NetUtils.isWifiDataEnable(getApplicationContext()) && System.currentTimeMillis() - last >= WAIT_TIME_MILLIS) {
updateOfflineData();
}
uploadMarkData();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}