翰林优商.apk(点击下载) / c.java


package com.umeng.commonsdk.internal;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.sigmob.sdk.base.mta.PointCategory;
import com.umeng.analytics.CoreProtocol;
import com.umeng.analytics.pro.aa;
import com.umeng.analytics.pro.am;
import com.umeng.analytics.pro.ao;
import com.umeng.analytics.pro.ap;
import com.umeng.analytics.pro.aq;
import com.umeng.analytics.pro.l;
import com.umeng.analytics.pro.o;
import com.umeng.commonsdk.UMConfigureImpl;
import com.umeng.commonsdk.a;
import com.umeng.commonsdk.config.FieldManager;
import com.umeng.commonsdk.debug.SelfChecker;
import com.umeng.commonsdk.debug.UMRTLog;
import com.umeng.commonsdk.framework.UMEnvelopeBuild;
import com.umeng.commonsdk.framework.UMFrUtils;
import com.umeng.commonsdk.framework.UMLogDataProtocol;
import com.umeng.commonsdk.framework.UMWorkDispatch;
import com.umeng.commonsdk.internal.crash.UMCrashManager;
import com.umeng.commonsdk.listener.OnGetOaidListener;
import com.umeng.commonsdk.service.UMGlobalContext;
import com.umeng.commonsdk.stateless.d;
import com.umeng.commonsdk.statistics.UMServerURL;
import com.umeng.commonsdk.statistics.b;
import com.umeng.commonsdk.statistics.common.ULog;
import com.umeng.commonsdk.statistics.idtracking.h;
import com.umeng.commonsdk.utils.UMUtils;
import com.umeng.commonsdk.utils.onMessageSendListener;
import com.umeng.commonsdk.vchannel.Sender;
import java.io.File;
import java.lang.reflect.Method;
import org.json.JSONObject;

/* compiled from: UMInternalDataProtocol */
public class c implements UMLogDataProtocol {
    public static final String a = "um_policy_grant";
    public static final String b = "preInitInvokedFlag";
    public static final String c = "policyGrantInvokedFlag";
    public static final String d = "policyGrantResult";
    private static int f = 1;
    private static final String g = "info";
    private static final String h = "stat";
    private static Class<?> i = null;
    private static Method j = null;
    private static Method k = null;
    private static Method l = null;
    private static boolean m = false;
    private Context e;

    @Override // com.umeng.commonsdk.framework.UMLogDataProtocol
    public void removeCacheData(Object obj) {
    }

    @Override // com.umeng.commonsdk.framework.UMLogDataProtocol
    public JSONObject setupReportData(long j2) {
        return null;
    }

    static {
        c();
    }

    private static void c() {
        try {
            Class<?> cls = Class.forName("com.umeng.umzid.ZIDManager");
            if (cls != null) {
                i = cls;
                Method declaredMethod = cls.getDeclaredMethod("getInstance", new Class[0]);
                if (declaredMethod != null) {
                    j = declaredMethod;
                }
                Method declaredMethod2 = i.getDeclaredMethod("getZID", Context.class);
                if (declaredMethod2 != null) {
                    k = declaredMethod2;
                }
                Method declaredMethod3 = i.getDeclaredMethod("getSDKVersion", new Class[0]);
                if (declaredMethod3 != null) {
                    l = declaredMethod3;
                }
            }
        } catch (Throwable unused) {
        }
    }

    public String a() {
        Method method;
        Class<?> cls = i;
        if (cls == null || (method = j) == null || k == null) {
            return "";
        }
        try {
            Object invoke = method.invoke(cls, new Object[0]);
            if (invoke != null) {
                return (String) k.invoke(invoke, this.e);
            }
            return "";
        } catch (Throwable unused) {
            return "";
        }
    }

    public static String b() {
        Method method;
        Class<?> cls = i;
        if (cls == null || (method = j) == null || l == null) {
            return "";
        }
        try {
            Object invoke = method.invoke(cls, new Object[0]);
            if (invoke != null) {
                return (String) l.invoke(invoke, new Object[0]);
            }
            return "";
        } catch (Throwable unused) {
            return "";
        }
    }

    public c(Context context) {
        if (context != null) {
            this.e = context.getApplicationContext();
        }
    }

