和通讯录 v4.2.0版本的 MD5 值为:f213fa766dccbfebde0dd8add5534518

以下内容为反编译后的 f.java 源代码,内容仅作参考


package com.chinamobile.icloud.im.sync.b;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Build;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.android.common.speech.LoggingEvents;
import com.android.internal.telephony.PhoneConstants;
import com.chinamobile.contacts.im.mms2.view.MessageListItem;
import com.chinamobile.contacts.im.setting.BrowserHandle;
import com.chinamobile.icloud.im.monitor.mode.MethodLogInfo;
import com.chinamobile.icloud.im.monitor.mode.MonitorLogEntity;
import com.chinamobile.icloud.im.sync.a.v;
import com.chinamobile.icloud.im.sync.data.ContactAccessor;
import com.google.gson.Gson;
import com.huawei.mcs.api.McsApi;
import com.huawei.mcs.auth.data.AASConstants;
import com.huawei.mcs.base.constant.Constant;
import com.huawei.mcs.cloud.msg.base.mms.Telephony;
import com.iflytek.cloud.SpeechConstant;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.simpleframework.xml.strategy.Name;

public class f {
    private static f e;
    private Context g;
    private TelephonyManager i;
    private boolean j;
    private boolean k;
    private MonitorLogEntity r;
    private long s;
    private static String d = "3.1.6";
    private static boolean f = true;
    private static boolean l = false;
    private static HashMap<Integer, String> x = new HashMap<>();

    com.chinamobile.icloud.im.sync.c.p f4003a = new com.chinamobile.icloud.im.sync.c.p("ContactManager");
    private j h = null;
    private boolean m = false;
    private SimpleDateFormat n = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private boolean o = true;
    private boolean p = false;
    private PrintWriter q = null;
    private final List<MethodLogInfo> t = new ArrayList();
    private boolean u = true;

    String[] f4004b = {"android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS", "android.permission.READ_PHONE_STATE"};
    private boolean w = false;
    com.chinamobile.icloud.im.d.b c = new g(this);
    private com.chinamobile.icloud.im.sync.c.f v = new com.chinamobile.icloud.im.sync.c.f();

    public void a(boolean z) {
        this.p = z;
    }

    public boolean a() {
        return this.p;
    }

    public void b(boolean z) {
        this.o = z;
    }

    public com.chinamobile.icloud.im.sync.c.f b() {
        return this.v;
    }

    public static void a(Context context) {
        if (e == null) {
            e = new f(context);
            com.chinamobile.icloud.im.c.b.b.a(context);
        }
    }

    public f(Context context) {
        this.g = context.getApplicationContext();
        this.i = (TelephonyManager) this.g.getSystemService(PhoneConstants.PHONE_KEY);
        ContactAccessor.getFilterArgs(context);
        StringBuffer stringBuffer = new StringBuffer();
        int length = ContactAccessor.getSimSelectionArgs().length;
        for (int i = 0; i < length; i++) {
            stringBuffer.append(ContactAccessor.getSimSelectionArgs()[i]);
            if (i != length - 1) {
                stringBuffer.append(",");
            }
        }
        b(this.g, stringBuffer.toString());
    }

    public static f c() {
        return e;
    }

    public void a(i iVar) {
        if (this.j) {
            iVar.b(iVar.b());
        } else if (this.h == null) {
            this.h = new j(this, this.g, iVar);
            this.h.start();
        }
    }

    public void a(String str, String str2, com.chinamobile.icloud.im.d.b bVar) {
        if (!com.chinamobile.icloud.im.a.b.c.c(h())) {
            com.chinamobile.icloud.im.a.b.c.a(h(), str, str2, bVar);
        } else {
            this.f4003a.b("已经注册");
        }
    }

