package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.SystemProperties;
import android.util.Log;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.base.ItemButtonAction;
import com.ifpdos.debugmenu.event.ActivityEvent;
import com.seewo.sdk.SDKSystemHelper;
import d.f.a.r2.u2;
import d.f.a.r2.v2;
import d.f.a.s1.e;
import d.i.c.a;
import java.io.File;
import k.c.a.c;

/* JADX INFO: loaded from: classes.dex */
public class ReplaceLogoAndAnimationAction extends ItemButtonAction {
    public static final String ANDROID_LOGO_FILE_TYPE = ".bmp";
    private static final int ANIMATION_LIMIT_SIZE;
    private static final int BOOT_VIDEO_LIMIT_SIZE;
    private static final int HEIGHT = 1080;
    private static final int LOGO_LIMIT_SIZE;
    private static final int LOGO_LIMIT_SIZE_HISI = 7340032;
    private static final String LOGO_LIMIT_SIZE_HISI_STRING = "7 MB";
    private static final String LOGO_LIMIT_SIZE_STRING;
    private static final int NUMBER_OF_SHIFT = 20;
    private static final String TAG = "ReplaceLogoAndAnimation";
    private static final int WIDTH = 1920;

    public interface CallBack {
        boolean onHasCorrectFile(File file);

        void onNoCorrectFile();
    }

    public interface LogoAnimationHelper {
        void replaceAnimation();

        boolean replaceBootVideo();

        void replaceLogo();
    }

    public class LogoAnimationHelperFor510 implements LogoAnimationHelper {
        private LogoAnimationHelperFor510() {
        }

        private boolean isSupportBootVideo() {
            return "3030".equals(SystemProperties.get("persist.vendor.media.bootvideo", ""));
        }

        private boolean only1080PReplace(File file) {
            Bitmap bitmapDecodeFile = BitmapFactory.decodeFile(file.getPath());
            if (bitmapDecodeFile == null) {
                return false;
            }
            int width = bitmapDecodeFile.getWidth();
            int height = bitmapDecodeFile.getHeight();
            Log.i(ReplaceLogoAndAnimationAction.TAG, " width: " + width + " height: " + height);
            return width == ReplaceLogoAndAnimationAction.WIDTH && height == ReplaceLogoAndAnimationAction.HEIGHT;
        }

        @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.LogoAnimationHelper
        public void replaceAnimation() {
            ReplaceLogoAndAnimationAction.this.toReplaceAnimation("bootanimation.zip", Integer.MAX_VALUE, new CallBack() { // from class: com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.LogoAnimationHelperFor510.1
                @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.CallBack
                public boolean onHasCorrectFile(File file) {
                    return true;
                }

                @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.CallBack
                public void onNoCorrectFile() {
                    ReplaceLogoAndAnimationAction replaceLogoAndAnimationAction = ReplaceLogoAndAnimationAction.this;
                    replaceLogoAndAnimationAction.toastMessage(replaceLogoAndAnimationAction.mContext.getString(R.string.str_debug_replace_logo_animation_not_found_unlimit, "bootanimation.zip"));
                }
            });
        }

        @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.LogoAnimationHelper
        public boolean replaceBootVideo() {
            return ReplaceLogoAndAnimationAction.this.resultOfReplaceBootVideo("bootvideo", ReplaceLogoAndAnimationAction.BOOT_VIDEO_LIMIT_SIZE, new CallBack() { // from class: com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.LogoAnimationHelperFor510.3
                @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.CallBack
                public boolean onHasCorrectFile(File file) {
                    return true;
                }

                @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.CallBack
                public void onNoCorrectFile() {
                    ReplaceLogoAndAnimationAction.this.toastMessage(a.n() ? ReplaceLogoAndAnimationAction.this.mContext.getString(R.string.str_debug_replace_bootvideo_not_found_unlimit, "bootvideo") : ReplaceLogoAndAnimationAction.this.mContext.getString(R.string.str_debug_replace_bootvideo_not_found, "bootvideo", Integer.valueOf(ReplaceLogoAndAnimationAction.BOOT_VIDEO_LIMIT_SIZE >> 20)));
                }
            });
        }

        @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.LogoAnimationHelper
        public void replaceLogo() {
            ReplaceLogoAndAnimationAction.this.toReplaceLogo(u2.f3338b, ReplaceLogoAndAnimationAction.LOGO_LIMIT_SIZE_HISI, new CallBack() { // from class: com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.LogoAnimationHelperFor510.2
                @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.CallBack
                public boolean onHasCorrectFile(File file) {
                    return true;
                }

                @Override // com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.CallBack
                public void onNoCorrectFile() {
                    Log.e(ReplaceLogoAndAnimationAction.TAG, "onNoCorrectFile: 文件不正确");
                    ReplaceLogoAndAnimationAction.this.toastMessage(a.n() ? ReplaceLogoAndAnimationAction.this.mContext.getString(R.string.str_debug_replace_logo_boot_not_found_unlimit, u2.f3338b) : ReplaceLogoAndAnimationAction.this.mContext.getString(R.string.str_debug_replace_logo_not_found_unlimit, u2.f3338b, ReplaceLogoAndAnimationAction.LOGO_LIMIT_SIZE_HISI_STRING, ".bmp"));
                }
            });
        }
    }

