package com.bytedance.android.livesdk.performance.opt;

import X.0aP;
import X.0b0;
import X.0cm;
import X.2d7;
import X.2d8;
import X.7hc;
import X.7he;
import X.C0358TSu;
import X.C0359TSv;
import X.C0449TWh;
import X.C0450TWi;
import X.C0451TWj;
import X.C0452TWk;
import X.C0453TWl;
import X.C0454TWm;
import X.C0455TWn;
import X.Crj;
import X.GIv;
import X.GIw;
import X.Glh;
import X.GtA;
import X.H7d;
import X.HEP;
import X.HEj;
import X.HJZ;
import X.LWw;
import X.T7s;
import X.T7u;
import X.TUH;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.text.TextUtils;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.livesdk.livesetting.performance.LivePerformanceSettingSetting;
import com.bytedance.android.livesdk.livesetting.performance.LivePullSdkGetDataIntervalSettings;
import com.bytedance.android.livesdk.log.monitor.IPerformanceManager;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.host.IHostApp;
import com.bytedance.android.livesdkapi.host.IHostPerformanceMonitor;
import com.bytedance.covode.number.Covode;
import com.bytedance.fresco.nativeheif.BuildConfig;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import com.bytedance.ugc.glue.monitor.UGCMonitor;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.FutureTask;
import kotlin.h.b.n;
import org.json.JSONException;
import org.json.JSONObject;

public final class LivePerformanceManagerV2 implements IPerformanceManager {
    public static final Crj LJIJ = 7he.LIZ(7hc.SYNCHRONIZED, TUH.LIZ);
    public static final C0359TSv LJIJI = new C0359TSv((byte) 0);
    public boolean LIZ;
    public final int LIZIZ;
    public final int LIZJ;
    public final int LIZLLL;
    public IHostPerformanceMonitor LJ;
    public Handler LJFF;
    public Map<String, String> LJI;
    public Map<String, Double> LJII;
    public Map<String, Long> LJIIIIZZ;
    public float LJIIIZ;
    public int LJIIJ;
    public long LJIIJJI;
    public String LJIIL;
    public String LJIILIIL;
    public String LJIILJJIL;
    public String LJIILL;
    public String LJIILLIIL;
    public Map<String, String> LJIIZILJ;
    public GIv LJIJJ;
    public long LJIJJLI;
    public boolean LJIL;
    public String LJJ;
    public HandlerThread LJJI;
    public Handler LJJIFFI;
    public C0449TWh LJJII;
    public boolean LJJIII;
    public final 2d8 LJJIIJ;
    public final C0452TWk LJJIIJZLJL;
    public float LJJIIZ;
    public double LJJIIZI;
    public float LJJIJ;
    public long LJJIJIIJI;
    public long LJJIJIIJIL;
    public long LJJIJIL;
    public boolean LJJIJL;
    public C0453TWl LJJIJLIJ;
    public final C0450TWi LJJIL;

    public final void onExitRoom() {
    }

    public final void onInit() {
    }

    public final void reportBatteryDrainage() {
    }

    public final void resetInitValue() {
        release();
    }

    public final void initStartValue() {
        initStartValue(0);
    }

    public final void onEnterRoom() {
        boolean z = this.LJJII.LIZ;
    }

    public final boolean hasInitValue() {
        if (this.LJII == null || this.LJIIIIZZ == null) {
            return false;
        }
        return true;
    }

    static {
        Covode.recordClassIndex(19975);
    }

    private final String LIZLLL() {
        JSONObject jSONObject = new JSONObject();
        try {
            for (2d7 r0 : this.LJJIIJ.LIZ.values()) {
                n.LIZIZ(r0, BuildConfig.VERSION_NAME);
                jSONObject.put(r0.LIZ, r0.LIZ());
            }
        } catch (Exception unused) {
        }
        String jSONObject2 = jSONObject.toString();
        n.LIZIZ(jSONObject2, BuildConfig.VERSION_NAME);
        return jSONObject2;
    }

