package cgmblelib.utils;

import android.content.Context;
import android.content.pm.PackageManager;

import androidx.core.content.ContextCompat;

/**
 * Created by 6020 on 2019/8/12.
 * 权限是否授权检测累
 */
public class PermissionCheckTool {

    private final Context mContext;

    public PermissionCheckTool(Context context) {
        mContext = context.getApplicationContext();
    }

    /**
     * 判断权限集合，是否所有的权限已授权
     * @param permissions 权限
     * @return 有权限未被授权
     */
    public boolean lacksPermissions(String... permissions) {
        if (permissions != null && permissions.length > 0){
            for (String permission : permissions) {
                if (lacksPermission(permission)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 验证是否权限给予
     * @param permission 权限
     * @return true:未被授权
     */
    public boolean lacksPermission(String permission) {
        if (permission != null){
            return ContextCompat.checkSelfPermission(mContext, permission) == PackageManager.PERMISSION_DENIED;
        }
        return false;
    }
}