    public static void a(JSONObject jSONObject, q qVar) {
        JSONObject jSONObject2 = new JSONObject();
        JSONObject jSONObject3 = new JSONObject();
        JSONObject jSONObject4 = new JSONObject();
        if (qVar.a() != null) {
            Iterator<com.chinamobile.icloud.im.sync.a.q> it = qVar.a().iterator();
            while (it.hasNext()) {
                JSONObject jsonMapItem = it.next().getJsonMapItem();
                String string = jsonMapItem.getString("key");
                String string2 = jsonMapItem.getString(LoggingEvents.VoiceSearch.EXTRA_QUERY_UPDATED_VALUE);
                if (!TextUtils.isEmpty(string) && !TextUtils.isEmpty(string2) && !TextUtils.equals("0", string) && !TextUtils.equals("0", string2)) {
                    jSONObject2.put(string, string2);
                }
            }
        }
        if (qVar.b() != null) {
            Iterator<com.chinamobile.icloud.im.sync.a.q> it2 = qVar.b().iterator();
            while (it2.hasNext()) {
                JSONObject jsonMapItem2 = it2.next().getJsonMapItem();
                String string3 = jsonMapItem2.getString("key");
                String string4 = jsonMapItem2.getString(LoggingEvents.VoiceSearch.EXTRA_QUERY_UPDATED_VALUE);
                if (!TextUtils.isEmpty(string3) && !TextUtils.isEmpty(string4) && !TextUtils.equals("0", string3) && !TextUtils.equals("0", string4)) {
                    jSONObject3.put(string3, string4);
                }
            }
        }
        if (qVar.c() != null) {
            Iterator<com.chinamobile.icloud.im.sync.a.q> it3 = qVar.c().iterator();
            while (it3.hasNext()) {
                JSONObject jsonMapItem3 = it3.next().getJsonMapItem();
                String string5 = jsonMapItem3.getString("key");
                String string6 = jsonMapItem3.getString(LoggingEvents.VoiceSearch.EXTRA_QUERY_UPDATED_VALUE);
                if (!TextUtils.isEmpty(string5) && !TextUtils.isEmpty(string6) && !TextUtils.equals("0", string5) && !TextUtils.equals("0", string6)) {
                    jSONObject4.put(string5, string6);
                }
            }
        }
        JSONObject jSONObject5 = jSONObject.getJSONObject(SpeechConstant.PARAMS);
        jSONObject5.put("add_ids", jSONObject2);
        jSONObject5.put("update_ids", jSONObject3);
        jSONObject5.put("delete_ids", jSONObject4);
    }

    public static String b(Context context) {
        String str = d;
        if (l) {
            return d;
        }
        if (context != null || e != null) {
            if (context == null) {
                if (e != null) {
                    context = e.g;
                } else {
                    return str;
                }
            }
            try {
                return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
            } catch (PackageManager.NameNotFoundException e2) {
                e2.printStackTrace();
                return str;
            }
        }
        return str;
    }

    private void a(File file, String str) {
        PrintWriter printWriter;
        PrintWriter printWriter2 = null;
        try {
            try {
                printWriter = new PrintWriter(new FileWriter(file, true));
                try {
                    printWriter.write(str);
                    if (printWriter != null) {
                        printWriter.flush();
                        printWriter.close();
                    }
                } catch (Exception e2) {
                    e = e2;
                    e.printStackTrace();
                    if (printWriter != null) {
                        printWriter.flush();
                        printWriter.close();
                    }
                }
            } catch (Throwable th) {
                th = th;
                printWriter2 = printWriter;
                if (printWriter2 != null) {
                    printWriter2.flush();
                    printWriter2.close();
                }
                throw th;
            }
        } catch (Exception e3) {
            e = e3;
            printWriter = null;
        } catch (Throwable th2) {
            th = th2;
            if (printWriter2 != null) {
            }
            throw th;
        }
    }

    private PrintWriter k() {
        if (Environment.getExternalStorageState().equals("mounted")) {
            if (this.q != null) {
                return this.q;
            }
            try {
                String str = Environment.getExternalStorageDirectory() + Constant.FilePath.IDND_PATH + "sync_contact.log";
                File file = new File(str);
                if (file.length() > 12582912) {
                    file.delete();
                    this.f4003a.b("delete file size:" + str);
                    file.createNewFile();
                }
                this.q = new PrintWriter(new FileWriter(file, true));
            } catch (IOException e2) {
                e2.printStackTrace();
            }
            return this.q;
        }
        this.f4003a.d("sdcard is not available. or other reason..");
        return null;
    }

