package com.ifpdos.factorytest;

import android.content.Context;
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.util.AttributeSet;
import android.util.Log;
import com.ifpdos.Utils.ToastUtils;

/* JADX INFO: loaded from: classes.dex */
public class NFCTest extends TestItem {
    private static final String TAG = "NFCTest";
    private OnAskDialogResultListener mAskRetListener;
    private AskDialog mDialog;

    public NFCTest(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mAskRetListener = null;
        this.mDialog = null;
        if (hasNfc(context)) {
            return;
        }
        testDone(false, this.mTagDone);
    }

    @Override // com.ifpdos.factorytest.TestItem
    boolean doTest() {
        try {
            ((MainTestActivity) this.mContext).startActivityForResult(new Intent(this.mContext, (Class<?>) NfcTestActivity.class), this.mId.ordinal());
            this.mAskRetListener = new OnAskDialogResultListener() { // from class: com.ifpdos.factorytest.NFCTest.1
                @Override // com.ifpdos.factorytest.OnAskDialogResultListener
                public void onAskDialogResult(Context context, boolean z) {
                    NFCTest.this.mDialog = null;
                    NFCTest nFCTest = NFCTest.this;
                    nFCTest.testDone(z, nFCTest.mTagDone);
                }
            };
            this.mDialog = new AskDialog(this.mContext, getTitle(), this.mContext.getString(R.string.test_nfc_ask_dialog), this.mAskRetListener);
        } catch (Throwable th) {
            Log.e(TAG, "start NfcTestActivity error", th);
            ToastUtils.showToast(this.mContext, this.mContext.getResources().getString(R.string.launch_nfc_fail) + th.toString());
            testDone(false, this.mTagDone);
        }
        return false;
    }

    private boolean hasNfc(Context context) {
        NfcAdapter defaultAdapter = ((NfcManager) context.getSystemService("nfc")).getDefaultAdapter();
        if (defaultAdapter == null || !defaultAdapter.isEnabled()) {
            Log.d(TAG, "NFC unavailable");
            return false;
        }
        Log.d(TAG, "NFC available");
        return true;
    }

    @Override // com.ifpdos.factorytest.TestItem
    void onStop() {
        super.onStop();
        if (this.mDialog != null) {
            this.mContext.startService(new Intent(this.mContext, (Class<?>) FloatNavbarService.class));
        }
    }
}
