package P0;

import D.AbstractC0031b;
import L1.A;
import L1.B;
import android.app.Activity;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.google.android.gms.internal.measurement.A1;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class a implements MethodChannel.MethodCallHandler {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final Context f2495k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final c f2496l;

    public a(Context context, A a5, c cVar, B b2) {
        this.f2495k = context;
        this.f2496l = cVar;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r8v2 */
    /* JADX WARN: Type inference failed for: r8v3 */
    /* JADX WARN: Type inference failed for: r8v4, types: [int] */
    /* JADX WARN: Type inference failed for: r8v6 */
    /* JADX WARN: Type inference failed for: r8v7 */
    /* JADX WARN: Type inference failed for: r8v8 */
    @Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler
    public final void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        Context context;
        c cVar;
        String str = methodCall.method;
        str.getClass();
        context = this.f2495k;
        cVar = this.f2496l;
        switch (str) {
            case "checkServiceStatus":
                int i = Integer.parseInt(methodCall.arguments.toString());
                Objects.requireNonNull(result);
                if (context != null) {
                    if (i == 3 || i == 4 || i == 5) {
                        ?? IsLocationEnabled = 0;
                        IsLocationEnabled = 0;
                        IsLocationEnabled = 0;
                        if (Build.VERSION.SDK_INT >= 28) {
                            LocationManager locationManager = (LocationManager) context.getSystemService(LocationManager.class);
                            if (locationManager != null) {
                                IsLocationEnabled = locationManager.isLocationEnabled();
                            }
                        } else {
                            try {
                                if (Settings.Secure.getInt(context.getContentResolver(), "location_mode") != 0) {
                                    IsLocationEnabled = 1;
                                }
                            } catch (Settings.SettingNotFoundException e2) {
                                e2.printStackTrace();
                            }
                        }
                        result.success(Integer.valueOf((int) IsLocationEnabled));
                    } else if (i == 21) {
                        result.success(Integer.valueOf(((BluetoothManager) context.getSystemService("bluetooth")).getAdapter().isEnabled() ? 1 : 0));
                    } else if (i == 8) {
                        PackageManager packageManager = context.getPackageManager();
                        if (packageManager.hasSystemFeature("android.hardware.telephony")) {
                            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
                            if (telephonyManager == null || telephonyManager.getPhoneType() == 0) {
                                result.success(2);
                            } else {
                                Intent intent = new Intent("android.intent.action.CALL");
                                intent.setData(Uri.parse("tel:123123"));
                                if ((Build.VERSION.SDK_INT >= 33 ? packageManager.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(0L)) : packageManager.queryIntentActivities(intent, 0)).isEmpty()) {
                                    result.success(2);
                                } else if (telephonyManager.getSimState() != 5) {
                                    result.success(0);
                                } else {
                                    result.success(1);
                                }
                            }
                        } else {
                            result.success(2);
                        }
                    } else if (i == 16) {
                        result.success(1);
                    } else {
                        result.success(2);
                    }
                    break;
                } else {
                    Log.d("permissions_handler", "Context cannot be null.");
                    result.error("PermissionHandler.ServiceManager", "Android context cannot be null.", null);
                    break;
                }
                break;
            case "shouldShowRequestPermissionRationale":
                int i5 = Integer.parseInt(methodCall.arguments.toString());
                Objects.requireNonNull(result);
                Activity activity = cVar.f2502m;
                if (activity != null) {
                    ArrayList arrayListJ = A1.j(activity, i5);
                    if (arrayListJ == null) {
                        Log.d("permissions_handler", "No android specific permissions needed for: " + i5);
                        result.success(Boolean.FALSE);
                    } else if (arrayListJ.isEmpty()) {
                        Log.d("permissions_handler", "No permissions found in manifest for: " + i5 + " no need to show request rationale");
                        result.success(Boolean.FALSE);
                    } else {
                        result.success(Boolean.valueOf(AbstractC0031b.f(cVar.f2502m, (String) arrayListJ.get(0))));
                    }
                    break;
                } else {
                    Log.d("permissions_handler", "Unable to detect current Activity.");
                    result.error("PermissionHandler.PermissionManager", "Unable to detect current Android Activity.", null);
                    break;
                }
                break;
            case "checkPermissionStatus":
                int i6 = Integer.parseInt(methodCall.arguments.toString());
                Objects.requireNonNull(result);
                result.success(Integer.valueOf(cVar.a(i6)));
                break;
            case "openAppSettings":
                Objects.requireNonNull(result);
                if (context != null) {
                    try {
                        Intent intent2 = new Intent();
                        intent2.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                        intent2.addCategory("android.intent.category.DEFAULT");
                        intent2.setData(Uri.parse("package:" + context.getPackageName()));
                        intent2.addFlags(268435456);
                        intent2.addFlags(1073741824);
                        intent2.addFlags(8388608);
                        context.startActivity(intent2);
                        result.success(Boolean.TRUE);
                    } catch (Exception unused) {
                        result.success(Boolean.FALSE);
                        return;
                    }
                    break;
                } else {
                    Log.d("permissions_handler", "Context cannot be null.");
                    result.error("PermissionHandler.AppSettingsManager", "Android context cannot be null.", null);
                    break;
                }
                break;
            case "requestPermissions":
                List<Integer> list = (List) methodCall.arguments();
                Objects.requireNonNull(result);
                N2.a aVar = new N2.a(2, result);
                if (cVar.f2503n > 0) {
                    result.error("PermissionHandler.PermissionManager", "A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time).", null);
                    break;
                } else if (cVar.f2502m == null) {
                    Log.d("permissions_handler", "Unable to detect current Activity.");
                    result.error("PermissionHandler.PermissionManager", "Unable to detect current Android Activity.", null);
                    break;
                } else {
                    cVar.f2501l = aVar;
                    cVar.f2504o = new HashMap();
                    cVar.f2503n = 0;
                    ArrayList arrayList = new ArrayList();
                    for (Integer num : list) {
                        if (cVar.a(num.intValue()) != 1) {
                            ArrayList arrayListJ2 = A1.j(cVar.f2502m, num.intValue());
                            if (arrayListJ2 != null && !arrayListJ2.isEmpty()) {
                                int i7 = Build.VERSION.SDK_INT;
                                if (num.intValue() == 16) {
                                    cVar.c(209, "android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS");
                                } else if (i7 >= 30 && num.intValue() == 22) {
                                    cVar.c(210, "android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION");
                                } else if (num.intValue() == 23) {
                                    cVar.c(211, "android.settings.action.MANAGE_OVERLAY_PERMISSION");
                                } else if (i7 >= 26 && num.intValue() == 24) {
                                    cVar.c(212, "android.settings.MANAGE_UNKNOWN_APP_SOURCES");
                                } else if (num.intValue() == 27) {
                                    cVar.c(213, "android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS");
                                } else if (i7 >= 31 && num.intValue() == 34) {
                                    cVar.c(214, "android.settings.REQUEST_SCHEDULE_EXACT_ALARM");
                                } else if (num.intValue() != 37 && num.intValue() != 0) {
                                    arrayList.addAll(arrayListJ2);
                                    cVar.f2503n = arrayListJ2.size() + cVar.f2503n;
                                } else if (cVar.b()) {
                                    arrayList.add("android.permission.WRITE_CALENDAR");
                                    arrayList.add("android.permission.READ_CALENDAR");
                                    cVar.f2503n += 2;
                                } else {
                                    cVar.f2504o.put(num, 0);
                                }
                            } else if (!cVar.f2504o.containsKey(num)) {
                                cVar.f2504o.put(num, 0);
                                if (num.intValue() != 22 || Build.VERSION.SDK_INT >= 30) {
                                    cVar.f2504o.put(num, 0);
                                } else {
                                    cVar.f2504o.put(num, 2);
                                }
                            }
                        } else if (!cVar.f2504o.containsKey(num)) {
                            cVar.f2504o.put(num, 1);
                        }
                    }
                    if (arrayList.size() > 0) {
                        AbstractC0031b.e(cVar.f2502m, (String[]) arrayList.toArray(new String[0]), 24);
                    }
                    N2.a aVar2 = cVar.f2501l;
                    if (aVar2 != null && cVar.f2503n == 0) {
                        ((MethodChannel.Result) aVar2.f2181l).success(cVar.f2504o);
                        break;
                    }
                }
                break;
            default:
                result.notImplemented();
                break;
        }
    }
}
