package com.ifpdos.factorytest;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import com.ifpdos.Utils.JsonUtils;
import com.ifpdos.Utils.UdiUtil;
import com.ifpdos.Utils.okhttp.OkHttpHelper;
import com.ifpdos.factorytest.entity.EmptyBody;
import com.ifpdos.factorytest.entity.EnabledBody;
import com.ifpdos.factorytest.entity.HotSpotConfigBody;
import com.seewo.vcommons.utils.ShellCommandUtils;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public class HotSpotTest extends TestItem {
    private static final String TAG = "HotSpotTest";
    AskDialog askDialog;
    private Disposable dis;
    private HotSpotConfigBody hotSpotConfigBody;
    private OnAskDialogResultListener mAskRetListener;
    private volatile boolean mAvailable;

    public HotSpotTest(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mAskRetListener = null;
        this.mAvailable = false;
    }

    private HotSpotConfigBody getHotSpotConfig() {
        return (HotSpotConfigBody) OkHttpHelper.getInstance().get(UdiUtil.hotspot_config_url, HotSpotConfigBody.class);
    }

    public static boolean openHotspot() {
        return ((EmptyBody) OkHttpHelper.getInstance().postSync(UdiUtil.hotspot_config_url, JsonUtils.toJson(new EnabledBody(true)), EmptyBody.class)) != null;
    }

    public static boolean closeHotspot() {
        return ((EmptyBody) OkHttpHelper.getInstance().postSync(UdiUtil.hotspot_config_url, JsonUtils.toJson(new EnabledBody(false)), EmptyBody.class)) != null;
    }

    public static Boolean getHotspotEnable() {
        HotSpotConfigBody hotSpotConfigBody = (HotSpotConfigBody) OkHttpHelper.getInstance().get(UdiUtil.hotspot_config_url, HotSpotConfigBody.class);
        if (hotSpotConfigBody == null) {
            return false;
        }
        return Boolean.valueOf(hotSpotConfigBody.enabled);
    }

    public static void setHotspotEnable(Boolean bool) {
        if (bool.booleanValue()) {
            openHotspot();
        } else {
            closeHotspot();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void closeAskDialog() {
        Disposable disposable = this.dis;
        if (disposable != null && !disposable.isDisposed()) {
            this.dis.dispose();
        }
        this.askDialog = null;
    }

    @Override // com.ifpdos.factorytest.TestItem
    public boolean doTest() {
        this.mTagWait = this.mContext.getString(R.string.volume_key_test_waiting);
        this.mStatusText.setText(this.mTagWait);
        this.mAskRetListener = new OnAskDialogResultListener() { // from class: com.ifpdos.factorytest.HotSpotTest.1
            @Override // com.ifpdos.factorytest.OnAskDialogResultListener
            public void onAskDialogResult(Context context, boolean z) {
                HotSpotTest hotSpotTest = HotSpotTest.this;
                hotSpotTest.testDone(z, hotSpotTest.mTagDone);
                HotSpotTest.this.closeAskDialog();
            }
        };
        this.askDialog = new AskDialog(this.mContext, getResources().getString(R.string.test_hotspot_ask_dialog), this.mContext.getString(R.string.test_hotspot_acquiring), this.mAskRetListener);
        this.dis = Observable.interval(0L, 1L, TimeUnit.SECONDS).filter(new Predicate() { // from class: com.ifpdos.factorytest.HotSpotTest$$ExternalSyntheticLambda0
            @Override // io.reactivex.functions.Predicate
            public final boolean test(Object obj) {
                return this.f$0.lambda$doTest$0((Long) obj);
            }
        }).takeUntil(new Predicate() { // from class: com.ifpdos.factorytest.HotSpotTest$$ExternalSyntheticLambda1
            @Override // io.reactivex.functions.Predicate
            public final boolean test(Object obj) {
                return this.f$0.lambda$doTest$1((Long) obj);
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer() { // from class: com.ifpdos.factorytest.HotSpotTest$$ExternalSyntheticLambda2
            @Override // io.reactivex.functions.Consumer
            public final void accept(Object obj) throws Exception {
                this.f$0.lambda$doTest$2((Long) obj);
            }
        });
        return true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ boolean lambda$doTest$0(Long l) throws Exception {
        HotSpotConfigBody hotSpotConfig = getHotSpotConfig();
        this.hotSpotConfigBody = hotSpotConfig;
        if (hotSpotConfig != null && hotSpotConfig.enabled) {
            this.mAvailable = this.hotSpotConfigBody.available.booleanValue();
        } else {
            openHotspot();
            this.mAvailable = false;
        }
        Log.e(TAG, "轮询中热点状态: " + this.mAvailable + " x=" + l);
        return l.longValue() == 5 || this.mAvailable;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ boolean lambda$doTest$1(Long l) throws Exception {
        return l.longValue() == 5 || this.mAvailable;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void lambda$doTest$2(Long l) throws Exception {
        updateText();
    }

    private synchronized void updateText() {
        if (this.askDialog != null) {
            if (!this.mAvailable) {
                this.askDialog.mDialog.setMessage(getResources().getString(R.string.test_hotspot_not_available));
            } else {
                HotSpotConfigBody hotSpotConfigBody = this.hotSpotConfigBody;
                if (hotSpotConfigBody != null) {
                    if (hotSpotConfigBody.password == null) {
                        this.hotSpotConfigBody.password = getResources().getString(R.string.test_hotspot_password_null);
                    }
                    StringBuilder sb = new StringBuilder();
                    String str = getResources().getString(R.string.test_hotspot_ssid) + this.hotSpotConfigBody.ssid;
                    String str2 = getResources().getString(R.string.test_hotspot_password) + this.hotSpotConfigBody.password;
                    sb.append(str).append(ShellCommandUtils.COMMAND_LINE_END);
                    sb.append(str2);
                    this.askDialog.mDialog.setMessage(sb.toString());
                }
            }
        }
    }
}