    private void a(Context context) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(b.a("appkey"), UMGlobalContext.getInstance(context).getAppkey());
            jSONObject.put(b.a("app_version"), UMGlobalContext.getInstance(context).getAppVersion());
            jSONObject.put(b.a(am.x), "Android");
            JSONObject buildZeroEnvelopeWithExtHeader = UMEnvelopeBuild.buildZeroEnvelopeWithExtHeader(context, jSONObject, null, UMServerURL.ZCFG_PATH);
            if (buildZeroEnvelopeWithExtHeader == null || !buildZeroEnvelopeWithExtHeader.has("exception")) {
                UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 构建零号报文 成功!!!");
            } else {
                UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 构建零号报文失败.");
            }
        } catch (Throwable unused) {
        }
    }

    private void b(Context context) {
        try {
            String imprintProperty = UMEnvelopeBuild.imprintProperty(context, am.g, "");
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(b.a("appkey"), UMGlobalContext.getInstance(context).getAppkey());
            jSONObject.put(b.a(am.g), imprintProperty);
            JSONObject buildSilentEnvelopeWithExtHeader = UMEnvelopeBuild.buildSilentEnvelopeWithExtHeader(context, jSONObject, null, UMServerURL.SILENT_HEART_BEAT);
            if (buildSilentEnvelopeWithExtHeader == null || !buildSilentEnvelopeWithExtHeader.has("exception")) {
                UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 构建心跳报文 成功!!!");
            } else {
                UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 构建心跳报文失败.");
            }
        } catch (Throwable unused) {
        }
    }

    private void d() {
        ao a2 = ao.a(this.e);
        ap a3 = a2.a(aq.c);
        if (a3 != null) {
            UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> [有状态]二级缓存记录构建成真正信封。");
            try {
                String str = a3.a;
                String str2 = a3.b;
                JSONObject a4 = new b().a(this.e.getApplicationContext(), new JSONObject(a3.c), new JSONObject(a3.d), a3.e, str2, a3.f);
                if (a4 == null || !a4.has("exception")) {
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> [有状态]二级缓存记录构建真正信封 成功! 删除二级缓存记录。");
                } else {
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> [有状态]二级缓存记录构建真正信封 失败。删除二级缓存记录");
                }
                a2.a(aq.c, str);
                a2.b();
            } catch (Throwable unused) {
            }
        }
    }

    private static void c(final Context context) {
        new Thread(new Runnable() {
            /* class com.umeng.commonsdk.internal.c.AnonymousClass1 */

            public void run() {
                try {
                    SharedPreferences sharedPreferences = context.getSharedPreferences(h.a, 0);
                    long currentTimeMillis = System.currentTimeMillis();
                    String a2 = aa.a(context);
                    long currentTimeMillis2 = System.currentTimeMillis();
                    if (!TextUtils.isEmpty(a2) && sharedPreferences != null) {
                        SharedPreferences.Editor edit = sharedPreferences.edit();
                        edit.putString(h.c, (currentTimeMillis2 - currentTimeMillis) + "");
                        edit.commit();
                    }
                    if (sharedPreferences != null) {
                        SharedPreferences.Editor edit2 = sharedPreferences.edit();
                        edit2.putString(h.b, a2);
                        edit2.commit();
                    }
                    UMConfigureImpl.removeInterruptFlag();
                } catch (Exception unused) {
                }
            }
        }).start();
    }

    private static void a(Context context, final OnGetOaidListener onGetOaidListener) {
        if (context != null) {
            final Context applicationContext = context.getApplicationContext();
            new Thread(new Runnable() {
                /* class com.umeng.commonsdk.internal.c.AnonymousClass2 */

                public void run() {
                    String a2 = aa.a(applicationContext);
                    OnGetOaidListener onGetOaidListener = onGetOaidListener;
                    if (onGetOaidListener != null) {
                        onGetOaidListener.onGetOaid(a2);
                    }
                }
            }).start();
        }
    }

    private static void d(final Context context) {
        if (FieldManager.allow(com.umeng.commonsdk.utils.c.G)) {
            a(context, new OnGetOaidListener() {
                /* class com.umeng.commonsdk.internal.c.AnonymousClass3 */

                @Override // com.umeng.commonsdk.listener.OnGetOaidListener
                public void onGetOaid(String str) {
                    if (!TextUtils.isEmpty(str)) {
                        try {
                            SharedPreferences sharedPreferences = context.getSharedPreferences(h.a, 0);
                            if (sharedPreferences != null && !sharedPreferences.getString(h.b, "").equalsIgnoreCase(str)) {
                                UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 更新本地缓存OAID");
                                SharedPreferences.Editor edit = sharedPreferences.edit();
                                edit.putString(h.b, str);
                                edit.commit();
                            }
                        } catch (Throwable unused) {
                        }
                    }
                }
            });
        }
    }

    private void e() {
        if (!m) {
            if (FieldManager.allow(com.umeng.commonsdk.utils.c.G)) {
                m = true;
                a(this.e, new OnGetOaidListener() {
                    /* class com.umeng.commonsdk.internal.c.AnonymousClass4 */

                    @Override // com.umeng.commonsdk.listener.OnGetOaidListener
                    public void onGetOaid(String str) {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> OAID云控参数更新(不采集->采集):采集完成");
                        if (TextUtils.isEmpty(str)) {
                            UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> oaid返回null或者空串,不需要 伪冷启动。");
                            return;
                        }
                        try {
                            SharedPreferences sharedPreferences = c.this.e.getSharedPreferences(h.a, 0);
                            if (sharedPreferences != null) {
                                SharedPreferences.Editor edit = sharedPreferences.edit();
                                edit.putString(h.b, str);
                                edit.commit();
                            }
                        } catch (Throwable unused) {
                        }
                        UMWorkDispatch.sendEvent(c.this.e, a.w, b.a(c.this.e).a(), null);
                    }
                });
            }
        } else if (!FieldManager.allow(com.umeng.commonsdk.utils.c.G)) {
            m = false;
        }
    }

    private void f() {
        if (FieldManager.allow(com.umeng.commonsdk.utils.c.G)) {
            m = true;
            UMConfigureImpl.registerInterruptFlag();
            UMConfigureImpl.init(this.e);
            f++;
            UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 要读取 oaid,需等待读取结果.");
            UMConfigureImpl.registerMessageSendListener(new onMessageSendListener() {
                /* class com.umeng.commonsdk.internal.c.AnonymousClass5 */

                @Override // com.umeng.commonsdk.utils.onMessageSendListener
                public void onMessageSend() {
                    if (c.this.e != null) {
                        UMWorkDispatch.sendEvent(c.this.e, a.x, b.a(c.this.e).a(), null);
                    }
                    UMConfigureImpl.removeMessageSendListener(this);
                }
            });
            c(this.e);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:58:0x01f5, code lost:
        if (r12.isDirectory() != false) goto L_0x01f9;
     */
    @Override // com.umeng.commonsdk.framework.UMLogDataProtocol
    public void workEvent(Object obj, int i2) {
        SharedPreferences sharedPreferences;
        SharedPreferences.Editor edit;
        boolean z = true;
        boolean z2 = false;
        ULog.i("walle", "[internal] workEvent");
        if (!com.umeng.commonsdk.utils.b.a()) {
            switch (i2) {
                case a.f:
                    ULog.i("walle", "[internal] workEvent send envelope");
                    try {
                        long currentTimeMillis = System.currentTimeMillis();
                        String a2 = aa.a(this.e);
                        long currentTimeMillis2 = System.currentTimeMillis();
                        if (!TextUtils.isEmpty(a2) && (sharedPreferences = this.e.getSharedPreferences(h.a, 0)) != null) {
                            SharedPreferences.Editor edit2 = sharedPreferences.edit();
                            edit2.putString(h.b, a2);
                            edit2.putString(h.c, (currentTimeMillis2 - currentTimeMillis) + "");
                            edit2.commit();
                        }
                    } catch (Throwable unused) {
                    }
                    Class<?> cls = Class.forName("com.umeng.commonsdk.internal.UMInternalManagerAgent");
                    if (cls != null) {
                        cls.getMethod("sendInternalEnvelopeByStateful2", Context.class).invoke(cls, this.e);
                        return;
                    }
                    return;
                case a.g:
                case a.i:
                case a.j:
                case 32778:
                case 32780:
                case a.q:
                case a.r:
                case 32789:
                case 32794:
                case 32795:
                case 32796:
                case 32797:
                case 32798:
                case 32799:
                default:
                    return;
                case a.h:
                    ULog.i("walle", "[internal] workEvent cache battery, event is " + obj.toString());
                    Class<?> cls2 = Class.forName("com.umeng.commonsdk.internal.utils.UMInternalUtilsAgent");
                    if (cls2 != null) {
                        cls2.getMethod("saveBattery", Context.class, String.class).invoke(cls2, this.e, (String) obj);
                        return;
                    }
                    return;
                case a.k:
                    Class<?> cls3 = Class.forName("com.umeng.commonsdk.internal.utils.ApplicationLayerUtilAgent");
                    if (cls3 != null) {
                        cls3.getMethod("wifiChange", Context.class).invoke(cls3, this.e);
                        return;
                    }
                    return;
                case a.l:
                    try {
                        Class<?> cls4 = Class.forName("com.umeng.commonsdk.internal.utils.InfoPreferenceAgent");
                        if (cls4 != null) {
                            cls4.getMethod("saveUA", Context.class, String.class).invoke(cls4, this.e, (String) obj);
                            return;
                        }
                        return;
                    } catch (Throwable unused2) {
                        return;
                    }
                case a.m:
                    SharedPreferences sharedPreferences2 = this.e.getApplicationContext().getSharedPreferences(g, 0);
                    if (sharedPreferences2 != null) {
                        sharedPreferences2.edit().putString(h, (String) obj).commit();
                        return;
                    }
                    return;
                case a.n:
                    ULog.i("walle", "[internal] workEvent send envelope");
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put(am.aN, a.e);
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put(am.au, new JSONObject());
                    JSONObject buildEnvelopeWithExtHeader = UMEnvelopeBuild.buildEnvelopeWithExtHeader(this.e, jSONObject, jSONObject2);
                    if (buildEnvelopeWithExtHeader != null && !buildEnvelopeWithExtHeader.has("exception")) {
                        ULog.i("walle", "[internal] workEvent send envelope back, result is ok");
                        return;
                    }
                    return;
                case a.o:
                    Sender.handleEvent(this.e, (com.umeng.commonsdk.vchannel.b) obj);
                    return;
                case a.p:
                    if (!UMFrUtils.hasEnvelopeFile(this.e, UMLogDataProtocol.UMBusinessType.U_ZeroEnv)) {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 构建零号报文");
                        a(this.e);
                        return;
                    }
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 零号报文信封文件已存在,尝试发送之!");
                    return;
                case a.s:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 零号报文流程,接收到云控配置加载成功通知(成功收到零号报文应答)。");
                    f();
                    f--;
                    g();
                    return;
                case a.t:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> [有状态]接收到消费二级缓存数据通知.");
                    if (ao.a(this.e).c()) {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> [有状态]已消费完毕,二级缓存数据库为空.");
                        return;
                    }
                    d();
                    if (!UMWorkDispatch.eventHasExist(a.t)) {
                        Context context = this.e;
                        UMWorkDispatch.sendEvent(context, a.t, b.a(context).a(), null);
                        return;
                    }
                    return;
                case a.u:
                    UMCrashManager.buildEnvelope(this.e, obj);
                    return;
                case a.v:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 触发2号仓遗留信封检查动作。");
                    String a3 = d.a(this.e, false);
                    String a4 = d.a(this.e, true);
                    if (!TextUtils.isEmpty(a3)) {
                        File file = new File(a3);
                        if (file.exists() && file.isDirectory()) {
                            z2 = true;
                        }
                    }
                    if (!TextUtils.isEmpty(a4)) {
                        File file2 = new File(a4);
                        if (file2.exists()) {
                            break;
                        }
                    }
                    z = z2;
                    if (!z) {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 触发2号仓遗留信封检查,没有需要处理的目录,不需要处理。");
                        return;
                    } else if (!com.umeng.commonsdk.stateless.b.a()) {
                        new com.umeng.commonsdk.stateless.b(this.e);
                        com.umeng.commonsdk.stateless.b.b();
                        return;
                    } else {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 触发2号仓遗留信封检查,Sender已创建,不需要处理。");
                        return;
                    }
                case a.w:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 云控下发参数更新,触发 伪冷启动。");
                    b.a();
                    e();
                    if (FieldManager.allow(com.umeng.commonsdk.utils.c.E) && !UMWorkDispatch.eventHasExist()) {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 云控下发参数更新 前台计数器功能 打开,触发 5秒周期检查机制");
                        Context context2 = this.e;
                        UMWorkDispatch.sendEventEx(context2, o.a.D, CoreProtocol.getInstance(context2), null, 5000);
                    }
                    if (FieldManager.allow(com.umeng.commonsdk.utils.c.F)) {
                        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 云控下发参数更新 FirstResume功能 打开,触发 trigger");
                        l.a(this.e).b(this.e);
                        return;
                    }
                    return;
                case a.x:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 成功接收到(OAID)读取结束通知。");
                    f--;
                    g();
                    return;
                case a.y:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 正常冷启动流程,接收到云控配置加载成功通知。");
                    d(this.e);
                    a.a(this.e);
                    e(this.e);
                    return;
                case a.z:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 保存隐私授权结果.");
                    if (obj instanceof Integer) {
                        int intValue = ((Integer) obj).intValue();
                        SharedPreferences sharedPreferences3 = this.e.getApplicationContext().getSharedPreferences(a, 0);
                        if (sharedPreferences3 != null) {
                            sharedPreferences3.edit().putInt("policyGrantResult", intValue).commit();
                            return;
                        }
                        return;
                    }
                    return;
                case a.A:
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 保存preInit执行结果及授权API是否调用结果.");
                    if (obj instanceof JSONObject) {
                        JSONObject jSONObject3 = (JSONObject) obj;
                        if (jSONObject3.has(a.H)) {
                            int i3 = jSONObject3.getInt(a.H);
                            int i4 = jSONObject3.getInt(a.I);
                            int i5 = jSONObject3.getInt("policyGrantResult");
                            SharedPreferences sharedPreferences4 = this.e.getApplicationContext().getSharedPreferences(a, 0);
                            if (!(sharedPreferences4 == null || (edit = sharedPreferences4.edit()) == null)) {
                                edit.putInt(b, i3);
                                edit.putInt(c, i4);
                                edit.putInt("policyGrantResult", i5);
                                edit.commit();
                            }
                            File filesDir = this.e.getFilesDir();
                            File file3 = new File(filesDir.getAbsolutePath() + File.separator + aq.m);
                            if (!file3.exists()) {
                                file3.createNewFile();
                                return;
                            }
                            return;
                        }
                        return;
                    }
                    return;
                case a.B:
                    File filesDir2 = this.e.getFilesDir();
                    File file4 = new File(filesDir2.getAbsolutePath() + File.separator + aq.m);
                    if (file4.exists()) {
                        file4.delete();
                        return;
                    }
                    return;
                case a.C:
                    SelfChecker.doCheck(this.e);
                    return;
            }
        } else if (32802 == i2) {
            UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 静默模式:进入心跳处理逻辑!");
            long currentTimeMillis3 = System.currentTimeMillis();
            long b2 = com.umeng.commonsdk.utils.b.b(this.e);
            boolean e2 = com.umeng.commonsdk.utils.b.e(this.e);
            if (com.umeng.commonsdk.utils.b.a(b2, currentTimeMillis3, com.umeng.commonsdk.utils.b.a(this.e))) {
                if (!UMFrUtils.hasEnvelopeFile(this.e, UMLogDataProtocol.UMBusinessType.U_Silent)) {
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 构建静默心跳信封.");
                    b(this.e);
                } else {
                    UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 静默心跳信封文件已存在,尝试发送之!");
                }
                UMEnvelopeBuild.registerNetReceiver(this.e);
            }
            if (!e2) {
                UMRTLog.i(UMRTLog.RTLOG_TAG, "--->>> send REBUILD_DB msg in silent mode.");
                Context context3 = this.e;
                UMWorkDispatch.sendEvent(context3, o.a.p, CoreProtocol.getInstance(context3), null, 2000);
            }
        }
    }

    private static Class<?> a(String str) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException unused) {
            return null;
        }
    }

    private void e(Context context) {
        Object invoke;
        Method declaredMethod;
        Context applicationContext = context.getApplicationContext();
        String appkey = UMUtils.getAppkey(context);
        try {
            Class<?> a2 = a("com.umeng.umzid.ZIDManager");
            Method declaredMethod2 = a2.getDeclaredMethod("getInstance", new Class[0]);
            if (declaredMethod2 != null && (invoke = declaredMethod2.invoke(a2, new Object[0])) != null && (declaredMethod = a2.getDeclaredMethod(PointCategory.INIT, Context.class, String.class, a("com.umeng.umzid.IZIDCompletionCallback"))) != null) {
                declaredMethod.invoke(invoke, applicationContext, appkey, null);
            }
        } catch (Throwable unused) {
        }
    }

    private void g() {
        if (f <= 0) {
            h();
            e(this.e);
        }
    }

    private static void f(Context context) {
        File filesDir = context.getFilesDir();
        File file = new File(filesDir.getAbsolutePath() + File.separator + aq.l);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (Throwable unused) {
            }
        }
    }

    private void h() {
        UMRTLog.e(UMRTLog.RTLOG_TAG, "--->>> 真实构建条件满足,开始构建业务信封。");
        if (UMUtils.isMainProgress(this.e)) {
            f(this.e);
            a.a(this.e);
            Context context = this.e;
            UMWorkDispatch.sendEvent(context, o.a.y, CoreProtocol.getInstance(context), null);
            Context context2 = this.e;
            UMWorkDispatch.sendEvent(context2, a.t, b.a(context2).a(), null);
        }
    }
}