������������������.apk分析 / a.java


package com.baidu.techain.b;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import com.baidu.techain.ac.Callback;
import com.baidu.techain.b;
import com.baidu.techain.core.d;
import com.baidu.techain.i.c;
import com.heytap.msp.push.HeytapPushManager;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.xiaomi.mipush.sdk.Constants;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

/* compiled from: VendorPushHelper */
public final class a {
    public static void a(Context context, String str, Intent intent) {
        long j;
        try {
            if (str.equals("onNotificationClicked")) {
                int intExtra = intent.getIntExtra("type", -1);
                String stringExtra = intent.getStringExtra("content");
                b.a();
                if (!TextUtils.isEmpty(stringExtra)) {
                    try {
                        JSONObject jSONObject = new JSONObject(stringExtra);
                        String optString = jSONObject.optString("id");
                        try {
                            j = jSONObject.optLong("msg_id", -1);
                        } catch (Throwable unused) {
                            j = (long) jSONObject.optInt("msg_id", -1);
                            c.a();
                        }
                        int optInt = jSONObject.optInt("msg_type", -1);
                        JSONObject jSONObject2 = jSONObject.getJSONObject("action");
                        int optInt2 = jSONObject2.optInt("action_type", -1);
                        String optString2 = jSONObject2.optString("target");
                        Intent intent2 = null;
                        String str2 = null;
                        intent2 = null;
                        switch (optInt2) {
                            case 6:
                                JSONObject jSONObject3 = new JSONObject(optString2);
                                try {
                                    String optString3 = jSONObject3.optString("package_name");
                                    context.getPackageManager().getPackageInfo(optString3, 0);
                                    intent2 = context.getPackageManager().getLaunchIntentForPackage(optString3);
                                    a(jSONObject3, intent2);
                                    break;
                                } catch (PackageManager.NameNotFoundException unused2) {
                                    intent2 = a(context, jSONObject3);
                                    a(jSONObject3, intent2);
                                    break;
                                } catch (Throwable unused3) {
                                    c.a();
                                    break;
                                }
                            case 7:
                                JSONObject jSONObject4 = new JSONObject(optString2);
                                intent2 = Intent.parseUri(jSONObject4.optString("class_name"), 0);
                                if (!a(context, intent2)) {
                                    intent2.addFlags(268435456);
                                    a(jSONObject4, intent2);
                                    break;
                                } else {
                                    throw new IllegalStateException("component is not permitted to called");
                                }
                            case 8:
                                JSONObject jSONObject5 = new JSONObject(optString2);
                                String optString4 = jSONObject5.optString("class_name");
                                try {
                                    str2 = jSONObject5.optString("package_name");
                                } catch (Throwable unused4) {
                                    c.a();
                                }
                                if (TextUtils.isEmpty(str2)) {
                                    str2 = context.getPackageName();
                                }
                                Intent intent3 = new Intent();
                                intent3.setClassName(str2, optString4);
                                if (!a(context, intent3)) {
                                    a(jSONObject5, intent3);
                                    intent2 = intent3;
                                    break;
                                } else {
                                    throw new IllegalStateException("component is not permitted to called");
                                }
                            case 9:
                                intent2 = new Intent("android.intent.action.VIEW", Uri.parse(new JSONObject(optString2).optString("url")));
                                if (a(context, intent2)) {
                                    throw new IllegalStateException("component is not permitted to called");
                                }
                                break;
                            default:
                                b.b();
                                break;
                        }
                        if (intent2 != null) {
                            intent2.addFlags(268435456);
                            context.startActivity(intent2);
                        }
                        if (!TextUtils.isEmpty(optString)) {
                            try {
                                HashMap hashMap = new HashMap();
                                hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, Integer.valueOf(intExtra));
                                hashMap.put("1", optString);
                                hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, Integer.valueOf(optInt2));
                                hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Long.valueOf(j));
                                hashMap.put(PushConstants.PUSH_TYPE_WITHDRAW_NOTIFICATION, Integer.valueOf(optInt));
                                c.a(context, "1025125", hashMap);
                            } catch (Throwable unused5) {
                                c.a();
                            }
                        }
                    } catch (Throwable unused6) {
                        c.a();
                    }
                }
            } else {
                d.a(100019, str, new Callback() {
                    /* class com.baidu.techain.b.a.AnonymousClass1 */

                    @Override // com.baidu.techain.ac.Callback
                    public final Object onEnd(Object... objArr) {
                        return super.onEnd(objArr);
                    }
                }, new Class[]{Context.class, Intent.class}, context, intent);
            }
        } catch (Throwable unused7) {
            c.a();
        }
    }

    private static void a(JSONObject jSONObject, Intent intent) {
        if (intent == null) {
            b.a();
            return;
        }
        try {
            String optString = jSONObject.optString("class_param_key");
            String optString2 = jSONObject.optString("class_param_value");
            if (!TextUtils.isEmpty(optString) && !TextUtils.isEmpty(optString2)) {
                String[] split = optString.split(Constants.ACCEPT_TIME_SEPARATOR_SP);
                String[] split2 = optString2.split(Constants.ACCEPT_TIME_SEPARATOR_SP);
                if (!(split == null || split2 == null || split.length != split2.length)) {
                    for (int i = 0; i < split.length; i++) {
                        String str = split[i];
                        String str2 = split2[i];
                        StringBuilder sb = new StringBuilder("key:");
                        sb.append(str);
                        sb.append(",val:");
                        sb.append(str2);
                        b.a();
                        if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
                            intent.putExtra(str, str2);
                        }
                    }
                }
            }
            JSONObject optJSONObject = jSONObject.optJSONObject(com.heytap.mcssdk.a.a.p);
            if (optJSONObject != null) {
                Iterator<String> keys = optJSONObject.keys();
                while (keys.hasNext()) {
                    String next = keys.next();
                    String string = optJSONObject.getString(next);
                    StringBuilder sb2 = new StringBuilder("key:");
                    sb2.append(next);
                    sb2.append(",value:");
                    sb2.append(string);
                    b.a();
                    if (!TextUtils.isEmpty(next) && !TextUtils.isEmpty(string)) {
                        intent.putExtra(next, string);
                    }
                }
            }
        } catch (Throwable unused) {
            c.a();
        }
    }

    private static Intent a(Context context, JSONObject jSONObject) throws Throwable {
        JSONObject optJSONObject = jSONObject.optJSONObject("market_list");
        String optString = jSONObject.optString("package_name");
        if (optJSONObject != null) {
            Iterator<String> keys = optJSONObject.keys();
            Intent intent = null;
            while (keys.hasNext()) {
                String next = keys.next();
                List<PackageInfo> installedPackages = context.getPackageManager().getInstalledPackages(0);
                ArrayList arrayList = new ArrayList();
                if (installedPackages != null) {
                    for (int i = 0; i < installedPackages.size(); i++) {
                        arrayList.add(installedPackages.get(i).packageName);
                    }
                }
                if (arrayList.contains(next)) {
                    String optString2 = optJSONObject.optString(next);
                    if (optString2 == null) {
                        b.b();
                    } else {
                        if (optString2.startsWith("market:")) {
                            intent = new Intent("android.intent.action.VIEW", Uri.parse(optString2));
                        } else if (optString2.startsWith("android-app:") || optString2.startsWith("intent:")) {
                            intent = Intent.parseUri(optString2, 1);
                        }
                        if (!(intent == null || intent.resolveActivity(context.getPackageManager()) == null)) {
                            StringBuilder sb = new StringBuilder("Market list valid =");
                            sb.append(next);
                            sb.append(" url=");
                            sb.append(optString2);
                            b.a();
                            intent.putExtra("ins_t", 0);
                            intent.putExtra("ins_d", next);
                            intent.putExtra("ins_p", optString);
                            return intent;
                        }
                    }
                }
            }
        }
        b.a();
        Intent intent2 = new Intent("android.intent.action.VIEW", Uri.parse(jSONObject.optString("url")));
        intent2.putExtra("ins_t", 1);
        intent2.putExtra("ins_d", jSONObject.optString("url"));
        intent2.putExtra("ins_p", optString);
        if (intent2.resolveActivity(context.getPackageManager()) != null) {
            return intent2;
        }
        return null;
    }

    public static void a(Context context, Bundle bundle) {
        try {
            Intent intent = new Intent("com.baidu.techain.push.action.PUSH_EVENT");
            intent.addCategory(context.getPackageName());
            intent.setPackage(context.getPackageName());
            if (bundle.size() > 0) {
                intent.putExtras(bundle);
            }
            context.sendBroadcast(intent);
        } catch (Throwable unused) {
            c.a();
        }
    }

    public static JSONArray a(String[] strArr) {
        if (strArr != null) {
            try {
                if (strArr.length != 0) {
                    JSONArray jSONArray = new JSONArray();
                    if (strArr != null) {
                        for (String str : strArr) {
                            jSONArray.put(str);
                        }
                    }
                    return jSONArray;
                }
            } catch (Throwable unused) {
                c.a();
                return new JSONArray();
            }
        }
        return new JSONArray();
    }

    public static JSONArray a(long[] jArr) {
        if (jArr != null) {
            try {
                if (jArr.length != 0) {
                    JSONArray jSONArray = new JSONArray();
                    if (jArr != null) {
                        for (long j : jArr) {
                            jSONArray.put(j);
                        }
                    }
                    return jSONArray;
                }
            } catch (Throwable unused) {
                c.a();
                return new JSONArray();
            }
        }
        return new JSONArray();
    }

    public static JSONArray a(int[] iArr) {
        if (iArr != null) {
            try {
                if (iArr.length != 0) {
                    JSONArray jSONArray = new JSONArray();
                    if (iArr != null) {
                        for (int i : iArr) {
                            jSONArray.put(i);
                        }
                    }
                    return jSONArray;
                }
            } catch (Throwable unused) {
                c.a();
                return new JSONArray();
            }
        }
        return new JSONArray();
    }

    public static String a(String str) {
        try {
            if (!TextUtils.isEmpty(str)) {
                return str;
            }
            return "";
        } catch (Throwable unused) {
            c.a();
            return "";
        }
    }

    public static String a(Activity activity) {
        try {
            Method method = Class.forName("android.app.Activity").getMethod("getActivityToken", new Class[0]);
            method.setAccessible(true);
            Object invoke = method.invoke(activity, new Object[0]);
            Class<?> cls = Class.forName("android.app.ActivityManagerNative");
            Method method2 = cls.getMethod("getDefault", new Class[0]);
            method2.setAccessible(true);
            Object invoke2 = method2.invoke(cls, new Object[0]);
            String a = a(activity, invoke2, invoke);
            if (TextUtils.isEmpty(a)) {
                a = a(invoke2, invoke);
            }
            if (!TextUtils.isEmpty(a)) {
                return a.contains(Constants.COLON_SEPARATOR) ? a.substring(0, a.lastIndexOf(Constants.COLON_SEPARATOR)) : a;
            }
            return "";
        } catch (Throwable unused) {
            c.a();
            return "";
        }
    }

    private static String a(Activity activity, Object obj, Object obj2) {
        try {
            Method method = obj.getClass().getMethod("getLaunchedFromUid", IBinder.class);
            method.setAccessible(true);
            String nameForUid = activity.getPackageManager().getNameForUid(((Integer) method.invoke(obj, obj2)).intValue());
            if (!TextUtils.isEmpty(nameForUid)) {
                return nameForUid;
            }
            return "";
        } catch (Throwable unused) {
            c.a();
            return "";
        }
    }

    private static String a(Object obj, Object obj2) {
        try {
            Method method = obj.getClass().getMethod("getLaunchedFromPackage", IBinder.class);
            method.setAccessible(true);
            String str = (String) method.invoke(obj, obj2);
            if (!TextUtils.isEmpty(str)) {
                return str;
            }
            return "";
        } catch (Throwable unused) {
            c.a();
            return "";
        }
    }

    private static boolean a(Context context, Intent intent) {
        ActivityInfo activityInfo;
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager == null || (activityInfo = packageManager.getActivityInfo(intent.getComponent(), 1)) == null || activityInfo.exported) {
                return false;
            }
            return true;
        } catch (Throwable unused) {
            c.a();
            return false;
        }
    }

    public static boolean a(Context context, String str) {
        if (context != null && !TextUtils.isEmpty(str)) {
            if (str.equals(context.getPackageName()) || "android.uid.system".equals(str)) {
                return true;
            }
            try {
                PackageInfo packageInfo = context.getPackageManager().getPackageInfo(str, 0);
                if (!(packageInfo == null || (packageInfo.applicationInfo.flags & 1) == 0)) {
                    return true;
                }
            } catch (Throwable unused) {
                c.a();
            }
        }
        return false;
    }

    public static String a(Context context, int i) {
        if (i == 0) {
            try {
                return b(context, "sdk_version_hw");
            } catch (Throwable unused) {
                return "";
            }
        } else if (i == 1) {
            return b(context, "sdk_version_mui");
        } else {
            if (i == 4) {
                return HeytapPushManager.getSDKVersion();
            }
            if (i == 3) {
                return b(context, "sdk_version_vivo");
            }
            return i == 2 ? b(context, "sdk_version_mz") : "";
        }
    }

    private static String b(Context context, String str) {
        try {
            Object obj = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128).metaData.get(str);
            if (obj == null) {
                return null;
            }
            String valueOf = String.valueOf(obj);
            if (!TextUtils.isEmpty(valueOf)) {
                return valueOf;
            }
            return null;
        } catch (Exception unused) {
            return null;
        }
    }
}