    public final JSONObject LIZIZ() {
        HashMap hashMap = new HashMap();
        LIZ((Map<String, String>) hashMap);
        Map<String, String> map = this.LJIIZILJ;
        if (map != null) {
            hashMap.putAll(map);
        }
        hashMap.put("cpu", this.LJIIL);
        hashMap.put("pss", this.LJIILIIL);
        hashMap.put("thermal", this.LJIILJJIL);
        hashMap.put("stream", this.LJIILL);
        hashMap.put("battery", this.LJIILLIIL);
        return LIZIZ(hashMap);
    }

    public final Map<String, Double> getCpuRateEnableCache() {
        Map<String, Double> map = this.LJJIIJZLJL.LIZ;
        if (!map.isEmpty()) {
            return map;
        }
        if (this.LJ == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
            return LWw.LIZ();
        }
        IHostPerformanceMonitor iHostPerformanceMonitor = this.LJ;
        if (iHostPerformanceMonitor == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
        }
        Map<String, Double> LIZ2 = iHostPerformanceMonitor.LIZ();
        n.LIZIZ(LIZ2, BuildConfig.VERSION_NAME);
        return LIZ2;
    }

    public final Map<String, Long> getMemoryEnableCache() {
        Map<String, Long> map = this.LJJIIJZLJL.LIZIZ;
        if (!map.isEmpty()) {
            return map;
        }
        if (this.LJ == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
            return LWw.LIZ();
        }
        IHostPerformanceMonitor iHostPerformanceMonitor = this.LJ;
        if (iHostPerformanceMonitor == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
        }
        Map<String, Long> LIZIZ2 = iHostPerformanceMonitor.LIZIZ();
        n.LIZIZ(LIZIZ2, BuildConfig.VERSION_NAME);
        return LIZIZ2;
    }

