code: public static boolean hasPermission(@NonNull final Context context,
                                          @NonNull final String permission) {
          //TODO Update to new (M preview) permission model https://developer.android.com/preview/features/runtime-permissions.html#coding
          if (TextUtils.isEmpty(permission)) {
              throw new IllegalArgumentException("Permission can't be null or empty.");
          }
  
          try {
              final PackageInfo info = context.getPackageManager()
                      .getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
              final String[] requestedPermissions = info.requestedPermissions;
              if (requestedPermissions != null) {
                  for (String requestedPermission : requestedPermissions) {
                      if (TextUtils.equals(permission, requestedPermission)) {
                          return true;
                      }
                  }
              }
          } catch (PackageManager.NameNotFoundException ignore) {
              // ignore
          }
  
          return false;
      }
docs: Similar to {@link #checkPermission(Context, String)} but instead of throwing exception returns false if
  permission is not granted.
  
  @return True if supplied permission is granted, false otherwise.