package com.atmob.voiceai.utils;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;

import androidx.activity.ComponentActivity;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.content.ContextCompat;

import com.atmob.common.runtime.ContextUtil;

public class PermissionUtil {


    public static boolean hasFilePermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return Environment.isExternalStorageManager();
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return PermissionUtil.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        } else {
            return true;
        }
    }

    public static boolean hasPermission(String... permissions) {
        if (permissions == null) {
            return true;
        }
        Context context = ContextUtil.getContext();
        for (String permission : permissions) {
            boolean hasPermission = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
            if (!hasPermission) {
                return false;
            }
        }
        return true;
    }


}