    static {
        LOGO_LIMIT_SIZE = a.m() ? 256000 : 1572864;
        LOGO_LIMIT_SIZE_STRING = a.m() ? "250 KB" : "1.5 MB";
        ANIMATION_LIMIT_SIZE = (a.n() || a.r()) ? Integer.MAX_VALUE : 5242880;
        BOOT_VIDEO_LIMIT_SIZE = a.n() ? Integer.MAX_VALUE : 8388608;
    }

    public ReplaceLogoAndAnimationAction(Context context) {
        super(context);
    }

    private boolean noCorrectFile(File file, int i2) {
        if (file == null || !file.exists()) {
            return true;
        }
        if (!file.getName().endsWith(".bmp")) {
            if (file.getName().endsWith(".jpg")) {
                return !u2.n(file);
            }
            return false;
        }
        boolean zM = u2.m(file);
        Log.e(TAG, "是不是bmp文件 " + zM);
        return !zM;
    }

    private Boolean onHasFile(CallBack callBack, File file) {
        return callBack != null ? Boolean.valueOf(callBack.onHasCorrectFile(file)) : Boolean.TRUE;
    }

    private void onNoFile(CallBack callBack) {
        if (callBack != null) {
            callBack.onNoCorrectFile();
        }
    }

    private void replaceLogoAndAnimation() {
        LogoAnimationHelperFor510 logoAnimationHelperFor510 = new LogoAnimationHelperFor510();
        logoAnimationHelperFor510.replaceLogo();
        if (logoAnimationHelperFor510.replaceBootVideo()) {
            return;
        }
        logoAnimationHelperFor510.replaceAnimation();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean resultOfReplaceBootVideo(String str, int i2, CallBack callBack) {
        File fileD = u2.d(str);
        if (noCorrectFile(fileD, i2)) {
            onNoFile(callBack);
            return false;
        }
        if (!onHasFile(callBack, fileD).booleanValue()) {
            return false;
        }
        if (SDKSystemHelper.I.replaceBootVideo(fileD.getPath())) {
            toastMessage(R.string.str_debug_replace_bootvideo_success);
            return true;
        }
        toastMessage(R.string.str_debug_replace_bootvideo_fail);
        return false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void startReplace() {
        c.c().g(new ActivityEvent.ShowDebugMenuDialog(R.string.str_debug_replace_l_a, a.m() ? R.string.str_debug_replace_logo_animation_hint : R.string.str_debug_replace_logo_animation_hint_510, new e() { // from class: d.f.a.p1.w4
            @Override // d.f.a.s1.e
            public final void call() {
                this.a.h();
            }
        }));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void toReplaceAnimation(String str, int i2, CallBack callBack) {
        File fileD = u2.d(str);
        if (noCorrectFile(fileD, i2)) {
            onNoFile(callBack);
        } else if (onHasFile(callBack, fileD).booleanValue()) {
            if (SDKSystemHelper.I.replaceBootAnimation(fileD.getPath())) {
                toastMessage(R.string.str_debug_replace_logo_animation_success);
            } else {
                toastMessage(R.string.str_debug_replace_logo_animation_fail);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void toReplaceLogo(String str, int i2, CallBack callBack) {
        File fileD = u2.d(str);
        Log.e(TAG, "toReplaceLogo: " + fileD);
        if (noCorrectFile(fileD, i2)) {
            Log.e(TAG, "toReplaceLogo: logo文件不对");
            onNoFile(callBack);
        } else if (onHasFile(callBack, fileD).booleanValue()) {
            if (SDKSystemHelper.I.replaceBootLogo(fileD.getPath())) {
                toastMessage(R.string.str_debug_replace_logo_boot_success);
            } else {
                toastMessage(R.string.str_debug_replace_logo_boot_fail);
            }
        }
    }

    private void toastMessage(int i2) {
        d.b.a.a.a.J(i2, c.c());
    }

    public /* synthetic */ void h() {
        c.c().g(new ActivityEvent.DismissDialog());
        d.b.a.a.a.Y(true, c.c());
        replaceLogoAndAnimation();
        d.b.a.a.a.Y(false, c.c());
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction, d.f.a.j2.e.e.a
    public void onClick(Context context, d.f.a.j2.e.e eVar) {
        replace();
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction, d.f.a.j2.e.e.a
    public void onLongClick(Context context, d.f.a.j2.e.e eVar) {
    }

    public void replace() {
        if (7 == d.i.f.a.a.a || a.q()) {
            new v2(new v2.a() { // from class: com.ifpdos.debugmenu.action.ReplaceLogoAndAnimationAction.1
                @Override // d.f.a.r2.v2.a
                public void onFail() {
                    c.c().g(new ActivityEvent.ShowProgressDialog(false));
                    d.b.a.a.a.J(R.string.str_export_log_fail_no_usb, c.c());
                }

                @Override // d.f.a.r2.v2.a
                public void onSuccess() {
                    d.b.a.a.a.Y(false, c.c());
                    ReplaceLogoAndAnimationAction.this.startReplace();
                }
            }).a();
        } else {
            startReplace();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void toastMessage(String str) {
        c.c().g(new ActivityEvent.ShowToast(str));
    }
}
