万能钥匙.apk(点击下载) / a.java


package com.huawei.hms.support.api.push.a.a;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.webkit.URLUtil;
import com.appara.feed.constant.TTParam;
import java.util.ArrayList;

/* compiled from: SelfShowType */
public class a {

    /* renamed from: a  reason: collision with root package name */
    private static final String[] f5048a = {"phone", "url", "email", "app", "cosa", TTParam.SOURCE_rp};

    /* renamed from: b  reason: collision with root package name */
    private Context f5049b;
    private com.huawei.hms.support.api.push.a.b.a c;

    public a(Context context, com.huawei.hms.support.api.push.a.b.a aVar) {
        this.f5049b = context;
        this.c = aVar;
    }

    public static boolean a(String str) {
        int i = 0;
        while (true) {
            String[] strArr = f5048a;
            if (i >= strArr.length) {
                return false;
            }
            if (strArr[i].equals(str)) {
                return true;
            }
            i++;
        }
    }

    public void a() {
        com.huawei.hms.support.api.push.a.b.a aVar;
        com.huawei.hms.support.log.a.a("PushSelfShowLog", "enter launchNotify()");
        if (this.f5049b == null || (aVar = this.c) == null) {
            com.huawei.hms.support.log.a.a("PushSelfShowLog", "launchNotify  context or msg is null");
        } else if ("app".equals(aVar.k())) {
            d();
        } else if ("cosa".equals(this.c.k())) {
            g();
        } else if ("email".equals(this.c.k())) {
            c();
        } else if ("phone".equals(this.c.k())) {
            b();
        } else if (TTParam.SOURCE_rp.equals(this.c.k())) {
            com.huawei.hms.support.log.a.c("PushSelfShowLog", this.c.k() + " not support rich message.");
        } else if ("url".equals(this.c.k())) {
            com.huawei.hms.support.log.a.c("PushSelfShowLog", this.c.k() + " not support URL.");
        } else {
            com.huawei.hms.support.log.a.a("PushSelfShowLog", this.c.k() + " is not exist in hShowType");
        }
    }

    private void b() {
        com.huawei.hms.support.log.a.a("PushSelfShowLog", "enter launchCall");
        try {
            Intent intent = new Intent();
            Intent action = intent.setAction("android.intent.action.DIAL");
            action.setData(Uri.parse("tel:" + this.c.o())).setFlags(268435456);
            this.f5049b.startActivity(intent);
        } catch (Exception e) {
            com.huawei.hms.support.log.a.a("PushSelfShowLog", e.toString(), e);
        }
    }

