智能工厂.apk(点击下载) / d.java


package cn.jiguang.ap;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ProviderInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import cn.jiguang.android.IDataShare;
import cn.jiguang.aq.c;
import cn.jiguang.aw.h;
import cn.jiguang.f.a;
import cn.jiguang.internal.ActionManager;
import cn.jiguang.internal.JConstants;
import cn.jiguang.internal.JCoreInternalHelper;
import cn.jpush.android.service.DataShare;
import cn.jpush.android.service.JCommonService;
import cn.jpush.android.service.PushReceiver;
import java.util.HashMap;
import java.util.Map;

public class d {
    private static d a;
    private static Map<String, String> b = new HashMap();

    private d() {
    }

    private Bundle a(String str, String str2, Bundle bundle, String str3) {
        String str4 = str + "." + str2;
        try {
            IDataShare instance = DataShare.getInstance(str3);
            if (instance != null) {
                c.c("JMessenger", "sendByAidl, " + str4);
                if ("INTERNAL_API".equals(str)) {
                    return instance.execute(str, str2, bundle);
                }
                instance.onAction(str, str2, bundle);
                return new Bundle();
            }
            c.c("JMessenger", str3 + "'s aidl not found, " + str4);
            return null;
        } catch (Throwable th) {
            c.g("JMessenger", "sendByAidl, " + str4 + ", e=" + th);
            return null;
        }
    }

    public static d a() {
        if (a == null) {
            synchronized (d.class) {
                if (a == null) {
                    a = new d();
                }
            }
        }
        return a;
    }

    private static String a(Context context, String str) {
        StringBuilder sb;
        String str2 = b.get(str);
        if (!TextUtils.isEmpty(str2)) {
            return str2;
        }
        String str3 = context.getPackageName() + JConstants.DATA_PROVIDER_SUFFIX;
        ProviderInfo a2 = a.a(context, context.getPackageName(), str3);
        String str4 = null;
        if (str.equals(a2 != null ? a2.processName : null)) {
            sb = new StringBuilder();
        } else {
            str3 = context.getPackageName() + ".DownloadProvider";
            ProviderInfo a3 = a.a(context, context.getPackageName(), str3);
            if (a3 != null) {
                str4 = a3.processName;
            }
            if (!str.equals(str4)) {
                return "";
            }
            sb = new StringBuilder();
        }
        sb.append("content://");
        sb.append(str3);
        sb.append("/");
        String sb2 = sb.toString();
        b.put(str, sb2);
        return sb2;
    }

    private boolean a(Context context, Class cls, String str, Bundle bundle) {
        if (cls == null) {
            return false;
        }
        String str2 = cls.getName() + "." + str;
        try {
            Intent intent = new Intent();
            intent.setClass(context, cls);
            intent.setAction(str);
            intent.setPackage(context.getPackageName());
            if (bundle != null) {
                intent.putExtras(bundle);
            }
            if (BroadcastReceiver.class.isAssignableFrom(cls)) {
                context.sendBroadcast(intent);
                c.c("JMessenger", "sendByReceiver, " + str2);
                return true;
            }
            if (Service.class.isAssignableFrom(cls)) {
                if (context.startService(intent) != null) {
                    c.c("JMessenger", "sendByService, " + str2);
                    return true;
                }
                c.g("JMessenger", "startService, " + str2 + ", can't find component");
            }
            return false;
        } catch (Throwable th) {
            c.g("JMessenger", "sendByComponent, " + str2 + " e=" + th);
        }
    }

    private Bundle b(Context context, String str, String str2, Bundle bundle, String str3) {
        String str4 = str + "." + str2;
        try {
            if (Build.VERSION.SDK_INT < 11) {
                return null;
            }
            String a2 = a(context, str3);
            if (!TextUtils.isEmpty(a2)) {
                Uri parse = Uri.parse(a2);
                c.c("JMessenger", "sendByProvider, uri=" + a2 + ", " + str4);
                return context.getContentResolver().call(parse, str, str2, bundle);
            }
            c.c("JMessenger", "uri is null, check provider config");
            return null;
        } catch (Throwable th) {
            c.g("JMessenger", "provider call:" + th);
            return null;
        }
    }