    public void a(Object obj, int i) {
        if (this.o) {
            try {
                if (obj == null) {
                    if (this.q != null) {
                        this.q.close();
                        this.q = null;
                        return;
                    }
                    return;
                }
                try {
                    if (k() != null) {
                        if (obj instanceof Exception) {
                            Exception exc = (Exception) obj;
                            this.q.write("\r\n" + this.n.format(new Date()) + " " + exc.getMessage());
                            for (StackTraceElement stackTraceElement : exc.getStackTrace()) {
                                this.q.write(String.valueOf(this.n.format(new Date())) + " " + stackTraceElement.toString() + "\r\n");
                            }
                        } else if (obj instanceof byte[]) {
                            this.q.write(new String((byte[]) obj));
                        } else {
                            this.q.write("\r\n" + this.n.format(new Date()) + " " + obj.toString());
                        }
                        if (this.q != null) {
                            this.q.flush();
                        }
                    }
                    if (this.q != null) {
                        this.q.close();
                        this.q = null;
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    if (this.q != null) {
                        this.q.close();
                        this.q = null;
                    }
                }
            } catch (Throwable th) {
                if (this.q != null) {
                    this.q.close();
                    this.q = null;
                }
                throw th;
            }
        }
    }

    public void a(JSONObject jSONObject, List<com.chinamobile.icloud.im.sync.a.q> list, com.chinamobile.icloud.im.sync.a.a aVar, int i, File file) {
        jSONObject.put("session", aVar.l());
        jSONObject.put("push_sn", aVar.b());
        jSONObject.put("client_id", "4");
        jSONObject.put("contact_count", new StringBuilder().append(ContactAccessor.getInstance().getLocalContactsCount(this.g)).toString());
        jSONObject.put("device_id", aVar.q());
        if (!TextUtils.isEmpty(aVar.w())) {
            jSONObject.put("sync_frequency", aVar.w());
        }
        jSONObject.put("sync_mode", a(i, aVar));
        jSONObject.put(Telephony.BaseMmsColumns.FROM, aVar.u());
        jSONObject.put("format", "json");
        if (!TextUtils.isEmpty(aVar.j())) {
            jSONObject.put("sync_token", aVar.j());
        }
        jSONObject.put("version", TextUtils.isEmpty(aVar.r()) ? b(this.g) : aVar.r());
        a("current channel:" + aVar.u(), 0);
        JSONObject jSONObject2 = new JSONObject();
        JSONObject jSONObject3 = new JSONObject();
        JSONObject jSONObject4 = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        this.f4003a.b("start write file:");
        int i2 = 0;
        boolean z = false;
        while (true) {
            int i3 = i2;
            if (i3 >= list.size() || this.k) {
                break;
            }
            com.chinamobile.icloud.im.sync.a.q qVar = list.get(i3);
            if (qVar.getPhones().size() <= 50) {
                String l2 = Long.toString(qVar.getContactId());
                String l3 = Long.toString(qVar.getServerContactId());
                if (qVar.getState() == v.DEL) {
                    if (c(l2, l3)) {
                        jSONObject2.put(l2, l3);
                    }
                } else if (qVar.getState() == v.REP) {
                    if (c(l2, l3)) {
                        jSONObject3.put(l2, l3);
                    }
                    if (!z) {
                        z = true;
                        a(file, "\"" + l2 + "\":" + qVar.toJSONObject().toString());
                    } else {
                        a(file, ",\"" + l2 + "\":" + qVar.toJSONObject().toString());
                    }
                } else if (qVar.getState() == v.EQUAL) {
                    if (c(l2, l3)) {
                        jSONObject4.put(l2, l3);
                    }
                } else {
                    jSONArray.put(l2);
                    if (!z) {
                        z = true;
                        a(file, "\"" + l2 + "\":" + qVar.toJSONObject().toString());
                    } else {
                        a(file, ",\"" + l2 + "\":" + qVar.toJSONObject().toString());
                    }
                }
            }
            i2 = i3 + 1;
        }
        this.f4003a.b("write file over:");
        jSONObject.put("add_ids", jSONArray);
        jSONObject.put("delete_id_map", jSONObject2);
        jSONObject.put("update_id_map", jSONObject3);
        jSONObject.put("equal_id_map", jSONObject4);
    }

    private boolean c(String str, String str2) {
        if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2) && !TextUtils.equals("0", str) && !TextUtils.equals("0", str2)) {
            return true;
        }
        a("不正常数据,raw_id:" + str + "server_id: " + str2, 0);
        return false;
    }

    private String a(int i, com.chinamobile.icloud.im.sync.a.a aVar) {
        switch (i) {
            case 2:
                return "m";
            case 3:
                if (aVar.s()) {
                    return "d";
                }
                return "di";
            case 4:
                return "i";
            case 5:
                return "o";
            case 23:
                return Name.MARK;
            case 24:
                return "od";
            case 25:
                return "or";
            case 26:
                return "dii";
            case BrowserHandle.JS_ACTION_CALL_RUBBISH_ACTIVITY:
                return "dio";
            case MessageListItem.WPM_MESSGAE_TYPE:
                if (aVar.s()) {
                    return "dn";
                }
                return "din";
            default:
                return "";
        }
    }

    public void a(JSONObject jSONObject, com.chinamobile.icloud.im.sync.a.a aVar) {
        jSONObject.put("jsonrpc", McsApi.API_VERSION);
        jSONObject.put("method", "contact/syncn");
        jSONObject.put(Name.MARK, com.chinamobile.icloud.im.sync.c.j.a(2));
    }

    public String a(com.chinamobile.icloud.im.sync.a.a aVar) {
        JSONObject a2 = com.chinamobile.icloud.im.sync.a.m.a().a(4, aVar.l(), "", aVar.q(), aVar.u(), TextUtils.isEmpty(aVar.r()) ? b(this.g) : aVar.r());
        o oVar = new o(aVar, 0, false, a2);
        this.f4003a.b(a2.toString());
        String a3 = com.chinamobile.icloud.im.sync.c.j.a(this.g, com.chinamobile.icloud.im.sync.c.j.a(), this.v, oVar, false);
        if (a3 == null) {
            return null;
        }
        this.f4003a.d("result:" + a3);
        try {
            JSONObject jSONObject = new JSONObject(a3);
            if (jSONObject != null) {
                JSONObject b2 = p.b("result", jSONObject);
                if (b2 != null) {
                    String c = p.c("user_id", b2);
                    aVar.p(c);
                    aVar.b(0);
                    return c;
                }
                JSONObject b3 = p.b(Telephony.ThreadsColumns.ERROR, jSONObject);
                if (b3 != null) {
                    aVar.c(Integer.valueOf(b3.getString(LoggingEvents.VoiceIme.EXTRA_ERROR_CODE)).intValue());
                    aVar.g(b3.getString("message"));
                } else {
                    aVar.c(-1);
                    aVar.g("未知错误  返回串:" + a3);
                }
                aVar.b(-1);
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        } catch (Exception e3) {
            e3.printStackTrace();
        }
        return null;
    }

    public boolean d() {
        this.k = true;
        c().b().a();
        c(false);
        return this.k;
    }

    public boolean e() {
        return this.k;
    }

    public static boolean f() {
        if (c() == null) {
            return false;
        }
        return c().e();
    }

    public void a(Exception exc) {
        if (this.h != null) {
            i a2 = this.h.a();
            a2.a(a2.b(), a2.a(), exc);
        }
    }

    public void a(List list) {
        if (this.h != null) {
            this.h.a().b((List<com.chinamobile.icloud.im.sync.a.q>) list);
        }
    }

    public void a(int i, int i2, int i3) {
        if (this.h != null) {
            i a2 = this.h.a();
            a2.a(a2.b(), i, i2, i3);
        }
    }

    public void a(String str, String str2) {
        if (this.h != null) {
            this.h.a().a(str, str2);
        }
    }

    public void b(List<com.chinamobile.icloud.im.sync.a.q> list) {
        if (this.h != null) {
            this.h.a().a(list);
        }
    }

    public boolean g() {
        return this.j;
    }

    public void c(boolean z) {
        File file = new File(this.g.getCacheDir() + Constant.FilePath.IDND_PATH + "cache_data.txt");
        if (!z && file.exists()) {
            file.delete();
        }
    }

    public static String a(int i) {
        if (x.size() == 0) {
            x.put(2, "合并联系人");
            x.put(3, "自动同步");
            x.put(4, "上传通讯录");
            x.put(5, "下载通讯录");
            x.put(4, "上传通讯录");
            x.put(23, "通讯录增量上传");
            x.put(24, "通讯录增量下载");
            x.put(25, "通讯录还原下载");
            x.put(27, "将云端联系人完全替换为手机联系人");
            x.put(26, "将手机联系人完全替换为云端联系人");
        }
        return x.get(Integer.valueOf(i));
    }

    private int b(com.chinamobile.icloud.im.sync.a.a aVar, i iVar) {
        Exception e2;
        int i;
        if (this.g == null) {
            return -1;
        }
        try {
            Cursor query = this.g.getContentResolver().query(com.chinamobile.icloud.im.sync.provider.c.f4039a, null, "userid=?", new String[]{aVar.m()}, null);
            if (query == null) {
                return -1;
            }
            query.moveToLast();
            i = query.getCount();
            try {
                a("tag:读取本地人数量方法 --》读取映射关系表   " + i, 0);
                query.close();
                if (i >= 0) {
                    if (iVar != null && !iVar.c()) {
                        return -3;
                    }
                    i = ContactAccessor.getInstance().loadContactIdsByChangedState(this.g.getContentResolver(), aVar);
                    a("tag:读取本地人数量方法 --》比较映射关系表后数量   " + i, 0);
                    return i;
                }
                return i;
            } catch (Exception e3) {
                e2 = e3;
                e2.printStackTrace();
                a("tag:获取联系人变化的数量抛出异常 " + e2.getMessage(), 0);
                return i;
            }
        } catch (Exception e4) {
            e2 = e4;
            i = -1;
        }
    }

    public int b(com.chinamobile.icloud.im.sync.a.a aVar) {
        return b(aVar, (i) null);
    }

    public int a(com.chinamobile.icloud.im.sync.a.a aVar, i iVar) {
        return b(aVar, iVar);
    }

    public List<com.chinamobile.icloud.im.sync.a.q> a(ContentResolver contentResolver, com.chinamobile.icloud.im.sync.a.a aVar) {
        List<com.chinamobile.icloud.im.sync.a.q> loadContactIdsByState = ContactAccessor.getInstance().loadContactIdsByState(contentResolver, aVar);
        if (loadContactIdsByState != null && loadContactIdsByState.size() > 0) {
            int i = 0;
            while (true) {
                int i2 = i;
                if (i2 >= loadContactIdsByState.size()) {
                    break;
                }
                if (loadContactIdsByState.get(i2).getState() == v.EQUAL) {
                    loadContactIdsByState.remove(i2);
                }
                i = i2 + 1;
            }
        }
        return loadContactIdsByState;
    }

    public static void a(Context context, String str) {
        try {
            context.getContentResolver().delete(com.chinamobile.icloud.im.sync.provider.c.f4039a, "userid = ? ", new String[]{str});
            if (e != null) {
                e.a("删除映射关系完成", 0);
            }
            context.getSharedPreferences("token_setting", 0).edit().putString(str, "").commit();
        } catch (Exception e2) {
        }
    }

    public Context h() {
        return this.g;
    }

    private static boolean b(Context context, String str) {
        context.getSharedPreferences("setting_contact_sync", 0).edit().putString("load_contact_filter", str).commit();
        return true;
    }

    public static String c(Context context) {
        return context.getSharedPreferences("setting_contact_sync", 0).getString("load_contact_filter", null);
    }

    public String a(com.chinamobile.icloud.im.sync.a.a aVar, String str, String str2, String str3, String str4, List<String> list, a aVar2) {
        if (aVar2 != null) {
            new h(this, aVar2, aVar, str, str2, str3, str4, list).start();
            return null;
        }
        return a(aVar, str, str2, str3, str4, list);
    }

    public String a(com.chinamobile.icloud.im.sync.a.a aVar, String str, String str2, String str3, String str4, List<String> list) {
        JSONObject a2 = com.chinamobile.icloud.im.sync.a.m.a().a(aVar, str, TextUtils.isEmpty(str2) ? "RCS" : str2, str3, str4, list);
        if (f) {
            this.f4003a.d(String.valueOf(com.chinamobile.icloud.im.sync.c.j.b()) + " " + a2.toString());
        }
        a(a2, 0);
        String a3 = com.chinamobile.icloud.im.sync.c.j.a(this.g, com.chinamobile.icloud.im.sync.c.j.b(), a2.toString());
        if (f) {
            this.f4003a.d(a3);
        }
        a(a3, 0);
        return a3;
    }

    public boolean d(int i) {
        return i == 5 || i == 4 || i == 2 || i == 23 || i == 24 || i == 25 || i == 26 || i == 27;
    }

    public static boolean b(int i) {
        return i == 3 || i == 28;
    }

    public void b(i iVar) {
        com.chinamobile.icloud.im.b.b bVar = new com.chinamobile.icloud.im.b.b();
        if (iVar != null) {
            iVar.b().c(-103);
            throw bVar;
        }
        throw bVar;
    }

    public void a(Context context, long j) {
        com.chinamobile.icloud.im.monitor.a.a(context, j);
        c().a("tag:监控日志--->设置上传监控日志定时器,设置时间-->" + j + "分      ", 0);
    }

    public void d(Context context) {
        com.chinamobile.icloud.im.monitor.a.a(context);
        c().a("tag:监控日志--->停止上传监控日志定时器-->    ", 0);
    }

    public void a(Context context, com.chinamobile.icloud.im.sync.a.a aVar) {
        String r = aVar.r();
        this.r = new MonitorLogEntity();
        if (TextUtils.isEmpty(r)) {
            r = b(context);
        }
        if (TextUtils.isEmpty(r)) {
            r = "0.0";
        }
        this.r.setAppVersion(r);
        this.r.setDeviceId(aVar.q());
        this.r.setUserId(aVar.m());
        this.r.setSession(aVar.l());
        this.r.setDeviceName(Build.MODEL);
        this.r.setFrom(aVar.u());
        this.r.setImei(aVar.p());
        this.r.setNetwork(com.chinamobile.icloud.im.monitor.a.c.b(context));
        this.r.setOperator(new StringBuilder(String.valueOf(com.chinamobile.icloud.im.monitor.a.c.a(context))).toString());
        this.r.setOsVersion(Build.VERSION.RELEASE);
        this.r.setUserBehaviorStartTime(com.chinamobile.icloud.im.monitor.a.a.a("yyyy-MM-dd HH:mm:ss"));
        this.r.setLocalContactsCount("-1");
        this.r.setUserCost("-1");
        this.r.setIswhiteList("0");
        this.r.setMobile("");
        this.r.setUserBehaviorEndTime(com.chinamobile.icloud.im.monitor.a.a.a("yyyy-MM-dd HH:mm:ss"));
        MethodLogInfo b2 = b("0", "initMonitorLogInfo");
        this.r.setMethodInfoList(this.t);
        a(b2, com.chinamobile.icloud.im.monitor.a.a.a());
    }

    public MethodLogInfo b(String str, String str2) {
        MethodLogInfo methodLogInfo = new MethodLogInfo();
        methodLogInfo.setInterfaceStartTime(com.chinamobile.icloud.im.monitor.a.a.a("yyyy-MM-dd HH:mm:ss"));
        methodLogInfo.setInterfaceBehavior(str);
        methodLogInfo.setInterfaceName(str2);
        return methodLogInfo;
    }

    public void a(MethodLogInfo methodLogInfo, long j) {
        methodLogInfo.setInterfaceEndTime(com.chinamobile.icloud.im.monitor.a.a.a("yyyy-MM-dd HH:mm:ss"));
        methodLogInfo.setInterfaceCost(new StringBuilder(String.valueOf(com.chinamobile.icloud.im.monitor.a.a.a() - j)).toString());
        c().i().add(methodLogInfo);
    }

    public List<MethodLogInfo> i() {
        return this.t;
    }

    public void a(JSONObject jSONObject) {
        if (jSONObject != null && this.r != null) {
            int optInt = jSONObject.optInt("add_count");
            int optInt2 = jSONObject.optInt("update_count");
            int optInt3 = jSONObject.optInt("delete_count");
            int optInt4 = jSONObject.optInt("after_count");
            this.r.setServiceAddCount(new StringBuilder(String.valueOf(optInt)).toString());
            this.r.setServiceDeleteCount(new StringBuilder(String.valueOf(optInt2)).toString());
            this.r.setServiceUpdateCount(new StringBuilder(String.valueOf(optInt3)).toString());
            this.r.setServiceContactsCount(new StringBuilder(String.valueOf(optInt4)).toString());
        }
    }

    public void b(JSONObject jSONObject) {
        if (jSONObject != null && this.r != null) {
            JSONObject optJSONObject = jSONObject.optJSONObject("add_ids");
            JSONObject optJSONObject2 = jSONObject.optJSONObject("update_ids");
            JSONObject optJSONObject3 = jSONObject.optJSONObject("delete_ids");
            this.r.setClientAddCount(new StringBuilder(String.valueOf(optJSONObject.length())).toString());
            this.r.setClientDeleteCount(new StringBuilder(String.valueOf(optJSONObject2.length())).toString());
            this.r.setClientUpdateCount(new StringBuilder(String.valueOf(optJSONObject3.length())).toString());
        }
    }

    public void b(int i, com.chinamobile.icloud.im.sync.a.a aVar) {
        String a2 = a(i, aVar);
        if (TextUtils.isEmpty(a2)) {
            a2 = new StringBuilder(String.valueOf(i)).toString();
        }
        if (this.r != null) {
            this.r.setUserBehavior(a2);
        }
    }

    public boolean j() {
        return this.u;
    }

    public void c(com.chinamobile.icloud.im.sync.a.a aVar) {
        try {
            String str = "0";
            String a2 = com.chinamobile.icloud.im.monitor.a.a.a("yyyy-MM-dd HH:mm:ss");
            if (!TextUtils.isEmpty(a2)) {
                this.r.setUserBehaviorEndTime(a2);
            }
            this.r.setLocalContactsCount(new StringBuilder(String.valueOf(ContactAccessor.getInstance().getLocalContactsCount(this.g))).toString());
            this.r.setUserCost(new StringBuilder(String.valueOf(com.chinamobile.icloud.im.monitor.a.a.a() - this.s)).toString());
            this.r.setMethodInfoList(this.t);
            JSONObject a3 = com.chinamobile.icloud.im.monitor.b.a("http://logupload.cytxl.com.cn/logupload/api/logSetting/getLogSetting", aVar.l(), aVar.u());
            if (a3 != null) {
                this.r.setIswhiteList(a3.optString("type", "0"));
                this.r.setMobile(a3.optString(AASConstants.ACCOUNT, ""));
                str = a3.optString("uploadFrequency", "0");
            }
            if (!TextUtils.isEmpty(this.r.getMobile())) {
                String json = new Gson().toJson(this.r);
                if (com.chinamobile.icloud.im.monitor.c.a(this.g).a(2500)) {
                    com.chinamobile.icloud.im.monitor.c.a(this.g).a();
                }
                com.chinamobile.icloud.im.monitor.c.a(this.g).a(aVar.m(), this.r.getIswhiteList(), json);
                if (!TextUtils.equals("0", str)) {
                    a(this.g, Long.valueOf(str).longValue());
                } else {
                    d(this.g);
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void a(String str, Exception exc) {
        if (this.r != null) {
            this.r.setErrorType(str);
            String str2 = "";
            if (exc != null) {
                str2 = exc.getMessage();
            }
            if (TextUtils.isEmpty(str2)) {
                str2 = "未知错误";
            }
            this.r.setErrorCause(str2);
        }
    }

    public static boolean c(int i) {
        return i == 26 || i == 27 || i == 3 || i == 28;
    }

    public static boolean e(Context context) {
        return com.chinamobile.icloud.im.sync.c.a.a(context);
    }

    public void f(Context context) {
        Intent intent = new Intent();
        intent.putExtra("pkg", context.getPackageName());
        intent.setAction("com.chinamobile.contact.im.ACTION_STOP_CONTACTOBSERVER");
        intent.setFlags(32);
        context.sendBroadcast(intent);
        a("取消联系人变化监听", 0);
    }

    public void g(Context context) {
        Intent intent = new Intent();
        intent.putExtra("pkg", context.getPackageName());
        intent.setAction("com.chinamobile.contact.im.ACTION_START_CONTACTOBSERVER");
        intent.setFlags(32);
        context.sendBroadcast(intent);
        a("开启联系人变化监听", 0);
    }

    public int h(Context context) {
        ContactAccessor contactAccessor = ContactAccessor.getInstance();
        if (contactAccessor != null) {
            return contactAccessor.getLocalContactsCount(context);
        }
        return 0;
    }

    public String b(String str, Exception exc) {
        String str2 = "";
        if (exc != null) {
            str2 = exc.getMessage();
        }
        return TextUtils.isEmpty(str2) ? str : str2;
    }
}