    private void c() {
        com.huawei.hms.support.log.a.a("PushSelfShowLog", "enter launchMail");
        try {
            if (this.c.p() != null) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.SENDTO").setFlags(268435456).setData(Uri.fromParts("mailto", this.c.p(), null)).putExtra("android.intent.extra.SUBJECT", this.c.q()).putExtra("android.intent.extra.TEXT", this.c.r()).setPackage("com.android.email");
                this.f5049b.startActivity(intent);
            }
        } catch (Exception e) {
            com.huawei.hms.support.log.a.a("PushSelfShowLog", e.toString(), e);
        }
    }

    private void d() {
        try {
            com.huawei.hms.support.log.a.b("PushSelfShowLog", "enter launchApp, appPackageName =" + this.c.s() + ",and msg.intentUri is " + this.c.g());
            if (com.huawei.hms.support.api.push.a.d.a.c(this.f5049b, this.c.s())) {
                g();
                return;
            }
            com.huawei.hms.support.log.a.b("PushSelfShowLog", "enter launch app, appPackageName =" + this.c.s() + ",and msg.intentUri is " + this.c.g());
            e();
        } catch (Exception e) {
            com.huawei.hms.support.log.a.d("PushSelfShowLog", "launchApp error:" + e.toString());
        }
    }

    private String b(String str) {
        try {
            int indexOf = str.indexOf(63);
            if (indexOf == -1) {
                return str;
            }
            int i = indexOf + 1;
            String[] split = str.substring(i).split("&");
            ArrayList arrayList = new ArrayList();
            for (String str2 : split) {
                if (!str2.startsWith("h_w_hiapp_referrer") && !str2.startsWith("h_w_gp_referrer")) {
                    arrayList.add(str2);
                }
            }
            StringBuilder sb = new StringBuilder();
            int size = arrayList.size();
            for (int i2 = 0; i2 < size; i2++) {
                sb.append((String) arrayList.get(i2));
                if (i2 < arrayList.size() - 1) {
                    sb.append("&");
                }
            }
            String substring = arrayList.size() == 0 ? str.substring(0, indexOf) : str.substring(0, i) + sb.toString();
            com.huawei.hms.support.log.a.a("PushSelfShowLog", "after delete referrer, the new IntentUri is:".concat(String.valueOf(substring)));
            return substring;
        } catch (RuntimeException unused) {
            com.huawei.hms.support.log.a.d("PushSelfShowLog", "self show receiver exception");
            return str;
        } catch (Exception unused2) {
            com.huawei.hms.support.log.a.d("PushSelfShowLog", "delete referrer exception");
            return str;
        }
    }

    private void e() {
        try {
            StringBuilder sb = new StringBuilder();
            if (!TextUtils.isEmpty(this.c.g())) {
                sb.append("&referrer=");
                sb.append(Uri.encode(b(this.c.g())));
            }
            String str = "market://details?id=" + this.c.s() + ((Object) sb);
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(Uri.parse(str));
            intent.setPackage("com.huawei.appmarket");
            Intent intent2 = new Intent("android.intent.action.VIEW");
            intent2.setData(Uri.parse(str));
            intent2.setPackage("com.android.vending");
            if (com.huawei.hms.support.api.push.a.d.a.a(this.f5049b, "com.android.vending", intent2).booleanValue()) {
                intent2.setFlags(402653184);
                com.huawei.hms.support.log.a.b("PushSelfShowLog", "open google play store's app detail, IntentUrl is:" + intent2.toURI());
                this.f5049b.startActivity(intent2);
            } else if (com.huawei.hms.support.api.push.a.d.a.a(this.f5049b, "com.huawei.appmarket", intent).booleanValue()) {
                intent.setFlags(402653184);
                com.huawei.hms.support.log.a.b("PushSelfShowLog", "open HiApp's app detail, IntentUrl is:" + intent.toURI());
                this.f5049b.startActivity(intent);
            } else {
                com.huawei.hms.support.log.a.b("PushSelfShowLog", "open app detail by browser.");
                f();
            }
        } catch (Exception e) {
            com.huawei.hms.support.log.a.d("PushSelfShowLog", "open market app detail failed,exception:".concat(String.valueOf(e)));
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x002f, code lost:
        com.huawei.hms.support.log.a.c("PushSelfShowLog", "parse intentUri error");
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x0037, code lost:
        com.huawei.hms.support.log.a.c("PushSelfShowLog", "parse intentUri error");
     */
    /* JADX WARNING: Code restructure failed: missing block: B:6:0x0019, code lost:
        com.huawei.hms.support.log.a.b("PushSelfShowLog", "parse h_w_hiapp_referrer faied");
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:16:? A[ExcHandler: RuntimeException (unused java.lang.RuntimeException), PHI: r0 
      PHI: (r0v9 java.lang.String) = (r0v0 java.lang.String), (r0v0 java.lang.String), (r0v0 java.lang.String), (r0v10 java.lang.String), (r0v10 java.lang.String) binds: [B:1:0x0004, B:2:?, B:4:0x0014, B:9:0x0022, B:10:?] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC, Splitter:B:1:0x0004] */
    private void f() {
        String str;
        String str2 = "";
        String str3 = "";
        try {
            Uri parse = Uri.parse(Uri.decode(this.c.g()));
            str2 = parse.getQueryParameter("h_w_hiapp_referrer");
            str3 = parse.getQueryParameter("h_w_gp_referrer");
        } catch (Exception unused) {
            com.huawei.hms.support.log.a.b("PushSelfShowLog", "parse h_w_hiapp_referrer faied");
        } catch (RuntimeException unused2) {
        }
        if (!com.huawei.hms.support.api.push.b.a.a.a.c() || !com.huawei.hms.support.api.push.b.a.a.a.d()) {
            com.huawei.hms.support.log.a.b("PushSelfShowLog", "not EMUI system or not in China, open google play web, referrer: ".concat(String.valueOf(str3)));
            str = Uri.decode(str3);
            if (!URLUtil.isValidUrl(str)) {
                str = "https://play.google.com/store/apps/details?id=" + this.c.s();
            }
        } else {
            com.huawei.hms.support.log.a.b("PushSelfShowLog", "It is China device, open Huawei market web, referrer: ".concat(String.valueOf(str2)));
            str = Uri.decode(str2);
            if (!URLUtil.isValidUrl(str)) {
                str = "http://a.vmall.com/";
            }
        }
        com.huawei.hms.support.log.a.b("PushSelfShowLog", "open the URL by browser: ".concat(String.valueOf(str)));
        com.huawei.hms.support.api.push.a.d.a.d(this.f5049b, str);
    }

    private void g() {
        com.huawei.hms.support.log.a.b("PushSelfShowLog", "run into launchCosaApp ");
        try {
            com.huawei.hms.support.log.a.b("PushSelfShowLog", "enter launchExistApp cosa, appPackageName =" + this.c.s() + ",and msg.intentUri is " + this.c.g());
            Intent b2 = com.huawei.hms.support.api.push.a.d.a.b(this.f5049b, this.c.s());
            boolean z = false;
            if (this.c.g() != null) {
                try {
                    Intent parseUri = Intent.parseUri(this.c.g(), 0);
                    com.huawei.hms.support.log.a.b("PushSelfShowLog", "Intent.parseUri(msg.intentUri, 0)," + parseUri.toURI());
                    z = com.huawei.hms.support.api.push.a.d.a.a(this.f5049b, this.c.s(), parseUri).booleanValue();
                    if (z) {
                        b2 = parseUri;
                    }
                } catch (RuntimeException unused) {
                    com.huawei.hms.support.log.a.c("PushSelfShowLog", "intentUri error");
                } catch (Exception unused2) {
                    com.huawei.hms.support.log.a.c("PushSelfShowLog", "intentUri error");
                }
            } else {
                if (this.c.t() != null) {
                    Intent intent = new Intent(this.c.t());
                    if (com.huawei.hms.support.api.push.a.d.a.a(this.f5049b, this.c.s(), intent).booleanValue()) {
                        b2 = intent;
                    }
                }
                b2.setPackage(this.c.s());
            }
            if (b2 == null) {
                com.huawei.hms.support.log.a.b("PushSelfShowLog", "launchCosaApp,intent == null");
            } else if (!com.huawei.hms.support.api.push.a.d.a.a(this.f5049b, b2)) {
                com.huawei.hms.support.log.a.c("PushSelfShowLog", "no permission to start Activity");
            } else {
                if (z) {
                    b2.addFlags(268435456);
                } else {
                    b2.setFlags(805437440);
                }
                com.huawei.hms.support.log.a.b("PushSelfShowLog", "start " + b2.toURI());
                this.f5049b.startActivity(b2);
            }
        } catch (RuntimeException unused3) {
            com.huawei.hms.support.log.a.d("PushSelfShowLog", "launch Cosa App exception");
        } catch (Exception unused4) {
            com.huawei.hms.support.log.a.d("PushSelfShowLog", "launch Cosa App exception");
        }
    }
}