package com.epson.mobilephone.common.wifidirect;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NfcAdapter;
import android.os.Build;
import org.opencv.videoio.Videoio;

public class NfcDispatchUtils {
    @SuppressLint({"NewApi", "MissingPermission"})
    public static void enableForegroundDispatch(Activity activity, IntentFilter[] intentFilterArr, String[][] strArr) {
        if (Build.VERSION.SDK_INT >= 14) {
            try {
                NfcAdapter defaultAdapter = NfcAdapter.getDefaultAdapter(activity);
                if (defaultAdapter != null) {
                    PendingIntent activity2 = PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()).addFlags(Videoio.CAP_INTELPERC_DEPTH_GENERATOR), 0);
                    if (Build.VERSION.SDK_INT < 23) {
                        defaultAdapter.enableForegroundDispatch(activity, activity2, intentFilterArr, strArr);
                    } else if (activity.checkSelfPermission("android.permission.NFC") == 0) {
                        defaultAdapter.enableForegroundDispatch(activity, activity2, intentFilterArr, strArr);
                    }
                }
            } catch (Exception unused) {
            }
        }
    }

    @SuppressLint({"NewApi", "MissingPermission"})
    public static void disableForegroundDispatch(Activity activity) {
        if (Build.VERSION.SDK_INT >= 14) {
            try {
                NfcAdapter defaultAdapter = NfcAdapter.getDefaultAdapter(activity);
                if (defaultAdapter == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT < 23) {
                    defaultAdapter.disableForegroundDispatch(activity);
                } else if (activity.checkSelfPermission("android.permission.NFC") == 0) {
                    defaultAdapter.disableForegroundDispatch(activity);
                }
            } catch (Exception unused) {
            }
        }
    }
}
