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


package cn.jiguang.i;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import androidx.core.app.NotificationManagerCompat;
import cn.jiguang.o.d;
import cn.jiguang.o.e;
import cn.jiguang.v.c;
import com.baidu.speech.asr.SpeechConstant;
import com.nordnetab.chcp.main.js.PluginResultHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;

public class b extends cn.jiguang.o.a {
    @SuppressLint({"StaticFieldLeak"})
    private static volatile b d;
    private Context a;
    private Set<String> b;
    private List<cn.jiguang.j.a> c;

    public class a extends e {
        private Context c;
        private Intent d;

        a(Context context, Intent intent) {
            this.c = context;
            this.d = intent;
            this.b = "JAppMovement#MovementAction";
        }

        @Override // cn.jiguang.o.e
        public void a() {
            try {
                b.this.b((b) this.c, (Context) this.d);
            } catch (Throwable th) {
                cn.jiguang.af.a.d("JAppMovement", "dealMovementAction throwable:" + th.getMessage());
            }
        }
    }

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

    private void a(String str, int i, String str2, int i2) {
        try {
            Map<String, cn.jiguang.j.a> a2 = cn.jiguang.k.a.a(this.a);
            String str3 = "";
            if (a2 != null) {
                cn.jiguang.j.a aVar = a2.get(str);
                if (aVar == null) {
                    aVar = cn.jiguang.k.a.c(this.a, str);
                }
                if (aVar != null) {
                    str3 = aVar.a;
                }
            }
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(PluginResultHelper.JsParams.General.ACTION, str2);
            jSONObject.put("app_name", str3);
            jSONObject.put(SpeechConstant.APP_ID, str);
            jSONObject.put("source", i2);
            if (i != -1000) {
                jSONObject.put("install_type", i);
            }
            d.a(this.a, jSONObject, "app_add_rmv");
            d.a(this.a, (Object) jSONObject);
        } catch (JSONException e) {
            cn.jiguang.af.a.d("JAppMovement", "package json exception:" + e.getMessage());
        }
    }