    public final void release() {
        Handler handler = this.LJFF;
        if (handler == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
        }
        if (handler != null) {
            Handler handler2 = this.LJFF;
            if (handler2 == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler2.removeCallbacksAndMessages((Object) null);
            this.LJIL = false;
        }
        if (this.LJJIFFI == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
        } else {
            Handler handler3 = this.LJJIFFI;
            if (handler3 == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler3.removeCallbacksAndMessages((Object) null);
        }
        this.LJJIIJZLJL.LIZ();
        this.LJII = null;
        this.LJIIIIZZ = null;
        this.LJIIIZ = -1.0f;
        this.LJIIJ = -1;
        this.LJIIJJI = 0;
    }

    public final void startTimerMonitor() {
        if (this.LJJII.LIZ && !this.LJJIJL) {
            this.LJJIJL = true;
            if (this.LJJIII) {
                Handler handler = this.LJFF;
                if (handler == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                handler.post(new C0454TWm(this));
            }
            Handler handler2 = this.LJFF;
            if (handler2 == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler2.removeCallbacks(this.LJJIJLIJ);
            Handler handler3 = this.LJFF;
            if (handler3 == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler3.post(this.LJJIJLIJ);
        }
    }

    public final void stopTimerMonitor() {
        if (this.LJJII.LIZ && this.LJJIJL) {
            this.LJJIJL = false;
            Handler handler = this.LJFF;
            if (handler == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler.removeCallbacks(this.LJJIJLIJ);
            if (this.LJJIII) {
                Handler handler2 = this.LJFF;
                if (handler2 == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                handler2.post(new C0455TWn(this));
            }
        }
    }

    private final String LIZJ() {
        JSONObject LJ2;
        JSONObject jSONObject = new JSONObject();
        try {
            if (!this.LIZ) {
                HJZ hjz = (HJZ) DataChannelGlobal.LIZLLL.LIZIZ(HEj.class);
                if (!(hjz == null || (LJ2 = hjz.LJ()) == null)) {
                    jSONObject.put("preview_fps", LJ2.optDouble("render_fps:", -1.0d));
                    jSONObject.put("real_fps", LJ2.optDouble("push_client_fps:", -1.0d));
                    jSONObject.put("pull_cdn_ip", LJ2.optString("cdn_ip:", BuildConfig.VERSION_NAME));
                    jSONObject.put("pull_play_url", LJ2.optString("url:", BuildConfig.VERSION_NAME));
                    jSONObject.put("pull_download_speed", LJ2.optLong("download_Speed:", -1));
                }
            } else {
                jSONObject.put("preview_fps", (double) this.LJJIJ);
                jSONObject.put("in_cap_fps", (double) this.LJJIIZ);
                jSONObject.put("real_fps", this.LJJIIZI);
            }
        } catch (Exception unused) {
        }
        String jSONObject2 = jSONObject.toString();
        n.LIZIZ(jSONObject2, BuildConfig.VERSION_NAME);
        return jSONObject2;
    }

    public final JSONObject getPerformanceJsonObject() {
        boolean z;
        if (System.currentTimeMillis() - this.LJJIJIL > LivePullSdkGetDataIntervalSettings.INSTANCE.getValue()) {
            z = true;
        } else {
            z = false;
        }
        if (z || TextUtils.isEmpty(this.LJIILIIL)) {
            FutureTask futureTask = new FutureTask(new C0358TSu(this));
            Handler handler = this.LJFF;
            if (handler == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler.post(futureTask);
            try {
                Object obj = futureTask.get();
                if (obj == null) {
                    n.LIZIZ();
                }
                return (JSONObject) obj;
            } catch (Exception e) {
                0aP.LIZ("LivePerformanceManagerV2", e);
            }
        }
        return LIZIZ();
    }

    public LivePerformanceManagerV2() {
        this.LJJ = BuildConfig.VERSION_NAME;
        this.LIZIZ = 1;
        this.LIZJ = 2;
        this.LIZLLL = 3;
        this.LJJII = LivePerformanceSettingSetting.INSTANCE.getValue();
        this.LJJIII = true;
        this.LJJIIJ = new 2d8();
        this.LJJIIJZLJL = new C0452TWk();
        this.LJJIIZ = -1.0f;
        this.LJJIIZI = -1.0d;
        this.LJJIJ = -1.0f;
        this.LJIIIZ = -1.0f;
        this.LJIIJ = -1;
        String jSONObject = new JSONObject().toString();
        n.LIZIZ(jSONObject, BuildConfig.VERSION_NAME);
        this.LJIIL = jSONObject;
        String jSONObject2 = new JSONObject().toString();
        n.LIZIZ(jSONObject2, BuildConfig.VERSION_NAME);
        this.LJIILIIL = jSONObject2;
        String jSONObject3 = new JSONObject().toString();
        n.LIZIZ(jSONObject3, BuildConfig.VERSION_NAME);
        this.LJIILJJIL = jSONObject3;
        String jSONObject4 = new JSONObject().toString();
        n.LIZIZ(jSONObject4, BuildConfig.VERSION_NAME);
        this.LJIILL = jSONObject4;
        String jSONObject5 = new JSONObject().toString();
        n.LIZIZ(jSONObject5, BuildConfig.VERSION_NAME);
        this.LJIILLIIL = jSONObject5;
        this.LJIIZILJ = new HashMap();
        if (this.LJJII.LIZ) {
            HandlerThread handlerThread = new HandlerThread("LivePerformanceManagerThread", 0);
            this.LJJI = handlerThread;
            handlerThread.start();
            HandlerThread handlerThread2 = this.LJJI;
            if (handlerThread2 == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            this.LJFF = new Handler(handlerThread2.getLooper());
            this.LJJIFFI = new Handler(Looper.getMainLooper());
            IHostPerformanceMonitor LIZ2 = 0cm.LIZ(IHostPerformanceMonitor.class);
            n.LIZIZ(LIZ2, BuildConfig.VERSION_NAME);
            this.LJ = LIZ2;
            if (this.LJJIII) {
                Handler handler = this.LJFF;
                if (handler == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                handler.post(new Runnable(this) {
                    public final /* synthetic */ LivePerformanceManagerV2 LIZ;

                    static {
                        Covode.recordClassIndex(19976);
                    }

                    {
                        this.LIZ = r1;
                    }

                    public final void run() {
                        IHostPerformanceMonitor LIZ2 = LivePerformanceManagerV2.LIZ(this.LIZ);
                        if (LIZ2 != null) {
                            LIZ2.LIZLLL();
                        }
                    }
                });
            }
        }
        this.LJJIJLIJ = new C0453TWl(this);
        this.LJJIL = new C0450TWi(this);
    }

    public final void LIZ() {
        if (this.LJ == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
            return;
        }
        try {
            if (!n.LIZ(Looper.myLooper(), Looper.getMainLooper())) {
                this.LJIIZILJ = new HashMap(16);
                long currentTimeMillis = System.currentTimeMillis();
                IHostPerformanceMonitor iHostPerformanceMonitor = this.LJ;
                if (iHostPerformanceMonitor == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                Map LIZ2 = iHostPerformanceMonitor.LIZ();
                this.LJIIL = LIZ(LIZ2, System.currentTimeMillis() - currentTimeMillis);
                long currentTimeMillis2 = System.currentTimeMillis();
                IHostPerformanceMonitor iHostPerformanceMonitor2 = this.LJ;
                if (iHostPerformanceMonitor2 == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                Map LIZIZ2 = iHostPerformanceMonitor2.LIZIZ();
                this.LJIILIIL = LIZIZ(LIZIZ2, System.currentTimeMillis() - currentTimeMillis2);
                T7s t7s = T7u.LIZ;
                n.LIZIZ(t7s, BuildConfig.VERSION_NAME);
                this.LJIILJJIL = LIZ(t7s.LIZJ);
                this.LJIILL = LIZJ();
                C0452TWk tWk = this.LJJIIJZLJL;
                n.LIZIZ(LIZ2, BuildConfig.VERSION_NAME);
                tWk.LIZ(LIZ2);
                C0452TWk tWk2 = this.LJJIIJZLJL;
                n.LIZIZ(LIZIZ2, BuildConfig.VERSION_NAME);
                tWk2.LIZIZ(LIZIZ2);
                Map<String, String> map = this.LJIIZILJ;
                if (map != null) {
                    Map LIZ3 = 0cm.LIZ(IHostPerformanceMonitor.class).LIZ(0b0.LJ());
                    n.LIZIZ(LIZ3, BuildConfig.VERSION_NAME);
                    map.putAll(LIZ3);
                }
                Map<String, String> map2 = this.LJIIZILJ;
                if (map2 != null) {
                    HashMap hashMap = new HashMap(2);
                    if (this.LJJIII) {
                        if (this.LJ == null) {
                            n.LIZ(BuildConfig.VERSION_NAME);
                        } else {
                            long currentTimeMillis3 = System.currentTimeMillis();
                            IHostPerformanceMonitor iHostPerformanceMonitor3 = this.LJ;
                            if (iHostPerformanceMonitor3 == null) {
                                n.LIZ(BuildConfig.VERSION_NAME);
                            }
                            double LJFF2 = iHostPerformanceMonitor3.LJFF();
                            long currentTimeMillis4 = System.currentTimeMillis() - currentTimeMillis3;
                            if (LJFF2 > 0.0d) {
                                hashMap.put("gpu_cost", String.valueOf(currentTimeMillis4));
                                hashMap.put("gpu", String.valueOf(LJFF2));
                            }
                        }
                    }
                    map2.putAll(hashMap);
                }
            }
        } catch (Throwable th) {
            this.LJJIJIL = System.currentTimeMillis();
            this.LJIL = false;
            throw th;
        }
        this.LJJIJIL = System.currentTimeMillis();
        this.LJIL = false;
    }

    public /* synthetic */ LivePerformanceManagerV2(byte b) {
        this();
    }

    public final void setExtraParams(Map<String, String> map) {
        this.LJI = map;
    }

    public final void setIsAnchor(boolean z) {
        this.LIZ = z;
    }

    public final void setPreviewFps(float f) {
        this.LJJIJ = f;
    }

    public final void setStreamFps(double d) {
        this.LJJIIZI = d;
    }

    public final void setStreamType(GIv gIv) {
        this.LJIJJ = gIv;
    }

    public final void setVideoCaptureFps(float f) {
        this.LJJIIZ = f;
    }

    public static final /* synthetic */ IHostPerformanceMonitor LIZ(LivePerformanceManagerV2 livePerformanceManagerV2) {
        IHostPerformanceMonitor iHostPerformanceMonitor = livePerformanceManagerV2.LJ;
        if (iHostPerformanceMonitor == null) {
            n.LIZ(BuildConfig.VERSION_NAME);
        }
        return iHostPerformanceMonitor;
    }

    public final void onModuleStop(String str) {
        if (this.LJJII.LIZ) {
            this.LJJIIJ.LIZ(str);
        }
    }

    public final void initStartValue(long j) {
        if (this.LJJII.LIZ) {
            Handler handler = this.LJFF;
            if (handler == null) {
                n.LIZ(BuildConfig.VERSION_NAME);
            }
            handler.postDelayed(new C0451TWj(this), j);
        }
    }

    private final String LIZ(float f) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("value", (double) f);
            Map<String, String> map = this.LJIIZILJ;
            if (map != null) {
                map.put("temperature", String.valueOf(f));
            }
            float f2 = this.LJIIIZ;
            if (f2 != -1.0f) {
                jSONObject.put("non_live_value", (double) f2);
                Map<String, String> map2 = this.LJIIZILJ;
                if (map2 != null) {
                    map2.put("non_live_temperature", String.valueOf(this.LJIIIZ));
                }
            }
        } catch (Exception unused) {
        }
        String jSONObject2 = jSONObject.toString();
        n.LIZIZ(jSONObject2, BuildConfig.VERSION_NAME);
        return jSONObject2;
    }

    public final String getRoomType(GIv gIv) {
        if (gIv == null) {
            return UGCMonitor.TYPE_VIDEO;
        }
        int i = GIw.LIZ[gIv.ordinal()];
        if (i == 1) {
            return "official";
        }
        if (i == 2) {
            return "game";
        }
        if (i == 3) {
            return "audio";
        }
        if (i != 4) {
            return UGCMonitor.TYPE_VIDEO;
        }
        return "third_party";
    }

    public final long LIZ(int i) {
        if (i == this.LIZIZ) {
            if (this.LJJII.LIZIZ > 0) {
                return this.LJJII.LIZIZ;
            }
            return 15000;
        } else if (i == this.LIZJ) {
            if (this.LJJII.LIZJ > 0) {
                return this.LJJII.LIZJ;
            }
            return 8000;
        } else if (i != this.LIZLLL) {
            return 15000;
        } else {
            if (this.LJJII.LIZLLL > 0) {
                return this.LJJII.LIZLLL;
            }
            return 1000;
        }
    }

    public final JSONObject LIZIZ(Map<String, String> map) {
        JSONObject jSONObject = new JSONObject();
        for (Map.Entry next : map.entrySet()) {
            try {
                jSONObject.put((String) next.getKey(), next.getValue());
            } catch (JSONException unused) {
            }
        }
        return jSONObject;
    }

    public final void monitorPerformance(String str) {
        if (this.LJJII.LIZ && !n.LIZ(Looper.getMainLooper(), Looper.myLooper())) {
            this.LJJ = str;
            if (!this.LJIL && System.currentTimeMillis() - this.LJIJJLI > LIZ(this.LIZJ)) {
                this.LJIL = true;
                Handler handler = this.LJFF;
                if (handler == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                handler.removeCallbacks(this.LJJIL);
                Handler handler2 = this.LJFF;
                if (handler2 == null) {
                    n.LIZ(BuildConfig.VERSION_NAME);
                }
                handler2.postDelayed(this.LJJIL, LIZ(this.LIZLLL));
                if ((!n.LIZ("resident", str)) && this.LJJIJL) {
                    Handler handler3 = this.LJFF;
                    if (handler3 == null) {
                        n.LIZ(BuildConfig.VERSION_NAME);
                    }
                    handler3.removeCallbacks(this.LJJIJLIJ);
                    Handler handler4 = this.LJFF;
                    if (handler4 == null) {
                        n.LIZ(BuildConfig.VERSION_NAME);
                    }
                    handler4.postDelayed(this.LJJIJLIJ, LIZ(this.LIZIZ));
                }
            }
        }
    }

    public final /* synthetic */ void reportPreviewFeedFirstFps(Double d) {
        String str;
        double doubleValue = d.doubleValue();
        HashMap hashMap = new HashMap();
        hashMap.put("anchor_id", String.valueOf(this.LJJIJIIJIL));
        hashMap.put("room_type", getRoomType(this.LJIJJ));
        if (this.LIZ) {
            str = "1";
        } else {
            str = "0";
        }
        hashMap.put("is_anchor", str);
        hashMap.put("scene", "preview");
        hashMap.put("avg_fps", String.valueOf(doubleValue));
        hashMap.put("room_id", String.valueOf(this.LJJIJIIJI));
        GtA LIZ2 = GtA.LJFF.LIZ("livesdk_performance_monitor_fps");
        LIZ2.LIZ(hashMap);
        LIZ2.LIZLLL();
    }

    public final void LIZ(Map<String, String> map) {
        String str;
        String str2;
        Room room;
        map.putAll(GtA.LJFF.LIZ(BuildConfig.VERSION_NAME).LJFF());
        if (!map.containsKey("room_id") && (room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class)) != null) {
            map.put("room_id", String.valueOf(room.getId()));
        }
        if (!map.containsKey("anchor_id")) {
            Glh LIZIZ2 = H7d.LIZ().LIZIZ();
            n.LIZIZ(LIZIZ2, BuildConfig.VERSION_NAME);
            User LIZ2 = LIZIZ2.LIZ();
            n.LIZIZ(LIZ2, BuildConfig.VERSION_NAME);
            if (LIZ2 instanceof User) {
                String idStr = LIZ2.getIdStr();
                n.LIZIZ(idStr, BuildConfig.VERSION_NAME);
                map.put("anchor_id", idStr);
            }
        }
        String str3 = this.LJJ;
        if (str3 == null) {
            n.LIZIZ();
        }
        map.put("scene", str3);
        map.put("room_type", getRoomType(this.LJIJJ));
        String str4 = "1";
        if (this.LIZ) {
            str = str4;
        } else {
            str = "0";
        }
        map.put("is_anchor", str);
        map.put("modules", LIZLLL());
        T7s t7s = T7u.LIZ;
        n.LIZIZ(t7s, BuildConfig.VERSION_NAME);
        if (t7s.LJIIJ) {
            str2 = str4;
        } else {
            str2 = "0";
        }
        map.put("is_charging", str2);
        IHostApp LIZ3 = 0cm.LIZ(IHostApp.class);
        n.LIZIZ(LIZ3, BuildConfig.VERSION_NAME);
        if (!LIZ3.isAppForeground()) {
            str4 = "0";
        }
        map.put("is_foreground", str4);
    }

    public final void setExtraParams(long j, long j2) {
        this.LJJIJIIJI = j;
        this.LJJIJIIJIL = j2;
    }

    public final void onModuleStart(String str, Map<String, String> map) {
        if (this.LJJII.LIZ) {
            this.LJJIIJ.LIZ(str, map);
        }
    }

    private final String LIZ(Map<String, Double> map, long j) {
        String valueOf;
        Map<String, String> map2;
        String valueOf2;
        Map<String, String> map3;
        String valueOf3;
        Map<String, String> map4;
        String valueOf4;
        Map<String, String> map5;
        JSONObject jSONObject = new JSONObject();
        if (map != null) {
            try {
                if (Build.VERSION.SDK_INT >= 26) {
                    jSONObject.put("cpu_speed", map.get("cpu_speed"));
                    Double d = map.get("cpu_speed");
                    if (!(d == null || (valueOf4 = String.valueOf(d.doubleValue())) == null || (map5 = this.LJIIZILJ) == null)) {
                        map5.put("cpu_speed", valueOf4);
                    }
                    Map<String, Double> map6 = this.LJII;
                    if (map6 != null) {
                        jSONObject.put("non_live_cpu_speed", map6.get("cpu_speed"));
                        Map<String, Double> map7 = this.LJII;
                        if (map7 == null) {
                            n.LIZIZ();
                        }
                        Double d2 = map7.get("cpu_speed");
                        if (!(d2 == null || (valueOf3 = String.valueOf(d2.doubleValue())) == null || (map4 = this.LJIIZILJ) == null)) {
                            map4.put("non_live_cpu_speed", valueOf3);
                        }
                    }
                } else {
                    jSONObject.put("cpu_rate", map.get("cpu_rate"));
                    Double d3 = map.get("cpu_rate");
                    if (!(d3 == null || (valueOf2 = String.valueOf(d3.doubleValue())) == null || (map3 = this.LJIIZILJ) == null)) {
                        map3.put("cpu_rate", valueOf2);
                    }
                    Map<String, Double> map8 = this.LJII;
                    if (map8 != null) {
                        jSONObject.put("non_live_cpu_rate", map8.get("cpu_rate"));
                        Map<String, Double> map9 = this.LJII;
                        if (map9 == null) {
                            n.LIZIZ();
                        }
                        Double d4 = map9.get("cpu_rate");
                        if (!(d4 == null || (valueOf = String.valueOf(d4.doubleValue())) == null || (map2 = this.LJIIZILJ) == null)) {
                            map2.put("non_live_cpu_rate", valueOf);
                        }
                    }
                }
            } catch (Exception unused) {
            }
        }
        jSONObject.put("cost", j);
        String jSONObject2 = jSONObject.toString();
        n.LIZIZ(jSONObject2, BuildConfig.VERSION_NAME);
        return jSONObject2;
    }

    private final String LIZIZ(Map<String, Long> map, long j) {
        String valueOf;
        Map<String, String> map2;
        String valueOf2;
        Map<String, String> map3;
        JSONObject jSONObject = new JSONObject();
        if (map != null) {
            try {
                jSONObject.put("java_total", map.get("mem_java_total"));
                jSONObject.put("java_free", map.get("mem_java_free"));
                jSONObject.put("java_used", map.get("mem_java_used"));
                jSONObject.put("pss_dalvik", map.get("mem_pss_dalvik"));
                jSONObject.put("pss_native", map.get("mem_pss_native"));
                jSONObject.put("pss_total", map.get("mem_pss_total"));
                jSONObject.put("graphics", map.get("mem_graphics"));
                jSONObject.put("vmsize", map.get("mem_vmsize"));
                Long l = map.get("mem_pss_total");
                if (!(l == null || (valueOf2 = String.valueOf(l.longValue())) == null || (map3 = this.LJIIZILJ) == null)) {
                    map3.put("pss_total", valueOf2);
                }
            } catch (Exception unused) {
            }
        }
        Map<String, Long> map4 = this.LJIIIIZZ;
        if (map4 != null) {
            jSONObject.put("non_live_java_total", map4.get("mem_java_total"));
            Map<String, Long> map5 = this.LJIIIIZZ;
            if (map5 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_java_free", map5.get("mem_java_free"));
            Map<String, Long> map6 = this.LJIIIIZZ;
            if (map6 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_java_used", map6.get("mem_java_used"));
            Map<String, Long> map7 = this.LJIIIIZZ;
            if (map7 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_pss_dalvik", map7.get("mem_pss_dalvik"));
            Map<String, Long> map8 = this.LJIIIIZZ;
            if (map8 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_pss_native", map8.get("mem_pss_native"));
            Map<String, Long> map9 = this.LJIIIIZZ;
            if (map9 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_pss_total", map9.get("mem_pss_total"));
            Map<String, Long> map10 = this.LJIIIIZZ;
            if (map10 == null) {
                n.LIZIZ();
            }
            Long l2 = map10.get("mem_pss_total");
            if (!(l2 == null || (valueOf = String.valueOf(l2.longValue())) == null || (map2 = this.LJIIZILJ) == null)) {
                map2.put("non_live_pss_total", valueOf);
            }
            Map<String, Long> map11 = this.LJIIIIZZ;
            if (map11 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_graphics", map11.get("mem_graphics"));
            Map<String, Long> map12 = this.LJIIIIZZ;
            if (map12 == null) {
                n.LIZIZ();
            }
            jSONObject.put("non_live_vmsize", map12.get("mem_vmsize"));
        }
        jSONObject.put("cost", j);
        String jSONObject2 = jSONObject.toString();
        n.LIZIZ(jSONObject2, BuildConfig.VERSION_NAME);
        return jSONObject2;
    }
}