    public Bundle a(Context context, String str, String str2, Bundle bundle, String str3) {
        if (TextUtils.isEmpty(str3)) {
            return null;
        }
        String a2 = a.a(context);
        if (TextUtils.isEmpty(a2)) {
            return null;
        }
        if (a2.equals(str3)) {
            return b(context, str, str2, bundle);
        }
        Bundle a3 = a(str, str2, bundle, str3);
        if (a3 != null) {
            return a3;
        }
        Bundle b2 = b(context, str, str2, bundle, str3);
        if (b2 != null) {
            return b2;
        }
        return null;
    }

    public boolean a(Context context, String str, String str2, Bundle bundle) {
        Class<?> cls;
        Throwable th;
        String str3 = str + "." + str2;
        String str4 = null;
        try {
            cls = Class.forName(str);
            try {
                if (Service.class.isAssignableFrom(cls)) {
                    str4 = a.a(context, str);
                } else if (BroadcastReceiver.class.isAssignableFrom(cls)) {
                    str4 = a.b(context, str);
                }
            } catch (Throwable th2) {
                th = th2;
                c.c("JMessenger", str3 + " meet e:" + th);
                return true;
            }
        } catch (Throwable th3) {
            th = th3;
            cls = null;
            c.c("JMessenger", str3 + " meet e:" + th);
            return true;
        }
        try {
            if (a(context, str, str2, bundle, str4) != null || a(context, cls, str2, bundle)) {
                return true;
            }
        } catch (Throwable th4) {
            c.g("JMessenger", "send, " + str3 + " meet e:" + th4);
        }
        c.i("JMessenger", "send all failed, " + str3);
        return false;
    }

    public Bundle b(Context context, String str, String str2, Bundle bundle) {
        try {
            c.c("JMessenger", "directHandle, " + str + "." + str2);
            if (!"INTERNAL_API".equals(str)) {
                Class<?> cls = Class.forName(str);
                if (!BroadcastReceiver.class.isAssignableFrom(cls) && !Service.class.isAssignableFrom(cls)) {
                    c.i("JMessenger", "directHandle, not support " + str + "." + str2);
                    return null;
                } else if (JCommonService.class.isAssignableFrom(cls)) {
                    c.c("JMessenger", "JCommonService handle succeed," + str + "." + str2);
                    JCoreInternalHelper.getInstance().onEvent(context, JConstants.SDK_TYPE, 2, true, str2, bundle, new Object[0]);
                    return new Bundle();
                } else {
                    Intent intent = new Intent(str2);
                    intent.setClass(context, cls);
                    if (bundle != null) {
                        intent.putExtras(bundle);
                    }
                    intent.setPackage(context.getPackageName());
                    intent.addCategory(context.getPackageName());
                    if (PushReceiver.class.isAssignableFrom(cls)) {
                        c.c("JMessenger", "PushReceiver handle succeed," + str + "." + str2);
                        ActionManager.getInstance().handleMessage(context, bundle != null ? bundle.getString("sdktype") : null, intent);
                    } else if (BroadcastReceiver.class.isAssignableFrom(cls)) {
                        c.c("JMessenger", "Receiver onReceive," + str + "." + str2);
                        ((BroadcastReceiver) cls.newInstance()).onReceive(context, intent);
                    } else {
                        c.c("JMessenger", "Service onStartCommand," + str + "." + str2);
                        ((Service) cls.newInstance()).onStartCommand(intent, 0, 0);
                    }
                    return new Bundle();
                }
            } else if (str2.equals("isTcpLoggedIn")) {
                boolean d = h.a().d();
                Bundle bundle2 = new Bundle();
                bundle2.putBoolean("state", d);
                return bundle2;
            } else {
                c.i("JMessenger", "directHandle, not support " + str + "." + str2);
                return null;
            }
        } catch (Throwable th) {
            c.i("JMessenger", "directHandle e:" + th);
            return null;
        }
    }
}