    private boolean a(int i, String str) {
        if (i != 1) {
            return false;
        }
        cn.jiguang.af.a.d("JAppMovement", "the " + str + " app is system app,need dealAction all apps,to executeMovementAction JAppAll");
        return true;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void b(Context context, Intent intent) {
        String dataString;
        String str;
        int i;
        String action = intent.getAction();
        if (action == null || TextUtils.isEmpty(action)) {
            cn.jiguang.af.a.d("JAppMovement", "the action'" + action + "'is illegal");
        } else if ((action.equals("android.intent.action.PACKAGE_ADDED") || action.equals("android.intent.action.PACKAGE_REMOVED")) && (dataString = intent.getDataString()) != null && !TextUtils.isEmpty(dataString) && dataString.length() > 8 && dataString.startsWith("package:")) {
            String substring = dataString.substring(8);
            cn.jiguang.af.a.a("JAppMovement", "receive the action'" + action + ",package:" + substring);
            boolean z = false;
            if (action.equals("android.intent.action.PACKAGE_ADDED")) {
                i = cn.jiguang.k.a.a(cn.jiguang.k.a.a(context, substring));
                cn.jiguang.af.a.a("JAppMovement", "report add app:" + substring);
                str = "add";
            } else {
                cn.jiguang.af.a.a("JAppMovement", "report remove app:" + substring);
                i = NotificationManagerCompat.IMPORTANCE_UNSPECIFIED;
                str = "rmv";
            }
            a(substring, i, str, 0);
            this.b = e();
            Set<String> set = this.b;
            if (set == null || set.isEmpty()) {
                cn.jiguang.af.a.d("JAppMovement", "get cache appList failed");
            } else {
                try {
                    if (action.equals("android.intent.action.PACKAGE_ADDED")) {
                        this.b.add(substring);
                        z = true;
                    }
                    if (action.equals("android.intent.action.PACKAGE_REMOVED")) {
                        this.b.remove(substring);
                        z = true;
                    }
                    if (z && this.b != null) {
                        String a2 = cn.jiguang.k.a.a(this.b);
                        if (!TextUtils.isEmpty(a2)) {
                            cn.jiguang.af.a.a("JAppMovement", "update installedAppList cache:" + this.b);
                            c.a(context, "bal.catch", a2);
                        }
                    }
                } catch (Throwable th) {
                    cn.jiguang.af.a.d("JAppMovement", "cache appList add remove failed:" + th.getMessage());
                }
            }
            cn.jiguang.af.a.a("JAppMovement", "executeAction: [JAppMovement]");
            a(context, "JAppMovement");
            b(context, "JAppMovement");
        }
    }

    private Set<String> e() {
        String c2 = c.c(this.a, "bal.catch");
        if (!TextUtils.isEmpty(c2) && c2 != null && !TextUtils.isEmpty(c2)) {
            return cn.jiguang.k.a.a(c2);
        }
        return null;
    }

    /* access modifiers changed from: protected */
    @Override // cn.jiguang.o.a
    public String a(Context context) {
        this.a = context;
        return "JAppMovement";
    }

    public void a(Context context, Intent intent) {
        String a2 = a(context);
        cn.jiguang.af.a.a("JAppMovement", "executeMovementAction: [" + a2 + "] from broadcast");
        if (b()) {
            d.a(new a(context, intent));
        }
    }

    /* access modifiers changed from: protected */
    @Override // cn.jiguang.o.a
    public void a(Context context, String str) {
        super.a(context, str);
        List<cn.jiguang.j.a> a2 = cn.jiguang.k.a.a(context, true, false);
        if (a2 == null || a2.isEmpty()) {
            cn.jiguang.af.a.d("JAppMovement", "collect installedAppList failed");
            return;
        }
        cn.jiguang.af.a.a("JAppMovement", "collect installedAppList success");
        if (a2.size() != 1 || !a2.get(0).b.equals(context.getPackageName())) {
            this.b = e();
            Set<String> set = this.b;
            if (set == null || set.isEmpty()) {
                cn.jiguang.af.a.d("JAppMovement", "current appList cache is empty,need collect appList first,to executeMovementAction JAppAll");
                a.a().c(context);
                return;
            }
            cn.jiguang.af.a.a("JAppMovement", "get installedAppList cache:" + this.b);
            this.c = new ArrayList(a2);
            for (cn.jiguang.j.a aVar : a2) {
                if (this.b.remove(aVar.b)) {
                    this.c.remove(aVar);
                }
            }
            if (!this.b.isEmpty() || !this.c.isEmpty()) {
                String a3 = cn.jiguang.k.a.a(a2);
                if (!TextUtils.isEmpty(a3)) {
                    cn.jiguang.af.a.a("JAppMovement", "update installedAppList cache:" + a2);
                    c.a(context, "bal.catch", a3);
                    return;
                }
                return;
            }
            cn.jiguang.af.a.a("JAppMovement", "installedAppList has no change");
            return;
        }
        cn.jiguang.af.a.d("JAppMovement", "installedAppList only has one app and this app is itself");
    }

    /* access modifiers changed from: protected */
    @Override // cn.jiguang.o.a
    public void b(Context context, String str) {
        List<cn.jiguang.j.a> list = this.c;
        if (list == null || list.isEmpty()) {
            cn.jiguang.af.a.d("JAppMovement", "there are no add app data to report");
        } else {
            for (cn.jiguang.j.a aVar : this.c) {
                if (!a(aVar.e, "add")) {
                    a(aVar.b, aVar.e, "add", 1);
                    super.b(context, str);
                } else {
                    a.a().c(context);
                }
            }
        }
        Set<String> set = this.b;
        if (set == null || set.isEmpty()) {
            cn.jiguang.af.a.d("JAppMovement", "there are no remove app data to report");
        } else {
            for (String str2 : this.b) {
                if (!a(NotificationManagerCompat.IMPORTANCE_UNSPECIFIED, "rmv")) {
                    a(str2, NotificationManagerCompat.IMPORTANCE_UNSPECIFIED, "rmv", 1);
                    super.b(context, str);
                } else {
                    a.a().c(context);
                }
            }
        }
        this.c = null;
        this.b = null;
    }

    /* access modifiers changed from: protected */
    @Override // cn.jiguang.o.a
    public boolean b() {
        cn.jiguang.af.a.a("JAppMovement", "for googlePlay:false");
        return true;
    }

    /* access modifiers changed from: protected */
    @Override // cn.jiguang.o.a
    public boolean c(Context context, String str) {
        return cn.jiguang.o.b.a(context, str);
    }

    /* access modifiers changed from: protected */
    @Override // cn.jiguang.o.a
    public boolean d(Context context, String str) {
        Set<String> set;
        List<cn.jiguang.j.a> list = this.c;
        return (list != null && !list.isEmpty()) || ((set = this.b) != null && !set.isEmpty());
    }
}