// Path: adal-utils/src/main/java/com/massivedisaster/adal/utils/LogUtils.java
// public final class LogUtils {
// 
//     /**
//      * Private constructor to avoid user implement as a single instance instead of a Singleton
//      */
//     private LogUtils() {
// 
//     }
// 
//     /**
//      * Logs a error exception
//      *
//      * @param enclosingClass the caller class
//      * @param exception      the exception
//      */
//     public static void logErrorException(@NonNull Class<?> enclosingClass, @NonNull Throwable exception) {
//         String message = exception.getMessage() == null ? "Exception error." : exception.getMessage();
//         Log.e(enclosingClass.getName(), message, exception);
//     }
// 
// }


import com.massivedisaster.adal.utils.LogUtils;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
/*
 * ADAL - A set of Android libraries to help speed up Android development.
 *
 * Copyright (c) 2017 ADAL
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.massivedisaster.adal.permissions;



/**
 * Permissions utilities.
 */
public final class PermissionUtils {

    /**
     * Private constructor to avoid user implement as a single instance instead of a Singleton.
     */
    private PermissionUtils() {
    }

    /**
     * Verify if all permissions given are granted
     *
     * @param context     the application context
     * @param permissions one or more permission to check
     * @return true if all permissions are granted
     */
    public static boolean hasPermissions(Context context, String... permissions) {
        if (permissions == null || permissions.length == 0) {
            return false;
        }

        for (String permission : permissions) {
            if ((ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED)) {
                return false;
            }
        }

        return true;
    }

    /**
     * Verify if the permission given are added on manifest
     *
     * @param context    the application context
     * @param permission the permission to check
     * @return true if permission are added on manifest
     */
    public static boolean hasPermissionInManifest(Context context, String permission) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
            if (info.requestedPermissions != null) {
                for (String p : info.requestedPermissions) {
                    if (p.equals(permission)) {
                        return true;
                    }
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
// Path: adal-utils/src/main/java/com/massivedisaster/adal/utils/LogUtils.java
// public final class LogUtils {
// 
//     /**
//      * Private constructor to avoid user implement as a single instance instead of a Singleton
//      */
//     private LogUtils() {
// 
//     }
// 
//     /**
//      * Logs a error exception
//      *
//      * @param enclosingClass the caller class
//      * @param exception      the exception
//      */
//     public static void logErrorException(@NonNull Class<?> enclosingClass, @NonNull Throwable exception) {
//         String message = exception.getMessage() == null ? "Exception error." : exception.getMessage();
//         Log.e(enclosingClass.getName(), message, exception);
//     }
// 
// }


// Path: adal-permissions/src/main/java/com/massivedisaster/adal/permissions/PermissionUtils.java
import com.massivedisaster.adal.utils.LogUtils;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;

/*
 * ADAL - A set of Android libraries to help speed up Android development.
 *
 * Copyright (c) 2017 ADAL
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.massivedisaster.adal.permissions;



/**
 * Permissions utilities.
 */
public final class PermissionUtils {

    /**
     * Private constructor to avoid user implement as a single instance instead of a Singleton.
     */
    private PermissionUtils() {
    }

    /**
     * Verify if all permissions given are granted
     *
     * @param context     the application context
     * @param permissions one or more permission to check
     * @return true if all permissions are granted
     */
    public static boolean hasPermissions(Context context, String... permissions) {
        if (permissions == null || permissions.length == 0) {
            return false;
        }

        for (String permission : permissions) {
            if ((ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED)) {
                return false;
            }
        }

        return true;
    }

    /**
     * Verify if the permission given are added on manifest
     *
     * @param context    the application context
     * @param permission the permission to check
     * @return true if permission are added on manifest
     */
    public static boolean hasPermissionInManifest(Context context, String permission) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
            if (info.requestedPermissions != null) {
                for (String p : info.requestedPermissions) {
                    if (p.equals(permission)) {
                        return true;
                    }
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            LogUtils.logErrorException(PermissionUtils.class, e);