package com.seewo.ota.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import com.seewo.libmyousdk.model.RomUpdateInfo;
import com.seewo.ota.R;
import com.seewo.ota.data.UpdateInfo;
import com.seewo.ota.update.speechi.Config;
import d.e.h.e.f;

/* JADX INFO: compiled from: BaseUpgradeActivity.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class d2 extends Activity {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    protected RomUpdateInfo f2011b;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    protected int f2012f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    protected boolean f2013g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    protected String f2014h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    protected boolean f2015i = true;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private boolean f2016j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private View f2017k;
    private WindowManager l;
    private String[] m;

    public d2() {
        new Handler(Looper.getMainLooper());
    }

    private void b() {
        PackageManager packageManager = getPackageManager();
        try {
            for (String str : this.m) {
                packageManager.setApplicationEnabledSetting(str, 2, 0);
            }
        } catch (Exception e2) {
            Log.e("@BaseUpgradeAct", "disableGMS error: " + e2.getMessage());
        }
    }

    private void f() {
        if (this.f2017k == null) {
            this.f2017k = LayoutInflater.from(this).inflate(d(), (ViewGroup) null, false);
        }
    }

    private void g() {
        View view;
        WindowManager windowManager = this.l;
        if (windowManager == null || (view = this.f2017k) == null || !this.f2016j) {
            return;
        }
        this.f2016j = false;
        windowManager.removeView(view);
        this.l = null;
    }

    private void h() {
        if (this.f2016j) {
            return;
        }
        this.l = (WindowManager) getApplicationContext().getSystemService("window");
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.type = 2018;
        layoutParams.format = 1;
        layoutParams.flags = 131840;
        layoutParams.gravity = 17;
        layoutParams.width = -1;
        layoutParams.height = -1;
        this.f2016j = true;
        this.l.addView(this.f2017k, layoutParams);
    }

    private boolean i() {
        if (a()) {
            f.a aVarA = d.e.h.e.f.a("enable-verity");
            Log.d("@BaseUpgradeAct", "unremount result: " + aVarA.a + " ,successMsg:" + aVarA.f3605b + "  ,errorMsg:" + aVarA.f3606c);
            z = aVarA.a == 0;
            if (z) {
                b();
                com.seewo.ota.data.a.g().S(new UpdateInfo(this.f2011b, c(), true, this.f2015i));
                com.seewo.ota.util.u.i(this);
            }
        }
        return z;
    }

    public boolean a() {
        return Build.VERSION.SDK_INT >= 33 && !com.seewo.ota.util.u.d(this) && com.seewo.ota.util.u.f();
    }

    protected String c() {
        return !TextUtils.isEmpty(this.f2014h) ? this.f2014h : this.f2012f == 1 ? com.seewo.ota.data.b.i().j() : com.seewo.ota.data.b.i().k();
    }

    public abstract int d();

    public void e() {
        if (this.f2011b != null) {
            com.seewo.ota.q.a aVar = new com.seewo.ota.q.a();
            aVar.c(this.f2011b.getVersionCode());
            aVar.a(com.seewo.ota.data.b.i().b().format(Long.valueOf(System.currentTimeMillis())));
            aVar.b(this.f2012f);
            com.seewo.ota.util.t.q(this, aVar, this.f2012f);
        }
    }

    @Override // android.app.Activity
    public <T extends View> T findViewById(int i2) {
        if (this.f2017k == null) {
            f();
        }
        return (T) this.f2017k.findViewById(i2);
    }

    @Override // android.app.Activity
    public void finish() {
        super.finish();
        g();
    }

    public void j(boolean z) {
        Log.d("@BaseUpgradeAct", "upgrade ota file:" + c());
        if (i()) {
            Log.i("@BaseUpgradeAct", "upgradeSystem: tryGMSUpgrade success, reboot.");
        } else {
            k(z);
        }
    }

    public void k(boolean z) {
        h();
    }

    @Override // android.app.Activity
    public void onBackPressed() {
        Log.d("@BaseUpgradeAct", "onBackPressed intercept.");
    }

    @Override // android.app.Activity
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (com.seewo.vcommons.data.d.m("sys.ota.interrupt_upgrade", false)) {
            com.seewo.ota.util.s.a().c(this, R.string.interrupt_upgrade);
            Log.d("@BaseUpgradeAct", "interrupt upgrade, finish.");
            return;
        }
        Intent intent = getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            this.f2011b = (RomUpdateInfo) extras.getSerializable(Config.KEY_UPDATE);
            this.f2012f = extras.getInt("update_type", 0);
            this.f2013g = extras.getBoolean("auto_upgrade", false);
            this.f2014h = extras.getString("update_src_path", "");
            this.f2015i = extras.getBoolean("update_is_reboot", true);
        }
        requestWindowFeature(1);
        setContentView(R.layout.layout_empty);
        d.e.f.a aVarB = d.e.f.a.b(this);
        if (aVarB != null) {
            aVarB.a();
        }
        f();
        this.m = getResources().getStringArray(R.array.gms_packages);
    }

    @Override // android.app.Activity
    protected void onDestroy() {
        super.onDestroy();
        g();
    }
}
